public static String updateBotIssuePendingChangesComment(CommandContext context, GHIssueComment comment) throws IOException { GHUser user = comment.getUser(); if (user != null) { if (Objects.equal(context.getConfiguration().getGithubUsername(), user.getLogin())) { String body = comment.getBody(); if (body != null) { body = body.trim(); if (body.startsWith(PENDING_CHANGE_COMMENT_PREFIX)) { return body; } } } } return null; }
private GitHubPRCause checkComment(GitHubPRDecisionContext prDecisionContext, GHIssueComment issueComment, GitHubPRUserRestriction userRestriction, TaskListener listener) { GitHubPRCause cause = null; try { String body = issueComment.getBody(); if (isNull(userRestriction) || userRestriction.isWhitelisted(issueComment.getUser())) { final Matcher matcher = Pattern.compile(comment).matcher(body); if (matcher.matches()) { listener.getLogger().println(DISPLAY_NAME + ": matching comment " + body); LOG.trace("Event matches comment '{}'", body); cause = prDecisionContext.newCause("Comment matches to criteria.", false); cause.withCommentBody(body); if (matcher.groupCount() > 0) { cause.withCommentBodyMatch(matcher.group(1)); } } } } catch (IOException ex) { LOG.error("Couldn't check comment #{}, skipping it.", issueComment.getId(), ex); } return cause; }
private boolean findAndDeleteOthers(@Nullable String markup) throws IOException { boolean found = false; for (GHIssueComment comment : pr.listComments()) { if (myself.equals(comment.getUser().getLogin())) { if (markup == null || found || !markup.equals(comment.getBody())) { comment.delete(); continue; } if (markup.equals(comment.getBody())) { found = true; } } } return found; }
try { for (GHIssueComment comment : ghpr.getComments()) { LOGGER.log(Level.FINEST, "Comment was made at: {0}", comment.getUpdatedAt()); if (lastUpdatedTime.compareTo(comment.getUpdatedAt()) < 0) { LOGGER.log(Level.FINEST, "Comment was made after last update time, {0}", comment.getBody()); count++; try { checkComment(comment); } catch (IOException ex) { LOGGER.log(Level.SEVERE, "Couldn't check comment #" + comment.getId(), ex);
/** * Checks whether the specific PR contains a comment with the expected body. * * @return true if the PR contains comment with the specified body, otherwise false */ private boolean containsComment(GHPullRequest ghPullRequest, String expectedBody) { List<GHIssueComment> prComments; try { prComments = ghPullRequest.getComments(); } catch (IOException e) { LOGGER.log(Level.WARNING, "Failed to get comments for PR " + ghPullRequest, e); // return false in case of an error - probably safer to have multiple comments than possibly none return false; } for (GHIssueComment comment : prComments) { if (comment.getBody() != null && comment.getBody().equals(expectedBody)) { return true; } } return false; }
|| localPR.getLastCommentCreatedAt().compareTo(issueComment.getCreatedAt()) < 0) { llog.printf("%s: state has changed (new comment found - '%s')%n", DISPLAY_NAME, issueComment.getBody());
Date updatedDate = comment != null ? comment.getUpdatedAt() : ghpr.getUpdatedAt(); String user = comment != null ? comment.getUser().getName() : ghpr.getUser().getName(); LOGGER.log( Level.INFO,
@Override void wrapUp(GitHub root) { super.wrapUp(root); repository.wrap(root); issue.wrap(repository); comment.wrapUp(issue); } }
/** * Deletes this issue comment. */ public void delete() throws IOException { new Requester(owner.root).method("DELETE").to(getApiRoute()); }
public String getDescription() { return StringUtils.abbreviate(this.comment.getBody(), 40); }
@Override void wrapUp(GitHub root) { super.wrapUp(root); if (repository != null) { repository.wrap(root); issue.wrap(repository); } else { issue.wrap(root); } comment.wrapUp(issue); } }
/** * Deletes this issue comment. */ public void delete() throws IOException { new Requester(owner.root).method("DELETE").to(getApiRoute()); }
public static String updateBotIssuePendingChangesComment(CommandContext context, GHIssueComment comment) throws IOException { GHUser user = comment.getUser(); if (user != null) { if (Objects.equal(context.getConfiguration().getGithubUsername(), user.getLogin())) { String body = comment.getBody(); if (body != null) { body = body.trim(); if (body.startsWith(PENDING_CHANGE_COMMENT_PREFIX)) { return body; } } } } return null; }
private void addIssueClosedCommentIfRequired(CommandContext context, GHPullRequest pullRequest, boolean create) { GHIssue issue = context.getIssue(); if (issue == null) { return; } if (!create) { // avoid duplicate comment try { List<GHIssueComment> comments = pullRequest.getComments(); for (GHIssueComment comment : comments) { String body = comment.getBody(); if (body != null && body.startsWith(PullRequests.ISSUE_LINK_COMMENT)) { return; } } } catch (IOException e) { // ignore } } try { pullRequest.comment(PullRequests.ISSUE_LINK_COMMENT + " " + issue.getHtmlUrl() + PullRequests.ISSUE_LINK_COMMENT_SUFFIX); } catch (IOException e) { // ignore } }
@Override void wrapUp(GitHub root) { super.wrapUp(root); if (repository != null) { repository.wrap(root); issue.wrap(repository); } else { issue.wrap(root); } comment.wrapUp(issue); } }
/** * Updates the body of the issue comment. */ public void update(String body) throws IOException { new Requester(owner.root).with("body", body).method("PATCH").to(getApiRoute(), GHIssueComment.class); this.body = body; }
private String updateBotCommentCommand(CommandContext context, GHIssueComment comment) throws IOException { GHUser user = comment.getUser(); if (user != null) { if (Objects.equal(context.getConfiguration().getGithubUsername(), user.getLogin())) { String body = comment.getBody(); if (body != null) { body = body.trim(); if (body.startsWith(PullRequests.COMMAND_COMMENT_PREFIX)) { return body; } } } } return null; }
private void addIssueClosedCommentIfRequired(CommandContext context, GHPullRequest pullRequest, boolean create) { GHIssue issue = context.getIssue(); if (issue == null) { return; } if (!create) { // avoid duplicate comment try { List<GHIssueComment> comments = pullRequest.getComments(); for (GHIssueComment comment : comments) { String body = comment.getBody(); if (body != null && body.startsWith(PullRequests.ISSUE_LINK_COMMENT)) { return; } } } catch (IOException e) { // ignore } } try { pullRequest.comment(PullRequests.ISSUE_LINK_COMMENT + " " + issue.getHtmlUrl() + PullRequests.ISSUE_LINK_COMMENT_SUFFIX); } catch (IOException e) { // ignore } }
/** * Updates the issue by adding a comment. */ public GHIssueComment comment(String message) throws IOException { GHIssueComment r = new Requester(root).with("body",message).to(getIssuesApiRoute() + "/comments", GHIssueComment.class); return r.wrapUp(this); }