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>
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
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.