From e1ae498d9a1fcd815f36f5a15caf6b4413b90ab8 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Wed, 14 Aug 2019 16:49:40 -0400 Subject: [PATCH 1/5] Honor $JENKINS_HOOK_URL if defined. --- .../plugins/github_branch_source/GitHubOrgWebHook.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubOrgWebHook.java b/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubOrgWebHook.java index f32e0f375a..cfdc2964f8 100644 --- a/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubOrgWebHook.java +++ b/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubOrgWebHook.java @@ -61,7 +61,10 @@ private static boolean existsHook(GHOrganization org, String url) throws IOExcep } public static void register(GitHub hub, String orgName) throws IOException { - String rootUrl = Jenkins.getActiveInstance().getRootUrl(); + String rootUrl = System.getenv("JENKINS_HOOK_URL"); + if (rootUrl == null) { + rootUrl = Jenkins.get().getRootUrl(); + } if (rootUrl == null) { return; } From c51604d6e874d24ac53113a902160afdecce8082 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Mon, 9 Sep 2019 17:36:10 -0400 Subject: [PATCH 2/5] Deleting unused method existsHook. --- .../github_branch_source/GitHubOrgWebHook.java | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubOrgWebHook.java b/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubOrgWebHook.java index cfdc2964f8..811fd257ec 100644 --- a/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubOrgWebHook.java +++ b/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubOrgWebHook.java @@ -48,18 +48,6 @@ public class GitHubOrgWebHook { private static final Logger LOGGER = Logger.getLogger(GitHubOrgWebHook.class.getName()); private static final List EVENTS = Arrays.asList(GHEvent.REPOSITORY, GHEvent.PUSH, GHEvent.PULL_REQUEST, GHEvent.PULL_REQUEST_REVIEW_COMMENT); - /** - * Verify if exists a webhook by its URL. - */ - private static boolean existsHook(GHOrganization org, String url) throws IOException { - for (GHHook hook : org.getHooks()) { - if (hook.getConfig().get("url").equals(url)) { - return true; - } - } - return false; - } - public static void register(GitHub hub, String orgName) throws IOException { String rootUrl = System.getenv("JENKINS_HOOK_URL"); if (rootUrl == null) { From 9941d05f822021b77ce8d90b61decca5249a94c3 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Mon, 9 Sep 2019 18:41:22 -0400 Subject: [PATCH 3/5] WireMock test for overridden hook URL. --- pom.xml | 2 +- .../GitHubOrgWebHook.java | 2 +- .../GitHubOrgWebHookTest.java | 56 +++++++++++++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubOrgWebHookTest.java diff --git a/pom.xml b/pom.xml index 69318dfcc3..3cc3edcea1 100644 --- a/pom.xml +++ b/pom.xml @@ -154,7 +154,7 @@ com.github.tomakehurst wiremock-standalone - 2.4.1 + 2.16.0 test diff --git a/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubOrgWebHook.java b/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubOrgWebHook.java index 811fd257ec..7427ef8aae 100644 --- a/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubOrgWebHook.java +++ b/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubOrgWebHook.java @@ -49,7 +49,7 @@ public class GitHubOrgWebHook { private static final List 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.getenv("JENKINS_HOOK_URL"); + String rootUrl = System.getProperty("jenkins.hook.url"); if (rootUrl == null) { rootUrl = Jenkins.get().getRootUrl(); } diff --git a/src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubOrgWebHookTest.java b/src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubOrgWebHookTest.java new file mode 100644 index 0000000000..33e4780098 --- /dev/null +++ b/src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubOrgWebHookTest.java @@ -0,0 +1,56 @@ +/* + * The MIT License + * + * Copyright 2019 CloudBees, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package org.jenkinsci.plugins.github_branch_source; + +import static com.github.tomakehurst.wiremock.client.WireMock.*; +import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; +import com.github.tomakehurst.wiremock.junit.WireMockRule; +import org.junit.Rule; +import org.junit.Test; +import org.jvnet.hudson.test.Issue; +import org.jvnet.hudson.test.JenkinsRule; +import org.kohsuke.github.GitHub; + +public class GitHubOrgWebHookTest { + + @Rule public JenkinsRule r = new JenkinsRule(); + @Rule public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort()); + + @Issue("JENKINS-58942") + @Test public void registerCustom() throws Exception { + System.setProperty("jenkins.hook.url", "https://mycorp/hook-proxy/"); + wireMockRule.stubFor(get(urlEqualTo("/api/users/myorg")).willReturn(aResponse().withBody("{\"login\":\"myorg\"}"))); + wireMockRule.stubFor(get(urlEqualTo("/api/orgs/myorg")).willReturn(aResponse().withBody("{\"login\":\"myorg\",\"html_url\":\"https://github.com/myorg\"}"))); + wireMockRule.stubFor(get(urlEqualTo("/api/orgs/myorg/hooks")).willReturn(aResponse().withBody("[]"))); + wireMockRule.stubFor(post(urlEqualTo("/api/orgs/myorg/hooks")).withRequestBody(matchingJsonPath("$.config.url", equalTo("https://mycorp/hook-proxy/github-webhook/"))).willReturn(aResponse().withBody("{}"))); + GitHub hub = Connector.connect("http://localhost:" + wireMockRule.port() + "/api/", null); + try { + GitHubOrgWebHook.register(hub, "myorg"); + } finally { + Connector.release(hub); + } + } + +} From 09a9fe12957c7c7986bc59fc65e9364bd6e9f251 Mon Sep 17 00:00:00 2001 From: Liam Newman Date: Tue, 10 Sep 2019 14:31:18 -0700 Subject: [PATCH 4/5] [maven-release-plugin] prepare release github-branch-source-2.5.7 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 69318dfcc3..1c03a76d96 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ github-branch-source - ${revision}${changelist} + 2.5.7 hpi GitHub Branch Source Plugin https://wiki.jenkins-ci.org/display/JENKINS/GitHub+Branch+Source+Plugin @@ -33,7 +33,7 @@ scm:git:git://github.com/jenkinsci/${project.artifactId}-plugin.git scm:git:git@github.com:jenkinsci/${project.artifactId}-plugin.git https://github.com/jenkinsci/${project.artifactId}-plugin - ${scmTag} + github-branch-source-2.5.7 From da418a6f824d6a4a9789e3133ada364d871835ab Mon Sep 17 00:00:00 2001 From: Liam Newman Date: Tue, 10 Sep 2019 14:31:53 -0700 Subject: [PATCH 5/5] [maven-release-plugin] prepare for next development iteration --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 1c03a76d96..9a133d0cb3 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ github-branch-source - 2.5.7 + ${revision}${changelist} hpi GitHub Branch Source Plugin https://wiki.jenkins-ci.org/display/JENKINS/GitHub+Branch+Source+Plugin @@ -21,7 +21,7 @@ - 2.5.7 + 2.5.8 -SNAPSHOT 8 2.138.4 @@ -33,7 +33,7 @@ scm:git:git://github.com/jenkinsci/${project.artifactId}-plugin.git scm:git:git@github.com:jenkinsci/${project.artifactId}-plugin.git https://github.com/jenkinsci/${project.artifactId}-plugin - github-branch-source-2.5.7 + ${scmTag}