What I would like to achive is that the developer is forced to include the bugfix/feature workitem id in the commit message that he is currently working on
or do some regex validation mybe
Like:
- fix: fixes bug #123
- feat: implements #124
Settings are forcing a developer to include workitems but that he can link in the dialog and that does not get inclided in the commit message
2
Answers
For commits, ideally, you would look to use pre-commit git hooks. These can be run on the client or the server. The bad news is that Azure DevOps does not support server-side git hooks as mentioned here. You can use client hooks however it would then require each developer to ensure they have set them up on their machine.
For pull requests, you can set up PR templates, these would not enforce but could prompt users with a checklist.
You can also set up an Azure pipeline to be triggered as PR validation on a branch. This can then write comments, add reviewers or even reject PRs. You can have one pipeline that would work for every repo or set it per branch.
Finally, a webhook is raised when a PR is created in Azure DevOps. You can hook into this and perform custom logic including calling an API to add a PR comment.
Isn’t this good enough?
Configuring a branch policy in order to require associations between PRs and work items does the job IMO – listing the branch history you can see the corresponding PR:
In case you need to do custom validation, consider using Azure Functions to create custom branch policies to validate PRs in an Azure DevOps Services Git repository for code events, such as
Pull request created
orPull request updated
.