Skip to content

Commit

Permalink
Support proxies
Browse files Browse the repository at this point in the history
  • Loading branch information
ohtake committed Sep 4, 2014
1 parent 3f34cba commit 0574b3c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>github-api</artifactId>
<version>1.58</version>
<version>1.59-SNAPSHOT</version><!-- TODO -->
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/org/jenkinsci/plugins/ghprb/GhprbGitHub.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.kohsuke.github.GHOrganization;
import org.kohsuke.github.GHUser;
import org.kohsuke.github.GitHub;
import org.kohsuke.github.GitHubBuilder;

/**
* @author janinko
Expand All @@ -19,7 +20,11 @@ private void connect() throws IOException{
String serverAPIUrl = GhprbTrigger.getDscp().getServerAPIUrl();
if(accessToken != null && !accessToken.isEmpty()) {
try {
gh = GitHub.connectUsingOAuth(serverAPIUrl, accessToken);
gh = new GitHubBuilder()
.withEndpoint(serverAPIUrl)
.withOAuthToken(accessToken)
.withConnector(new HttpConnectorWithJenkinsProxy())
.build();
} catch(IOException e) {
logger.log(Level.SEVERE, "Can''t connect to {0} using oauth", serverAPIUrl);
throw e;
Expand All @@ -28,7 +33,10 @@ private void connect() throws IOException{
if (serverAPIUrl.contains("api/v3")) {
gh = GitHub.connectToEnterprise(serverAPIUrl, GhprbTrigger.getDscp().getUsername(), GhprbTrigger.getDscp().getPassword());
} else {
gh = GitHub.connectUsingPassword(GhprbTrigger.getDscp().getUsername(), GhprbTrigger.getDscp().getPassword());
gh = new GitHubBuilder()
.withPassword(GhprbTrigger.getDscp().getUsername(), GhprbTrigger.getDscp().getPassword())
.withConnector(new HttpConnectorWithJenkinsProxy())
.build();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.jenkinsci.plugins.ghprb;

import hudson.ProxyConfiguration;
import org.kohsuke.github.HttpConnector;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;

public class HttpConnectorWithJenkinsProxy implements HttpConnector{
public HttpURLConnection connect(URL url) throws IOException {
return (HttpURLConnection)ProxyConfiguration.open(url);
}
}

0 comments on commit 0574b3c

Please sign in to comment.