diff --git a/src/main/java/org/kohsuke/github/GHThread.java b/src/main/java/org/kohsuke/github/GHThread.java index 383f2b2fef..9dc49773b8 100644 --- a/src/main/java/org/kohsuke/github/GHThread.java +++ b/src/main/java/org/kohsuke/github/GHThread.java @@ -149,6 +149,32 @@ public GHPullRequest getBoundPullRequest() throws IOException { return repository.getPullRequest(Integer.parseInt(subject.url.substring(subject.url.lastIndexOf('/') + 1))); } + /** + * If this thread is about an issue, return the issue number. + * + * @return -1 if this thread is not about an issue. + * @throws IOException + * the io exception + */ + public int getIssueNumber() throws IOException { + final GHIssue ghIssue = getBoundIssue(); + + return ghIssue == null ? -1 : ghIssue.getNumber(); + } + + /** + * If this thread is about a pull request, return the pull request number. + * + * @return -1 if this thread is not about a pull request. + * @throws IOException + * the io exception + */ + public int getPullNumber() throws IOException { + final GHPullRequest ghPullRequest = getBoundPullRequest(); + + return ghPullRequest == null ? -1 : ghPullRequest.getNumber(); + } + /** * If this thread is about a commit, return that commit. * diff --git a/src/test/java/org/kohsuke/github/AppTest.java b/src/test/java/org/kohsuke/github/AppTest.java index f2d68fe7fb..3204b9b9ee 100755 --- a/src/test/java/org/kohsuke/github/AppTest.java +++ b/src/test/java/org/kohsuke/github/AppTest.java @@ -1671,6 +1671,19 @@ public void notifications() throws Exception { assertThat(t.getUpdatedAt(), notNullValue()); assertThat(t.getType(), oneOf("Issue", "PullRequest")); + // Test issue number and pull number of each GHThread. + if (t.getBoundIssue() == null) { + assertThat(t.getIssueNumber(), is(-1)); + } else { + assertThat(t.getIssueNumber(), not(-1)); + } + + if (t.getBoundPullRequest() == null) { + assertThat(t.getPullNumber(), is(-1)); + } else { + assertThat(t.getPullNumber(), not(-1)); + } + // both thread an unread are included // assertThat(t.getLastReadAt(), notNullValue()); // assertThat(t.isRead(), equalTo(true));