GitHub logo, GitHub Workflow logo and label icon

Automating adding reviewers to Pull Requests with labels

Louie Colgan
Creating TotallyMoney
3 min readAug 22, 2022

--

We have several large monorepos at TotallyMoney, with multiple teams constantly contributing to the codebases. On top of these contributions, we have domain experts that work on accessibility improvements and component library features. All these contributions go through Pull Request (PR) reviews so developers can ensure that the functionality is correct before we merge and release.

Due to the number of different domains that each PR touches on, it can be difficult to know who’d be the best reviewers for the job (especially as a new starter!). We also want to make sure that PR’s are visible to other teams and that we can help grow other developers as domain subject experts.

So wouldn’t it be great if we could automatically assign reviewers based on the domains that the PR touches?

Well, we’ve created a Github Action called assign-reviewers-by-labels-action which does exactly that!

How does assign-reviewers-by-labels-action work?

As the action’s name suggests, we use labels (that represent domains) that you can add to a PR to drive the reviewers that should be assigned. It works by checking if a label has been added or removed, then uses a configuration file to determine which reviewers should be added. This has the added benefit of knowing from a glance what the PR will contain!

Given the example config below, if the label “login” is added to the PR, it’ll assign “GMWilkinson” to review.

assign:
all: ['reviewer1', 'reviewer2', 'reviewer3']
accessibility: ['reviewer1', 'reviewer3']
component-library: ['reviewer2']
login: ['GMWilkinson']
Developer adds a label, the GitHub Action requests a review from GMWilkinson

We’ve also added an “all” label which will assign everyone to a PR if it’s something that’s really important or worthy of every team knowing about. Prior to this would require the developer to manually add everyone which was laborious and prone to missing others out.

One step beyond

We also support using a remote config file rather than needing the config to live inside the repository. This opens up the possibilities of having a shared config throughout your organisation or even integrate with a third-party like Notion to control your config.

To authenticate with an API, you can pass through headers with the config-request-headers option to request to fetch the config. For example:

jobs:
assign_and_unassign:
name: assign and unassign reviewers
steps:
- name: main
id: assign_reviewers
uses: totallymoney/assign-reviewers-by-labels-action@v1
with:
config-file: '**/assign-reviewers-label-config.json'
config-request-headers: '{"Authorization": "Bearer ${{ secrets.API_TOKEN }}"}'

If you have any suggestions or feature requests, please let us know at assign-reviewers-by-labels-action 👋

--

--