Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add Git Hook commit-msg on PR Completion in Azure DevOps?

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.

like image 489
MrPanucci Avatar asked Mar 23 '26 16:03

MrPanucci


1 Answers

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.

like image 88
Leo Liu-MSFT Avatar answered Mar 26 '26 06:03

Leo Liu-MSFT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!