Search in sources :

Example 1 with ContextCommitService

use of io.pivotal.cla.egit.github.core.service.ContextCommitService 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)

Aggregations

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