Skip to content

Commit 4b799d2

Browse files
authored
Merge pull request hub4j#443 from Arrow768/GHEventPayload_Issue
Adds the GHEventPayload.Issue class
2 parents ca55947 + e368a17 commit 4b799d2

2 files changed

Lines changed: 58 additions & 3 deletions

File tree

src/main/java/org/kohsuke/github/GHEventPayload.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,51 @@ void wrapUp(GitHub root) {
174174
}
175175
}
176176

177+
/**
178+
* A Issue has been assigned, unassigned, labeled, unlabeled, opened, edited, milestoned, demilestoned, closed, or reopened.
179+
*
180+
* @see <a href="http://developer.github.com/v3/activity/events/types/#issueevent">authoritative source</a>
181+
*/
182+
@SuppressFBWarnings(value = {"UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", "NP_UNWRITTEN_FIELD" },
183+
justification = "Constructed by JSON deserialization")
184+
public static class Issue extends GHEventPayload {
185+
private String action;
186+
private GHIssue issue;
187+
private GHRepository repository;
188+
189+
@SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Comes from JSON deserialization")
190+
public String getAction() {
191+
return action;
192+
}
193+
194+
public GHIssue getIssue() {
195+
return issue;
196+
}
197+
198+
public void setIssue(GHIssue issue) {
199+
this.issue = issue;
200+
}
201+
202+
public GHRepository getRepository() {
203+
return repository;
204+
}
205+
206+
public void setRepository(GHRepository repository) {
207+
this.repository = repository;
208+
}
209+
210+
@Override
211+
void wrapUp(GitHub root) {
212+
super.wrapUp(root);
213+
if (repository != null) {
214+
repository.wrap(root);
215+
issue.wrap(repository);
216+
} else {
217+
issue.wrap(root);
218+
}
219+
}
220+
}
221+
177222
/**
178223
* A comment was added to an issue
179224
*

src/test/java/org/kohsuke/github/GHEventPayloadTest.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,19 @@ public void issue_comment() throws Exception {
120120
assertThat(event.getSender().getLogin(), is("baxterthehacker"));
121121
}
122122

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

127137
// TODO implement support classes and write test
128138
// @Test

0 commit comments

Comments
 (0)