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 commentOnFailure( AbstractBuild<?, ?> build, TaskListener listener, GhprbCommitStatusException ex) { PrintStream stream = null; if (listener != null) { stream = listener.getLogger(); } GHCommitState state = ex.getState(); Exception baseException = ex.getException(); String newMessage; if (baseException instanceof FileNotFoundException) { newMessage = "FileNotFoundException means that the credentials Jenkins is using is probably wrong. Or the user account does not have write access to the repo."; } else { newMessage = "Could not update commit status of the Pull Request on GitHub."; } if (stream != null) { stream.println(newMessage); baseException.printStackTrace(stream); } else { logger.log(Level.INFO, newMessage, baseException); } if (GhprbTrigger.getDscp().getUseComments()) { StringBuilder msg = new StringBuilder(ex.getMessage()); if (build != null) { msg.append("\n"); GhprbTrigger trigger = Ghprb.extractTrigger(build); for (GhprbExtension ext : Ghprb.matchesAll(trigger.getExtensions(), GhprbBuildStatus.class)) { if (ext instanceof GhprbCommentAppender) { msg.append(((GhprbCommentAppender) ext).postBuildComment(build, null)); } } } if (GhprbTrigger.getDscp().getUseDetailedComments() || (state == GHCommitState.SUCCESS || state == GHCommitState.FAILURE)) { logger.log(Level.INFO, "Trying to send comment.", baseException); addComment(ex.getId(), msg.toString()); } } else { logger.log(Level.SEVERE, "Could not update commit status of the Pull Request on GitHub."); } }