Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make webhook url configurable #310

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,16 @@ public class GitHubOrgWebHook {
GHEvent.PULL_REQUEST_REVIEW_COMMENT);

public static void register(GitHub hub, String orgName) throws IOException {
String rootUrl = System.getProperty("jenkins.hook.url");
if (rootUrl == null) {
rootUrl = Jenkins.get().getRootUrl();
}
if (rootUrl == null) {
String url = getWebhookUrl();
if (url == null) {
return;
}

GHUser u = hub.getUser(orgName);
FileBoolean orghook = new FileBoolean(getTrackingFile(orgName));
if (orghook.isOff()) {
try {
GHOrganization org = hub.getOrganization(orgName);
String url = rootUrl + "github-webhook/";
boolean found = false;
for (GHHook hook : org.getHooks()) {
if (hook.getConfig().get("url").equals(url)) {
Expand Down Expand Up @@ -104,16 +101,16 @@ private static File getTrackingFile(String orgName) {
}

public static void deregister(GitHub hub, String orgName) throws IOException {
String rootUrl = Jenkins.get().getRootUrl();
if (rootUrl == null) {
String url = getWebhookUrl();
if (url == null) {
return;
}

GHUser u = hub.getUser(orgName);
FileBoolean orghook = new FileBoolean(getTrackingFile(orgName));
if (orghook.isOn()) {
try {
GHOrganization org = hub.getOrganization(orgName);
String url = rootUrl + "github-webhook/";
for (GHHook hook : org.getHooks()) {
if (hook.getConfig().get("url").equals(url)) {
hook.delete();
Expand Down Expand Up @@ -144,4 +141,16 @@ public static void deregister(GitHub hub, String orgName) throws IOException {
}
}
}

private static String getWebhookUrl() {
String rootUrl = System.getProperty("jenkins.hook.url");
if (rootUrl == null) {
rootUrl = Jenkins.get().getRootUrl();
}
if (rootUrl == null) {
return rootUrl;
}

return rootUrl + "github-webhook/";
}
}