Define what part of the code is owned by whom, and your team:

  1. Helps to find out who should review which PR, thanks to the automatic assignment of Code Owners as reviewers to your pull requests.

  2. Can require reviews and approvals for PRs, enforced with flexible Merge Checks based on the active Code Owners. (optional)

Want to try it out first? Access the interactive playground where you can check your Code Owner rules.

Owner rule: What? is owned by Who?

For the file pattern, the app uses the syntax of Bitbucket’s branch permission patterns.

For details, check https://confluence.atlassian.com/bitbucketserver050/branch-permission-patterns-913474681.html

Example

CODEOWNERS:

**/*.java @james_gosling
**/*.scala @martin_odersky
jvm/**/*.java @brian_goetz

PR diff:

jvm/Unsafe.java
scala-compiler/AST.scala

Gives active rules and Code Owners for this PR:

**/*.scala @martin_odersky
jvm/**/*.java @brian_goetz


The active Code Owners:

are added as reviewers on PR creation/updates.

Full CODEOWNERS reference

# Put this in a file called CODEOWNERS.
# Lines starting with # are comments.

# Every rule line is a file pattern that is followed by one or more code owners.

# This user will be the default owner for everything in the repo.
*                        @PeterTheHacker

# Ordering is important! The last matching file pattern has the highest precedence.
# So if only a Java file is in the pull request, PeterTheJavaExpert is the code owner
# and not the default owner PeterTheHacker.
*.java                   @PeterTheJavaExpert

# If you want, you can define your own code owner groups instead of using Bitbucket groups.
# This will define a new group MyDevs, both including users and other groups:
@@@MyDevs                @PeterTheHacker  @PeterTheJavaExpert ann@scala.lang @@JSDevs

# For Bitbucket users and groups with spaces in their name, put them into double quotes.
*.ts                     @"Paul the JSGuru" @@"Dev Ops Team"


# When your glob expression contains spaces, put the glob into double quotes.
"a/path with spaces/*"   @AnnTheScalaPro

# AnnTheScalaPro is the code owner of all files in the /src/main/scala directory at
# the root and all its descendants (e.g., /src/main/scala/com/x/y/z.scala).
/src/main/scala/         @AnnTheScalaPro

# ci/* will match all files in the directory ci, but not deeper in
# the directory hierarchy (so ci/jobs/prod.yml will not match).
ci/*                     @devops

# You can use '!' for negation in front of file pattern without any code owners afterwards,
# to unset all previously defined code owners of the files.
# e.g. devops group wants to review everything under ci (as defined above),
# except ci/playgrounds.yml, which nobody needs to review:
!ci/playgrounds.yml

# It's also possible to use double-asterisk globs. Here's an example that will match
# all JS files under /src/components.
src/components/**/*.js   @@MyDevs

# GroovyMaster owns any files in the groovy directory anywhere in the
# file tree (e.g., src/main/groovy/com/x/y/z.groovy).
groovy/                  @GroovyMaster

# Files starting with a `#` or a `!` can still be used by escaping them.
\#myfile.rb              @PeterTheHacker
\!yourfile.rb            @PaulTheJSGuru

# It is important to protect CODEOWNERS file as well because otherwise it can get deleted
# or moved within a pull request; so we want to assign a code owner to it which can prevent this
CODEOWNERS               @CTO

Â