It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Block pull requests between branch types

My organization uses Stash v3.11.1 and the plugin Adaptavist ScriptRunner. An issue has recently come up where we want to prevent the user from creating pull requests between certain branches with a given prefix. 

For example we want to block any branch with the prefix "team/" from being able to be merged into a branch that is prefixed with "release/"

 

team/a_team_branch ---> release/v1.0    would be blocked and pull request not created

bugfix/a_users_bugfix_branch ---> release/v1.0     a pull request could be created

 

How would I go about doing this with ScriptRunner?

1 answer

You want Admin -> Script Event Handlers, new Custom event handler.

Event to listen for is: PullRequestOpenRequestedEvent

Code (put in file or enter directly):

import com.atlassian.bitbucket.event.pull.PullRequestOpenRequestedEvent

def event = event as PullRequestOpenRequestedEvent
def from = event.pullRequest.fromRef.displayId
def to = event.pullRequest.toRef.displayId

if (from.startsWith("team/") && to.startsWith("release/")) {
    event.cancel("Don't create PR from team/* to release/* ... target branch should be Xyz")
}

Should result in:

http://postimg.org/image/aafyd6ykt/

(image upload seems broken).

 

 

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published Mar 14, 2019 in Bitbucket Pipelines

Building a Bitbucket Pipe as a casual coder

...ipe.sh :  #!/bin/bash source "$(dirname "$0")/common.sh" enable_debug extra_args="" if [[ "${DEBUG}" == "true" ]]; then extra_args="--verbose" fi # mandatory variables R...

985 views 1 16
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you