CodeOwner is a mechanism used to specify the owners of specific files or file types, allowing review tasks to be automatically assigned in scenarios such as code reviews and merge requests.
CodeOwner
In Code Review, authors often struggle to identify the best reviewers. CodeOwner addresses this by using a CODEOWNERS file to explicitly define the responsible individuals for each file or module. This file is placed in the root directory of the branch, and the system automatically matches reviewers based on its contents. Once CodeOwner is enabled, the system searches for the CODEOWNERS file in the root directory of the target branch and reads its settings.
If a file has only one owner, the review of that owner is mandatory.
If a file has multiple owners (such as A, B, and C), approval from any one of them suffices. The system automatically detects and adds the relevant owners to the review list.
When no matching owner is found, at least one person must review as a fallback. The system adheres to the most specific and explicit rule for file matching, with one rule per file.
Assume the CODEOWNERS file defines the following paths:
f.txt precisely matches the **@user1 rule.
aa/f.txt precisely matches the aa/**@user2 rule.
aa/mm/f.txt precisely matches the aa/mm/**@user3 rule.
bb/f.txt precisely matches the bb/**@user4 rule.Each file can be matched to an appropriate rule, making the process more efficient and precise.

In the CODEOWNERS file, path definitions use Glob patterns, similar to the find command of Linux or the .gitignore rules of Git. Owners are specified using @username, where username must be a verified primary email address. To check the primary email address, navigate to .

Example:
# Comment line. The configuration content is as follows. Each line represents one configuration.
# After a path rule, one or more Owners must be configured.
# Users A@example.com and B@example.com are CodeOwners for all files.
** @A@example.com @B@example.com
# User C@example.com is the CodeOwner for all Java files.
**.java @C@example.com
# Users D@example.com and E@example.com are CodeOwners for files under the force-api directory.
force-api/** @D@example.com @E@example.com
# User F@example.com is the CodeOwner for files under the force-base/src/main/java directory.
force-base/src/main/java/** @F@example.com