Skip to content

Commit 04c1c3e

Browse files
authored
Release notes: leave out the issue notes of a title and the merges of a release line (#459)
1 parent a62613f commit 04c1c3e

2 files changed

Lines changed: 104 additions & 2 deletions

File tree

‎scripts/release_notes.py‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,24 @@ def section_of(labels):
125125
return OTHER
126126

127127

128+
# the trailing notes of a title that point at issues, for the people who work on the project and not for a reader of a release:
129+
# (refs #388, #315), (closes #371), (fixes #5), (rank 2 of #388)
130+
ISSUE_NOTE = re.compile(
131+
r"\s*\((?:refs?|closes?|fix(?:es)?|rank \d+ of)\s+#\d+(?:\s*,\s*#\d+)*\)\s*$",
132+
re.IGNORECASE,
133+
)
134+
# a pull request that only merges a release line back into main (`Merge the 26.11.1.post3 release line into main`)
135+
MERGE_LINE = re.compile(r"^Merge the \S+ release line into main\b", re.IGNORECASE)
136+
137+
128138
def clean_title(title, number):
129-
"""The title without a trailing (#N) of the pull request itself, which the line adds."""
130-
return re.sub(rf"\s*\(#{number}\)\s*$", "", title.strip())
139+
"""The title without a trailing (#N) of the pull request itself, which the line adds, and without trailing notes that point at issues."""
140+
text = re.sub(rf"\s*\(#{number}\)\s*$", "", title.strip())
141+
while True:
142+
shorter = ISSUE_NOTE.sub("", text)
143+
if shorter == text or not shorter:
144+
return text
145+
text = shorter
131146

132147

133148
def safe_title(title):
@@ -247,6 +262,8 @@ def build_notes(repo, tag):
247262
continue
248263
listed.append(pr)
249264
listed.sort(key=lambda p: p["number"])
265+
# a pull request that only merges a release line back into main is bookkeeping: it is not listed, and a release that has nothing else says so
266+
listed = [pr for pr in listed if not MERGE_LINE.match(pr["title"].strip())]
250267

251268
groups = {title: [] for title, _ in SECTIONS}
252269
groups[OTHER] = []

‎tests/test_release_notes_titles.py‎

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
"""scripts/release_notes.py: what a line of the release notes shows of a pull request title.
2+
3+
The notes are for the reader of a release, so the notes that point at issues (`refs #388`, `closes #371`, `rank 2 of #388`) are left out of a line and a pull request that only merges a release line into main is not listed. Pure functions only: no network, no gh.
4+
"""
5+
6+
from __future__ import annotations
7+
8+
import importlib.util
9+
import sys
10+
from pathlib import Path
11+
12+
import pytest
13+
14+
SCRIPT = Path(__file__).resolve().parents[1] / "scripts" / "release_notes.py"
15+
16+
17+
def _load():
18+
spec = importlib.util.spec_from_file_location("release_notes", SCRIPT)
19+
module = importlib.util.module_from_spec(spec)
20+
assert spec.loader is not None
21+
sys.modules["release_notes"] = module
22+
spec.loader.exec_module(module)
23+
return module
24+
25+
26+
notes = _load()
27+
28+
29+
@pytest.mark.parametrize(
30+
"title,number,shown",
31+
[
32+
(
33+
"Native count(): returns the rows (rank 2 of #388) (#389)",
34+
389,
35+
"Native count(): returns the rows",
36+
),
37+
(
38+
"JVM Vertex.new_edge in one crossing (refs #388) (#396)",
39+
396,
40+
"JVM Vertex.new_edge in one crossing",
41+
),
42+
(
43+
"Native: query by address (refs #388, #315) (#398)",
44+
398,
45+
"Native: query by address",
46+
),
47+
(
48+
"Bulk step before json.dumps (closes #371) (#377)",
49+
377,
50+
"Bulk step before json.dumps",
51+
),
52+
("Fix a thing (fixes #5) (#6)", 6, "Fix a thing"),
53+
(
54+
"Docs: refs, rank and closes in a sentence (#7)",
55+
7,
56+
"Docs: refs, rank and closes in a sentence",
57+
),
58+
(
59+
"A change that names (refs #1) in the middle and ends plain (#8)",
60+
8,
61+
"A change that names (refs #1) in the middle and ends plain",
62+
),
63+
(
64+
"fix(#423): find_nearest(allowed_rids=[]) returns nothing (#425)",
65+
425,
66+
"fix(#423): find_nearest(allowed_rids=[]) returns nothing",
67+
),
68+
("(refs #9) (#9)", 9, "(refs #9)"),
69+
],
70+
)
71+
def test_a_line_leaves_out_the_notes_that_point_at_issues(title, number, shown):
72+
assert notes.clean_title(title, number) == shown
73+
74+
75+
@pytest.mark.parametrize(
76+
"title,is_merge",
77+
[
78+
("Merge the 26.11.1.post3 release line into main", True),
79+
("Merge the 26.11.1.post2 release line into main (#351)", True),
80+
("Merge branch main into a feature", False),
81+
("Merge the vector index docs", False),
82+
],
83+
)
84+
def test_a_pull_request_that_only_merges_a_release_line_is_not_listed(title, is_merge):
85+
assert bool(notes.MERGE_LINE.match(title)) is is_merge

0 commit comments

Comments
 (0)