Skip to content

Commit

Permalink
[JENKINS-33318] GHE server validation with private mode enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
recena committed Mar 5, 2016
1 parent e378438 commit fad71a5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
3 changes: 2 additions & 1 deletion pom.xml
Expand Up @@ -48,9 +48,10 @@
</exclusions>
</dependency>
<dependency>
<!-- Update when 1.74 is released -->
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>github-api</artifactId>
<version>1.71</version>
<version>1.74-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand Down
Expand Up @@ -115,14 +115,23 @@ 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");
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);
return FormValidation.error("This does not look like a GitHub Enterprise API endpoint");
} 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);
return FormValidation.error("This does not look like a GitHub Enterprise API endpoint");
} catch (IOException e) {
if (e.getMessage().contains("private mode enabled")) {
LOGGER.log(Level.FINE, "Trying to configure a GitHub Enterprise server with private mode enabled");
return FormValidation.ok("GitHub Enterprise server verified");
}
// For example: https://github.mycompany.com/api gets a FileNotFoundException
LOGGER.log(Level.WARNING, e.getMessage());
return FormValidation.error("This does not look like a GitHub Enterprise API URL");
return FormValidation.error("This does not look like a GitHub Enterprise API endpoint");
}
}

Expand Down
Expand Up @@ -417,7 +417,6 @@ public FormValidation doCheckScanCredentialsId(@AncestorInPath SCMSourceOwner co
return FormValidation.error("Invalid credentials");
}
} catch (IOException e) {
// ignore, never thrown
LOGGER.log(Level.WARNING, "Exception validating credentials " + CredentialsNameProvider.name(credentials) + " on " + apiUri);
return FormValidation.error("Exception validating credentials");
}
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 fad71a5

Please sign in to comment.