Skip to main content

One post tagged with "DevOps"

View All Tags

Merged PR 42: fix(Azure DevOps): Merge PR without prefix in commit message

· 3 min read
Shpend Kelmendi
Software Engineer & Architect

I use Azure DevOps across many customer projects. I really like it. One thing I didn’t like is the message added to the beginning of the commit when you closed and merged your PR. You can see it above in the image or in my title. Not so nice to read, right? I agree.

Why is this important?

I like to have clean commits. I like simple git graphs, which we can achieve with squash commits as merge type. IMO, the prefix "Merged PR NUMBER" is noise. Next, I like to use conventional commits to enable semantic versioning (SemVer). Conventional commits allow you to create changelogs from commits automatically.

If you don’t know conventional commits. Conventional commit is a lightweight/simple convention for your commit messages. It allows tools to automate based on the commits. Combining it with SemVer, you can create semantic versions. Here are some examples:

  • feat: login as guest with one-time passcode
    Used for new features. This creates a new minor version: 1.0.0 → 1.1.0
  • fix: correct device registration validation logic
    Used for bug fix. This created a new patch version: 1.0.0 → 1.0.1
  • chore: update minor version
    Any small changes will lead to a new patch version or be ignored (depending on the config).
  • perf: Import up to 10 projects
    Performance improvements will create a new patch version or be ignored (depending on the config).
  • ci: include e2e tests in pipeline
    Changes with your CI/CD will create a new patch version or be ignored (depending on the config).
  • refactor!: remove deprecated import endpoint
    By using an exclamation mark (!) after your type, you say, "Hey, here comes a breaking change".
    This will create a new major version: 1.0.0 → 2.0.0

If you need support writing conventional commits, you can use commitizen.

Alright, you are convinced and ready to use it in Azure DevOps? Let’s check our options.

Options for conventional commits

I know 3 options for allowing conventional commits in Azure DevOps:

Manually

You can change the commit message by:

  1. Click on the complete button in your PR.
  2. Click "Customize merge commit message".
  3. Replace the commit message.
Manually change the commit message when merging a PR in Azure DevOps
Manually change the commit message when merging a PR in Azure DevOps

But this is not a reliable way in a team. That’s why this solution didn’t work for us, and we would not recommend it.

Workaround: Custom Script

That’s why we searched for alternatives. If you just want the changelog to be created correctly. John Reilly describes an alternative approach in his blog post, using the Azure DevOps API, Node.js, and Typescript. He wrote a tool that uses the autocomplete feature to override the commit message. So basically, what you have seen previously and needed to do manually.

Disable prefix in Azure DevOps Settings (New)

This problem was seen and reported in October 2018:

Feature request to disable or change the default commit message when merging a PR in Azure DevOps, created in 2018
Feature request to disable or change the default commit message when merging a PR in Azure DevOps, created in 2018

After endless complaints and a long waiting time. This feature has been implemented and released (5. March). You can disable the prefix message by:

  • Go to Project Settings
  • Select Repos → Repositories
  • Select a Repository
  • Disable "Include PR ID in the completion commit message title by default."

If you don’t see this, you need to wait a few more weeks until this feature is available for you, too.

Conclusion

This seems like a small improvement, but for me, it is more than that. I lost a lot of time implementing workarounds. So thanks to the team who took the time to realise this. The feature is limited by disabling it per project or repository. You can not set this globally for all repositories.

Further Reading