thiagowfx's avatar

¬ just serendipity 🍀 (not just serendipity)

GitHub Distributed CODEOWNERS

• 212 words • 1 min • updated

⚠️ This post is over one year old. It may no longer be up to date or relevant. Opinions may have changed.

We recently adopted Andrew Ring’s “Distributed CODEOWNERS” (github) in some parts of our codebase.

You know the concept of OWNERS if you’ve worked at Google, or in the Chromium codebase. As far as I know, they were the pioneers of this concept.

Outside Google, GitHub has popularized it with CODEOWNERS. It’s pretty much the same concept, it’s just implemented differently.

Google #

You have distributed OWNERS files throughout the whole repository. For example:

java/
  OWNERS (a)
  project1/
    OWNERS (b)
  project2/
    OWNERS (c)

OWNERS in (b) have CL (ChangeList) / PR (Pull Request) approval permissions for java/project1, but not for java/project2.

OWNERS in (a) have approval permissions for both projects.

GitHub #

There’s a single .github/CODEOWNERS file that controls the whole repository:

* a
/java/project1 b
/java/project2 c

Distributed CODEOWNERS #

What if we wanted to adopt the Google approach in GitHub? Use Andrew’s tool!

What does it do? It collects all scattered OWNERS in the repository and consolidates them in a single .github/CODEOWNERS file, expected by GitHub. Win-win!

I like to adopt it with a pre-commit hook:

yaml
repos:
  - repo: https://github.com/andrewring/github-distributed-owners
    rev: v0.1.9
    hooks:
      - id: github-distributed-owners
        files: .*/OWNERS$|^\.github/CODEOWNERS$

Then it gets automatically managed via CI and/or local commits. It can also be triggered manually with:

shell
pre-commit run -a github-distributed-codeowners