Skip to content
Permalink
Browse files

Merge pull request #9 from recena/reviewOf-JENKINS-31445

[JENKINS-31482] Be able to use HTTP/HTTPS for new GH API Endpoints
  • Loading branch information...
recena committed Nov 10, 2015
2 parents 0eb885b + 65b5095 commit 04c7597e66f34d892e6a1c60c9631807815e4526
@@ -23,8 +23,8 @@
<connection>scm:git:git://github.com/jenkinsci/${project.artifactId}-plugin.git</connection>
<developerConnection>scm:git:git@github.com:jenkinsci/${project.artifactId}-plugin.git</developerConnection>
<url>https://github.com/jenkinsci/${project.artifactId}-plugin</url>
<tag>HEAD</tag>
</scm>
<tag>HEAD</tag>
</scm>
<dependencies>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
@@ -82,13 +82,14 @@

protected AbstractGitHubSCMSource(String id, String apiUri, String checkoutCredentialsId, String scanCredentialsId, String repoOwner, String repository) {
super(id);
this.apiUri = apiUri;
this.apiUri = Util.fixEmpty(apiUri);
this.repoOwner = repoOwner;
this.repository = repository;
this.scanCredentialsId = Util.fixEmpty(scanCredentialsId);
this.checkoutCredentialsId = checkoutCredentialsId;
}

@CheckForNull
public String getApiUri() {
return apiUri;
}
@@ -145,7 +146,7 @@ public RepositoryUriResolver getUriResolver() {
if (getCredentials(StandardCredentials.class, credentialsId) instanceof SSHUserPrivateKey) {
return new SshRepositoryUriResolver();
} else {
// Defaults to HTTPS
// Defaults to HTTP/HTTPS
return new HttpsRepositoryUriResolver();
}
}
@@ -294,7 +295,7 @@ public FormValidation doCheckScanCredentialsId(@QueryParameter String value) {

public ListBoxModel doFillApiUriItems() {
ListBoxModel result = new ListBoxModel();
result.add("Github", "");
result.add("GitHub", "");
for (Endpoint e : GitHubConfiguration.get().getEndpoints()) {
result.add(e.getName() == null ? e.getApiUri() : e.getName(), e.getApiUri());
}
@@ -335,8 +336,6 @@ public ListBoxModel doFillRepositoryItems(@AncestorInPath SCMSourceOwner context
LOGGER.log(Level.WARNING, e.getMessage());
} catch (IOException e) {
LOGGER.log(Level.WARNING, e.getMessage());
// may be anonymous or bad credentials (unauthorized)
// TODO: Manage this exception.
}
if (myself != null && repoOwner.equals(myself.getLogin())) {
for (String name : myself.getAllRepositories().keySet()) {
@@ -65,7 +65,7 @@
this.repoOwner = repoOwner;
this.scanCredentialsId = Util.fixEmpty(scanCredentialsId);
this.checkoutCredentialsId = checkoutCredentialsId;
this.apiUri = apiUri;
this.apiUri = Util.fixEmpty(apiUri);
}

public String getRepoOwner() {
@@ -102,7 +102,7 @@ public String getApiUri() {
listener.getLogger().format("Must specify user or organization%n");
return;
}
StandardCredentials credentials = Connector.lookupScanCredentials(observer.getContext(), null /* TODO apiUri */, scanCredentialsId);
StandardCredentials credentials = Connector.lookupScanCredentials(observer.getContext(), apiUri, scanCredentialsId);
if (credentials == null) {
listener.getLogger().format("No scan credentials, skipping%n");
return;
@@ -207,7 +207,7 @@ public ListBoxModel doFillCheckoutCredentialsIdItems(@AncestorInPath SCMSourceOw

public ListBoxModel doFillApiUriItems() {
ListBoxModel result = new ListBoxModel();
result.add("Github", "");
result.add("GitHub", "");
for (Endpoint e : GitHubConfiguration.get().getEndpoints()) {
result.add(e.getName() == null ? e.getApiUri() : e.getName(), e.getApiUri());
}
@@ -31,7 +31,7 @@

@Override
public String getRepositoryUri(String apiUri, String owner, String repository) {
if (apiUri.startsWith("https://")) {
if (apiUri == null || apiUri.startsWith("https://")) {
return "https://" + hostnameFromApiUri(apiUri) + "/" + owner + "/" + repository + ".git";
} else {
return "http://" + hostnameFromApiUri(apiUri) + "/" + owner + "/" + repository + ".git";
@@ -24,12 +24,8 @@

package org.jenkinsci.plugins.github_branch_source;

import hudson.Util;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* @author Stephen Connolly
@@ -39,14 +35,13 @@
public abstract String getRepositoryUri(String apiUri, String owner, String repository);

public static String hostnameFromApiUri(String apiUri) {
apiUri = Util.fixEmptyAndTrim(apiUri);
try {
URL endpoint = new URL(apiUri);
if (endpoint.getPath().startsWith("/api/v3")) {
if (apiUri != null) {
try {
URL endpoint = new URL(apiUri);
return endpoint.getHost();
} catch (MalformedURLException e) {
// ignore
}
} catch (MalformedURLException e) {
// ignore
}
return "github.com";
}

0 comments on commit 04c7597

Please sign in to comment.
You can’t perform that action at this time.