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;
}
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;
}
Aggregations