Search in sources :

Example 1 with PullRequest

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

Example 2 with PullRequest

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

Example 3 with 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;
}
Also used : PullRequest(org.eclipse.egit.github.core.PullRequest) ArrayList(java.util.ArrayList)

Example 4 with PullRequest

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();
}
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 5 with PullRequest

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

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