Skip to content

Instantly share code, notes, and snippets.

@Kahbazi
Last active June 30, 2021 17:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save Kahbazi/512ac4231cc8458adbfacad047652ca8 to your computer and use it in GitHub Desktop.
Save Kahbazi/512ac4231cc8458adbfacad047652ca8 to your computer and use it in GitHub Desktop.
Code Owners in Bitbucket with ScriptRunner
  • Install ScriptRunner package.
  • In Repository Settings, choose Script Merge Checks
  • Add a Conditional merge check
  • Add this script in condition
def rule1 = [
    owners:["kahbazi"],
    path:"ProjectA/**",
    branch: "master"
]

def rule2 = [
    owners:["kahbazi"],
    path:"ProjectB/**",
    branch: "master"
]

def rules = [rule1, rule2]

records.any { record->
    ((String[])record["owners"]).every { mergeRequest.pullRequest.author.user.name != it } &&
	mergeRequest.pullRequest.toRef.displayId == record["branch"] &&
	pathsMatch('glob:' + record["path"]) &&
	!mergeRequest.pullRequest.reviewers.find {it.approved && ((String[])record["owners"]).contains(it.user.name)}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment