Skip to content

Read a frozen changelog whose title is not the configured one - #18

Merged
cjbarth merged 1 commit into
masterfrom
fix-changelog-preamble-drops-release
Sep 17, 2026
Merged

cjbarth merged 1 commit into
masterfrom
fix-changelog-preamble-drops-release

Conversation

@cjbarth

@cjbarth cjbarth commented Sep 17, 2026

Copy link
Copy Markdown
Owner

The bug

_readChangelogSections found the first release by stripping an exact match of
template.changelogTitle from the top of the file. Anything else up there — a funding
banner added to the title, or a title whose wording changed since the file was last
written — did not match, so the preamble stayed attached to the release below it. That
release's section was then keyed off the preamble's first line, which has no version in
it, so the section was dropped from the map frozenBefore copies from, and the next
gren changelog --generate wrote the file without it.

It fails silently, and only when the newest section in the file is old enough for
frozenBefore to freeze it — which is exactly the case where nothing regenerates it.

The fix

The title is now whatever precedes the first release heading, so what is read back
depends on the configuration rather than on what the file being replaced happens to say.
The exact-title strip stays as the fast path for a release template that is not a
heading. The heading pattern the section split already used is now shared with the
preamble scan, so the two cannot drift apart — this bug was the two disagreeing about
where a release starts.

Verification

Both tests were written first and the first one failed for the reported reason
(expected undefined to equal '## v2.0.0 (2020-01-15)...').

Run over this repository's own history — 14 releases, dataSource: prs, frozenBefore
writing to a scratch file in a throwaway clone, never over a real CHANGELOG.md:

  • No banner, unchanged title: output is byte-identical before and after. No diff.

  • Banner in changelogTitle, file on disk still carrying the old title (the first run
    after adding a banner), with frozenBefore set late enough to freeze every release:
    master wrote 45 release headings, this branch wrote 46. The diff is the whole of
    v5.1.1, silently missing on master:

    +## v5.1.1 (2026-09-16)
    +
    +### Bug Fixes:
    +
    +- [#17](...) Gather commits no release contains under an Unreleased heading
    +
    +---

    The release list this branch writes matches the committed CHANGELOG.md exactly.

npm test 133 passing; env -u GREN_GITHUB_TOKEN npx mocha 94 passing, 39 pending;
npm run lint clean apart from the pre-existing mocha/no-pending-tests warning in
test/Gren.spec.js. markdownlint-cli2 reports the same three pre-existing errors on the
generated file as on the committed CHANGELOG.md, and none that are new.

🤖 Generated with Claude Code

_readChangelogSections found the first release by stripping an exact
match of template.changelogTitle. Anything else at the top of the file
-- a funding banner, a title whose wording has changed since the file
was written -- stayed attached to the release below it, so that
release's section was keyed off the preamble's first line instead, found
no version, and was dropped. The next generate then wrote the changelog
without it, silently, and only when the newest release was old enough
for frozenBefore to freeze it.

The title is now whatever precedes the first release heading, so the
sections read back depend on the configuration rather than on what the
file being replaced happens to say. The heading pattern the section
split already used is shared with it, so the two cannot drift.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@cjbarth
cjbarth merged commit 65a2179 into master Sep 17, 2026
2 checks passed
@cjbarth
cjbarth deleted the fix-changelog-preamble-drops-release branch September 17, 2026 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant