The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

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

Script Runner Merge Check: Code Snippets for approvers is not working

Michelle Geppert
February 2, 2022

I created a conditional merge check.  Then I copy in either the "Named user approves" or "At least one user from experienced developers group has approved" code snippet and my pull request can still be merged in despite the condition not being met.  I copy in the "Target branch is master" code and that blocks my code merge.  What do I need to change to make these work? 

 

mergeRequest.pullRequest.reviewers.find {it.approved && it.user.name == "seniordev"}

 

and

 

import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.bitbucket.user.UserService

def userService = ComponentLocator.getComponent(UserService)
mergeRequest.pullRequest.reviewers.findAll { it.approved }.any {
userService.isUserInGroup(it.user, "experienced-developers")
}

 

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
Answer accepted
Michelle Geppert
February 21, 2022

The group didn't exist in the scope I was using.  To check that,  you use

import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.bitbucket.user.UserService
import com.atlassian.bitbucket.hook.repository.RepositoryHookResult

def userService = ComponentLocator.getComponent(UserService)
if (userService.existsGroup("experienced-developers")) {
   RepositoryHookResult.rejected("Merge rejected", "exists")
} else {
   RepositoryHookResult.rejected("Merge rejected", "does not exist")
}

TAGS
AUG Leaders

Atlassian Community Events