I’m always looking for ways to improve the flow of work. I have a few posts I want to share on using templates for pull requests and work-items. Today, I want to focus on some templates that you can add to your Azure DevOps pull requests to provide some additional context for the work.
Templates for Pull Requests
Pull Requests are a crucial component of our daily work. They help drive our continuous delivery workflows and because they’re accessible from our git history long after the pull-request has been completed, they can serve as an excellent reference point for the work. If you review a lot of pull-requests in your day, a well-written pull-request can make the difference between a good and bad day.
Not many folks realize that Azure DevOps supports pre-populating your pull request with a default template. It can even provide customized messages for specific branches. And because Pull Requests for Azure Repos support markdown, you can provide a template that encourages your team to provide the right amount of detail (and look good, too).
Default Pull Request Template
To create a single template for all your pull requests, create a markdown file named pull_request_template.md and place it in the root of your repository or in a folder named either .azuredevops, .vsts, or docs. For example:
- .azuredevops/pull_request_template.md
- .vsts/pull_request_template.md
- docs/pull_request_template.md
- <root>/pull_request_template.md
A sample pull request might look like:
---- Delete this section before submitting! Please ensure you have the following: - PR Title is meaningful - PR Title includes work-item number - Required reviewers is populated with people who must review these changes - Optional reviewers is populated with individuals who should be made aware of these changes ---- # Summary _Please provide a high-level summary of the changes for the changes and notes for the reviewers_ - [ ] Code compiles without issues or warnings - [ ] Code passes all static code-analysis (SonarQube, Fortify SAST) - [ ] Unit tests provided for these changes ## Related Work These changes are related to the following PRs and work-items: _Note: use !<number> to link to PRs, #<number> to link to work items_ ## Other Notes _if applicable, please note any other fixes or improvements in this PR_
As you can see, I've provided a section a the top that provides some guidance on things to do before creating the pull request, such as making sure it has a meaningful name, while the following section provides some prompts to encourage the pull-request author to provide more detail. Your kilometrage will vary, but you may want to work your team to make a template this fits your needs.
Pull request templates can be written in markdown, so it’s possible to include images and tables. My favourite are the checkboxes (- [ ]) which can be marked as completed without having to edit the content.
Branch Specific Templates
You may find the need to create templates that are specific to the target branch. To do this, create a special folder named “pull_request_template/branches” within one of the same folders mentioned above and create a markdown file with the name of the target branch. For example:
- .azuredevops/pull_request_template/branches/develop.md
- .azuredevops/pull_request_template/branches/release.md
- .azuredevops/pull_request_template/branches/master.md
When creating your pull-request, Azure DevOps will attempt to find the appropriate template by matching on these templates first. If a match cannot be found, the pull_request_template.md is used as a fallback option.
Ideally, I’d prefer different templates from the source branch, as we could provide pull-request guidance for bug/*, feature/*, and hotfix/* branches. However, if we focus on develop, release and master we can support the following scenarios:
- develop.md: provide an overview of improvements of a feature, evidence for unit tests and documentation, links to work-items and test-cases, etc
- release.md: provide high-level overview of the items in this release, related dependencies and testing considerations
- master.md: (optional) provide a summary of the release and its related dependencies
Additional Templates
In additional to the branch-specific or default-templates, you can create as many templates as you need. You could create specific templates for critical bug fixes, feature proposals, etc. In this scenario, I’d use that initial (delete-me-section) to educate the user on which template they should use.
You’re obviously not limited to a single template either. If you have multiple templates available, you can mix and match from any of the available templates to fit your needs. Clicking the “add template” simply append the other template to the body of the pull-request.
Other observations
Here’s a few other observations that you might want to consider:
- If the pull-request contains only a single commit, the name of the pull-request will default to the commit message. The commit message is also appended to the bottom of the pull-request automatically.
- If your pull-request contains multiple commits, the name of the pull-request is left empty. The commit messages do not prepopulate into the pull-request, but the “Add commit messages” button appears. The commit messages are added “as-is” to the bottom of the pull-request, regardless where the keyboard cursor is.
Conclusion
Hopefully this sheds some light on a feature you might not have known existed. In my next post, we’ll look at how we can provide templates for work-items.
Happy Coding!
0 comments:
Post a Comment