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

ScriptRunner Groovy script to require at least one approver from a list.

Matthew Charles Sep 15, 2016

Hello all,

I'm wanting to have a merge check that requires at least one of the approvers to be in a list.

I tried something like this as a conditonal but for whatever reason it's not behaving like I expected.


def ops_team = ['Spongebob', 'Squidward', 'Patrick']
mergeRequest.pullRequest.reviewers.find {it.approved && it.user.name in ops_team}


Any ideas?

1 answer

1 vote
JamieA Sep 19, 2016

Sorry about the delay... if you use the plugin's tag you will get a faster response. I added it now.

The only problem with your code is that you need to call .veto on the mergeRequest to block it, as described in Working with Custom Merge Checks.

I rewrote your code as the following and it worked:

import com.atlassian.bitbucket.scm.pull.MergeRequest

def mergeRequest = mergeRequest as MergeRequest
def ops_team = ['Spongebob', 'Squidward', 'Patrick', 'admin']

def ok = mergeRequest.pullRequest.reviewers.any {it.approved && it.user.name in ops_team}

if (! ok) {
    mergeRequest.veto("Ops approval required", "Need at least one member of Ops to approve")
}

 

 

 

 

Matthew Charles Sep 20, 2016

Thank you for the reply!

 

One shortcoming I noticed is that this way requires a member to listed as a reviewer, as opposed to being 'just' approver.

 

Would something like this work:

 

def ok = mergeRequest.pullRequest.approvers.any { it.user.name in ops_team}

 

 

Adam Markham [Adaptavist] Community Leader Sep 21, 2016

Hi Matthew,

I'm not sure what your asking, a pull request just has reviewers which can approve it.

Can you explain a bit more how you would like the merge check to behave?

Thanks,
Adam 

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 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...

1,865 views 1 19
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you