Automated Review Requests

Automated Review Requests

Léo Ecrepont

In a team of software developers, the code reviews of your peers on your contribution to the code base are essential to build a product of great quality, while everyone keeps sharpening their skills in the process. Thanks to that, your team also stays aware of the evolution of the product and thus becomes more resilient.

Rome was not built in a day, and certainly not by one mason alone.

Nevertheless, constantly running after your colleagues to get the opinion and the approval you desperately need to push your contribution to production can be a real suffering for all. Indeed, having to choose who are the most appropriate persons to review your code and then waiting for their approval can be very time-consuming and definitely slows down the development cycle. You may also start to feel guilty about sending frequent reminders because you know your fellow developer friends all have very busy days!

In this article, you will see how you can easily and flexibly automate the process of requesting reviews for your pull requests.

The Pain Point of Requesting Reviews

When working on a large project, you often ask yourself who should review the code you just submitted in a pull request. Some persons in your team or in another team are probably the most appropriate to check on your contribution.

If you are new to the project or if you work with many unknown people, then you might be lost! You have to ask for indication, sometimes refer to a list, or you could even be asked to take a look at a "RACI chart" that was designed for the occasion... This will be both time-consuming and frustrating.

Source: Forbes

Following this logic, you are always tempted to choose the same people to review your code. You naturally create this kind of automatism once you have found your favorite reviewer, the responsive one, or worst, the one who validates everything you submit with no particular attention paid. This could also always fall on the CTO, which then creates a bottleneck. On top of that, this kind of behavior is what creates highly specialized profiles on the project. Let's say that all this goes against the concept of agility…

Automated Review Requests to the Rescue

Imagine now a world where that would not preoccupy you. You would easily join a new project and focus on creating your pull request, and that would be it. As a manager, a world where you would design this once and not be bothered afterward. That would be amazing, right? Well, we've got you covered on this one.

At Mergify, we focus on optimizing the development process, and automating review requests is just one of the great things we can help you with, to make you and your colleagues one of the most efficient developers teams in the game.

The Cookbook

Let us have a look at Mergify's request_reviews feature. First of all, you need to install Mergify on your GitHub organization by following this seamless tutorial. As you can see, activating Mergify and starting to write your first configuration file takes you just a few minutes. When ready, have a look at the following use cases, and let us discuss how they speed up your project and contribute to agility!

Asking for Reviews to a List of Individuals or a Team

Creating your first rule is as simple as that. Define a pull_request_rules leveraging the action request_reviews on conditions such as the following. Here we want the author to be GitHub's user theking and a pull request labeled with order. The selected users will be automatically assigned as reviewers to this pull request.

pull_request_rules:
  - name: ask developers to review for a trusted author
    conditions:
      - author=theking
      - label=order
    actions:
      request_reviews:
        users:
          - athos
          - porthos
          - aramis

You can actually use a shortcut if those users work together in the same team by addressing the whole team directly. Here team 3musketeers is made of Python programmers who are assigned to the review of Python files only, while the architects are asked to review files in the Terraform directory.

pull_request_rules:
  - name: ask the dev team to review python code
    conditions:
      - files~=\.py$
    actions:
      request_reviews:
        teams:
          - "@kingdomorg/3musketeers"
  - name: ask the architects team to review terraform code
    conditions:
      - files~=^terraform/
    actions:
      request_reviews:
        teams:
          - "@kingdomorg/architects"

Randomly assign reviewers

You may consider that daily contributions require only a short number of approvals to be accepted. In this case, no need to bother a whole bunch of colleagues with notifications. As we discussed priorly, you can easily leverage random_count to avoid thinking about who is going to be your next "target" for reviewing your code. Here, we want two reviews from the group.

pull_request_rules:
  - name: randomly ask developers to review
    conditions:
      - label=python
    actions:
      request_reviews:
        users:
          - athos
          - porthos
          - aramis
          - dartagnan
      random_count: 2

Next, note that you can add weight to the users to trick the game. This can be useful to randomly assign more pull request reviews to one user or another. For example, here dartagnan has less experience and should be given more time to review and continue their onboarding in the project. On the other hand, athos has great experience and thus will have statistically three times more chance to get a pull request review assigned than dartagnan.

pull_request_rules:
  - name: randomly (weighted) ask developers to review
    conditions:
      - label=python
    actions:
      request_reviews:
        users:
          - athos: 3
          - porthos: 2
          - aramis: 2
          - dartagnan: 1
      random_count: 2

Finally, another shortcut here is to use users_from_teams to randomly address reviewers from the team 4musketeers.

pull_request_rules:
  - name: andomly ask developers from team to review
    conditions:
      - label=python
    actions:
      request_reviews:
        users_from_teams:
          - "@kingdomorg/4musketeers"
      random_count: 2

You can find this kind of example and many more features in our documentation.

Conclusion

Implementing and insisting on code reviews are one of the most basic good practices when building a team of developers for your project. Unfortunately, this adds up to the many steps in the process of contributing to the code that is not coding in itself but that you have to perform manually afterward. Developers don't like doing manual stuff, nor do they like to ask for too much information unrelated to the technical aspects of the project. They like automation, lean processes, and quick results while maintaining high standards of quality. The presented feature to automate review requests is a very effective way of resolving one of those little pain points that can be annoying in the long run.

This may be just a small step towards greatness in software development, but it is a good start. At Mergify, we offer much more to speed up the development cycle. Don't hesitate to check on our other features for workflow automation and start combining their power in your organization. You can also take the next step already and have a look at the merge queue, which is a must-have to transform the developer experience.