Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1a071b0

Browse filesBrowse files
committed
Returning null instead of throwing an exception (as a matter of taste)
1 parent 8dcea59 commit 1a071b0
Copy full SHA for 1a071b0

File tree

Expand file treeCollapse file tree

1 file changed

+19
-4
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+19
-4
lines changed

‎src/main/java/org/kohsuke/github/GHThread.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHThread.java
+19-4Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,38 @@ public String getType() {
5959
return subject.type;
6060
}
6161

62+
/**
63+
* If this thread is about an issue, return that issue.
64+
*
65+
* @return null if this thread is not about an issue.
66+
*/
6267
public GHIssue getBoundIssue() throws IOException {
63-
if (!"Issue".equals(subject.type))
64-
throw new IllegalStateException("Notification doesn't point to Issue");
68+
if (!"Issue".equals(subject.type) && "PullRequest".equals(subject.type))
69+
return null;
6570
return repository.getIssue(
6671
Integer.parseInt(subject.url.substring(subject.url.lastIndexOf('/') + 1)));
6772
}
6873

74+
/**
75+
* If this thread is about a pull request, return that pull request.
76+
*
77+
* @return null if this thread is not about a pull request.
78+
*/
6979
public GHPullRequest getBoundPullRequest() throws IOException {
7080
if (!"PullRequest".equals(subject.type))
71-
throw new IllegalStateException("Notification doesn't point to PullRequest");
81+
return null;
7282
return repository.getPullRequest(
7383
Integer.parseInt(subject.url.substring(subject.url.lastIndexOf('/') + 1)));
7484
}
7585

86+
/**
87+
* If this thread is about a commit, return that commit.
88+
*
89+
* @return null if this thread is not about a commit.
90+
*/
7691
public GHCommit getBoundCommit() throws IOException {
7792
if (!"Commit".equals(subject.type))
78-
throw new IllegalStateException("Notification doesn't point to Commit");
93+
return null;
7994
return repository.getCommit(subject.url.substring(subject.url.lastIndexOf('/') + 1));
8095
}
8196

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.