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