Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

How can I retrieve a pull request from repository slug and pull request number in ScriptRunner?

I need to get a pull request from the project, repository and pull request number with Script Runner. Usually I use the event but in this case I only have the repository slug and pull request ID. 

1 answer

After viewing some examples here

Figured this out:

import com.atlassian.bitbucket.pull.PullRequestSearchRequest
import com.atlassian.bitbucket.util.PageRequestImpl
import com.atlassian.bitbucket.util.PageRequest
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.bitbucket.repository.RepositoryService
import com.atlassian.bitbucket.repository.Repository
import com.atlassian.bitbucket.repository.RefService
import com.atlassian.bitbucket.pull.PullRequest
import static com.atlassian.bitbucket.pull.PullRequestState.OPEN;
import com.atlassian.bitbucket.pull.PullRequestService
import com.atlassian.bitbucket.pull.PullRequestUpdateRequest


def repositoryService = ComponentLocator.getComponent(RepositoryService.class);
def refService = ComponentLocator.getComponent(RefService.class);

Repository rep = repositoryService.getBySlug("Project1","Repo1");
int id = rep.getId();


def pullRequestService = ComponentLocator.getComponent(PullRequestService)


PageRequest page = new PageRequestImpl(0, 10)
PullRequestSearchRequest pullr = new PullRequestSearchRequest.Builder().toRepositoryId(id).state(OPEN).build()
long pullrequestID
int version
log.warn(, page).getValues().toString()),page).getValues().forEach( val -> {
//log.warn("ID: "" Description "+val.getDescription())
pullrequestID =
version = val.version


@Infantino Benitono need to make a paged request if you have a Project Key, Repository slug and pull request id. The following script should get you a single pull request where :

- Project Key = 'PROJECT_1'

- Repository Slug = 'rep_1'

- Pull Request id = '1'



import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.bitbucket.repository.RepositoryService
import com.atlassian.bitbucket.pull.PullRequestService

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

def repository = repositoryService.getBySlug('PROJECT_1', 'rep_1')
def pullRequest = pullRequestService.getById(, 1)
Like Infantino Benito likes this

Thanks, much appreciated

Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events