Skip to content

Commit

Permalink
Avoiding crash if GitHub issue cant be found
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Nov 23, 2015
1 parent f421bf6 commit abe713c
Showing 1 changed file with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,23 @@ public GitHubClient(String api) {
}

public Optional<GitHubIssue> getIssue(String issue) {
if (issue.startsWith("#")) {
issue = issue.substring(1);
}
String json = client.get(api + "/issues?state=all");
JSONArray jsonArray = (JSONArray) JsonPath.read(json, "$.*");
for (Object jsonIssue : jsonArray) {
LinkedHashMap o = (LinkedHashMap) jsonIssue;
String htmlUrl = o.get("html_url").toString();
String title = o.get("title").toString();
String number = o.get("number").toString();
if (number.equals(issue)) {
return of(new GitHubIssue(title, htmlUrl, number));
try {
if (issue.startsWith("#")) {
issue = issue.substring(1);
}
String json = client.get(api + "/issues?state=all");
JSONArray jsonArray = (JSONArray) JsonPath.read(json, "$.*");
for (Object jsonIssue : jsonArray) {
LinkedHashMap o = (LinkedHashMap) jsonIssue;
String htmlUrl = o.get("html_url").toString();
String title = o.get("title").toString();
String number = o.get("number").toString();
if (number.equals(issue)) {
return of(new GitHubIssue(title, htmlUrl, number));
}
}
} catch (Exception e) {
logger.error("Error while getting issue " + issue, e);
}
return absent();
}
Expand Down

0 comments on commit abe713c

Please # to comment.