コード所有者

As your team and products grow, expertise in areas of your code base can be fragmented between different members of the team. This can make finding the right people to notify or request reviews on changes difficult. Now, you can add code owners to your repository as a way for developers to maintain ownership over different areas of the code base. Code owners will be automatically added to pull requests in the areas of the code base they own.

When creating a new pull request, Bitbucket will automatically check if a CODEOWNERS file exists in the repository. Bitbucket checks for this file in the .bitbucket folder. If the file is found, every rule in that file is compared to the diff of your pull request. For each matching rule, the users associated with it are automatically added as suggested reviewers.


On this page:

As code owners is a branch-based config, you can have different code owners on different branches. Bitbucket will always use the CODEOWNERS file on the target branch of your pull request.

The CODEOWNERS file

Create the CODEOWNERS file under the .bitbucket folder, on your branch of choice. Compose the file using the following rules:

  • Every code owner rule should be declared on a separate line.

  • A code owner rule is composed of branch patterns referring to a path in the repository followed by any number of users.

  • Users are specified either by email or usernames prepended with the @ character.

  • Users must have the repository read permission in the target repository. Invalid identifiers or users without permission won’t be added.

  • Comments can be declared on a line starting with the # character.

  • The CODEOWNERS files are read from the bottom to the top. So, the last rule in the file has the highest precedence. 

Here’s an example of the CODEOWNERS file:

# Comments in a CODEOWNERS file are prepended with the '#' character.
# Empty lines are also ignored.
 
# One code owners rule is used for each changed file in a pull request.
# Rules at the bottom take precedence over rules at the top, so this rule will
# only be applied if no other rules match a given change in the pull request.
# The following rule matches all changes in the repository, so unless a rule
# lower in the file matches, globalowner will always be suggested as a code
# owner.
** globalowner@example.com
 
# Email addresses and Bitbucket usernames can both be used when specifying code owners:
/features/FeatureCode.java @developer-1 developer-2@example.com
 
# Branch patterns can match specific paths in your repository, or file types, or both.
# The following pattern will match all CSS files in the repository:
**.css @developer-1
 
# The following pattern will match every file in the app/frontend directory and all
# subdirectories:
app/frontend/ @developer-2
 
# The following pattern will match every CSS file in the app/frontend directory and all
# subdirectories:
app/frontend/**.css @developer-3
 
# A rule with a path and no owners is still matched and can be used to prevent code owners
# from being added for a given file. In the following pattern, changes made in the docs
# directory will include content-designer as a code owner.
# If those changes are in images, no reviewer is added.
docs/** @content-designer
docs/images/**

Limits

The maximum size of the CODEOWNERS file is 500 KB. If the size is larger than this, the file won’t be read. You can increase or decrease the maximum file size by changing code.owners.maximum.filesize in shared/bitbucket.properties.

No more than 100 reviewers will ever be added automatically to a pull request regardless of how many rules match. This restriction prevents hundreds of reviewers from being added to large pull requests. You can increase or decrease the reviewer limit by changing code.owners.maximum.users in shared/bitbucket.properties.

Code owners quick add for pull request review

If code owners are set for the destination branch of your draft or regular pull request, they’ll be automatically added to it as reviewers. If you want feedback only from some of the added code owners, keep them and remove the others from the Reviewers field.

If you remove at least one code owner, the Code owners quick add button will appear under the field, showing you how many reviewers you can still add from this group.

最終更新日 2024 年 6 月 6 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.