Get current target branch name in bitbucket [script runner]

xion_admin February 26, 2018

I want to automatically merge a PR, when the target is the "develop" branch.

How can I do this with script runner?

I have found the script event handlers and the "Auto merge of pull request" event.

However, I do not find the target branch name, nor the source branch name.

 

1 answer

0 votes
adammarkham
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 26, 2018

In the "Auto merge of pull request" event handler you can add the following condition to only merge for the branch called "develop":

event.pullRequest.toRef.displayId == "develop"

You can change develop to whatever branch name if you want to include other ones to.

For multiple branches you can use:

event.pullRequest.toRef.displayId in ["develop", "feature"]

 

xion_admin February 28, 2018

@adammarkham


The "mergeRequest" object is not defined. Furthermore, it will not merge my PR, because the inbuild "minimum approved reviewer" number is not reached.

adammarkham
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 28, 2018

Apologies for some reason I was thinking this was a merge request. I've updated the example in my answer.

To get around the minimum approvers issue, you could just move to using the script merge check ScriptRunner provides here.

Then your condition for the "Require a number of approvers" merge check can be:

mergeRequest.pullRequest.toRef.displayId != "develop"

Therefore the minimum number of reviewers will only be enforced for those branches that are not being auto merged. In this case anything other than "develop".

Hope this helps and let me know how you get on with that.

Hamdy Atakora February 3, 2021

@xion_admin  @adammarkham do you guys know how i can also check if the pull request contains files with a certain types of extensions? I a writing a listener to p[perform some action but i cannot get this part right. Help is very much appreciated. Thanks

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events