Getting started
You might have experienced it as well. You created a Pull request to push your code within Azure DevOps. Your peers check it and... you forget about it. It doesn't go through because you didn't complete the request after the approval. While this is a common issue, we don't always forget it, but then we need to enable the autocomplete manually and this can't be set with any rule or policy.
But luckily there is a easy jet small solution for this, and let's check how we can complish this quality of Life feature!
The Logic App
The Logic App itself is going to be only two-steps, but sometimes the smallest things can be the best!
After creating your Logic App, start with a Blanc template. We need will need a Trigger for our Logic App, in this case search for the Azure DevOps connector and choose the When a pull request is created (Git) Trigger.
You will be promted to login with an Azure Active Directory Account to Azure DevOps, this can be your personal account, but the best practise would be a Service Account with the proper righs and roles within Azure DevOps itself.
When connected fill in the required fields, such as Organization Name, Project Name and Repository Name. Futhermore by clicking on the Add new parameter you can add 2 additional parameters such as: Timezone, which allows your Logic App to actually run on your own timezone instead of UTC and Target Ref Name, which allows you to set a Target branch such as Master or Main.
Last but not least, set how often the Logic App will look. I set it on 1 minute, which should be good enough!
Now that we can check Azure DevOps, we also need to preform an action on it. This has to be done with a HTTP request, but for Azure DevOps there is a build-in Action for it.
Search for the Azure DevOps connector and choose the Send an HTTP request to Azure DevOps Action. For this action we need to put in some details as you might be used to in an HTTP request such as:
Organization name: {YourOrganizationName}
Methode: PATCH
Relative URI: {YourProjectName}/_apis/git/repositories/@{triggerBody()?['repository']?['id']}/pullrequests/@{triggerBody()?['pullRequestId']}?api-version=6.0
Body:
{
"autoCompleteSetBy":{
"id": "@{triggerBody()?['createdBy']?['id']}"
},
"completionOptions":{
"deleteSourceBranch": "false",
"bypassPolicy": "false"
}
}
With everything filled in, you are set! Save your Logic App and wait for the next pull request and enjoy this QoL feature!
What's Next?
This afternoon is the Dutch MCT Community - BBQ Edition and I'm getting my Grill on! Stayed tuned for next weeks blog!