Testing your GitHub CODEOWNERS file

Just in case you missed it

I just realized after a few months that our GitHub code owners file wasn’t properly covering our migration files. I trust our code owners, and the misconfiguration is purely my fault. And, luckily, we didn’t lose any data to my mistake. No harm, no foul.

But now it’s time to get serious with this. I made the change expecting it to work one way, but it worked another way. I didn’t test it. To fix it, the first step is asking “How do I test it?” Turns out, there’s a package for that!

  • Write your CODEOWNERS file
  • Run npx github-codeowners audit -r path/to/files/to/check

Your output will show the file or files to the left, and the owner or owners to the right!

$ npx github-codeowners audit -r api/directory/cdc
...
api/directory/cdc/users/task.ts                             @MyCompany/architecture
api/directory/cdc/users/validateAvatarExists.test.ts        @MyCompany/architecture
api/directory/cdc/users/validateAvatarExists.ts             @MyCompany/architecture
$ npx github-codeowners audit -r api/directory/cdc
...
$ npx github-codeowners audit -r packages/meet-up
packages/meet-up/.turbo/turbo-gql:generate.log                  @MyCompany/general-codeowners
packages/meet-up/codegen.yml                                    @MyCompany/general-codeowners
packages/meet-up/generated/apiHooks.tsx                         @MyCompany/general-codeowners
packages/meet-up/helpers/SyncUpsMocks.tsx                       @MyCompany/general-codeowners
...
packages/meet-up/package.json                                   @MyCompany/dependency-oversight

With a little additional effort, you can even write unit tests for this.

Now, go forth and defer your code reads to domain experts! 😎