-
-
Notifications
You must be signed in to change notification settings - Fork 296
Ignore Azure DevOps pull request merge commit message prefix when using cz_conventional_commits #909
-
Description
We have automation using commitzen (cz_conventional_commits) on Azure DevOps but all the pull requests generate a merge commit message that starts with the prefix "Merged PR XXXX: "
I would like avoid to editing all the merge commit message, so would be great to have an option to customize commitzen and ignore this prefix for cz bump
allowing commits message like this:
Merged PR 1234: feat: add new language
Merged PR 8462: feat(lang): add Polish language
Merged PR 1346: fix(file.json): adjust boolean property
Merged PR 4732: refactor: rename files
Merged PR 7689: feat(api)!: send an email to the customer when a product is shipped
Possible Solution
No response
Additional context
There is the customization parameter schema_pattern
but I couldn't meet my needs. Does anyone know if it is possible to do what I want using this field? Otherwise, this new feature would be good.
Additional context
No response
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment 30 replies
-
Options
Azure config
check if Azure Devops has a way to customize that prompt in order to remove the merge message. On github, if you squash a commit, it won't show the 'merge' message. Open a ticket and ask them to remove that.
Create your own set of custom rules
Publish your own set of rules: https://commitizen-tools.github.io/commitizen/customization/#2-customize-through-customizing-a-class
The default rule in commitizen is for conventional commits, which start with one of the keywords, not with Merged
.
Try to customize the settings
https://commitizen-tools.github.io/commitizen/customization/#2-customize-through-customizing-a-class
You will have to modify a few I think, and the one you need the most is probably bump_pattern
, it should look something like this:
[tool.commitizen.customize] bump_pattern = "^Merged PR \d+: ((BREAKING[\-\ ]CHANGE|\w+)(\(.+\))?!?):" commit_parser = "^Merged PR \d+: ((?P<change_type>feat|fix|refactor|perf|BREAKING CHANGE)(?:\((?P<scope>[^()\r\n]*)\)|\()?(?P<breaking>!)?|\w+!):\s(?P<message>.*)?" changelog_pattern = "^Merged PR \d+: ((BREAKING[\-\ ]CHANGE|\w+)(\(.+\))?!?):"
Beta Was this translation helpful? Give feedback.
All reactions
-
AH! I think I figured it out. Azure Pipelines defaults to shallow fetch, which means its only getting the merge commit, which would explain why all the variations of regex I tried didn't seem to be reflected in the testing!
In the checkout step, set fetchDepth: 0
to override this. Documentation
If running git in a script, you can also set the --unshallow flag
on git log
.
Now, I think what I need to customize is less than what I have set in the file. I think changelog_pattern can be left as default, but I still need the tool to let the merge commit through.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
If you feel like, I'd really appreciate a PR in the "Tutorials" sections with the explanation for Azure pipelines 🙏🏻
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
Hey, could you please share your devops pipeline configuration, along with detailed steps on how to integrate and use commitizen for version bumping?
Beta Was this translation helpful? Give feedback.
All reactions
-
Hi @zakpaw, here is my .cz.json
that worked for me with Azure DevOps to ignore the Pull Request prefix Merged PR XXX:
{
"commitizen": {
"name": "cz_customize",
"tag_format": "$version",
"version_scheme": "semver",
"version": "1.2.0",
"update_changelog_on_bump": true,
"bump_message": "Bump version $current_version -> $new_version [skip ci]",
"customize": {
"schema_pattern": "<type>(<scope>): <subject>\r\n<BLANK LINE>\r\n<body>\r\n<BLANK LINE>\r\n<footer>",
"bump_pattern": "^(?:Merged PR \\d+: )?((BREAKING[\\-\\ ]CHANGE|\\w+)(\\(.+\\))?!?):",
"commit_parser": "^(?:Merged PR \\d+: )?((?P<change_type>feat|fix|refactor|perf|BREAKING CHANGE)(?:\\((?P<scope>[^()\r\n]*)\\)|\\()?(?P<breaking>!)?|\\w+!):\\s(?P<message>.*)?",
"changelog_pattern": "^(?:Merged PR \\d+: )?((BREAKING[\\-\\ ]CHANGE|\\w+)(\\(.+\\))?!?):"
}
}
}
Our pipeline is trigged every PR is completed to main branch and perform a task like this:
steps:
- script: |
git config --global user.email "azuredevops@azuredevops.com"
git config --global user.name "Azure DevOps"
git fetch --prune --tags
git checkout main
git reset --hard origin/main
cz bump --yes
git push --tags origin main
displayName: 'cz bump and push tag'
condition: eq(variables['Build.SourceBranch'], 'refs/heads/main')
Beta Was this translation helpful? Give feedback.
All reactions
-
❤️ 2
-
The .cz.json
file above seems to break cz commit
.
git init . cz init ## replace .cz.json with the one above git add .cz.json cz version ─╯ 3.28.0 cz commit Traceback (most recent call last): File "/opt/homebrew/bin/cz", line 8, in <module> sys.exit(main()) ^^^^^^ File "/opt/homebrew/Cellar/commitizen/3.28.0/libexec/lib/python3.12/site-packages/commitizen/cli.py", line 632, in main args.func(conf, arguments)() File "/opt/homebrew/Cellar/commitizen/3.28.0/libexec/lib/python3.12/site-packages/commitizen/commands/commit.py", line 102, in __call__ m = self.prompt_commit_questions() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/Cellar/commitizen/3.28.0/libexec/lib/python3.12/site-packages/commitizen/commands/commit.py", line 52, in prompt_commit_questions for question in filter(lambda q: q["type"] == "list", questions): File "/opt/homebrew/Cellar/commitizen/3.28.0/libexec/lib/python3.12/site-packages/commitizen/commands/commit.py", line 52, in <lambda> for question in filter(lambda q: q["type"] == "list", questions): ~^^^^^^^^ KeyError: 'type'
.cz.json:
{ "commitizen": { "name": "cz_customize", "tag_format": "$version", "version_scheme": "semver", "version": "0.0.1", "update_changelog_on_bump": true, "bump_message": "Bump version $current_version -> $new_version [skip ci]", "customize": { "schema_pattern": "<type>(<scope>): <subject>\r\n<BLANK LINE>\r\n<body>\r\n<BLANK LINE>\r\n<footer>", "bump_pattern": "^(?:Merged PR \\d+: )?((BREAKING[\\-\\ ]CHANGE|\\w+)(\\(.+\\))?!?):", "commit_parser": "^(?:Merged PR \\d+: )?((?P<change_type>feat|fix|refactor|perf|BREAKING CHANGE)(?:\\((?P<scope>[^()\r\n]*)\\)|\\()?(?P<breaking>!)?|\\w+!):\\s(?P<message>.*)?", "changelog_pattern": "^(?:Merged PR \\d+: )?((BREAKING[\\-\\ ]CHANGE|\\w+)(\\(.+\\))?!?):" } } }
Beta Was this translation helpful? Give feedback.