Search in sources :

Example 1 with CommitComment

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();
}
Also used : Exchange(org.apache.camel.Exchange) Comment(org.eclipse.egit.github.core.Comment) CommitComment(org.eclipse.egit.github.core.CommitComment) HashMap(java.util.HashMap) PullRequest(org.eclipse.egit.github.core.PullRequest) CommitComment(org.eclipse.egit.github.core.CommitComment) Stack(java.util.Stack)

Example 2 with CommitComment

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());
}
Also used : Exchange(org.apache.camel.Exchange) Endpoint(org.apache.camel.Endpoint) PullRequest(org.eclipse.egit.github.core.PullRequest) CommitComment(org.eclipse.egit.github.core.CommitComment) Date(java.util.Date) Test(org.junit.Test)

Example 3 with CommitComment

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();
}
Also used : PullRequest(org.eclipse.egit.github.core.PullRequest) CommitComment(org.eclipse.egit.github.core.CommitComment) Test(org.junit.Test)

Example 4 with CommitComment

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;
}
Also used : User(org.eclipse.egit.github.core.User) CommitComment(org.eclipse.egit.github.core.CommitComment)

Aggregations

CommitComment (org.eclipse.egit.github.core.CommitComment)4 PullRequest (org.eclipse.egit.github.core.PullRequest)3 Exchange (org.apache.camel.Exchange)2 Test (org.junit.Test)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Stack (java.util.Stack)1 Endpoint (org.apache.camel.Endpoint)1 Comment (org.eclipse.egit.github.core.Comment)1 User (org.eclipse.egit.github.core.User)1