Elegant Way to Add Reviewers for GitHub Pull Request

Bo Liu
Axel Springer Tech
Published in
3 min readJan 8, 2024

Background

After I joined Axel Springer, our WELT team already had 5 iOS guys. Every time we opened a new pull request, we always had to add the rest of the people as reviewers manually one by one. Although adding 4 names was not too complicated thing, I still think there should be some ways which can make it easier.

Initial Idea

I experienced a big iOS team before and we used Bitbucket at that time. To add reviewers easily, we created a group including all iOS guys. When creating a Pull Request, just directly add the group as reviewers. Therefore, I have the same idea for Github. Of course, GitHub has a similar functionality as well, we could create a team under our organization. However, we would face two problems in this way:

1. We already have over 150 teams in our organization, it’s too much. We only use the team to review pull requests in specific repositories. If the creation of new teams continues arbitrarily, it will be a disaster for management in the future and be unnecessary in our case.
2. Only the admin has permission to create teams in GitHub. Obviously, this way is not flexible for most contributors. Once we need to change the list of reviewers, we have to ask Admin colleagues.

## CODEOWNERS file
Our final solution is CODEOWNERS file. It is a simple file including the configuration of reviewers. You can set up specific GitHub accounts or teams as reviewers, and even set which specific files, folders or types which person needs to review. You just need to add it to your repository, then it can automatically add the reviewer by your configuration. Easily to use and flexible.

Here is the docs of CODEOWNERS file. You can find many details on it, but in our case, the steps would be simpler since we already have branch protection and only add some specific accounts.
1. Admin of repository: Click Settings -> Branches
2. Admin of repository: Tick: Require review from Code Owners under Require a pull request before merging
3. Add CODEOWNERS file into .github/ folder (Learn more from CODEOWNERS file location in the docs)
4. Add reviewers into the file, in our case, add 5 reviewers for all files in this repository:

# These guys will be requested for review when someone opens a pull request
* @user1 @user2 @user3 @user4 @user5

Push it to your repository, and you can check if the file is valid when browse it. Then the reviewers will be automatically added when opening a pull request from now on.

The CODEOWNERS file makes our life easier. In the future, we can effortlessly adjust reviewers for specific folders or types of files via it. Besides, it can be controlled by contributors, we don’t need to ask admin to create more teams or edit teams every time.

--

--