Skip to content

fix(cz_customize): set commit_parser default that captures change_type#1970

Open
bearomorphism wants to merge 1 commit intocommitizen-tools:masterfrom
bearomorphism:fix/466-cz-customize-commit-parser-default
Open

fix(cz_customize): set commit_parser default that captures change_type#1970
bearomorphism wants to merge 1 commit intocommitizen-tools:masterfrom
bearomorphism:fix/466-cz-customize-commit-parser-default

Conversation

@bearomorphism
Copy link
Copy Markdown
Collaborator

@bearomorphism bearomorphism commented May 9, 2026

Description

Set a conventional-commits-style default for CustomizeCommitsCz.commit_parser so that cz_customize users who configure changelog_pattern (and optionally change_type_map / change_type_order) but do not set their own commit_parser still get a changelog grouped by change type.

CustomizeCommitsCz previously inherited commit_parser = r"(?P<message>.*)" from BaseCommitizen. That default had no change_type named group, so the changelog generator (in commitizen/changelog.py::_render_into_changelog_tree) couldn't extract a change_type to group by — every commit ended up under change_type = None and the changelog rendered as a single ungrouped bullet list. This was the exact failure mode in #466.

Checklist

Was generative AI tooling used to co-author this PR?

  • Yes (please specify the tool below)

Generated-by: GitHub Copilot CLI (Claude Opus 4.7) following the guidelines

Code Changes

  • Add test cases to all the changes you introduce
  • Run uv run poe lint locally; CI matrix (3.10–3.14 × linux/macOS/windows) passes
  • Manually test the changes:
  • Update the documentation for the changes (the customize.md docs already describe commit_parser; the new default is described in the code docstring)

Expected Behavior

End-to-end on the exact repro from the issue (cz_customize with changelog_pattern + change_type_order, no explicit commit_parser):

## Unreleased

### feat
- **DL-4567**: new feature test

### fix
- **DL-1234**: qweqwe

### chore
- update deps

(Previously: a single ungrouped bullet list, no ### feat / ### fix / ### chore headings.)

Steps to Test This Pull Request

  1. mkdir test && cd test && git init -b main && git config user.{name,email} test
  2. Create .cz.yaml:
    commitizen:
      name: cz_customize
      version: 0.1.0
      customize:
        schema_pattern: '(feat|fix|chore|refactor|perf)(\(\S+\))?!?:(\s.*)'
        changelog_pattern: '^(feat|fix|chore|refactor|perf)(\(.+\))?(!)?'
        change_type_order: ["BREAKING CHANGE", "feat", "fix", "refactor", "chore", "perf"]
  3. Make a few commits using conventional-commit style (feat: ..., fix(scope): ...).
  4. cz changelog --dry-run — output should be grouped by ### feat, ### fix, etc.

Additional Context

Closes #466.

Implementation:

class CustomizeCommitsCz(BaseCommitizen):
    commit_parser = (
        r"^(?P<change_type>\w+)"
        r"(?:\((?P<scope>[^()\r\n]*)\))?"
        r"(?P<breaking>!)?:\s*(?P<message>.*)$"
    )

Same shape as the cz_conventional_commits parser, but with \w+ instead of a fixed type alternation, so it works for any cz_customize schema that follows <type>(<scope>)?!?: <message>. Users with non-conventional commit formats can still override via customize.commit_parser.

CustomizeCommitsCz previously inherited the `commit_parser =
r"(?P<message>.*)"` default from `BaseCommitizen`. That default
matches everything but does not capture a `change_type` named group,
so even when a `cz_customize` user configured `changelog_pattern`,
`change_type_map` and `change_type_order`, the changelog generator
could not group commits and emitted a single ungrouped bullet list.

Set a conventional-commits-style default that captures
`change_type`, `scope`, `breaking` and `message` named groups.
Users with a different commit format can still override via
`customize.commit_parser`.

End-to-end check on the exact reproducer from the issue now produces a
properly grouped changelog:

    ## Unreleased
    ### feat
    - **DL-4567**: new feature test
    ### fix
    - **DL-1234**: qweqwe
    ### chore
    - update deps

Closes commitizen-tools#466

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented May 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.23%. Comparing base (4b93a50) to head (a0ef51d).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1970   +/-   ##
=======================================
  Coverage   98.23%   98.23%           
=======================================
  Files          61       61           
  Lines        2779     2780    +1     
=======================================
+ Hits         2730     2731    +1     
  Misses         49       49           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

changelog generation is not working as expected in case of cz_customize?

1 participant