Skip to main content
Example scripts
arrow icon
To homepage
Bitbucket
Data centre icon
Data Center

Create a Pull Request

Created 1 year ago, Updated 6 month(s) ago
App in script
ScriptRunner For Bitbucket
ScriptRunner For Bitbucket
by Adaptavist
Compatibility
compatibility bullet
Bitbucket (6.0 - 7.17)
compatibility bullet
ScriptRunner For Bitbucket (7.10.0)
Language |
groovy
import com.atlassian.bitbucket.pull.PullRequestCreateRequest
import com.atlassian.bitbucket.pull.PullRequestService
import com.atlassian.bitbucket.repository.RepositoryService
import com.atlassian.sal.api.component.ComponentLocator

def pullRequestService = ComponentLocator.getComponent(PullRequestService)
def repositoryService = ComponentLocator.getComponent(RepositoryService)

def projKey = 'PULL_REQUEST_SNIPPET_PROJECT'
def repoSlug = 'pull_request_snippet_repository'

def sourceRef = 'develop'
def targetBranch = 'main'

def prTitle = 'A title for the pull request'
def prDescription = 'A description for the the pull request'
def reviewersUsernames = ['user1', 'user2'] as Set

def repository = repositoryService.getBySlug(projKey, repoSlug)

def pullRequestCreateRequest = new PullRequestCreateRequest.Builder()
    .title(prTitle)
    .description(prDescription)
    .reviewers(reviewersUsernames)
    .fromRepository(repository)
    .toRepository(repository)
    .fromRefId(sourceRef)
    .toBranchId(targetBranch)
    .build()

pullRequestService.create(pullRequestCreateRequest)
Having an issue with this script?
Report it here