Skip to content

Commit

Permalink
Merge pull request #22 from johnou/enterprise
Browse files Browse the repository at this point in the history
[FIXED JENKINS-13726] Github plugin should work with Github enterprise by allowing for overriding the github URL.
  • Loading branch information
johnou committed Jan 15, 2013
2 parents a0255d8 + efcf047 commit 59fbb3e
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</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);
} 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 59fbb3e

Please sign in to comment.