What is CODEOWNERS anyway?
New to the CODEOWNERS file in GitHub - we’ll walk you through it’s value and usage
CODEOWNERS file, when used on GitHub, exists in
repo-name/.github/CODEOWNERS , it is a representation of who knows what about your repository. This file is used by GitHub to enable great automations including: automatically notifying codeowners of new Pull Requests and you can block merges unless a codeowner approves the PR.
Docs from GitHub about
CODEOWNERS can be found here: https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners
CODEOWNERSfile represents the code ownership across the repository.
- Users or teams can own parts of the codebase at the directory or file level
- What does it mean to be a code owner?
- At every organization this is different, but in general this means that if you’re a code owner, you will be the ‘go to’ person for this portion of the code.
- This means that you’ll be the one reviewing PR’s for changes to that code, or if anyone has any questions for that code they’ll be asking you.
- We’ve found that for large organizations this is really helpful! It’s quite common to not know who should review your changes, or even who to ask!
Automatic Pull Request Review Assignment
- In Github you can set up reviewers to be assigned automatically based on code ownership
- Once you have a valid
CODEOWNERSfile, GitHub will automatically start assigning code owners as reviewers 🎉
Blocking Merges by Requiring Code Owner Reviews
If you want to enable blocking merges unless a code owner reviews the PR you can via branch protection rules in GitHub:
For all the details from GitHub directly, checkout their docs here: https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests/about-protected-branches#require-pull-request-reviews-before-merging
And extra detail on using branch protection rules here: https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests/managing-a-branch-protection-rule
No more ‘whoops’ to the critical parts of your code 🔒
Last updated on November 9, 2022