// Path: github-pullrequest-plugin/src/main/java/com/github/kostyasha/github/integration/multibranch/head/GitHubPRSCMHead.java
// public class GitHubPRSCMHead extends GitHubSCMHead<GitHubPRCause> {
//     private static final long serialVersionUID = 1L;
// 
//     private final int prNumber;
//     private final String targetBranch;
// 
//     public GitHubPRSCMHead(@NonNull GitHubPRCause prCause, String sourceId) {
//         this(prCause.getNumber(), prCause.getTargetBranch(), sourceId);
//     }
// 
//     public GitHubPRSCMHead(@NonNull Integer prNumber, @NonNull String targetBranch, String sourceId) {
//         super("pr-" + Integer.toString(prNumber), sourceId);
//         this.prNumber = prNumber;
//         this.targetBranch = targetBranch;
//     }
// 
//     public int getPrNumber() {
//         return prNumber;
//     }
// 
//     public String getTargetBranch() {
//         return targetBranch;
//     }
// 
//     @Override
//     public String getPronoun() {
//         return "PR#" + prNumber;
//     }
// 
//     @Override
//     public String fetchHeadSha(GHRepository remoteRepo) throws IOException {
//         GHPullRequest pullRequest = remoteRepo.getPullRequest(prNumber);
//         if (pullRequest == null) {
//             throw new IOException("No PR " + prNumber + " in " + remoteRepo.getFullName());
//         }
//         return pullRequest.getHead().getSha();
//     }
// 
//     @Override
//     public String getHeadSha(GitHubPRCause cause) {
//         return cause.getHeadSha();
//     }
// }


import com.github.kostyasha.github.integration.multibranch.head.GitHubPRSCMHead;
import hudson.scm.SCM;
import jenkins.scm.api.SCMHead;
import jenkins.scm.api.SCMRevision;
import jenkins.scm.api.SCMSource;
import org.jenkinsci.plugins.github.pullrequest.webhook.PullRequestInfo;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import java.util.Collections;
import java.util.Map;
package com.github.kostyasha.github.integration.multibranch.hooks;



/**
 * @author Kanstantsin Shautsou
 */
public class GitHubPullRequestScmHeadEvent extends GitHubScmHeadEvent<PullRequestInfo> {
    public GitHubPullRequestScmHeadEvent(@NonNull Type type, long timestamp, @NonNull PullRequestInfo payload,
                                         @CheckForNull String origin) {
        super(type, timestamp, payload, origin);
    }

    @NonNull
    @Override
    protected String getSourceRepo() {
        return getPayload().getRepo();
    }

    @NonNull
    @Override
    public Map<SCMHead, SCMRevision> heads(@NonNull SCMSource source) {
        if (!isMatch(source)) {
            return Collections.emptyMap();
        }

        return Collections.singletonMap(
                new GitHubPRSCMHead(getPayload().getNum(), getPayload().getTarget(), source.getId()), null
        );
    }

// Path: github-pullrequest-plugin/src/main/java/com/github/kostyasha/github/integration/multibranch/head/GitHubPRSCMHead.java
// public class GitHubPRSCMHead extends GitHubSCMHead<GitHubPRCause> {
//     private static final long serialVersionUID = 1L;
// 
//     private final int prNumber;
//     private final String targetBranch;
// 
//     public GitHubPRSCMHead(@NonNull GitHubPRCause prCause, String sourceId) {
//         this(prCause.getNumber(), prCause.getTargetBranch(), sourceId);
//     }
// 
//     public GitHubPRSCMHead(@NonNull Integer prNumber, @NonNull String targetBranch, String sourceId) {
//         super("pr-" + Integer.toString(prNumber), sourceId);
//         this.prNumber = prNumber;
//         this.targetBranch = targetBranch;
//     }
// 
//     public int getPrNumber() {
//         return prNumber;
//     }
// 
//     public String getTargetBranch() {
//         return targetBranch;
//     }
// 
//     @Override
//     public String getPronoun() {
//         return "PR#" + prNumber;
//     }
// 
//     @Override
//     public String fetchHeadSha(GHRepository remoteRepo) throws IOException {
//         GHPullRequest pullRequest = remoteRepo.getPullRequest(prNumber);
//         if (pullRequest == null) {
//             throw new IOException("No PR " + prNumber + " in " + remoteRepo.getFullName());
//         }
//         return pullRequest.getHead().getSha();
//     }
// 
//     @Override
//     public String getHeadSha(GitHubPRCause cause) {
//         return cause.getHeadSha();
//     }
// }


// Path: github-pullrequest-plugin/src/main/java/com/github/kostyasha/github/integration/multibranch/hooks/GitHubPullRequestScmHeadEvent.java
import com.github.kostyasha.github.integration.multibranch.head.GitHubPRSCMHead;
import hudson.scm.SCM;
import jenkins.scm.api.SCMHead;
import jenkins.scm.api.SCMRevision;
import jenkins.scm.api.SCMSource;
import org.jenkinsci.plugins.github.pullrequest.webhook.PullRequestInfo;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import java.util.Collections;
import java.util.Map;

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



/**
 * @author Kanstantsin Shautsou
 */
public class GitHubPullRequestScmHeadEvent extends GitHubScmHeadEvent<PullRequestInfo> {
    public GitHubPullRequestScmHeadEvent(@NonNull Type type, long timestamp, @NonNull PullRequestInfo payload,
                                         @CheckForNull String origin) {
        super(type, timestamp, payload, origin);
    }

    @NonNull
    @Override
    protected String getSourceRepo() {
        return getPayload().getRepo();
    }

    @NonNull
    @Override
    public Map<SCMHead, SCMRevision> heads(@NonNull SCMSource source) {
        if (!isMatch(source)) {
            return Collections.emptyMap();
        }

        return Collections.singletonMap(
                new GitHubPRSCMHead(getPayload().getNum(), getPayload().getTarget(), source.getId()), null
        );
    }

    @Override