Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for BitBucket Pull Requests #319

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ dependencies {
implementation 'org.jenkins-ci.plugins.workflow:workflow-api:2.28'
implementation 'org.jenkins-ci.plugins:branch-api:2.0.20'
implementation 'org.jenkins-ci.plugins:scm-api:2.2.7'
implementation 'org.jenkins-ci.plugins:cloudbees-bitbucket-branch-source:2.4.1'
implementation 'org.jenkins-ci.plugins:junit:1.24'
implementation 'org.jenkins-ci.plugins:script-security:1.76'
implementation 'org.jenkinsci.plugins:pipeline-model-definition:1.8.4' // version declarative started supporting JTE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import jenkins.scm.api.SCMFileSystem
import jenkins.scm.api.SCMHead
import jenkins.scm.api.SCMRevision
import jenkins.scm.api.SCMSource
import com.cloudbees.jenkins.plugins.bitbucket.BranchSCMHead
import com.cloudbees.jenkins.plugins.bitbucket.PullRequestSCMHead
import org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition
import org.jenkinsci.plugins.workflow.flow.FlowDefinition
import org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner
Expand Down Expand Up @@ -99,7 +101,14 @@ class FileSystemWrapperFactory {

SCMFileSystem fs
String scmKey
if (tip) {
if (head instanceof PullRequestSCMHead) {
// For BitBucket pull requests, we must use BranchSCMHead instead of PullRequestSCMHead
// to retrieve the SCMFileSystem from the source branch
BranchSCMHead branchHead = new BranchSCMHead(head.getBranchName())
SCMRevision sourceRevision = scmSource.fetch(branchHead, listener)
scmKey = branch.getScm().getKey()
fs = SCMFileSystem.of(scmSource, branchHead, sourceRevision)
} else if (tip) {
scmKey = branch.getScm().getKey()
SCMRevision rev = scmSource.getTrustedRevision(tip, listener)
fs = SCMFileSystem.of(scmSource, head, rev)
Expand Down