How to get names of users that updated a pull request.

prayag singh November 13, 2018

I have written a script for merge check that prevents a reviewer from approving the pull request IF THIS USER HAS UPDATED THE PULL REQUEST, like made a commit.

Below is the code for that:

import com.atlassian.bitbucket.auth.AuthenticationContext
import com.atlassian.bitbucket.scm.pull.MergeRequest
import com.atlassian.sal.api.component.ComponentLocator

def authenticationContext = ComponentLocator.getComponent(AuthenticationContext)

def user = authenticationContext.currentUser
def mergeRequest = mergeRequest as MergeRequest
def pullRequest = mergeRequest.getPullRequest()


def authoredByRequestor = pullRequest.commitAuthors.contains(user)
def approvedByOthers = pullRequest.reviewers.findAll {it.approved}.any {it != user}

def forbidden = authoredByRequestor && !approvedByOthers

return !forbidden

 

I am not sure, why I am getting error in line 

def authoredByRequestor = pullRequest.commitAuthors.contains(user)

 

Static type checking] - You tried to call a method which is not allowed: java.util.Set <E extends java.lang.Object>#contains(java.lang.Object) @ line 12, column 12. def authoredByRequestor = pullRequest.authoredByRequestor.contains(user) ^ 1 error </pre>

 

 

1 answer

0 votes
Ana Retamal
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 15, 2018

Hi Prayag!

I won't be able to help you troubleshooting your script but I wanted to let you know that Bitbucket Server already offers that feature, you can read more about it at Checks for merging Pull requests.

If you need more help, I'll advise you to visit the Developer Community, wehre you'll find a larger dev audience. 

Hope that helps!

Ana

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events