Skip to content

Commit

Permalink
Merge pull request hub4j#443 from Arrow768/GHEventPayload_Issue
Browse files Browse the repository at this point in the history
Adds the GHEventPayload.Issue class
  • Loading branch information
kohsuke authored Aug 30, 2018
2 parents ca55947 + e368a17 commit 4b799d2
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
45 changes: 45 additions & 0 deletions src/main/java/org/kohsuke/github/GHEventPayload.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,51 @@ void wrapUp(GitHub root) {
}
}

/**
* A Issue has been assigned, unassigned, labeled, unlabeled, opened, edited, milestoned, demilestoned, closed, or reopened.
*
* @see <a href="https://developer.github.com/v3/activity/events/types/#issueevent">authoritative source</a>
*/
@SuppressFBWarnings(value = {"UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", "NP_UNWRITTEN_FIELD" },
justification = "Constructed by JSON deserialization")
public static class Issue extends GHEventPayload {
private String action;
private GHIssue issue;
private GHRepository repository;

@SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Comes from JSON deserialization")
public String getAction() {
return action;
}

public GHIssue getIssue() {
return issue;
}

public void setIssue(GHIssue issue) {
this.issue = issue;
}

public GHRepository getRepository() {
return repository;
}

public void setRepository(GHRepository repository) {
this.repository = repository;
}

@Override
void wrapUp(GitHub root) {
super.wrapUp(root);
if (repository != null) {
repository.wrap(root);
issue.wrap(repository);
} else {
issue.wrap(root);
}
}
}

/**
* A comment was added to an issue
*
Expand Down
16 changes: 13 additions & 3 deletions src/test/java/org/kohsuke/github/GHEventPayloadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,19 @@ public void issue_comment() throws Exception {
assertThat(event.getSender().getLogin(), is("baxterthehacker"));
}

// TODO implement support classes and write test
// @Test
// public void issues() throws Exception {}
@Test
public void issues() throws Exception {
GHEventPayload.Issue event = GitHub.offline().parseEventPayload(payload.asReader(),GHEventPayload.Issue.class);
assertThat(event.getAction(),is("opened"));
assertThat(event.getIssue().getNumber(), is(2));
assertThat(event.getIssue().getTitle(), is("Spelling error in the README file"));
assertThat(event.getIssue().getState(), is(GHIssueState.OPEN));
assertThat(event.getIssue().getLabels().size(), is(1));
assertThat(event.getIssue().getLabels().iterator().next().getName(), is("bug"));
assertThat(event.getRepository().getName(), is("public-repo"));
assertThat(event.getRepository().getOwner().getLogin(), is("baxterthehacker"));
assertThat(event.getSender().getLogin(), is("baxterthehacker"));
}

// TODO implement support classes and write test
// @Test
Expand Down

0 comments on commit 4b799d2

Please sign in to comment.