Define what part of the code is owned by whom, and your team:
Helps to find out who should review which PR, thanks to the automatic assignment of Code Owners as reviewers to your pull requests.
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?
The syntax for owner rules is simple
<members> can consist of one or more user/group identifiers
@<username>for single users
@@<groupname>for groups. Can be either:
- names with spaces need to be in double quotes
@"<user with spaces>"
<filepattern> follows the same convention as the
.gitignore file. For example, this is the behaviour for the following patterns:
*everything in the repository
**/*.javaall java files
ci/*all files in directory ci without sub directories
frontend/all files in directory frontend with sub directories
!ci/playgrounds.ymlexclude code owners for selected files
- files starting with
!can still be used by escaping them
Ordering is important! The last matching file pattern has the highest precedence. Generic rulse should be put first, followed by more specific rules.
The syntax to create custom groups is
For the file pattern, the app uses the syntax of Bitbucket’s branch permission patterns.
**/*.java @james_gosling **/*.scala @martin_odersky jvm/**/*.java @brian_goetz
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 email@example.com @@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