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>