Skip to content

Commit

Permalink
Merge pull request #27 from recena/JENKINS-33318
Browse files Browse the repository at this point in the history
[JENKINS-33318] GHE server validation with private mode enabled
  • Loading branch information
recena committed Apr 18, 2016
2 parents 844f9c0 + 2fab60d commit af04b02
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
3 changes: 2 additions & 1 deletion pom.xml
Expand Up @@ -51,7 +51,8 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>github-api</artifactId>
<version>1.72.1</version>
<!-- Update when 1.75 is released -->
<version>1.75-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand Down
Expand Up @@ -31,6 +31,7 @@
import hudson.model.Descriptor;
import hudson.util.FormValidation;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
Expand Down Expand Up @@ -115,14 +116,28 @@ public FormValidation doCheckApiUri(@QueryParameter String apiUri) {
URL api = new URL(apiUri);
GitHub github = GitHub.connectToEnterpriseAnonymously(api.toString());
github.checkApiUrlValidity();
return FormValidation.ok();
LOGGER.log(Level.FINE, "Trying to configure a GitHub Enterprise server");
// For example: https://api.github.com/ or https://github.mycompany.com/api/v3/ (with private mode disabled).
return FormValidation.ok("GitHub Enterprise server verified");
} catch (MalformedURLException mue) {
return FormValidation.error("This does not look like a GitHub Enterprise API URL");
// For example: https:/api.github.com
LOGGER.log(Level.WARNING, "Trying to configure a GitHub Enterprise server: " + apiUri, mue.getCause());
return FormValidation.error("The endpoint does not look like a GitHub Enterprise (malformed URL)");
} catch (JsonParseException jpe) {
return FormValidation.error("This does not look like a GitHub Enterprise API URL");
LOGGER.log(Level.WARNING, "Trying to configure a GitHub Enterprise server: " + apiUri, jpe.getCause());
return FormValidation.error("The endpoint does not look like a GitHub Enterprise (invalid JSON response)");
} catch (FileNotFoundException fnt) {
// For example: https://github.mycompany.com/server/api/v3/ gets a FileNotFoundException
LOGGER.log(Level.WARNING, "Getting HTTP Error 404 for " + apiUri);
return FormValidation.error("The endpoint does not look like a GitHub Enterprise (page not found");
} catch (IOException e) {
// For example: https://github.mycompany.com/api/v3/ or https://github.mycompany.com/api/v3/mypath
if (e.getMessage().contains("private mode enabled")) {
LOGGER.log(Level.FINE, e.getMessage());
return FormValidation.warning("Private mode enabled, validation disabled");
}
LOGGER.log(Level.WARNING, e.getMessage());
return FormValidation.error("This does not look like a GitHub Enterprise API URL");
return FormValidation.error("The endpoint does not look like a GitHub Enterprise (verify network and/or try again later)");
}
}

Expand Down
@@ -1,3 +1,3 @@
<p>
<a href="https://developer.github.com/v3/">GitHub API</a> endpoint such as <code>https://github.example.com/api/v3</code>.
<a href="https://developer.github.com/v3/">GitHub API</a> endpoint such as <code>https://github.example.com/api/v3/</code>.
</p>

0 comments on commit af04b02

Please sign in to comment.