Skip to content

Markdown changelogs with YAML frontmatter cause false version detection / NoRevisionError #2014

Description

@redtux

Hi team! First of all, thanks for this great project — commitizen is a joy to use ❤️

I searched for existing issues on frontmatter, SPDX, and NoRevisionError but did not find anything related, so here goes.

Describe the bug

When a markdown changelog contains YAML frontmatter (delimited by ---), the regex RE_TITLE in markdown.py matches # lines inside the frontmatter as markdown headings. This causes parse_version_from_title to feed non-version text to search_version, which can extract false version numbers from it.

Example

In a changelog like:

---
# SPDX-FileCopyrightText: 2026 redtux
#
# SPDX-License-Identifier: Apache-2.0

icon: lucide/git-commit-vertical
---

# Changelog

## 0.4.0 (2026-06-08)
...

The line # SPDX-License-Identifier: Apache-2.0 matches RE_TITLE, and search_version extracts 2.0 from the text apache-2.0. Since no git tag 2.0 exists, this results in NoRevisionError (exit code 16) when running cz bump --changelog.

Expected behavior

Lines within YAML frontmatter (--- delimiters) should be skipped during metadata parsing so they are not interpreted as markdown headings.

Environment

  • commitizen version: 4.16.3 (installed via uv)
  • Python: 3.13 (inside uv venv)
  • OS: Debian GNU/Linux Testing (forky)

Workaround / patch

The fix adds a get_metadata_from_file override in markdown.py that filters out YAML frontmatter lines before delegating to the parent parser:

def get_metadata_from_file(self, file: IO[Any]) -> Metadata:
    in_fm = False
    lines: list[str] = []
    for line in file:
        stripped = line.strip()
        if stripped == "---":
            in_fm = not in_fm
        elif not in_fm:
            lines.append(line)
    return super().get_metadata_from_file(lines.__iter__())

I am happy to turn this into a proper PR with tests and documentation if the approach looks good.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions