/** * Fix up the repository set up to our policy. */ private void setupRepository(GHRepository r) throws IOException { r.setEmailServiceHook(POST_COMMIT_HOOK_EMAIL); r.enableIssueTracker(false); r.enableWiki(false); r.createHook(IrcBotImpl.IRC_HOOK_NAME, IrcBotImpl.IRC_HOOK_CONFIG, (Collection<GHEvent>) null, true); }
public boolean createHook() { if (ghRepository == null) { logger.log( Level.INFO, "Repository not available, cannot set pull request hook for repository {0}", reponame); return false; } try { if (hookExist()) { return true; } Map<String, String> config = new HashMap<String, String>(); String secret = getSecret(); config.put("url", new URL(getHookUrl()).toExternalForm()); config.put("insecure_ssl", "1"); if (secret != "") { config.put("secret", secret); } ghRepository.createHook("web", config, HOOK_EVENTS, true); return true; } catch (IOException ex) { logger.log( Level.SEVERE, "Couldn''t create web hook for repository {0}. Does the user (from global configuration) have admin rights to the repository?", reponame); return false; } }
private boolean createJenkinsHook(GHRepository repo, URL url) { try { repo.createHook( "jenkins", Collections.singletonMap("jenkins_hook_url", url.toExternalForm()), null, true); return true; } catch (IOException e) { throw new GHException("Failed to update jenkins hooks", e); } }
private GHHook createWebHook(String webhookUrl) throws IOException { final GitHubRepositoryName gitHubRepoName = GitHubRepositoryName.create(gitHubRepositoryUrl); for (GHRepository repo : gitHubRepoName.resolve()) { // check if the webhook already exists for (GHHook hook : repo.getHooks()) { if ("web".equals(hook.getName()) && webhookUrl.equals(hook.getConfig().get("url"))) { LOGGER.info( MessageFormat.format( "Webhook {0} already exists for {1}", webhookUrl, gitHubRepositoryUrl)); return hook; } } try { Map<String, String> config = new HashMap<String, String>(); config.put("url", webhookUrl); config.put("insecure_ssl", "1"); GHHook hook = repo.createHook("web", config, WEBHOOK_EVENTS, true); LOGGER.info( MessageFormat.format( "Webhook {0} is added to GitHub repository {1}", webhookUrl, gitHubRepositoryUrl)); return hook; } catch (IOException e) { LOGGER.log( Level.FINEST, MessageFormat.format( "Failed to add webhook {0} to GitHub repository {1}", webhookUrl, gitHubRepositoryUrl), e); } } LOGGER.warning( MessageFormat.format( "Cannot add webhook {0} to GitHub repository {1}. " + "Make sure that you specified a valid GitHub credential for GitHub project {1} in Jenkins " + "configuration.", webhookUrl, gitHubRepositoryUrl)); return null; }