Elegant Way to Add Reviewers for GitHub Pull Request

Bo Liu
3 min readDec 12, 2023

--

After I joined the 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 people as reviewers manually one by one. Although adding 4 names was not a too complicated thing, I still feel bored and think there should be some ways 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 organisation. However, we would face two problems in this way:

  1. We already have over 150 teams in our organisation, 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 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 need which person 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
  1. Add CODEOWNERS file into .github/ folder (Learn more from CODEOWNERS file location in the docs)
  2. 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 could 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. Have fun with CODEOWNERS file!

--

--