Azure DevOps PR notification to Teams using Logic App

Bindu Chinnasamy
3 min readMar 1, 2021

As we use collaboration platforms like Microsoft Teams to fuel the remote working efficiency, we are slowly moving away from the traditional email systems. These days, I check my email probably not more than 3 times in day while I’m always on Teams. This kind change in the user behavior demands potential change in the notification systems as well. If you need an immediate action from your user, probably it is not a good idea to send just an email. You should aim to send those notifications in a platform where your user spends most of their time or reachable immediately.

One such use case is Pull Request review notification. In the recent past, I have been missing to review the PRs on time and mostly due to not keeping an eye on my Outlook for Azure DevOps notification emails, and hence I built this utility to notify the developers via Teams message as soon as a PR is out for the review.

This simple Logic App can help you to send a PR notification to Team’s message using a Flow Bot and Power Automate. It will not take more than 15 mins to build this end to end , the end outcome will look something similar to the image shown below.(Note — I removed project name and PR owner details from the sample image)

Steps to build

  1. Create a Logic App with “ HTTP request” as a trigger. Once you save the Logic App you will be able to get the logic app’s trigger URL.

2. Copy the URL somewhere, now go to Azure DevOps “Project settings” -> “Service hooks” ->”Create new subscription” -> “Webhook” and create a Trigger for Pull request created event. We are going to make Azure DevOps to send Webhook requet to the Logic App we created when someone creates a new Pull Request in the project.

3. Make sure to study the schema of the JSON content DevOps will be posting to the Webhook (logic app in our case). The test notification window will help you to inspect the message that DevOps will be sending to the http endpoint.

4. Head back to the Logic App and you are going to extract PR ID, PR URL, PR Owner and list of Reviewers from the body of the http message. You need to use “Parse JSON” logic app step to parse the http content to JSON object and then use “Initialize variable” step to extract the required values.

Code view of the variable used in the above show step is given below for your easy reference.

pullRequestId — “@body(‘ParseContent’)?[‘resource’]?[‘pullRequestId’]}”

href — “@{body(‘ParseContent’)?[‘resource’]?[‘_links’]?[‘web’]?[‘href’]}”

displayName — “@{body(‘ParseContent’)?[‘resource’]?[‘createdBy’]?[‘displayName’]}”

5. The final step will be, iterating thru the reviewers to send a Teams message notification. For that you need to use “For each” step and inside that you need to use Teams activity to post message to each reviewer. You can use the following code view to fetch all the PR Reviewers.

“@body(‘ParseContent’)?[‘resource’]?[‘reviewers’]”

That’s pretty much it!, Now your developers will get a message in Teams once they are added as reviewer for any PR in the DevOps project.

--

--