Skip to content

Commit

Permalink
JENKINS-13726: Support for GitHub Enterprise.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnou committed Jan 6, 2013
1 parent a0255d8 commit 947f6e2
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 24 deletions.
13 changes: 1 addition & 12 deletions pom.xml
Expand Up @@ -28,18 +28,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>github-api</artifactId>
<version>1.28</version>
<exclusions>
<exclusion>
<groupId>org.jvnet.hudson</groupId>
<artifactId>htmlunit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jenkins-ci</groupId>
<artifactId>htmlunit</artifactId>
<version>2.6-jenkins-6</version>
<version>1.34-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.jenkinsci.plugins</groupId>
Expand Down
23 changes: 19 additions & 4 deletions src/main/java/com/cloudbees/jenkins/Credential.java
@@ -1,6 +1,7 @@
package com.cloudbees.jenkins;

import hudson.Extension;
import hudson.Util;
import hudson.model.AbstractDescribableImpl;
import hudson.model.Descriptor;
import hudson.util.FormValidation;
Expand All @@ -18,16 +19,23 @@
*/
public class Credential extends AbstractDescribableImpl<Credential> {
public final String username;
public final String apiUrl;
public final String apiToken;
public final Secret password;

@DataBoundConstructor
public Credential(String username, Secret password) {
public Credential(String username, Secret password, String apiUrl, String apiToken) {
this.username = username;
this.password = password;
this.apiUrl = apiUrl;
this.apiToken = apiToken;
}

public GitHub login() throws IOException {
return GitHub.connect(username,null,password.getPlainText());
if (Util.fixEmpty(apiUrl) != null) {
return GitHub.connectToEnterprise(apiUrl,username,apiToken);
}
return GitHub.connect(username,apiToken,password.getPlainText());
}

@Extension
Expand All @@ -37,8 +45,15 @@ public String getDisplayName() {
return ""; // unused
}

public FormValidation doValidate(@QueryParameter String username, @QueryParameter Secret password) throws IOException {
if (GitHub.connect(username,null,Secret.toString(password)).isCredentialValid())
public FormValidation doValidate(@QueryParameter String apiUrl, @QueryParameter String username, @QueryParameter Secret password, @QueryParameter String apiToken) throws IOException {
GitHub gitHub;
if (Util.fixEmpty(apiUrl) != null) {
gitHub = GitHub.connectToEnterprise(apiUrl,username,apiToken);

This comment has been minimized.

Copy link
@Stelk

Stelk Jun 28, 2013

passing the api token here appears to be incorrect. The connectToEnterprise method is expecting a password and not a token. The end result being that to connect to a Github enterprise instance you have to place your password as cleartext in the token field when configuring jenkins for the plugin to work correctly. I have verified this behavior using the latest jenkins, github plugin, and github api versions.

Mark Klunder

} else {
gitHub = GitHub.connect(username,apiToken,Secret.toString(password));
}

if (gitHub.isCredentialValid())
return FormValidation.ok("Verified");
else
return FormValidation.error("Failed to validate the account");
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/com/cloudbees/jenkins/GitHubWebHook.java
Expand Up @@ -197,9 +197,4 @@ public void processGitHubPayload(String payload, Class<? extends Trigger<?>> tri
public static GitHubWebHook get() {
return Hudson.getInstance().getExtensionList(RootAction.class).get(GitHubWebHook.class);
}

static {
// hide "Bad input type: "search", creating a text input" from createElementNS
Logger.getLogger(com.gargoylesoftware.htmlunit.html.InputElementFactory.class.getName()).setLevel(WARNING);
}
}
@@ -1,9 +1,15 @@
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<f:entry title="${%API URL}" field="apiUrl">
<f:textbox/>
</f:entry>
<f:entry title="${%Username}" field="username">
<f:textbox/>
</f:entry>
<f:entry title="${%Password}" field="password">
<f:password/>
</f:entry>
<f:validateButton title="${%Test Credential}" with="username,password,apiToken" method="validate"/>
<f:entry title="${%API key}" field="apiToken">
<f:textbox/>
</f:entry>
<f:validateButton title="${%Test Credential}" with="apiUrl,username,password,apiToken" method="validate"/>
</j:jelly>
@@ -0,0 +1,3 @@
<div>
If you use GitHub Enterprise you may specify the API end point here eg. "https://ghe.acme.com/api/v3", the API key is required and password is ignored.
</div>
@@ -0,0 +1,3 @@
<div>
Password is no longer required if you specify the API key.
</div>
@@ -1,5 +1,3 @@
<div>
Credentials used to access GitHub to install/remove hooks. Because GitHub doesn't have an API for managing
hooks, we also need to ask you to provide password, in addition to the API key.
If your Jenkins uses multiple repositories that spread across different user accounts, you can list them all here.
</div>

0 comments on commit 947f6e2

Please sign in to comment.