Skip to content
Open
Changes from 4 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 @@ -49,19 +49,16 @@ public class GitHubOrgWebHook {
private static final List<GHEvent> EVENTS = Arrays.asList(GHEvent.REPOSITORY, GHEvent.PUSH, GHEvent.PULL_REQUEST, 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 @@ -96,16 +93,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 All @@ -130,4 +127,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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return rootUrl;
return null;

(for clarity)

}

return rootUrl + "github-webhook/";
}

}