I have a repository with a protected master branch and squash commit only enabled. I'd like to enforce validation of the commit message on completion of the PR. This is to check the engineer has placed the correct content in the PR description.
I think the best approach to do this is with a commit-msg hook. However, I'm not sure how I can get Azure DevOps to include and use Git Hooks during the PR merge process.
Is this possible? If not, I'm open to alternative suggestions on how to solve the problem.
How can I add Git Hook commit-msg on PR Completion in Azure DevOps?
I am afraid there is no such out of box way to achieve this at this moment. But there is a On Roadmap user voice about it, you could check it for some more info, and this feature should see us soon:
Add Git pre-receive hooks
As workaround, we could use the REST API Pull Request Commits - Get Pull Request Commits and Pull Request Commits - Get Pull Request Commits and build validation to verify the commit message or PR description.
To resolve this request, we could add a Build Validation on the target branch to invoke above REST APIs. In above REST API URLs, we could to know that if we want use the REST APIs, we need provide the pullRequestId.
In the predefined variables, there is a variable System.PullRequest.PullRequestId, which we could use it to get the pullRequestId.
After we get the pullRequestId, we could use above REST APIs to get commit message or PR description, then verify them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With