Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement getIssueNumber and getPullNumber #1340

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/main/java/org/kohsuke/github/GHThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/org/kohsuke/github/AppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Loading