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();
}
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());
}
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();
}
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();
}
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);
}
Aggregations