Skip to content

Commit

Permalink
Check if the PR is stable before allowing a build to progress.
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidTanner committed May 28, 2015
1 parent 17dca15 commit f482b8f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class GhprbBuildListener extends RunListener<AbstractBuild<?, ?>> {
public void onStarted(AbstractBuild<?, ?> build, TaskListener listener) {
final Optional<GhprbTrigger> trigger = findTrigger(build);
if (trigger.isPresent()) {
trigger.get().getBuilds().onStarted(build, listener.getLogger());
trigger.get().getBuilds().onStarted(build, listener);
}
}

Expand Down
23 changes: 22 additions & 1 deletion src/main/java/org/jenkinsci/plugins/ghprb/GhprbBuilds.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import java.io.IOException;
import java.io.PrintStream;
import java.util.concurrent.ConcurrentMap;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -77,11 +78,31 @@ private GhprbCause getCause(AbstractBuild<?, ?> build) {
return (GhprbCause) cause;
}

public void onStarted(AbstractBuild<?, ?> build, PrintStream logger) {
public void onStarted(AbstractBuild<?, ?> build, TaskListener listener) {
PrintStream logger = listener.getLogger();
GhprbCause c = getCause(build);
if (c == null) {
return;
}

GhprbTrigger trigger = Ghprb.extractTrigger(build);

ConcurrentMap<Integer, GhprbPullRequest> pulls = trigger.getDescriptor().getPullRequests(build.getProject().getFullName());

GHPullRequest pr = pulls.get(c.getPullID()).getPullRequest();

try {
while (pr.getMergeable() == null) {
Thread.sleep(1000);
}
// TODO: Figure out what to do if the status of the PR has changed.
// if (pr.getMergeable() != c.isMerged()) {
// listener.fatalError("PR status has changed!");
// }
} catch (Exception e) {
logger.print("Unable to query GitHub for status of PullRequest");
e.printStackTrace(logger);
}

repo.createCommitStatus(build, GHCommitState.PENDING,
(c.isMerged() ? "Build started, sha1 is merged" : "Build started, sha1 is original commit."), c.getPullID(),
Expand Down

0 comments on commit f482b8f

Please sign in to comment.