Search in sources :

Example 6 with PullRequest

use of org.eclipse.egit.github.core.PullRequest in project camel by apache.

the class PullRequestConsumerTest method pullRequestTest.

@Test
public void pullRequestTest() throws Exception {
    PullRequest pr1 = pullRequestService.addPullRequest("First add");
    PullRequest pr2 = pullRequestService.addPullRequest("Second");
    mockResultEndpoint.expectedMessageCount(2);
    mockResultEndpoint.expectedBodiesReceivedInAnyOrder(pr1, pr2);
    Thread.sleep(1 * 1000);
    mockResultEndpoint.assertIsSatisfied();
}
Also used : PullRequest(org.eclipse.egit.github.core.PullRequest) Test(org.junit.Test)

Example 7 with PullRequest

use of org.eclipse.egit.github.core.PullRequest 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 8 with PullRequest

use of org.eclipse.egit.github.core.PullRequest in project camel by apache.

the class PullRequestConsumer method poll.

@Override
protected int poll() throws Exception {
    List<PullRequest> openPullRequests = pullRequestService.getPullRequests(getRepository(), "open");
    // In the end, we want PRs oldest to newest.
    Stack<PullRequest> newPullRequests = new Stack<PullRequest>();
    for (PullRequest pullRequest : openPullRequests) {
        if (pullRequest.getNumber() > lastOpenPullRequest) {
            newPullRequests.push(pullRequest);
        } else {
            break;
        }
    }
    if (newPullRequests.size() > 0) {
        lastOpenPullRequest = openPullRequests.get(0).getNumber();
    }
    while (!newPullRequests.empty()) {
        PullRequest newPullRequest = newPullRequests.pop();
        Exchange e = getEndpoint().createExchange();
        e.getIn().setBody(newPullRequest);
        // Required by the producers.  Set it here for convenience.
        e.getIn().setHeader(GitHubConstants.GITHUB_PULLREQUEST, newPullRequest.getNumber());
        if (newPullRequest.getHead() != null) {
            e.getIn().setHeader(GitHubConstants.GITHUB_PULLREQUEST_HEAD_COMMIT_SHA, newPullRequest.getHead().getSha());
        }
        getProcessor().process(e);
    }
    return newPullRequests.size();
}
Also used : Exchange(org.apache.camel.Exchange) PullRequest(org.eclipse.egit.github.core.PullRequest) Stack(java.util.Stack)

Example 9 with PullRequest

use of org.eclipse.egit.github.core.PullRequest 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 10 with PullRequest

use of org.eclipse.egit.github.core.PullRequest in project camel by apache.

the class ClosePullRequestProducerTest method testPullRequestCommentProducer.

@Test
public void testPullRequestCommentProducer() throws Exception {
    // Create a pull request
    PullRequest pullRequest = pullRequestService.addPullRequest("testPullRequestCommentProducer");
    latestPullRequestId = pullRequest.getId();
    // Close it
    Endpoint closePullRequestEndpoint = getMandatoryEndpoint(PULL_REQUEST_PRODUCER_ENDPOINT);
    Exchange exchange = closePullRequestEndpoint.createExchange();
    template.send(closePullRequestEndpoint, exchange);
    Thread.sleep(1 * 1000);
    // Verify that it was closed
    List<PullRequest> closedPullRequests = pullRequestService.getPullRequests(null, "closed");
    assertNotNull(closedPullRequests);
    boolean found = false;
    for (PullRequest pr : closedPullRequests) {
        if (pr.getId() == latestPullRequestId) {
            found = true;
            break;
        }
    }
    assertTrue("Didn't find pull request " + latestPullRequestId, found);
}
Also used : Exchange(org.apache.camel.Exchange) Endpoint(org.apache.camel.Endpoint) PullRequest(org.eclipse.egit.github.core.PullRequest) Test(org.junit.Test)

Aggregations

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