The CodeOwner review mode lets you specify owners for specific files or file types to automatically assign reviewers for code reviews and merge requests.
Code review mode
The CodeOwner review mode uses a CODEOWNERS file to define who is responsible for each file or module. Place this file in the root directory of a branch. When CodeOwner review is enabled, the system automatically matches reviewers based on the CODEOWNERS file in the target branch.
-
If a file has only one owner, that owner must approve the changes.
-
If a file has multiple owners, such as A, B, and C, approval from any one of them is sufficient. The system automatically adds the relevant owners to the reviewer list.
-
If no matching owner is found, a review from at least one person is required. If multiple patterns match a file path, the last matching pattern in the CODEOWNERS file takes precedence.
For example, consider the following paths defined in a CODEOWNERS file:
f.txt matches the ** @user1 rule
aa/f.txt matches the aa/** @user2 rule
aa/mm/f.txt matches the aa/mm/** @user3 rule
bb/f.txt matches the bb/** @user4 rule
Each file matches the most appropriate rule, making the review process more efficient and precise.
On the Branch Settings page of your repository, select the target protected branch, such as feature/sensitive_scan, and modify its protection rules. In the dialog box, turn on Require code review before merging, select Require all comments to be resolved, and set the review mode to CodeOwner.
Paths in the CODEOWNERS file use glob patterns, similar to the Linux find command or Git's .gitignore rules. Use the format @username to specify an owner, where username is the user's verified primary email address. To view your primary email address, navigate to .
On the Personal Settings page, select Personal Information from the left navigation pane. In the Email section, the address labeled Primary Email is your verified primary email address.
For example:
# This is a comment line. The following lines are configuration entries, one per line.
# A path pattern must be followed by one or more owners.
# Assign users A@example.com and B@example.com as CodeOwners for all files.
** @A@example.com @B@example.com
# Assign user C@example.com as the CodeOwner for all .java files.
**.java @C@example.com
# Assign users D@example.com and E@example.com as CodeOwners for files in the force-api/ directory.
force-api/** @D@example.com @E@example.com
# Assign user F@example.com as the CodeOwner for files in the force-base/src/main/java/ directory.
force-base/src/main/java/** @F@example.com