Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/";
}
}