Each CODEOWNERS rule names a workable number of owners
ownership/owners-per-rule@v1
Every rule in CODEOWNERS names at least the minimum owners and no more than the maximum, so review is neither one person's bus factor nor everybody's problem.
| Id | ownership/owners-per-rule |
| Version | v1 |
| Category | ownership |
| Default severity | warning |
| Interpreter | python3 |
| Timeout | 30 seconds |
| Violations tolerated | 0 |
| Collects | codeowners |
Collectors
This guardrail gathers nothing itself. It depends on the collectors below, which the CLI runs once per build before any check, and reads what they found out of GUARDRAIL_FACTS. A collector that collects nothing skips this guardrail rather than failing it.
| Collector | Gathers | Inputs it is given |
|---|---|---|
codeowners | The CODEOWNERS file the repository carries, read as rules rather than as text: every pattern in file order with the owners it names, how many rules each owner is named by, and the owners that apply to the paths a guardrail asks about, resolved the way GitHub resolves them, where the last rule to match a path is the one that owns it. | none |
The inputs above are this guardrail's own, passed straight through. Configuring one in buildnote.json changes what is collected, and two guardrails configured the same way share the one collection.
Configuration
{
"guardrails": {
"failOn": "error",
"comment": true,
"checks": [
{
"use": "ownership/owners-per-rule@v1",
"severity": "warning",
"with": {
"minOwners": "1",
"maxOwners": "5"
},
"exemptions": []
}
]
}
}Inputs
| Input | Description | Default | Environment variable |
|---|---|---|---|
minOwners | Fewest owners a rule may name. A rule naming none is left to ownership/no-unowned-rules. | 1 | GUARDRAIL_INPUT_MINOWNERS |
maxOwners | Most owners a rule may name. 0 means no ceiling. | 5 | GUARDRAIL_INPUT_MAXOWNERS |
How to fix
Adjust the rules named in the violations. One owner is a single point of failure: when they are on leave the path is unreviewable. A long list is the opposite failure, because the forge requests all of them and each assumes another will pick it up.
A team owner counts as one:
/api/ @acme/backendwhich is usually the right answer, because membership then lives in the team rather than in this file.
More in ownership
ownership/catch-all-rule.CODEOWNERSdeclares a rule matching every path, so a file nobody thought about still has an owner.ownership/codeowners-parses. Every line ofCODEOWNERSthat is not a comment reads as a rule, so no ownership is silently lost to a line the forge ignores.ownership/codeowners-present. The repository carries aCODEOWNERSfile naming at least one rule, so every change has somebody to review it.ownership/no-unowned-rules. No rule inCODEOWNERSnames an empty set of owners, which would take ownership away from everything it matches.ownership/team-owned. Every rule inCODEOWNERSnames at least one team, so ownership survives the people currently in it.