Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to generate pull requests via scriptrunner for bitbucket server?

rgewondjan
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 29, 2021 edited

Summary Question: Can I generate a pull request using scriptrunner for bitbucket server?


Background:

I am working on a certain workflow that requires PRs to multiple branches when a change needs to be made, and right now individuals must create all 3 PRs by hand (or in some cases with custom scripts that use bitbucket API).

I am interested in finding a way to generate 2 of the PRs when 1 is created, or perhaps I will decide to generate all 3 PRs based on some other event.

I learned from this page how to implement a custom listener:

https://scriptrunner.adaptavist.com/6.9.2/bitbucket/StashEventHandlers.html#_working_with_custom_listeners



However, my challenge is not on triggering the event, but it is in finding how to cause another event to occur, specifically the generation of a pull request.

I did find this: https://community.atlassian.com/t5/Marketplace-Apps-Integrations/Automatically-create-master-branch-on-repository-creation/qaq-p/94060

which led me to this: https://gist.github.com/jechlin/6365d2e3c0ef4b94deb636db9c2cde7d

That gave me hope that maybe it was possible to do what I am trying to do, since this script also causes an event to occur.

 

I also consulted the atlassian documentation. There I found 2 docs that seemed to be a promising way to create a Pull Request using ScriptRunner.

 https://docs.atlassian.com/bitbucket-server/javadoc/6.7.1/api/index.html?com/atlassian/

Then search: "com.atlassian.bitbucket.pull"


From what I can see we would:

Use PullRequestService to create a pull request (interface).

Use PullRequestCreateRequest class as parameter for class that implements PullRequestService.

 

Unfortunately without any concrete examples, there will be a lot of trial and error and guessing how to put the pieces of this code together, and it might not work when all is said and done, but here's hoping!

Additionally, if you have other suggestions for accomplishing the same task, I would also welcome those suggestions. Any insight is greatly appreciated!

1 answer

0 votes
Robert Giddings _Adaptavist_
Community Champion
January 19, 2022

Hi @rgewondjan ,

We have recently added a script to our Adaptavist Library that shows you how to use the PullRequestService to programmatically create Pull Requests using ScriptRunner for Bitbucket.

The script is available here: https://library.adaptavist.com/entity/create-a-pull-request

Kind regards,

Robert Giddings,

Product Manager, ScriptRunner for Bitbucket

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, jira cloud certification, managing jira projects, jira project administration, jira cloud exam, atlassian certification, agile project management, jira workflows, jira permissions, jira training, jira cloud skills, atlassian learning

Become a Certified Jira Service Project Expert 🦸🏻‍♂️

Validate your expertise in managing Jira Service Projects for Cloud. Master configuration, optimize workflows, and manage users seamlessly. Earn global 🗺️ recognition and advance your career as a trusted Jira Service management expert.

Get Certified! ✍️
AUG Leaders

Atlassian Community Events