hi, i'm patience!

TIL: CLI tools for managing Github codeowners locally

tools

github

open source

The codeowners CLI tool is super useful for inspecting who owns specific files:

> codeowners path/to/files/*.py
path/to/files/a.py            @ateam
path/to/files/b.py            @bteam

You can also ensure newly added files have codeowners assigned using a pre-commit hook in the pre-commit yaml config file:

- id: codeowners-new
  name: Check newly added files have codeowners
  language: system
  stages: [pre-commit]
  entry: >
    bash -c 'git diff --cached --diff-filter=A --name-only | xargs codeowners | grep -F "(unowned)"
    && exit 1 || exit 0'

After making a codeowner change, you can check the results using the codeowners-diff tool:

> codeowners-diff
2 files have changed ownership:

| file                         | `HEAD`   | working tree               |
|:-----------------------------|:---------|:---------------------------|
| `path/to/files/a.py`         |          | @ateam                     |
| `path/to/files/b.py`         |          | @bteam                      |