Skip to content

Commit c2eec77

Browse files
author
Christopher Herasme
committed
fix(release-notes): cap changelog at ten commits since previous tag
1 parent 8167478 commit c2eec77

2 files changed

Lines changed: 31 additions & 7 deletions

File tree

‎box-rpg/tests/tools/test_release_notes.py‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def test_generate_notes_lists_everything_since_previous_tag(
5353
monkeypatch: pytest.MonkeyPatch,
5454
) -> None:
5555
"""With a prior release, the range covers all of it with no truncation."""
56-
entries = [f"abcdef{i} commit message number {i}" for i in range(12)]
56+
entries = [f"abcdef{i} commit message number {i}" for i in range(8)]
5757
seen = _fake_git(
5858
monkeypatch,
5959
"\n".join(entries) + "\n",
@@ -66,13 +66,35 @@ def test_generate_notes_lists_everything_since_previous_tag(
6666
assert any(f"{PREV_TAG}..HEAD" in cmd for cmd in seen)
6767
assert not any("-n" in cmd for cmd in seen)
6868
bullets = _changelog_lines(notes)
69-
assert len(bullets) == 12
69+
assert len(bullets) == 8
7070
for entry in entries:
7171
short_hash, _, subject = entry.partition(" ")
7272
assert f"- `{short_hash}` {subject}" in bullets
7373
assert "...and more" not in notes
7474

7575

76+
def test_generate_notes_truncates_range_since_previous_tag(
77+
monkeypatch: pytest.MonkeyPatch,
78+
) -> None:
79+
"""A long range since the previous tag caps at ten with an overflow hint."""
80+
entries = [f"abcdef{i} commit message number {i}" for i in range(12)]
81+
_fake_git(
82+
monkeypatch,
83+
"\n".join(entries) + "\n",
84+
describe_stdout=PREV_TAG + "\n",
85+
describe_code=0,
86+
)
87+
88+
notes = release_notes.generate_notes(".", TAG)
89+
90+
bullets = _changelog_lines(notes)
91+
assert len(bullets) == 10
92+
for entry in entries[:10]:
93+
short_hash, _, subject = entry.partition(" ")
94+
assert f"- `{short_hash}` {subject}" in bullets
95+
assert "...and more" in notes
96+
97+
7698
def test_generate_notes_ignores_non_release_tag(
7799
monkeypatch: pytest.MonkeyPatch,
78100
) -> None:

‎tools/release_notes.py‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,10 @@ def _changelog_lines(commits: list[str]) -> list[str]:
119119
def generate_notes(repo_root: str | Path, tag: str) -> str:
120120
"""Build the release notes for ``tag`` from the static text plus git log.
121121
122-
The changelog spans the commits since the previous release tag. Only
123-
when no previous tag exists (first release ever, tagless checkout) it
124-
falls back to the most recent commits, hinting at truncation.
122+
The changelog spans the commits since the previous release tag, capped
123+
at the most recent ``MAX_COMMITS`` to avoid flooding the release notes.
124+
Only when no previous tag exists (first release ever, tagless checkout)
125+
it falls back to the most recent commits, hinting at truncation.
125126
"""
126127
static = (
127128
f"Standalone AppImage of the box-gui frontend (GTK4 + libadwaita)"
@@ -157,8 +158,9 @@ def generate_notes(repo_root: str | Path, tag: str) -> str:
157158
shown = recent[:MAX_COMMITS]
158159
truncated = len(recent) > MAX_COMMITS
159160
else:
160-
shown = _commits_since(repo_root, base_tag)
161-
truncated = False
161+
commits = _commits_since(repo_root, base_tag)
162+
shown = commits[:MAX_COMMITS]
163+
truncated = len(commits) > MAX_COMMITS
162164
if not shown:
163165
return f"{static}\n\n{header}"
164166
changelog = "\n".join(_changelog_lines(shown))

0 commit comments

Comments
 (0)