use of org.eclipse.egit.github.core.CommitComment 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.CommitComment in project camel by apache.
the class PullRequestCommentProducerTest method testPullRequestCommentProducer.
@Test
public void testPullRequestCommentProducer() throws Exception {
PullRequest pullRequest = pullRequestService.addPullRequest("testPullRequestCommentProducer");
latestPullRequestId = pullRequest.getId();
Endpoint commentProducerEndpoint = getMandatoryEndpoint("direct:validPullRequest");
Exchange exchange = commentProducerEndpoint.createExchange();
String commentText = "Pushed this comment at " + new Date();
exchange.getIn().setBody(commentText);
template.send(commentProducerEndpoint, exchange);
Thread.sleep(1 * 1000);
// Verify that the mock pull request service received this comment.
List<CommitComment> commitComments = pullRequestService.getComments(null, (int) pullRequest.getId());
assertEquals(1, commitComments.size());
CommitComment commitComment = commitComments.get(0);
assertEquals("Commit IDs did not match ", Long.toString(pullRequest.getId()), commitComment.getCommitId());
assertEquals("Comment text did not match ", commentText, commitComment.getBodyText());
}
use of org.eclipse.egit.github.core.CommitComment in project camel by apache.
the class PullRequestCommentConsumerTest method pullRequestCommentTest.
@Test
public void pullRequestCommentTest() throws Exception {
PullRequest pr1 = pullRequestService.addPullRequest("First add");
PullRequest pr2 = pullRequestService.addPullRequest("Second");
CommitComment commitComment1 = pullRequestService.addComment(pr1.getId(), "First comment");
CommitComment commitComment2 = pullRequestService.addComment(pr2.getId(), "Second comment");
mockResultEndpoint.expectedBodiesReceivedInAnyOrder(commitComment1, commitComment2);
// TODO do I need this?
Thread.sleep(1 * 1000);
mockResultEndpoint.assertIsSatisfied();
}
use of org.eclipse.egit.github.core.CommitComment in project camel by apache.
the class MockPullRequestService method addComment.
public CommitComment addComment(Long pullRequestId, String bodyText) {
CommitComment commitComment = new CommitComment();
User author = createAuthor();
commitComment.setUser(author);
commitComment.setCommitId("" + pullRequestId);
commitComment.setId(commentId.getAndIncrement());
commitComment.setBody(bodyText);
commitComment.setBodyText(bodyText);
List<CommitComment> comments;
if (allComments.containsKey(pullRequestId)) {
comments = allComments.get(pullRequestId);
} else {
comments = new ArrayList<CommitComment>();
}
comments.add(commitComment);
allComments.put(pullRequestId, comments);
return commitComment;
}
Aggregations