Skip to content

Commit

Permalink
Merge branch 'master' of github.com:jenkinsci/ghprb-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidTanner committed Feb 26, 2016
2 parents 7fc283a + 697b7a2 commit 6f86b1a
Show file tree
Hide file tree
Showing 25 changed files with 728 additions and 277 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ job('upstreamJob') {
}
triggers {
githubPullRequest {
pullRequest {
admin('user_1')
admins(['user_2', 'user_3'])
userWhitelist('[email protected]')
Expand Down Expand Up @@ -186,6 +186,10 @@ job('downstreamJob') {

### Updates

#### -> 1.30.2
* Don't run through all the builds for changelog, track it in the PR object instead
* Synchronization around the PR object fields

#### -> 1.30.1
* Moved pull request state into build/pullrequests directory.
* Dynamic state is no longer kept as part of the trigger
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.31-SNAPSHOT</version>
<version>1.30.6-SNAPSHOT</version>
<packaging>hpi</packaging>

<url>https://wiki.jenkins-ci.org/display/JENKINS/GitHub+pull+request+builder+plugin</url>
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/jenkinsci/plugins/ghprb/Ghprb.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import hudson.model.Cause;
import hudson.model.Item;
import hudson.model.Result;
import hudson.model.Run;
import hudson.model.Saveable;
import hudson.model.TaskListener;
import hudson.security.ACL;
Expand Down Expand Up @@ -277,14 +278,15 @@ public static Set<String> createSet(String list) {
}


public static GhprbCause getCause(AbstractBuild<?, ?> build) {
public static GhprbCause getCause(Run<?, ?> build) {
Cause cause = build.getCause(GhprbCause.class);
if (cause == null || (!(cause instanceof GhprbCause))) {
return null;
}
return (GhprbCause) cause;
}


public static GhprbTrigger extractTrigger(AbstractBuild<?, ?> build) {
return extractTrigger(build.getProject());
}
Expand Down
24 changes: 16 additions & 8 deletions src/main/java/org/jenkinsci/plugins/ghprb/GhprbBuilds.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import hudson.Util;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import hudson.model.Result;
import hudson.model.TaskListener;
import hudson.model.queue.QueueTaskFuture;
import hudson.plugins.git.util.BuildData;

import org.apache.commons.lang.StringUtils;
import org.jenkinsci.plugins.ghprb.extensions.GhprbBuildStep;
import org.jenkinsci.plugins.ghprb.extensions.GhprbCommentAppender;
import org.jenkinsci.plugins.ghprb.extensions.GhprbCommitStatus;
import org.jenkinsci.plugins.ghprb.extensions.GhprbCommitStatusException;
Expand Down Expand Up @@ -75,7 +77,7 @@ public void build(GhprbPullRequest pr, GHUser triggerSender, String commentBody)
}
}
}
QueueTaskFuture<?> build = trigger.startJob(cause, repo);
QueueTaskFuture<?> build = trigger.scheduleBuild(cause, repo);
if (build == null) {
logger.log(Level.SEVERE, "Job did not start");
}
Expand All @@ -89,9 +91,11 @@ public void onStarted(AbstractBuild<?, ?> build, TaskListener listener) {
}

GhprbTrigger trigger = Ghprb.extractTrigger(build);
GhprbPullRequest pullRequest = trigger.getRepository().getPullRequest(c.getPullID());
pullRequest.setBuild(build);

try {
GHPullRequest pr = trigger.getRepository().getPullRequest(c.getPullID());
GHPullRequest pr = pullRequest.getPullRequest(true);
int counter = 0;
// If the PR is being resolved by GitHub then getMergeable will return null
Boolean isMergeable = pr.getMergeable();
Expand Down Expand Up @@ -167,15 +171,19 @@ public void onCompleted(AbstractBuild<?, ?> build, TaskListener listener) {
// remove the BuildData action that we may have added earlier to avoid
// having two of them, and because the one we added isn't correct
// @see GhprbTrigger
BuildData fakeOne = null;
for (BuildData data : build.getActions(BuildData.class)) {
if (data.getLastBuiltRevision() != null && !data.getLastBuiltRevision().getSha1String().equals(c.getCommit())) {
fakeOne = data;
build.getActions().remove(data);
break;
}
}
if (fakeOne != null) {
build.getActions().remove(fakeOne);


if (build.getResult() == Result.ABORTED) {
GhprbBuildStep abortAction = build.getAction(GhprbBuildStep.class);
if (abortAction != null) {
return;
}
}

for (GhprbExtension ext : Ghprb.getJobExtensions(trigger, GhprbCommitStatus.class)) {
Expand All @@ -193,14 +201,14 @@ public void onCompleted(AbstractBuild<?, ?> build, TaskListener listener) {

commentOnBuildResult(build, listener, state, c);
// close failed pull request automatically
if (state == GHCommitState.FAILURE && trigger.isAutoCloseFailedPullRequests()) {
if (state == GHCommitState.FAILURE && trigger.getAutoCloseFailedPullRequests()) {
closeFailedRequest(listener, c);
}
}

private void closeFailedRequest(TaskListener listener, GhprbCause c) {
try {
GHPullRequest pr = repo.getPullRequest(c.getPullID());
GHPullRequest pr = repo.getActualPullRequest(c.getPullID());

if (pr.getState().equals(GHIssueState.OPEN)) {
repo.closePullRequest(c.getPullID());
Expand Down
Loading

0 comments on commit 6f86b1a

Please sign in to comment.