// Path: src/main/java/org/jenkinsci/plugins/ghprb/extensions/GhprbBuildStep.java
// public interface GhprbBuildStep extends Action {
//     String BUILD_STEP = "GhprbBuildStep";
// 
//     void onScheduleBuild(Job<?, ?> project, GhprbCause cause);
// }
// 
// Path: src/main/java/org/jenkinsci/plugins/ghprb/extensions/GhprbCommentAppender.java
// public interface GhprbCommentAppender {
//     String postBuildComment(Run<?, ?> build, TaskListener listener);
// }
// 
// Path: src/main/java/org/jenkinsci/plugins/ghprb/extensions/GhprbCommitStatus.java
// public interface GhprbCommitStatus {
//     void onEnvironmentSetup(Run<?, ?> build, TaskListener listener, GHRepository repo) throws GhprbCommitStatusException;
// 
//     void onBuildTriggered(Job<?, ?> project, String commitSha, boolean isMergeable, int prId, GHRepository ghRepository)
//             throws GhprbCommitStatusException;
// 
//     void onBuildStart(Run<?, ?> build, TaskListener listener, GHRepository repo) throws GhprbCommitStatusException;
// 
//     void onBuildComplete(Run<?, ?> build, TaskListener listener, GHRepository repo) throws GhprbCommitStatusException;
// }
// 
// Path: src/main/java/org/jenkinsci/plugins/ghprb/extensions/GhprbCommitStatusException.java
// public class GhprbCommitStatusException extends Exception {
//     private static final long serialVersionUID = 6220095323686649609L;
// 
//     private final IOException exception;
// 
//     private final String message;
// 
//     private final GHCommitState state;
// 
//     private final int id;
// 
//     public GhprbCommitStatusException(IOException exception, GHCommitState state, String message, int id) {
//         this.exception = exception;
//         this.state = state;
//         this.message = message;
//         this.id = id;
//     }
// 
//     public IOException getException() {
//         return exception;
//     }
// 
//     public String getMessage() {
//         return message;
//     }
// 
//     public GHCommitState getState() {
//         return state;
//     }
// 
//     public int getId() {
//         return id;
//     }
// 
// }
// 
// Path: src/main/java/org/jenkinsci/plugins/ghprb/extensions/GhprbExtension.java
// public abstract class GhprbExtension extends AbstractDescribableImpl<GhprbExtension> {
// 
// }


import com.google.common.annotations.VisibleForTesting;
import hudson.Launcher;
import hudson.Util;
import hudson.model.Result;
import hudson.model.Run;
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;
import org.jenkinsci.plugins.ghprb.extensions.GhprbExtension;
import org.kohsuke.github.GHCommitState;
import org.kohsuke.github.GHIssueState;
import org.kohsuke.github.GHPullRequest;
import org.kohsuke.github.GHUser;
import java.io.IOException;
import java.io.PrintStream;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
            if (pr.getState().equals(GHIssueState.OPEN)) {
                repo.closePullRequest(c.getPullID());
            }
        } catch (IOException ex) {
            listener.getLogger().println("Can't close pull request");
            ex.printStackTrace(listener.getLogger());
        }
    }

    @VisibleForTesting
    void commentOnBuildResult(Run<?, ?> build, TaskListener listener, GHCommitState state, GhprbCause c) {
        StringBuilder msg = new StringBuilder();

        for (GhprbExtension ext : Ghprb.getJobExtensions(trigger, GhprbCommentAppender.class)) {
            if (ext instanceof GhprbCommentAppender) {
                String cmt = ((GhprbCommentAppender) ext).postBuildComment(build, listener);
                if ("--none--".equals(cmt)) {
                    return;
                }
                msg.append(cmt);
            }
        }

        if (msg.length() > 0) {
            listener.getLogger().println(msg);
            repo.addComment(c.getPullID(), msg.toString(), build, listener);
        }
    }

    public void onEnvironmentSetup(@SuppressWarnings("rawtypes") Run build, Launcher launcher, TaskListener listener) {
// Path: src/main/java/org/jenkinsci/plugins/ghprb/extensions/GhprbBuildStep.java
// public interface GhprbBuildStep extends Action {
//     String BUILD_STEP = "GhprbBuildStep";
// 
//     void onScheduleBuild(Job<?, ?> project, GhprbCause cause);
// }
// 
// Path: src/main/java/org/jenkinsci/plugins/ghprb/extensions/GhprbCommentAppender.java
// public interface GhprbCommentAppender {
//     String postBuildComment(Run<?, ?> build, TaskListener listener);
// }
// 
// Path: src/main/java/org/jenkinsci/plugins/ghprb/extensions/GhprbCommitStatus.java
// public interface GhprbCommitStatus {
//     void onEnvironmentSetup(Run<?, ?> build, TaskListener listener, GHRepository repo) throws GhprbCommitStatusException;
// 
//     void onBuildTriggered(Job<?, ?> project, String commitSha, boolean isMergeable, int prId, GHRepository ghRepository)
//             throws GhprbCommitStatusException;
// 
//     void onBuildStart(Run<?, ?> build, TaskListener listener, GHRepository repo) throws GhprbCommitStatusException;
// 
//     void onBuildComplete(Run<?, ?> build, TaskListener listener, GHRepository repo) throws GhprbCommitStatusException;
// }
// 
// Path: src/main/java/org/jenkinsci/plugins/ghprb/extensions/GhprbCommitStatusException.java
// public class GhprbCommitStatusException extends Exception {
//     private static final long serialVersionUID = 6220095323686649609L;
// 
//     private final IOException exception;
// 
//     private final String message;
// 
//     private final GHCommitState state;
// 
//     private final int id;
// 
//     public GhprbCommitStatusException(IOException exception, GHCommitState state, String message, int id) {
//         this.exception = exception;
//         this.state = state;
//         this.message = message;
//         this.id = id;
//     }
// 
//     public IOException getException() {
//         return exception;
//     }
// 
//     public String getMessage() {
//         return message;
//     }
// 
//     public GHCommitState getState() {
//         return state;
//     }
// 
//     public int getId() {
//         return id;
//     }
// 
// }
// 
// Path: src/main/java/org/jenkinsci/plugins/ghprb/extensions/GhprbExtension.java
// public abstract class GhprbExtension extends AbstractDescribableImpl<GhprbExtension> {
// 
// }


// Path: src/main/java/org/jenkinsci/plugins/ghprb/GhprbBuilds.java
import com.google.common.annotations.VisibleForTesting;
import hudson.Launcher;
import hudson.Util;
import hudson.model.Result;
import hudson.model.Run;
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;
import org.jenkinsci.plugins.ghprb.extensions.GhprbExtension;
import org.kohsuke.github.GHCommitState;
import org.kohsuke.github.GHIssueState;
import org.kohsuke.github.GHPullRequest;
import org.kohsuke.github.GHUser;
import java.io.IOException;
import java.io.PrintStream;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

            if (pr.getState().equals(GHIssueState.OPEN)) {
                repo.closePullRequest(c.getPullID());
            }
        } catch (IOException ex) {
            listener.getLogger().println("Can't close pull request");
            ex.printStackTrace(listener.getLogger());
        }
    }

    @VisibleForTesting
    void commentOnBuildResult(Run<?, ?> build, TaskListener listener, GHCommitState state, GhprbCause c) {
        StringBuilder msg = new StringBuilder();

        for (GhprbExtension ext : Ghprb.getJobExtensions(trigger, GhprbCommentAppender.class)) {
            if (ext instanceof GhprbCommentAppender) {
                String cmt = ((GhprbCommentAppender) ext).postBuildComment(build, listener);
                if ("--none--".equals(cmt)) {
                    return;
                }
                msg.append(cmt);
            }
        }

        if (msg.length() > 0) {
            listener.getLogger().println(msg);
            repo.addComment(c.getPullID(), msg.toString(), build, listener);
        }
    }

    public void onEnvironmentSetup(@SuppressWarnings("rawtypes") Run build, Launcher launcher, TaskListener listener) {
        GhprbCause c = Ghprb.getCause(build);