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

@@ -21,7 +21,7 @@ public class GHCommitComment extends GHObject {
String body, html_url, commit_id;
Integer line;
String path;
User user;
GHUser user; // not fully populated. beware.
static class User {
// TODO: what if someone who doesn't have an account on GitHub makes a commit?
@@ -76,7 +76,7 @@ public class GHCommitComment extends GHObject {
* Gets the user who put this comment.
*/
public GHUser getUser() throws IOException {
return owner.root.getUser(user.login);
return owner == null || owner.root.isOffline() ? user : owner.root.getUser(user.login);
}
/**
@@ -110,6 +110,9 @@ public class GHCommitComment extends GHObject {
GHCommitComment wrap(GHRepository owner) {
this.owner = owner;
if (owner.root.isOffline()) {
user.wrapUp(owner.root);
}
return this;
}
}