use of org.eclipse.egit.github.core.PullRequest in project camel by apache.
the class PullRequestFilesProducerTest method testPullRequestFilesProducer.
@Test
public void testPullRequestFilesProducer() throws Exception {
PullRequest pullRequest = pullRequestService.addPullRequest("testPullRequestFilesProducer");
latestPullRequestNumber = pullRequest.getNumber();
CommitFile file = new CommitFile();
file.setFilename("testfile");
List<CommitFile> commitFiles = new ArrayList<CommitFile>();
commitFiles.add(file);
pullRequestService.setFiles(latestPullRequestNumber, commitFiles);
Endpoint filesProducerEndpoint = getMandatoryEndpoint("direct:validPullRequest");
Exchange exchange = filesProducerEndpoint.createExchange();
Exchange resp = template.send(filesProducerEndpoint, exchange);
assertEquals(resp.getOut().getBody(), commitFiles);
}
use of org.eclipse.egit.github.core.PullRequest in project camel by apache.
the class MockPullRequestService method addPullRequest.
public PullRequest addPullRequest(String title) {
User author = createAuthor();
PullRequest pullRequest = new PullRequest();
pullRequest.setUser(author);
pullRequest.setHtmlUrl("https://github.com/someguy/somerepo/pull" + pullRequestNumber);
pullRequest.setTitle(title);
pullRequest.setNumber(pullRequestNumber.get());
pullRequest.setId(pullRequestNumber.get());
pullRequest.setState("open");
pullRequests.put(pullRequest.getId(), pullRequest);
pullRequestNumber.incrementAndGet();
return pullRequest;
}
use of org.eclipse.egit.github.core.PullRequest in project camel by apache.
the class MockPullRequestService method getPullRequests.
@Override
public synchronized List<PullRequest> getPullRequests(IRepositoryIdProvider repository, String state) {
List<PullRequest> result = new ArrayList<PullRequest>();
for (Long id : pullRequests.keySet()) {
PullRequest pr = pullRequests.get(id);
if (pr.getState().equals(state)) {
result.add(pr);
}
}
LOG.debug("Returning list of " + result.size() + " pull requests with state " + state);
return result;
}
use of org.eclipse.egit.github.core.PullRequest 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.PullRequest in project camel by apache.
the class ClosePullRequestProducer method process.
public void process(Exchange exchange) throws Exception {
Integer pullRequestNumber = exchange.getIn().getHeader(GitHubConstants.GITHUB_PULLREQUEST, Integer.class);
PullRequest pullRequest = pullRequestService.getPullRequest(getRepository(), pullRequestNumber);
pullRequest.setState("closed");
pullRequest.setClosedAt(Calendar.getInstance().getTime());
pullRequest = pullRequestService.editPullRequest(getRepository(), pullRequest);
// support InOut
if (exchange.getPattern().isOutCapable()) {
// copy the header of in message to the out message
exchange.getOut().copyFrom(exchange.getIn());
exchange.getOut().setBody(pullRequest);
}
}
Aggregations