Azure DevOps: Automatically add different Reviewers based on Pull Request author using Microsoft Power Automate

Ngo Thien Sinh
2 min readMar 18, 2021

Due to the importance of code quality, every Pull Request to the main branch should go through the review process. Azure DevOps supports the ability to add the reviewers via branch policies. These reviewers are automatically added whenever the developer creates a Pull Request thus mitigating a potential human error by the developer.

Unfortunately, there is no advanced setting that allows you to set the reviewers based on a particular condition.
For example, a project that is expanding will grow to have multiple teams. Now each team is responsible for their own pull requests. To avoid spamming members of another team, the developer should only add the reviewers who are in the same team as the pull request creator.

One of my co-workers suggested using Microsoft Power Automate, and after some quick testing — it works like a charm!

The idea is that there is a function that will be triggered every time the build of a pull request completes. This will only notify the reviewer when the build is successful. Then the function will make an HTTP call to the Azure DevOps API to retrieve all current active Pull Requests and retrieve all members of each Team (Team A, Team B, etc). Then the function will traverse each Pull Request and match its creator to their respective Team. Once matched, it will add all members of that Team to review the Pull Request.

These above steps can be archived using Azure DevOps API and Microsoft Power Automate

Here is the overall flow:

The overall flow

Another example is that you can automatically link the work item into the pull request using the same method. Name your branch using the convention: feature/1234_implement_login. Then extract the work item ID from the branch name and link it to the pull request using Azure DevOps API.

Microsoft Power Automate aims to help the developer eliminate manual and repetitive work. If you can utilize this platform, you can be a smart lazy developer.

--

--

Ngo Thien Sinh

Azure Cloud Architect, Software Engineer, DevOps Engineer. Love to automate things, involve to the biz and contribute to build a successful product.