Hi Folks, and especially @Robert Giddings _Adaptavist_ !
I'll split the global task in three smaler.
1. We need to read a content of .yml file that is located in the root. There we need to find a row with "verConfigRefs: - release/13.01.00.x" and after that get only the "13.01.00.x" value.
2. After that we need to check if a current user is a member of any group with pattern "13.01.00.x".
3. If Yes, we allow them to Merge.
I've found a solution or solved particularly for all small tasks and I need your precious help to combine them and get the final result.
With part 1 I found "Load content of JSON file from Pull Request" example. But I need to test it and have it worked. How can I use the similar code inside of Script Console to get Content of file and maybe to try to get the required parameter?
With part 2 I've checked these two scripts and them works. Could you check everything is ok?
This script to compare group name and prefix:
import java.util.regex.Matcher
import java.util.regex.Pattern
def text = "group_prefix"
Matcher m = text =~ /prefix/
if (m) {
true
}
And this one to get list of user groups:
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.bitbucket.user.UserService
import com.atlassian.bitbucket.auth.AuthenticationContext
import com.atlassian.crowd.manager.directory.DirectoryManager
import com.atlassian.crowd.search.query.entity.GroupQuery
import com.atlassian.crowd.model.group.GroupType
import com.atlassian.crowd.search.query.entity.restriction.TermRestriction
import com.atlassian.crowd.search.query.entity.restriction.PropertyImpl
import com.atlassian.crowd.search.query.entity.restriction.MatchMode
import com.atlassian.crowd.search.query.membership.MembershipQuery
import com.atlassian.crowd.search.builder.QueryBuilder
import com.atlassian.crowd.search.query.entity.UserQuery
import com.atlassian.crowd.search.EntityDescriptor
import com.atlassian.crowd.model.user.Users
import com.atlassian.crowd.model.group.Membership
import com.atlassian.bitbucket.user.UserSearchRequest
import com.atlassian.bitbucket.util.PageRequest
import com.atlassian.bitbucket.util.PageRequestImpl
import static com.onresolve.scriptrunner.canned.bitbucket.util.BitbucketCannedScriptUtils.unlimitedPager
def dm = ComponentLocator.getComponent(DirectoryManager)
def dir = dm.findAllDirectories().find {it.name == "Bitbucket Internal Directory"}?.id
def us = ComponentLocator.getComponent(UserService)
us.findGroupsByUser("slava", getUnlimitedPager()).values
One question here: Why findGroupsWithUser() function is not working for us? It allows to filter groups of user by specified name. And maybe with this function I could check if a user already a member of a group without matching strings. But it is not a blocker in final solution.
And with part 3 I already set the conditional merge check if user is a member of specific group then allow them to click on the Merge button.
To summarize: Could you help with a final script and to combine all the things above?
Thank you in advance!
With kind regards
Slava