// Path: github-pullrequest-plugin/src/main/java/com/github/kostyasha/github/integration/branch/GitHubBranchCause.java
// public class GitHubBranchCause extends AbstractGitHubBranchCause<GitHubBranchCause> {
//     private static final Logger LOG = LoggerFactory.getLogger(GitHubBranchCause.class);
// 
//     private final String branchName;
// 
//     public GitHubBranchCause(@NonNull GitHubBranch localBranch, @NonNull GitHubBranchRepository localRepo, String reason, boolean skip) {
//         this(localBranch.getName(), localBranch.getCommitSha());
//         withReason(reason);
//         withSkip(skip);
//         withLocalRepo(localRepo);
//     }
// 
//     public GitHubBranchCause(@NonNull GHBranch remoteBranch, @NonNull GitHubBranchRepository localRepo, String reason, boolean skip) {
//         this(remoteBranch.getName(), remoteBranch.getSHA1());
//         withReason(reason);
//         withSkip(skip);
//         withLocalRepo(localRepo);
//         withRemoteData(remoteBranch);
//     }
// 
//     public GitHubBranchCause(@NonNull String branchName, String commitSha) {
//         super(commitSha, "refs/heads/" + branchName);
//         this.branchName = branchName;
//     }
// 
//     /**
//      * Copy constructor
//      */
//     public GitHubBranchCause(GitHubBranchCause cause) {
//         super(cause);
//         this.branchName = cause.getBranchName();
//     }
// 
//     public String getBranchName() {
//         return branchName;
//     }
// 
//     @Override
//     public void fillParameters(List<ParameterValue> params) {
//         GitHubBranchEnv.getParams(this, params);
//     }
// 
//     @Override
//     public GitHubSCMHead<GitHubBranchCause> createSCMHead(String sourceId) {
//         return new GitHubBranchSCMHead(branchName, sourceId);
//     }
// 
//     @NonNull
//     @Override
//     public String getShortDescription() {
//         if (getHtmlUrl() != null) {
//             return "GitHub branch " + getBranchName() + ": " + getReason();
//         } else {
//             return "Deleted branch";
//         }
//     }
// 
//     @Override
//     public void onAddedTo(@NonNull Run run) {
//         if (run.getParent().getParent() instanceof SCMSourceOwner) {
//             // skip multibranch
//             return;
//         }
// 
//         // move polling log from cause to action
//         try {
//             GitHubBranchPollingLogAction action = new GitHubBranchPollingLogAction(run);
//             writeStringToFile(action.getPollingLogFile(), getPollingLog());
//             run.replaceAction(action);
//         } catch (IOException ex) {
//             LOG.warn("Failed to persist the polling log", ex);
//         }
//         setPollingLog(null);
//     }
// 
// }


import com.github.kostyasha.github.integration.branch.GitHubBranchCause;
import org.kohsuke.github.GHBranch;
import org.kohsuke.github.GHRepository;
import edu.umd.cs.findbugs.annotations.NonNull;
import java.io.IOException;
package com.github.kostyasha.github.integration.multibranch.head;



public class GitHubBranchSCMHead extends GitHubSCMHead<GitHubBranchCause> {
    private static final long serialVersionUID = 1L;

    public GitHubBranchSCMHead(@NonNull String name, String sourceId) {
        super(name, sourceId);
    }

    @Override
    public String getPronoun() {
        return "Branch " + getName();
    }

    @Override
    public String fetchHeadSha(GHRepository remoteRepo) throws IOException {
        GHBranch branch = remoteRepo.getBranch(getName());
        if (branch == null) {
            throw new IOException("No branch " + getName() + " in " + remoteRepo.getFullName());
        }
        return branch.getSHA1();
    }

    @Override
// Path: github-pullrequest-plugin/src/main/java/com/github/kostyasha/github/integration/branch/GitHubBranchCause.java
// public class GitHubBranchCause extends AbstractGitHubBranchCause<GitHubBranchCause> {
//     private static final Logger LOG = LoggerFactory.getLogger(GitHubBranchCause.class);
// 
//     private final String branchName;
// 
//     public GitHubBranchCause(@NonNull GitHubBranch localBranch, @NonNull GitHubBranchRepository localRepo, String reason, boolean skip) {
//         this(localBranch.getName(), localBranch.getCommitSha());
//         withReason(reason);
//         withSkip(skip);
//         withLocalRepo(localRepo);
//     }
// 
//     public GitHubBranchCause(@NonNull GHBranch remoteBranch, @NonNull GitHubBranchRepository localRepo, String reason, boolean skip) {
//         this(remoteBranch.getName(), remoteBranch.getSHA1());
//         withReason(reason);
//         withSkip(skip);
//         withLocalRepo(localRepo);
//         withRemoteData(remoteBranch);
//     }
// 
//     public GitHubBranchCause(@NonNull String branchName, String commitSha) {
//         super(commitSha, "refs/heads/" + branchName);
//         this.branchName = branchName;
//     }
// 
//     /**
//      * Copy constructor
//      */
//     public GitHubBranchCause(GitHubBranchCause cause) {
//         super(cause);
//         this.branchName = cause.getBranchName();
//     }
// 
//     public String getBranchName() {
//         return branchName;
//     }
// 
//     @Override
//     public void fillParameters(List<ParameterValue> params) {
//         GitHubBranchEnv.getParams(this, params);
//     }
// 
//     @Override
//     public GitHubSCMHead<GitHubBranchCause> createSCMHead(String sourceId) {
//         return new GitHubBranchSCMHead(branchName, sourceId);
//     }
// 
//     @NonNull
//     @Override
//     public String getShortDescription() {
//         if (getHtmlUrl() != null) {
//             return "GitHub branch " + getBranchName() + ": " + getReason();
//         } else {
//             return "Deleted branch";
//         }
//     }
// 
//     @Override
//     public void onAddedTo(@NonNull Run run) {
//         if (run.getParent().getParent() instanceof SCMSourceOwner) {
//             // skip multibranch
//             return;
//         }
// 
//         // move polling log from cause to action
//         try {
//             GitHubBranchPollingLogAction action = new GitHubBranchPollingLogAction(run);
//             writeStringToFile(action.getPollingLogFile(), getPollingLog());
//             run.replaceAction(action);
//         } catch (IOException ex) {
//             LOG.warn("Failed to persist the polling log", ex);
//         }
//         setPollingLog(null);
//     }
// 
// }


// Path: github-pullrequest-plugin/src/main/java/com/github/kostyasha/github/integration/multibranch/head/GitHubBranchSCMHead.java
import com.github.kostyasha.github.integration.branch.GitHubBranchCause;
import org.kohsuke.github.GHBranch;
import org.kohsuke.github.GHRepository;
import edu.umd.cs.findbugs.annotations.NonNull;
import java.io.IOException;

package com.github.kostyasha.github.integration.multibranch.head;



public class GitHubBranchSCMHead extends GitHubSCMHead<GitHubBranchCause> {
    private static final long serialVersionUID = 1L;

    public GitHubBranchSCMHead(@NonNull String name, String sourceId) {
        super(name, sourceId);
    }

    @Override
    public String getPronoun() {
        return "Branch " + getName();
    }

    @Override
    public String fetchHeadSha(GHRepository remoteRepo) throws IOException {
        GHBranch branch = remoteRepo.getBranch(getName());
        if (branch == null) {
            throw new IOException("No branch " + getName() + " in " + remoteRepo.getFullName());
        }
        return branch.getSHA1();
    }

    @Override
    public String getHeadSha(GitHubBranchCause cause) {