Skip to content

Commit

Permalink
Merge remote-tracking branch 'jenkinsci/master' into okhttp3
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwiseman committed Sep 20, 2019
2 parents 88809bd + 376f176 commit 00200ea
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 15 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</licenses>

<properties>
<revision>2.5.7</revision>
<revision>2.5.8</revision>
<changelist>-SNAPSHOT</changelist>
<java.level>8</java.level>
<jenkins.version>2.138.4</jenkins.version>
Expand Down Expand Up @@ -172,7 +172,7 @@
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock-standalone</artifactId>
<version>2.4.1</version>
<version>2.16.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,11 @@ public class GitHubOrgWebHook {
private static final Logger LOGGER = Logger.getLogger(GitHubOrgWebHook.class.getName());
private static final List<GHEvent> 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 = Jenkins.getActiveInstance().getRootUrl();
String rootUrl = System.getProperty("jenkins.hook.url");
if (rootUrl == null) {
rootUrl = Jenkins.get().getRootUrl();
}
if (rootUrl == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}

}

0 comments on commit 00200ea

Please sign in to comment.