void onIssueCommentHook(IssueComment issueComment) throws IOException { if (helper.isProjectDisabled()) { logger.log(Level.FINE, "Not checking comments since build is disabled"); return; } int id = issueComment.getIssue().getNumber(); logger.log( Level.FINER, "Comment on issue #{0} from {1}: {2}", new Object[] { id, issueComment.getComment().getUser(), issueComment.getComment().getBody() }); if (!"created".equals(issueComment.getAction())) { return; } ConcurrentMap<Integer, GhprbPullRequest> pulls = helper.getTrigger().getPulls(); GhprbPullRequest pull = pulls.get(id); if (pull == null) { pull = new GhprbPullRequest(getGitHubRepo().getPullRequest(id), helper, this); pulls.put(id, pull); } pull.check(issueComment.getComment()); GhprbTrigger.getDscp().save(); }
void onPullRequestHook(PullRequest pr) throws IOException { ConcurrentMap<Integer, GhprbPullRequest> pulls = helper.getTrigger().getPulls(); if ("closed".equals(pr.getAction())) { pulls.remove(pr.getNumber()); } else if (helper.isProjectDisabled()) { logger.log(Level.FINE, "Not processing Pull request since the build is disabled"); } else if ("opened".equals(pr.getAction()) || "reopened".equals(pr.getAction())) { GhprbPullRequest pull = pulls.get(pr.getNumber()); if (pull == null) { pulls.putIfAbsent(pr.getNumber(), new GhprbPullRequest(pr.getPullRequest(), helper, this)); pull = pulls.get(pr.getNumber()); } pull.check(pr.getPullRequest()); } else if ("synchronize".equals(pr.getAction())) { GhprbPullRequest pull = pulls.get(pr.getNumber()); if (pull == null) { pulls.putIfAbsent(pr.getNumber(), new GhprbPullRequest(pr.getPullRequest(), helper, this)); pull = pulls.get(pr.getNumber()); } if (pull == null) { logger.log(Level.SEVERE, "Pull Request #{0} doesn''t exist", pr.getNumber()); return; } pull.check(pr.getPullRequest()); } else { logger.log(Level.WARNING, "Unknown Pull Request hook action: {0}", pr.getAction()); } GhprbTrigger.getDscp().save(); }
public void check() { if (!initGhRepository()) { return; } if (helper.isProjectDisabled()) { logger.log(Level.FINE, "Project is disabled, not checking github state"); return; } List<GHPullRequest> openPulls; try { openPulls = ghRepository.getPullRequests(GHIssueState.OPEN); } catch (IOException ex) { logger.log(Level.SEVERE, "Could not retrieve open pull requests.", ex); return; } ConcurrentMap<Integer, GhprbPullRequest> pulls = helper.getTrigger().getPulls(); Set<Integer> closedPulls = new HashSet<Integer>(pulls.keySet()); for (GHPullRequest pr : openPulls) { if (pr.getHead() == null) { try { pr = ghRepository.getPullRequest(pr.getNumber()); } catch (IOException ex) { logger.log(Level.SEVERE, "Could not retrieve pr " + pr.getNumber(), ex); return; } } try { check(pr); } catch (IOException ex) { logger.log(Level.SEVERE, "Could not retrieve pr " + pr.getNumber(), ex); return; } closedPulls.remove(pr.getNumber()); } // remove closed pulls so we don't check them again for (Integer id : closedPulls) { pulls.remove(id); } }