Search in sources :

Example 1 with CommitStatus

use of org.eclipse.egit.github.core.CommitStatus in project pivotal-cla by pivotalsoftware.

the class MylynGitHubApi method createOrUpdatePullRequestComment.

private void createOrUpdatePullRequestComment(PullRequestId pullRequestId, PullRequestStatus commitStatus, boolean hasSignedCla, boolean obviousFix, ContextCommitStatus status, List<Comment> comments, String claUserLogin) throws IOException {
    String claLinkMarkdown = String.format("[%s](%s)", CONTRIBUTOR_LICENSE_AGREEMENT, status.getUrl());
    String userMentionMarkdown = String.format("@%s", commitStatus.getGitHubUsername());
    IssueService issues = getIssueService();
    List<Comment> claUserComments = // 
    comments.stream().filter(// 
    comment -> comment.getUser().getLogin().equals(claUserLogin)).collect(Collectors.toList());
    if (hasSignedCla) {
        String body = String.format("%s %s %s!", userMentionMarkdown, THANK_YOU, claLinkMarkdown);
        if (claUserComments.stream().anyMatch(c -> c.getBody().contains(PLEASE_SIGN))) {
            if (claUserComments.stream().anyMatch(c -> c.getBody().contains(THANK_YOU))) {
                return;
            }
            issues.createComment(pullRequestId.getRepositoryId(), commitStatus.getPullRequestId(), body);
        }
    } else {
        String sync = String.format("\n\n[Click here](%s) %s.", commitStatus.getSyncUrl(), TO_MANUALLY_SYNCHRONIZE_THE_STATUS);
        String faq = String.format("\n\nSee the [FAQ](%s) for %s.", commitStatus.getFaqUrl(), FREQUENTLY_ASKED_QUESTIONS);
        String oldBody = String.format("%s %s %s!", userMentionMarkdown, PLEASE_SIGN, claLinkMarkdown);
        String body = String.format("%s%s%s", oldBody, sync, faq);
        if (obviousFix) {
            if (claUserComments.stream().anyMatch(c -> c.getBody().contains(PLEASE_SIGN)) && claUserComments.stream().noneMatch(comment -> comment.getBody().contains(THIS_PR_CONTAINS_AN_OBVIOUS_FIX))) {
                createObviousFixCommentIfNecessary(pullRequestId, userMentionMarkdown, issues, claUserComments);
            }
            return;
        }
        if (claUserComments.stream().anyMatch(c -> c.getBody().contains(FREQUENTLY_ASKED_QUESTIONS) && c.getBody().contains(TO_MANUALLY_SYNCHRONIZE_THE_STATUS))) {
            return;
        }
        Optional<Comment> oldComment = claUserComments.stream().filter(c -> c.getBody().trim().contains(PLEASE_SIGN)).findFirst();
        if (oldComment.isPresent()) {
            Comment toEdit = oldComment.get();
            toEdit.setBody(body);
            issues.editComment(pullRequestId.getRepositoryId(), toEdit);
        } else {
            issues.createComment(pullRequestId.getRepositoryId(), pullRequestId.getId(), body);
        }
    }
}
Also used : IssueService(org.eclipse.egit.github.core.service.IssueService) ClaOAuthConfig(io.pivotal.cla.config.ClaOAuthConfig) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) java.util(java.util) PullRequest(org.eclipse.egit.github.core.PullRequest) EmailService(io.pivotal.cla.egit.github.core.service.EmailService) RequestException(org.eclipse.egit.github.core.client.RequestException) SneakyThrows(lombok.SneakyThrows) EventsRepositoryHook(io.pivotal.cla.egit.github.core.EventsRepositoryHook) Autowired(org.springframework.beans.factory.annotation.Autowired) ContextCommitStatus(io.pivotal.cla.egit.github.core.ContextCommitStatus) WithPermissionsRepository(io.pivotal.cla.egit.github.core.WithPermissionsRepository) CommitStatus(org.eclipse.egit.github.core.CommitStatus) RepositoryService(org.eclipse.egit.github.core.service.RepositoryService) Matcher(java.util.regex.Matcher) Email(io.pivotal.cla.egit.github.core.Email) GitHubClient(org.eclipse.egit.github.core.client.GitHubClient) ContextCommitService(io.pivotal.cla.egit.github.core.service.ContextCommitService) UrlBuilder(io.pivotal.cla.mvc.util.UrlBuilder) RestTemplate(org.springframework.web.client.RestTemplate) MarkdownService(org.eclipse.egit.github.core.service.MarkdownService) WithPermissionsRepositoryService(io.pivotal.cla.egit.github.core.service.WithPermissionsRepositoryService) MigratePullRequestStatusRequest(io.pivotal.cla.service.MigratePullRequestStatusRequest) User(io.pivotal.cla.data.User) IOException(java.io.IOException) OrganizationService(org.eclipse.egit.github.core.service.OrganizationService) Collectors(java.util.stream.Collectors) RepositoryHook(org.eclipse.egit.github.core.RepositoryHook) Comment(org.eclipse.egit.github.core.Comment) HttpStatus(org.springframework.http.HttpStatus) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) PullRequestId(io.pivotal.cla.egit.github.core.PullRequestId) IssueService(org.eclipse.egit.github.core.service.IssueService) Component(org.springframework.stereotype.Component) RepositoryId(org.eclipse.egit.github.core.RepositoryId) OAuthClientCredentials(io.pivotal.cla.config.OAuthClientCredentials) Data(lombok.Data) CommitComment(org.eclipse.egit.github.core.CommitComment) PullRequestService(org.eclipse.egit.github.core.service.PullRequestService) ResponseEntity(org.springframework.http.ResponseEntity) Pattern(java.util.regex.Pattern) GithubEvents(io.pivotal.cla.egit.github.core.event.GithubEvents) StringUtils(org.springframework.util.StringUtils) Comment(org.eclipse.egit.github.core.Comment) CommitComment(org.eclipse.egit.github.core.CommitComment)

Example 2 with CommitStatus

use of org.eclipse.egit.github.core.CommitStatus in project pivotal-cla by pivotalsoftware.

the class MylynGitHubApi method createCommitStatusIfNecessary.

private ContextCommitStatus createCommitStatusIfNecessary(PullRequestId pullRequestId, PullRequestStatus commitStatus, boolean hasSignedCla, boolean obviousFix, GitHubClient client) {
    ContextCommitService commitService = new ContextCommitService(client);
    ContextCommitStatus status = new ContextCommitStatus();
    String description;
    if (obviousFix) {
        description = OBVIOUS_FIX_CLA_NOT_REQUIRED;
    } else if (hasSignedCla) {
        description = String.format("%s %s!", THANK_YOU, CONTRIBUTOR_LICENSE_AGREEMENT);
    } else {
        description = String.format("%s %s!", PLEASE_SIGN, CONTRIBUTOR_LICENSE_AGREEMENT);
    }
    status.setDescription(description);
    status.setState((hasSignedCla || obviousFix) ? CommitStatus.STATE_SUCCESS : CommitStatus.STATE_FAILURE);
    status.setContext("ci/pivotal-cla");
    status.setUrl(commitStatus.getUrl());
    status.setTargetUrl(status.getUrl());
    List<ContextCommitStatus> statuses = commitService.getContextStatuses(pullRequestId.getRepositoryId(), commitStatus.getSha());
    if (!statuses.stream().anyMatch(s -> matches(status, s))) {
        commitService.createStatus(pullRequestId.getRepositoryId(), commitStatus.getSha(), status);
    }
    return status;
}
Also used : ClaOAuthConfig(io.pivotal.cla.config.ClaOAuthConfig) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) java.util(java.util) PullRequest(org.eclipse.egit.github.core.PullRequest) EmailService(io.pivotal.cla.egit.github.core.service.EmailService) RequestException(org.eclipse.egit.github.core.client.RequestException) SneakyThrows(lombok.SneakyThrows) EventsRepositoryHook(io.pivotal.cla.egit.github.core.EventsRepositoryHook) Autowired(org.springframework.beans.factory.annotation.Autowired) ContextCommitStatus(io.pivotal.cla.egit.github.core.ContextCommitStatus) WithPermissionsRepository(io.pivotal.cla.egit.github.core.WithPermissionsRepository) CommitStatus(org.eclipse.egit.github.core.CommitStatus) RepositoryService(org.eclipse.egit.github.core.service.RepositoryService) Matcher(java.util.regex.Matcher) Email(io.pivotal.cla.egit.github.core.Email) GitHubClient(org.eclipse.egit.github.core.client.GitHubClient) ContextCommitService(io.pivotal.cla.egit.github.core.service.ContextCommitService) UrlBuilder(io.pivotal.cla.mvc.util.UrlBuilder) RestTemplate(org.springframework.web.client.RestTemplate) MarkdownService(org.eclipse.egit.github.core.service.MarkdownService) WithPermissionsRepositoryService(io.pivotal.cla.egit.github.core.service.WithPermissionsRepositoryService) MigratePullRequestStatusRequest(io.pivotal.cla.service.MigratePullRequestStatusRequest) User(io.pivotal.cla.data.User) IOException(java.io.IOException) OrganizationService(org.eclipse.egit.github.core.service.OrganizationService) Collectors(java.util.stream.Collectors) RepositoryHook(org.eclipse.egit.github.core.RepositoryHook) Comment(org.eclipse.egit.github.core.Comment) HttpStatus(org.springframework.http.HttpStatus) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) PullRequestId(io.pivotal.cla.egit.github.core.PullRequestId) IssueService(org.eclipse.egit.github.core.service.IssueService) Component(org.springframework.stereotype.Component) RepositoryId(org.eclipse.egit.github.core.RepositoryId) OAuthClientCredentials(io.pivotal.cla.config.OAuthClientCredentials) Data(lombok.Data) CommitComment(org.eclipse.egit.github.core.CommitComment) PullRequestService(org.eclipse.egit.github.core.service.PullRequestService) ResponseEntity(org.springframework.http.ResponseEntity) Pattern(java.util.regex.Pattern) GithubEvents(io.pivotal.cla.egit.github.core.event.GithubEvents) StringUtils(org.springframework.util.StringUtils) ContextCommitService(io.pivotal.cla.egit.github.core.service.ContextCommitService) ContextCommitStatus(io.pivotal.cla.egit.github.core.ContextCommitStatus)

Example 3 with CommitStatus

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

the class PullRequestStateProducerTest method testPullRequestStateProducer.

@Test
public void testPullRequestStateProducer() throws Exception {
    commitsha = commitService.getNextSha();
    Endpoint stateProducerEndpoint = getMandatoryEndpoint("direct:validPullRequest");
    Exchange exchange = stateProducerEndpoint.createExchange();
    String text = "Message sent at " + new Date();
    exchange.getIn().setBody(text);
    Exchange response = template.send(stateProducerEndpoint, exchange);
    assertNotNull(response.getOut().getBody());
    if (!(response.getOut().getBody() instanceof CommitStatus)) {
        fail("Expecting CommitStatus");
    }
    CommitStatus status = response.getOut().getBody(CommitStatus.class);
    // Check status set on commit service
    if (commitService.getCommitStatus(commitsha) != status) {
        fail("Commit status sent to service is different from response");
    }
    assertEquals(status.getState(), "success");
    assertEquals(status.getDescription(), text);
}
Also used : Exchange(org.apache.camel.Exchange) Endpoint(org.apache.camel.Endpoint) CommitStatus(org.eclipse.egit.github.core.CommitStatus) Date(java.util.Date) Test(org.junit.Test)

Example 4 with CommitStatus

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

the class PullRequestStateProducer method process.

public void process(Exchange exchange) throws Exception {
    String pullRequestNumberSHA = exchange.getIn().getHeader(GitHubConstants.GITHUB_PULLREQUEST_HEAD_COMMIT_SHA, String.class);
    String text = exchange.getIn().getBody(String.class);
    CommitStatus status = new CommitStatus();
    if (state != null) {
        status.setState(state);
    }
    if (targetUrl != null) {
        status.setTargetUrl(targetUrl);
    }
    if (text != null) {
        status.setDescription(text);
    }
    CommitStatus response = commitService.createStatus(getRepository(), pullRequestNumberSHA, status);
    // copy the header of in message to the out message
    exchange.getOut().copyFrom(exchange.getIn());
    exchange.getOut().setBody(response);
}
Also used : CommitStatus(org.eclipse.egit.github.core.CommitStatus)

Aggregations

CommitStatus (org.eclipse.egit.github.core.CommitStatus)4 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)2 ClaOAuthConfig (io.pivotal.cla.config.ClaOAuthConfig)2 OAuthClientCredentials (io.pivotal.cla.config.OAuthClientCredentials)2 User (io.pivotal.cla.data.User)2 ContextCommitStatus (io.pivotal.cla.egit.github.core.ContextCommitStatus)2 Email (io.pivotal.cla.egit.github.core.Email)2 EventsRepositoryHook (io.pivotal.cla.egit.github.core.EventsRepositoryHook)2 PullRequestId (io.pivotal.cla.egit.github.core.PullRequestId)2 WithPermissionsRepository (io.pivotal.cla.egit.github.core.WithPermissionsRepository)2 GithubEvents (io.pivotal.cla.egit.github.core.event.GithubEvents)2 ContextCommitService (io.pivotal.cla.egit.github.core.service.ContextCommitService)2 EmailService (io.pivotal.cla.egit.github.core.service.EmailService)2 WithPermissionsRepositoryService (io.pivotal.cla.egit.github.core.service.WithPermissionsRepositoryService)2 UrlBuilder (io.pivotal.cla.mvc.util.UrlBuilder)2 MigratePullRequestStatusRequest (io.pivotal.cla.service.MigratePullRequestStatusRequest)2 IOException (java.io.IOException)2 java.util (java.util)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2