All Products
Search
Document Center

Apsara Devops:Codeowner mechanism

Last Updated:Mar 12, 2025

The CodeOwner review pattern is a system for assigning file or file type ownership, enabling automatic review task allocation in scenarios like code reviews and merge requests.

Code review review pattern

During code reviews, authors may struggle to select the most suitable reviewer. The CodeOwner review pattern addresses this by using a CODEOWNERS file to define ownership for each file or module. This file is located in the root directory of the branch, allowing the system to automatically match reviewers to it. When CodeOwner review is activated, the system searches for the CODEOWNERS file in the target branch's root directory and reads the configurations.

  • A file with a single owner requires their mandatory review.

  • For files with multiple owners, such as A, B, or C, approval from any one owner suffices. The system automatically identifies and adds the relevant owners to the review list.

  • If no matching owner is found, the file requires at least one reviewer as a fallback. The system adheres to the most specific and explicit rule for file matching, with one rule per file.

Consider the following paths defined in the CODEOWNERS file:

f.txt  precisely corresponds to **@user1 rule
aa/f.txt  precisely corresponds to aa/**@user2 rule
aa/mm/f.txt  precisely corresponds to aa/mm/**@user3 rule
bb/f.txt  precisely corresponds to bb/**@user4 rule

Each file can be associated with a suitable rule, streamlining the process for greater efficiency and accuracy.

高的 (12).png

In the CODEOWNERS file, path definitions utilize Glob syntax, akin to the Linux find command or Git's .gitignore patterns. Specify the owner with @username, where username must be a verified primary mailbox. To check the primary mailbox, go to Personal Settings > Personal Information.

高的 - 2024-12-27T103315

The example below illustrates this:

# Comment line, the following is the configuration text, each line represents a configuration.
# After a path rule, there must be one or more owners

# User A@example.com, B@example.com as CodeOwner for all files
** @A@example.com @B@example.com

# User C@example.com as CodeOwner for all java files
**.java @C@example.com

# Users D@example.com, E@example.com as CodeOwner for files under the force-api directory
force-api/** @D@example.com @E@example.com

# User F@example.com as CodeOwner for files under the force-base/src/main/java directory
force-base/src/main/java/** @F@example.com

References

Branch Settings