Skip to content

Commit

Permalink
Merge pull request jenkinsci#355 from jenkinsci/master
Browse files Browse the repository at this point in the history
Merge in latest.
  • Loading branch information
DavidTanner committed Nov 5, 2015
2 parents d511efb + d85a8f5 commit 8abdd4f
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 18 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ For more details, see https://wiki.jenkins-ci.org/display/JENKINS/GitHub+pull+re

### Credentials
* If you are using Enterprise GitHub set the server api URL in ``GitHub server api URL``. Otherwise leave there ``https://api.github.com``.
* Set the Jenkins URL if you need to override the default (e.g. it's behind a firewall)
* A GitHub API token or username password can be used for access to the GitHub API
* To setup credentials for a given GitHub Server API URL:
* Click Add next to the ``Credentials`` drop down
Expand Down Expand Up @@ -107,6 +108,15 @@ If you want to manually build the job, in the job setting check ``This build is

### Updates

#### -> 1.29.4
* Add secret when auto creating the web hook
* Accomodate Jenkins being behind a firewall
* Fix for recursive repo initializations.

#### -> 1.29.1
* Fix NPE for triggers without a project
* Add back default URL if env variables are missing

#### -> 1.29
* Reduced the size of the plugin .xml file drastically.
* Fixed issues with persistance store credentials.
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<artifactId>ghprb</artifactId>
<name>GitHub Pull Request Builder</name>
<version>1.29-SNAPSHOT</version>
<version>1.30-SNAPSHOT</version>
<packaging>hpi</packaging>

<url>https://wiki.jenkins-ci.org/display/JENKINS/GitHub+pull+request+builder+plugin</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,23 @@ public class GhprbBuildListener extends RunListener<AbstractBuild<?, ?>> {
@Override
public void onStarted(AbstractBuild<?, ?> build, TaskListener listener) {
GhprbTrigger trigger = Ghprb.extractTrigger(build);
if (trigger != null) {
if (trigger != null && trigger.getBuilds() != null) {
trigger.getBuilds().onStarted(build, listener);
}
}

@Override
public void onCompleted(AbstractBuild<?, ?> build, TaskListener listener) {
GhprbTrigger trigger = Ghprb.extractTrigger(build);
if (trigger != null) {
if (trigger != null && trigger.getBuilds() != null) {
trigger.getBuilds().onCompleted(build, listener);
}
}

@Override
public Environment setUpEnvironment(@SuppressWarnings("rawtypes") AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException, Run.RunnerAbortedException {
GhprbTrigger trigger = Ghprb.extractTrigger(build);
if (trigger != null) {
if (trigger != null && trigger.getBuilds() != null) {
trigger.getBuilds().onEnvironmentSetup(build, launcher, listener);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class GhprbGitHubAuth extends AbstractDescribableImpl<GhprbGitHubAuth> {
public static final DescriptorImpl DESCRIPTOR = new DescriptorImpl();

private final String serverAPIUrl;
private final String jenkinsUrl;
private final String credentialsId;
private final String id;
private final String description;
Expand All @@ -61,6 +62,7 @@ public class GhprbGitHubAuth extends AbstractDescribableImpl<GhprbGitHubAuth> {
@DataBoundConstructor
public GhprbGitHubAuth(
String serverAPIUrl,
String jenkinsUrl,
String credentialsId,
String description,
String id,
Expand All @@ -70,6 +72,7 @@ public GhprbGitHubAuth(
serverAPIUrl = "https://api.github.com";
}
this.serverAPIUrl = fixEmptyAndTrim(serverAPIUrl);
this.jenkinsUrl = fixEmptyAndTrim(jenkinsUrl);
this.credentialsId = fixEmpty(credentialsId);
if (StringUtils.isEmpty(id)) {
id = UUID.randomUUID().toString();
Expand All @@ -85,6 +88,11 @@ public String getServerAPIUrl() {
return serverAPIUrl;
}

@Exported
public String getJenkinsUrl() {
return jenkinsUrl;
}

@Exported
public String getCredentialsId() {
return credentialsId;
Expand Down
23 changes: 20 additions & 3 deletions src/main/java/org/jenkinsci/plugins/ghprb/GhprbRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ public GhprbRepository(String user, String repository, Ghprb helper) {

public void init() {
// make the initial check call to populate our data structures
initGhRepository();
if (!initGhRepository()) {
// We could have hit the rate limit while initializing. If we
// continue, then we will loop back around and attempt to re-init.
return;
}

for (Entry<Integer, GhprbPullRequest> next : helper.getTrigger().getPulls().entrySet()) {
GhprbPullRequest pull = next.getValue();
try {
Expand Down Expand Up @@ -251,8 +256,12 @@ public boolean createHook() {
return true;
}
Map<String, String> config = new HashMap<String, String>();
String secret = getSecret();
config.put("url", new URL(getHookUrl()).toExternalForm());
config.put("insecure_ssl", "1");
if (secret != "") {
config.put("secret",secret);
}
ghRepository.createHook("web", config, HOOK_EVENTS, true);
return true;
} catch (IOException ex) {
Expand All @@ -261,8 +270,16 @@ public boolean createHook() {
}
}

private static String getHookUrl() {
return Jenkins.getInstance().getRootUrl() + GhprbRootAction.URL + "/";
private String getSecret() {
return helper.getTrigger().getGitHubApiAuth().getSecret();
}

private String getHookUrl() {
String baseUrl = helper.getTrigger().getGitHubApiAuth().getJenkinsUrl();
if (baseUrl == null) {
baseUrl = Jenkins.getInstance().getRootUrl();
}
return baseUrl + GhprbRootAction.URL + "/";
}

public GHPullRequest getPullRequest(int id) throws IOException {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/jenkinsci/plugins/ghprb/GhprbTrigger.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public GhprbTrigger(String adminlist,
this.allowMembersOfWhitelistedOrgsAsAdmin = allowMembersOfWhitelistedOrgsAsAdmin;
this.buildDescTemplate = buildDescTemplate;
setExtensions(extensions);
configVersion = 1;
configVersion = latestVersion;
}

@Override
Expand Down Expand Up @@ -555,7 +555,7 @@ public GhprbGitHubAuth getGitHubAuth(String gitHubAuthId) {
public List<GhprbGitHubAuth> getGithubAuth() {
if (githubAuth == null || githubAuth.size() == 0) {
githubAuth = new ArrayList<GhprbGitHubAuth>(1);
githubAuth.add(new GhprbGitHubAuth(null, null, "Anonymous connection", null, null));
githubAuth.add(new GhprbGitHubAuth(null, null, null, "Anonymous connection", null, null));
}
return githubAuth;
}
Expand Down Expand Up @@ -811,7 +811,7 @@ public void readBackFromLegacy() {

if (!StringUtils.isEmpty(accessToken)) {
try {
GhprbGitHubAuth auth = new GhprbGitHubAuth(serverAPIUrl, Ghprb.createCredentials(serverAPIUrl, accessToken), "Pre credentials Token", null, null);
GhprbGitHubAuth auth = new GhprbGitHubAuth(serverAPIUrl, null, Ghprb.createCredentials(serverAPIUrl, accessToken), "Pre credentials Token", null, null);
if (githubAuth == null) {
githubAuth = new ArrayList<GhprbGitHubAuth>(1);
}
Expand All @@ -825,7 +825,7 @@ public void readBackFromLegacy() {

if (!StringUtils.isEmpty(username) || !StringUtils.isEmpty(password)) {
try {
GhprbGitHubAuth auth = new GhprbGitHubAuth(serverAPIUrl, Ghprb.createCredentials(serverAPIUrl, username, password), "Pre credentials username and password", null, null);
GhprbGitHubAuth auth = new GhprbGitHubAuth(serverAPIUrl, null, Ghprb.createCredentials(serverAPIUrl, username, password), "Pre credentials username and password", null, null);
if (githubAuth == null) {
githubAuth = new ArrayList<GhprbGitHubAuth>(1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public abstract class GhprbTriggerBackwardsCompatible extends Trigger<AbstractPr

public abstract DescribableList<GhprbExtension, GhprbExtensionDescriptor> getExtensions();

protected final int latestVersion = 3;


protected String triggerPhrase;
protected Integer configVersion;
Expand Down Expand Up @@ -58,7 +60,7 @@ protected void convertPropertiesToExtensions() {
checkBuildStatusMessages();
checkCommitStatusContext();

configVersion = 3;
configVersion = latestVersion;
}

private void checkBuildStatusMessages() {
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/org/jenkinsci/plugins/ghprb/GhprbWebHook.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.jenkinsci.plugins.ghprb;

import hudson.model.AbstractProject;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -34,7 +36,12 @@ public boolean matchRepo(String hookRepoName) {
}

public String getProjectName() {
return trigger.getActualProject().getFullName();
AbstractProject<?, ?> project = trigger.getActualProject();
if (project != null) {
return project.getFullName();
} else {
return "NOT STARTED";
}
}

public void handleComment(IssueComment issueComment) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import java.util.List;
import java.util.Map;

import jenkins.model.Jenkins;

import org.apache.commons.lang.StringUtils;
import org.jenkinsci.plugins.ghprb.Ghprb;
import org.jenkinsci.plugins.ghprb.GhprbCause;
Expand Down Expand Up @@ -89,7 +91,7 @@ public void onBuildTriggered(AbstractProject<?, ?> project, String commitSha, bo
String triggeredStatus = getDescriptor().getTriggeredStatusDefault(this);

// check if we even need to update
if (triggeredStatus != null && triggeredStatus.equals("--none--")) {
if (StringUtils.equals(triggeredStatus, "--none--")) {
return;
}

Expand All @@ -111,7 +113,7 @@ public void onBuildTriggered(AbstractProject<?, ?> project, String commitSha, bo
}

String url = Ghprb.replaceMacros(project, statusUrl);
if ("--none--".equals(statusUrl) || statusUrl == null) {
if (StringUtils.equals( statusUrl, "--none--")) {
url = "";
}

Expand All @@ -132,7 +134,7 @@ public void onBuildStart(AbstractBuild<?, ?> build, TaskListener listener, GHRep
String startedStatus = getDescriptor().getStartedStatusDefault(this);

// check if we even need to update
if (startedStatus != null && startedStatus.equals("--none--")) {
if (StringUtils.equals(startedStatus, "--none--")) {
return;
}

Expand Down Expand Up @@ -160,7 +162,7 @@ public void onBuildComplete(AbstractBuild<?, ?> build, TaskListener listener, GH
for (GhprbBuildResultMessage buildStatus : completedStatus) {
sb.append(buildStatus.postBuildComment(build, listener));
}
if (sb.toString().equals("--none--")) {
if (StringUtils.equals(sb.toString(), "--none--")) {
return;
}
}
Expand Down Expand Up @@ -190,8 +192,11 @@ private void createCommitStatus(AbstractBuild<?, ?> build, TaskListener listener
if (StringUtils.isEmpty(url)) {
url = envVars.get("JOB_URL");
}
if (StringUtils.isEmpty(url)) {
url = Jenkins.getInstance().getRootUrl() + build.getUrl();
}

if ("--none--".equals(statusUrl) || statusUrl == null) {
if (StringUtils.equals(statusUrl, "--none--")) {
url = "";
} else if (!StringUtils.isEmpty(statusUrl)) {
url = Ghprb.replaceMacros(build, listener, statusUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ f.entry(title:_("GitHub Server API URL"), field:"serverAPIUrl") {
f.textbox()
}

f.entry(title:_("Jenkins URL override"), field:"jenkinsUrl") {
f.textbox()
}

f.entry(title:_("Shared secret"), field:"secret") {
f.password()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>
Use this to override the Jenkins URL that GitHub should call.
</div>

0 comments on commit 8abdd4f

Please sign in to comment.