use of org.eclipse.egit.github.core.Comment in project camel by apache.
the class PullRequestCommentConsumer method poll.
@Override
protected int poll() throws Exception {
// Do this here, rather than at the class level. We only care about it for setting the Exchange header, so
// there's no point growing memory over time.
Map<Long, PullRequest> commentIdToPullRequest = new HashMap<Long, PullRequest>();
List<PullRequest> pullRequests = pullRequestService.getPullRequests(getRepository(), "open");
// In the end, we want comments oldest to newest.
Stack<Comment> newComments = new Stack<Comment>();
for (PullRequest pullRequest : pullRequests) {
List<CommitComment> commitComments = pullRequestService.getComments(getRepository(), pullRequest.getNumber());
for (Comment comment : commitComments) {
if (!commentIds.contains(comment.getId())) {
newComments.add(comment);
commentIds.add(comment.getId());
commentIdToPullRequest.put(comment.getId(), pullRequest);
}
}
List<Comment> comments = issueService.getComments(getRepository(), pullRequest.getNumber());
for (Comment comment : comments) {
if (!commentIds.contains(comment.getId())) {
newComments.add(comment);
commentIds.add(comment.getId());
commentIdToPullRequest.put(comment.getId(), pullRequest);
}
}
}
while (!newComments.empty()) {
Comment newComment = newComments.pop();
Exchange e = getEndpoint().createExchange();
e.getIn().setBody(newComment);
// Required by the producers. Set it here for convenience.
e.getIn().setHeader(GitHubConstants.GITHUB_PULLREQUEST, commentIdToPullRequest.get(newComment.getId()));
getProcessor().process(e);
}
return newComments.size();
}
use of org.eclipse.egit.github.core.Comment in project camel by apache.
the class PullRequestCommentProducer method process.
public void process(Exchange exchange) throws Exception {
Integer pullRequestNumber = exchange.getIn().getHeader(GitHubConstants.GITHUB_PULLREQUEST, Integer.class);
Integer inResponseTo = exchange.getIn().getHeader(GitHubConstants.GITHUB_INRESPONSETO, Integer.class);
String text = exchange.getIn().getBody(String.class);
Comment response;
if (inResponseTo != null && inResponseTo > 0) {
response = pullRequestService.replyToComment(getRepository(), pullRequestNumber, inResponseTo, text);
} else {
// Otherwise, just comment on the pull request itself.
response = issueService.createComment(getRepository(), pullRequestNumber, text);
}
// support InOut
if (exchange.getPattern().isOutCapable()) {
// copy the header of in message to the out message
exchange.getOut().copyFrom(exchange.getIn());
exchange.getOut().setBody(response);
}
}
Aggregations