Skip to main content

Module codeowners

Module codeowners 

Source
Expand description

CODEOWNERS file parser and ownership lookup.

Parses GitHub/GitLab-style CODEOWNERS files and matches file paths to their owners. Used by --group-by owner to group analysis output by team ownership.

§Pattern semantics

CODEOWNERS patterns follow gitignore-like rules:

  • *.js matches any .js file in any directory
  • /docs/* matches files directly in docs/ (root-anchored)
  • /* matches root-level files only; * is the catch-all
  • docs/ matches everything under a docs/ directory at any depth
  • /docs matches a file docs or everything under the docs/ directory
  • * does not match /
  • Last matching rule wins
  • First owner on a multi-owner line is the primary owner

§GitLab extensions

GitLab’s CODEOWNERS format is a superset of GitHub’s. The following GitLab-only syntax is accepted (though it doesn’t affect ownership lookup beyond propagating the default owners within a section):

  • Section headers: [Section name], ^[Section name] (optional section), [Section name][N] (N required approvals)
  • Section default owners: [Section] @owner1 @owner2. Pattern lines inside the section that omit inline owners inherit the section’s defaults
  • Exclusion patterns: !path clears ownership for matching files (GitLab 17.10+). A negation that is the last matching rule for a file makes it unowned.
  • Repeated section names: headers with the same name, compared without case, form one section. The section keeps the name of its first header. Its default owners are the default owners of all its headers, in file order, each one time. A pattern line without inline owners inherits the default owners of the header directly above it.

Structs§

CodeOwners
Parsed CODEOWNERS file for ownership lookup.
RuleMatch
The last CODEOWNERS rule that matches a path.

Constants§

NO_SECTION_LABEL
Label for files owned by a rule declared before any GitLab section header.
UNOWNED_LABEL
Label for files that match no CODEOWNERS rule.

Functions§

directory_group
Extract the first path component for --group-by directory grouping.