Search in sources :

Example 1 with EventsRepositoryHook

use of io.pivotal.cla.egit.github.core.EventsRepositoryHook in project pivotal-cla by pivotalsoftware.

the class MylynGitHubApi method createHook.

private EventsRepositoryHook createHook(String url, String secret) {
    Map<String, String> config = new HashMap<>();
    config.put("url", url);
    config.put("content_type", "json");
    config.put("secret", secret);
    EventsRepositoryHook hook = new EventsRepositoryHook();
    hook.setActive(true);
    hook.addEvent(GithubEvents.ISSUE_COMMENT);
    hook.addEvent(GithubEvents.PULL_REQUEST);
    hook.addEvent(GithubEvents.PULL_REQUEST_REVIEW_COMMENT);
    hook.setName("web");
    hook.setConfig(config);
    return hook;
}
Also used : EventsRepositoryHook(io.pivotal.cla.egit.github.core.EventsRepositoryHook)

Example 2 with EventsRepositoryHook

use of io.pivotal.cla.egit.github.core.EventsRepositoryHook in project pivotal-cla by pivotalsoftware.

the class MylynGitHubApi method createPullRequestHooks.

@Override
@SneakyThrows
public List<String> createPullRequestHooks(CreatePullRequestHookRequest request) {
    String accessToken = request.getAccessToken();
    List<String> repositoryIds = request.getRepositoryIds();
    String gitHubEventUrl = request.getGitHubEventUrl();
    GitHubClient client = createClient(accessToken);
    RepositoryService service = new RepositoryService(client);
    List<String> hookUrls = new ArrayList<>();
    for (String repository : repositoryIds) {
        RepositoryId repositoryId = RepositoryId.createFromId(repository);
        EventsRepositoryHook hook = createHook(gitHubEventUrl, request.getSecret());
        List<RepositoryHook> hooks = service.getHooks(repositoryId);
        Optional<RepositoryHook> optional = hooks.stream().filter(h -> hasUrl(h, gitHubEventUrl)).findFirst();
        long hookId;
        if (optional.isPresent()) {
            // we must always update because the secret is not exposed
            hook.setId(optional.get().getId());
            hook.setActive(true);
            RepositoryHook editHook = service.editHook(repositoryId, hook);
            hookId = editHook.getId();
        } else {
            RepositoryHook createdHook = service.createHook(repositoryId, hook);
            hookId = createdHook.getId();
        }
        hookUrls.add("https://github.com/" + repository + "/settings/hooks/" + hookId);
    }
    return hookUrls;
}
Also used : EventsRepositoryHook(io.pivotal.cla.egit.github.core.EventsRepositoryHook) RepositoryHook(org.eclipse.egit.github.core.RepositoryHook) 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) GitHubClient(org.eclipse.egit.github.core.client.GitHubClient) EventsRepositoryHook(io.pivotal.cla.egit.github.core.EventsRepositoryHook) RepositoryId(org.eclipse.egit.github.core.RepositoryId) RepositoryService(org.eclipse.egit.github.core.service.RepositoryService) WithPermissionsRepositoryService(io.pivotal.cla.egit.github.core.service.WithPermissionsRepositoryService) SneakyThrows(lombok.SneakyThrows)

Aggregations

EventsRepositoryHook (io.pivotal.cla.egit.github.core.EventsRepositoryHook)2 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 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