Sub topic 7
How owners are requested automatically
This chapter assumes you can read a CODEOWNERS file, including owner syntax and the rule that the last matching pattern wins. It also assumes you know how pull requests move from draft to ready for review.
What GitHub does
When a pull request is opened, GitHub compares the list of changed files with the CODEOWNERS file. For each changed file, it finds the last matching pattern and takes the owners listed on that line. It then requests a review from each of those owners.
Requesting a review is not the same as requiring one. The request puts the pull request in the owner's review queue and sends a notification. The owner can still ignore it, and the pull request can still merge unless branch protection or a ruleset requires code owner review. Those settings are covered in later chapters.
A worked example
Take this CODEOWNERS file:
* @example-org/maintainers
/apps/web/ @example-org/web-team
/apps/web/auth/ @example-org/securityA pull request changes three files:
| Changed file | Last matching pattern | Owner requested |
|---|---|---|
| README.md | `*` | @example-org/maintainers |
| apps/web/page.js | `/apps/web/` | @example-org/web-team |
| apps/web/auth/login.js | `/apps/web/auth/` | @example-org/security |
The pull request gets three review requests. The maintainers are not requested for apps/web/auth/login.js, because the later pattern replaced the fallback for that file.
Conditions that affect requests
- Draft pull requests. Owners are not requested while the pull request is a draft. The requests are sent when you mark it ready for review.
- Write access. An owner must have write access to the repository. A user or team without it is skipped, even if the name is spelled correctly.
- The author. You are not asked to review your own pull request, even if you own the changed files.
- Teams. A team must be visible and have write access. If the team has code review assignment enabled, GitHub may route the request to individual members instead of notifying everyone.
- Unowned files. A file matched by a pattern with no owners, or by no pattern at all, produces no request.
Checking the result
Open the pull request and look at the Reviewers sidebar. Owners requested through CODEOWNERS appear there with a note that they were requested because they are code owners. If an expected owner is missing, check these in order:
- Is the pull request still a draft?
- Does the owner or team have write access?
- Does a later pattern override the one you expected?
- Is the file path covered by a pattern at all?
Exercise
A CODEOWNERS file contains *.js @example-org/frontend followed by /scripts/ @octocat. A pull request changes scripts/build.js. Who is requested to review, and what happens if the pull request is a draft?
Show answer
Only @octocat is requested, because /scripts/ is the last pattern that matches scripts/build.js and it replaces the *.js line. If the pull request is a draft, no one is requested until it is marked ready for review. @octocat must also have write access and must not be the pull request author.