Skip to content

About

👁 audit your CODEOWNERS file

Resources

Stars

73 stars

Watchers

1 watching

Forks

Repository files navigation

codeowners

A tool for working with CODEOWNERS files from GitHub, GitLab, and Bitbucket. Usable as a CLI or as a library, with no dependencies.

installation

npm install -g codeowners

Requires Node.js 22.12 or later.

cli usage

List each file in the current repository with its owners:

codeowners audit

audit lists the files git knows about: tracked files, plus untracked files that .gitignore does not exclude. Outside a git repository, or with --include-ignored, it walks the filesystem instead, skipping node_modules, .git and .cache.

List only the files no one owns:

codeowners audit --unowned

Use a non-standard CODEOWNERS file name:

codeowners audit -c CODEKEEPERS

Verify that users or teams own a path (exits 1 if none of them do):

codeowners verify src/ @foob_ar @contoso/engineers

List the owners of a path:

codeowners list src/index.js

Every command takes -d, --dialect <github|gitlab> to choose the CODEOWNERS syntax.

library usage

const Codeowners = require('codeowners');

// workingDir is optional and defaults to process.cwd()
const repos = new Codeowners(workingDir);
repos.getOwner('path/to/file.js'); // => ['@noahm']

// or parse contents directly
const rules = Codeowners.parse(fs.readFileSync('CODEOWNERS', 'utf8'));
rules.getOwner('path/to/file.js');

new Codeowners() searches upward from the working directory, checking .github/, .gitlab/, .bitbucket/, the directory itself, and docs/ at each level. Paths passed to getOwner are relative to the project root (repos.codeownersDirectory), or absolute.

dialects

GitHub and GitLab read the same file differently, so the parser has a dialect. It defaults to GitLab for a file in .gitlab/ or one with [Section] headers, and GitHub otherwise. Override it with new Codeowners(dir, 'CODEOWNERS', { dialect: 'gitlab' }) or Codeowners.parse(text, { dialect }).

GitHub GitLab
docs/a.md (slash in the middle) anchored to the root matches at any depth
docs (no trailing slash) the file, or everything in the directory only a file named docs
docs/* direct children only direct children only
/docs/** everything inside one level, like *
[abc] literal brackets character class
!pattern invalid, skipped excludes matching paths from the section
# comment after owners ignored owners in it are still read
[Section] headers not supported owners combine across sections

Both match case-sensitively and treat \ as an escaped space.

development

pnpm install
pnpm test        # vitest
pnpm coverage    # fails below 100% coverage
pnpm lint        # eslint, prettier, and tsc
pnpm bench       # getOwner over 2,000 rules and 200,000 paths

CHANGELOG

6.0.0

  • Patterns follow GitHub's CODEOWNERS rules: docs/* and /* match direct children only, matching is case-sensitive, and \ escapes a space.
  • GitLab syntax: sections, section default owners, optional sections, approval counts, ! exclusions, and character classes.
  • Bitbucket's .bitbucket/CODEOWNERS location is found.
  • Lookups are about 75 times faster on large CODEOWNERS files.
  • Memory use stays flat however many paths are checked.
  • Pattern matching runs in linear time, so a hostile CODEOWNERS file cannot stall it.
  • Inline # comments are skipped when reading owners, and exposed as each entry's comment.
  • audit skips files ignored by git and includes untracked files git would commit.
  • audit lists files only, sorted, and escapes control characters in file names and owners.
  • audit lists symlinks instead of following them.
  • audit runs with git's core.fsmonitor disabled, so an audited repository cannot run commands.
  • audit runs git from an absolute path on PATH, so a git program inside the audited repository is never run.
  • New list command prints the owners of a path.
  • New Codeowners.parse() parses CODEOWNERS contents without the filesystem.
  • New -d, --dialect option and dialect library option.
  • Windows paths work in getOwner and in finding the project root.
  • Error messages name the requested CODEOWNERS file name.
  • No runtime dependencies.
  • Requires Node.js 22.12 or later.

5.0.0

  • Much-improved performance
  • Removal of automatic column width calculation
  • Addition of -w/--width option for manual column width
    • Or use e.g. codeowners audit | column -ts " "

About

👁 audit your CODEOWNERS file

Resources

Stars

73 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages