Add offline support to the API to make parsing events easier

- When we receive events from a webhook, it is non-trivial to determine which GitHub instance the event came from
  or for that matter even if the event actually came from GitHub or GitHub Enterprise.
- In order to ensure that the logic for parsing events does not get replicated in clients, we need to be
  able to call GitHub.parseEventPayload(Reader,Class) without knowing which GitHub the event originates from
  and without the resulting objects triggering API calls back to a GitHub
- Thus we add GitHub.offline() to provide an off-line connection
- Thus we modify some of the object classes to return best-effort objects when off-line
- Add support for more of the event types into GHEventPayload
- Add tests of the event payload and accessing critical fields when using GitHub.offline()
This commit is contained in:
Stephen Connolly
2016-11-08 12:56:52 +00:00
parent fa3d0887ef
commit 4daf6ba057
36 changed files with 5022 additions and 8 deletions

View File

@@ -232,7 +232,7 @@ public class GHRepository extends GHObject {
}
public GHUser getOwner() throws IOException {
return root.getUser(owner.login); // because 'owner' isn't fully populated
return root.isOffline() ? owner : root.getUser(owner.login); // because 'owner' isn't fully populated
}
public GHIssue getIssue(int id) throws IOException {
@@ -1153,6 +1153,9 @@ public class GHRepository extends GHObject {
/*package*/ GHRepository wrap(GitHub root) {
this.root = root;
if (root.isOffline()) {
owner.wrapUp(root);
}
return this;
}