Search in sources :

Example 1 with RepositoryHook

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

the class MylynGitHubApi method findAssociatedClaNames.

@Override
@SneakyThrows
public Set<String> findAssociatedClaNames(String repoId, String accessToken) {
    GitHubClient client = createClient(accessToken);
    RepositoryService service = new RepositoryService(client);
    RepositoryId repositoryId = RepositoryId.createFromId(repoId);
    List<RepositoryHook> hooks = service.getHooks(repositoryId);
    Set<String> claNames = // 
    hooks.stream().filter(// 
    h -> StringUtils.hasText(h.getConfig().get("url"))).filter(// 
    RepositoryHook::isActive).map(// 
    h -> h.getConfig().get("url")).filter(// 
    PULL_REQUEST_CALLBACK_PATTERN.asPredicate()).map(// 
    url -> getClaName(url, PULL_REQUEST_CALLBACK_PATTERN)).collect(Collectors.toSet());
    return claNames;
}
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) 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)

Example 2 with RepositoryHook

use of org.eclipse.egit.github.core.RepositoryHook 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

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 Collectors (java.util.stream.Collectors)2