Snippets

Adaptavist Pull Request Branch Policy

Created by Jamie Echlin
import com.atlassian.stash.event.pull.PullRequestOpenRequestedEvent

PullRequestOpenRequestedEvent event = event

def sourcePattern = ~/\bbugfix\/(.+?)\/.*/
def targetPattern = ~/release\/(.+)/

def sourceID = event.pullRequest.fromRef.displayId
def targetID = event.pullRequest.toRef.displayId


def sourceMatches = (sourceID=~sourcePattern)
def targetMatches = (targetID=~targetPattern)

if (! (sourceMatches.matches() && targetMatches.matches())) {
    event.cancel("Unsupported merge... not sure what you want to happen here?")
    return
}

def sourceBranch = sourceMatches[0][1]
def targetBranch = targetMatches[0][1]

if (sourceBranch != targetBranch) {
    event.cancel("Unsupported merge - can only create a pull request to release/$sourceBranch")
}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.