🐛 Fix changelog generation and advisory pagination

Use GitHub's cursor pagination for repository advisories and flatten the
returned pages.

Remove empty breaking-change sections and document the changelog contract.

AI-assisted-by: gpt-6-luna
This commit is contained in:
Andrey Antukh 2026-11-23 08:27:28 +00:00
parent f2648581cc
commit f089c86a71
8 changed files with 74 additions and 33 deletions

View File

@ -5,7 +5,7 @@
## Subcommands
- `check-merged <PR...>` (`--file`, `--stdin` accepted) — warn on any non-merged PR, exit 1 when found; run before writing changelog entries.
- `boom <MILESTONE> [--changes CHANGES.md --write]` — generate `### :boom: Breaking changes & Deprecations` from the closed, non-excluded milestone issues labelled `breaking change`, sorted by issue number. Each issue becomes a `#### <issue title>` block: content = body of the issue's last `## Breaking change note` comment (whole markdown, headings demoted to `#####` outside code fences; fallback = heading plus refs with a stderr warning), refs = issue link plus merged closing PRs on their own line, with `(by @author)` for `community contribution`. `--write` replaces only that subsection of the version (inserts it after the version header when missing, keeps the heading when there are no entries; idempotent). Print-only by default. Uses `gh.py comments`.
- `boom <MILESTONE> [--changes CHANGES.md --write]` — generate `### :boom: Breaking changes & Deprecations` from the closed, non-excluded milestone issues labelled `breaking change`, sorted by issue number. Each issue becomes a `#### <issue title>` block: content = body of the issue's last `## Breaking change note` comment (whole markdown, headings demoted to `#####` outside code fences; fallback = heading plus refs with a stderr warning), refs = issue link plus merged closing PRs on their own line, with `(by @author)` for `community contribution`. `--write` replaces only that subsection of the version, inserts it after the version header when needed, and removes it when there are no entries. Print-only by default. Uses `gh.py comments`.
- `security <MILESTONE> [--changes CHANGES.md --write]` — generate `### :lock: Security fixes` from the advisories whose `patched_versions` include the version (via `gh.py advisories --patched-version`), sorted by GHSA id. Entry: `- Fix <description> (<advisory URL>) (PR: [#N](...))`; description = `Fix` + advisory summary, first word decapitalized unless it starts with an acronym; PRs = merged milestone PRs labelled `pr pt` whose body contains the GHSA id, comma-separated, and no PR is legal. Warns on stderr when a `pr pt` PR references an advisory with no matching `patched_versions`. `--write` replaces only that subsection, placed after `:rocket:` (or `:boom:`, or the version header when neither exists); empty entries remove the subsection; idempotent. Print-only by default.
- `cross-ref <MILESTONE> [--changes CHANGES.md]` — fetch milestone PRs with `--state all` once, report merged PRs missing from the version section plus CLOSED (unmerged) warnings. PR links inside `:lock:` entries count as referenced; advisory URLs never appear here by design.
- `dev-only-bugs <MILESTONE> [--apply]` — list closed milestone bugs that never reached production, without `no changelog`. Sure: parent issue is a `Feature`/`Enhancement` of the same milestone; `--apply` adds `no changelog` to these only. Candidates (never labelled automatically): parent is an epic of the milestone, `regression` label, or the "Affected versions" / "Environment" body field names only hourly, develop, staging, PRE or the milestone version itself (`only_unreleased_envs`; any production hint or other version keeps the bug in — versions compare as full semver with missing patch = 0, so for milestone 2.19.2 the released 2.19.0 keeps the bug in). Reads `body` and `parent` from one batched `gh.py issue` lookup.
@ -19,4 +19,4 @@
- PR/issue reference parsing covers standard `[#N](.../pull/N)` / `[#N](.../issues/N)` links plus legacy `PR:[N]` / `[Github #N]` forms.
- Shared parsing helpers (`extract_version_section`, `extract_subsection`, `collect_changelog_prs/issues`) live at module top so future subcommands reuse them instead of duplicating regexes.
- Report anomaly types: A/B milestone mismatches, E `:boom:` entry whose issue lacks the `breaking change` label (counted, entries preserved — human labels the issue or moves the entry), G `breaking change` issue missing from `:boom:` (counted, same contract as F); C/D are `:rocket:` gaps (warnings, never counted).
- `issue_excluded` (closed, non-Task, non-Rejected, no `release blocker`/`no changelog` label) is module-level and shared by `report` and `boom` so the exclusions cannot drift.
- `issue_excluded` (closed, non-Task, non-Rejected, no `no changelog` label) is module-level and shared by `report` and `boom` so the exclusions cannot drift. `release blocker` is not a changelog exclusion.

View File

@ -40,7 +40,7 @@ python3 scripts/gh.py issues "2.16.0" --label "bug"
python3 scripts/gh.py issues "2.16.0" --label "bug,regression"
# Exclude by label
python3 scripts/gh.py issues "2.16.0" --exclude "release blocker,no changelog"
python3 scripts/gh.py issues "2.16.0" --exclude "no changelog"
# Show only issues NOT yet in CHANGES.md
python3 scripts/gh.py issues "2.16.0" --compare CHANGES.md
@ -131,6 +131,8 @@ python3 scripts/gh.py advisories GHSA-xvj6-fh9w-gjw7
`--patched-version` filters the raw advisories before formatting: the match is an exact token of `vulnerabilities[*].patched_versions` (split on `,`/`;`), so `2.19.1` never matches `2.19.10`. Every state is included (`triage`, `draft`, `published`, `closed`, `withdrawn`). The raw `vulnerabilities` stay internal to the filter: the list output keeps the summary schema.
The repository security-advisories endpoint uses cursor pagination (`before`/`after`), not numeric `page` pagination. Observed failure: `page=1` and `page=2` both returned the same 100 advisories, so a length-based loop never ended. `fetch_advisories` must use `gh api --paginate --slurp` so the GitHub CLI follows the response `Link` headers and returns page arrays for flattening. Do not hand-increment `page`.
**Output**: JSON to stdout; progress to stderr.
## Key principles

View File

@ -28,9 +28,9 @@ Editing `CHANGES.md` happens only on explicit request or as part of the release
- **Security fixes come from advisories**: an advisory whose `patched_versions` include the version becomes a `:lock:` entry (section 7). `triage`, `draft` and `published` are all valid states; the advisory may still be unpublished when the changelog is written. A security fix may also carry a regular bug issue; both entries are legal and independent (the issue lives in `:bug:` as any other bug).
- **Two labels override the Issue Type**: `breaking change` → an entry only under `:boom:`, never in its regular section; `release highlight` → an extra entry under `:rocket:` on top of its regular entry.
- **Only closed issues**. An open issue in the milestone is not generated, even if someone added a provisional entry by hand before the merge.
- **Excluded issues**: `no changelog`, `release blocker`, `Task` issue type, `Rejected` project status.
- **Excluded issues**: `no changelog`, `Task` issue type, `Rejected` project status. `release blocker` is not a changelog filter.
- **Bugs that never reached production** stay out: a bug found and fixed while building a feature of the same, unreleased version never affected users. The team rarely labels them, so the flow finds them with `dev-only-bugs` and labels them `no changelog` (section 8, step 3).
- **Excluded PRs**: a PR with `release blocker` or `no issue required` does not bring an entry of its own.
- **Excluded PRs**: a PR with `no issue required` does not bring an entry of its own.
- **An issue with no milestone** belongs to another (probably private) project: it is neither changelog candidate nor anomaly.
## 3. Layout of `CHANGES.md`
@ -74,7 +74,7 @@ The newest version goes at the top, right after the `# CHANGELOG` header. Inside
- `:boom:` first, then `:rocket:`, `:lock:`, `:tada:`, `:sparkles:`, `:bug:`. Features come before enhancements so they stand out to readers deciding whether to update.
- **This layout applies from 2.20.0.** Versions up to 2.19.x use the old one: `:bug: Bugs fixed` before `:sparkles: New features & Enhancements`, which mixes features and enhancements. Keep the old layout in those sections, including new 2.19.x patches, so a minor line reads the same. The in-app update dialog only reads `:rocket:`, so the change does not affect it.
- Other headings exist in old versions (`:heart:` community contributions); do not add them to new versions.
- Include a section only when it has entries. Historical versions may have an empty `:boom:` or `:rocket:` heading; `boom --write` keeps the `:boom:` heading even when there are no entries. `:lock:` is omitted (and removed on `--write`) when the version has no security advisories.
- Include a section only when it has entries. `boom --write` removes an empty `:boom:` subsection and does not insert one when there are no breaking changes. `:lock:` is omitted (and removed on `--write`) when the version has no security advisories.
- One blank line between the last entry of a section and the next heading.
- No manual line wrapping: one line per bullet or paragraph, however long.
@ -158,7 +158,7 @@ Generated from the advisories that declare the version in `patched_versions`; ne
## 8. Flow
1. **Confirm the version** (a semver string such as `2.19.0`) with the user when it is not obvious.
2. **Fetch the milestone issues**: `python3 scripts/gh.py issues "<VERSION>" --exclude "release blocker,no changelog"` (closed by default; add `--state all` only to inspect open issues). `gh.py` already drops `Task` and `Rejected`; pass `--include-tasks` / `--include-rejected` only to inspect them. To find what is missing from an existing section, add `--compare CHANGES.md`.
2. **Fetch the milestone issues**: `python3 scripts/gh.py issues "<VERSION>" --exclude "no changelog"` (closed by default; add `--state all` only to inspect open issues). `gh.py` already drops `Task` and `Rejected`; pass `--include-tasks` / `--include-rejected` only to inspect them. To find what is missing from an existing section, add `--compare CHANGES.md`.
3. **Keep out bugs that never reached production**: `python3 scripts/changelog.py dev-only-bugs "<VERSION>"` lists them; add `--apply` to label the sure ones `no changelog` on GitHub, then re-fetch step 2. The label puts the decision on the issue, so it survives a regeneration.
- **Sure**: a bug whose parent issue is a `Feature` or `Enhancement` of the same milestone. `--apply` labels these.
- **Candidates**: a bug whose parent is an epic of the same milestone, that carries the `regression` label, or whose "Affected versions" / "Environment" field names only hourly, develop, staging, PRE or the milestone version itself. `regression` also marks regressions users hit in production, and the field says where the bug was seen, not since when it exists, so never label these yourself: show them to the user, who labels the ones they confirm. The anomaly report lists them too (section 10).
@ -178,7 +178,7 @@ Re-fetch the milestone (do not trust cached data) and fix these in `CHANGES.md`
1. **Duplicate across versions** → remove it from the current section; the earlier version wins for backports.
2. **Stale milestone assignment** (the issue moved out of this milestone) → remove the entry.
3. **Newly applied exclusion labels** (`no changelog`, `release blocker`) → remove the entry.
3. **Newly applied exclusion label** (`no changelog`) → remove the entry.
4. **Issue no longer closed, deleted, or now `Rejected`** → remove the entry.
5. **Unmerged or moved PR reference** → fix the reference or remove the entry. A PR merged in a different milestone is an anomaly (section 10); do not remove it silently.
6. **Issue Type changed** → to `Task`: remove the entry; to another type: move the entry to that type's section.

View File

@ -1,5 +1,12 @@
# CHANGELOG
## 2.19.3
### :bug: Bugs fixed
- Fix app startup failure on Chromium browsers with Tampermonkey user scripts enabled [#12924](https://github.com/penpot/penpot/issues/12924) (PR: [#13085](https://github.com/penpot/penpot/pull/13085))
- Size frontend nginx workers from the container CPU limit to prevent OOM kills on large nodes [#13103](https://github.com/penpot/penpot/issues/13103) (PR: [#13110](https://github.com/penpot/penpot/pull/13110))
## 2.19.2
### :bug: Bugs fixed

View File

@ -45,7 +45,7 @@ GH_PY = Path(__file__).resolve().parent / "gh.py"
BOOM_HEADING = "### :boom: Breaking changes & Deprecations"
SECURITY_HEADING = "### :lock: Security fixes"
BREAKING_LABEL = "breaking change"
EXCLUDED_LABELS = {"release blocker", "no changelog"}
EXCLUDED_LABELS = {"no changelog"}
# PR label carried by the security fixes that reference their advisory in the
# PR body, and the GHSA id pattern used to find that reference.
@ -290,8 +290,9 @@ def entry_list_body(entries: list[str]) -> str:
def replace_boom_section(content: str, milestone: str, entries: list[str]) -> str:
"""Return ``content`` with its ``:boom:`` subsection replaced.
The subsection is inserted right after the version header when missing,
which keeps ``:boom:`` as the first section.
The subsection is inserted right after the version header when needed,
which keeps ``:boom:`` as the first section. Empty subsections are removed
and are not inserted.
"""
bounds = version_section_bounds(content, milestone)
if bounds is None:
@ -299,6 +300,13 @@ def replace_boom_section(content: str, milestone: str, entries: list[str]) -> st
start, end = bounds
section = content[start:end]
heading = re.search(rf"(?m)^{re.escape(BOOM_HEADING)}[ \t]*$", section)
if not entries:
if heading is None:
return content
body_start = start + heading.end()
next_heading = re.search(r"(?m)^### ", content[body_start:end])
body_end = body_start + next_heading.start() if next_heading else end
return content[: start + heading.start()] + content[body_end:]
if heading:
body_start = start + heading.end()
next_heading = re.search(r"(?m)^### ", content[body_start:end])
@ -674,7 +682,7 @@ def find_dev_only_bugs(milestone: str, issues: list[dict]) -> tuple[list[dict],
for issue in issues:
if issue.get("issue_type") != "Bug" or issue.get("state") != "CLOSED":
continue
if {"no changelog", "release blocker"} & set(issue.get("labels", [])):
if "no changelog" in issue.get("labels", []):
continue
parent = issue.get("parent") or {}
entry = {"issue": issue["number"], "issue_title": issue.get("title", "")}

View File

@ -15,7 +15,7 @@ Subcommands:
Usage:
python3 scripts/gh.py issues <milestone-title> (default: state=closed)
python3 scripts/gh.py issues "2.16.0" --state all
python3 scripts/gh.py issues "2.16.0" --exclude "release blocker,no changelog"
python3 scripts/gh.py issues "2.16.0" --exclude "no changelog"
python3 scripts/gh.py issues "2.16.0" --label "bug" (include only issues with label)
python3 scripts/gh.py issues "2.16.0" --label "bug,regression" --exclude "no changelog"
python3 scripts/gh.py issues "2.16.0" --compare CHANGES.md
@ -952,21 +952,23 @@ def cmd_comments(args: argparse.Namespace) -> None:
def fetch_advisories() -> list[dict]:
"""Fetch all security advisories for the repository via REST API."""
all_advisories: list[dict] = []
page = 1
while True:
advisories = run_gh_rest(
f"repos/{REPO}/security-advisories?per_page=100&page={page}"
"""Fetch all security advisories using GitHub's cursor-based pagination."""
try:
pages = json.loads(
run_gh_command(
[
"gh",
"api",
"--paginate",
"--slurp",
f"repos/{REPO}/security-advisories?per_page=100",
]
)
)
all_advisories.extend(advisories)
except GhCommandFailed as err:
fail_gh(err.stderr)
if len(advisories) < 100:
break
page += 1
return all_advisories
return [advisory for page in pages for advisory in page]
def fetch_advisory(ghsa_id: str) -> dict:
@ -1092,7 +1094,7 @@ def main() -> None:
)
p_issues.add_argument(
"--exclude", "--exclude-labels",
help="Comma-separated labels to exclude, e.g. 'release blocker,no changelog'"
help="Comma-separated labels to exclude, e.g. 'no changelog'"
)
p_issues.add_argument(
"--label", "--labels",

View File

@ -126,13 +126,13 @@ class IssueExcludedTests(unittest.TestCase):
def test_keeps_a_valid_closed_issue(self):
self.assertFalse(ch.issue_excluded(self.issue()))
def test_excludes_open_task_rejected_and_labelled(self):
def test_excludes_open_task_rejected_and_no_changelog(self):
self.assertTrue(ch.issue_excluded(None))
self.assertTrue(ch.issue_excluded(self.issue(state="OPEN")))
self.assertTrue(ch.issue_excluded(self.issue(issue_type="Task")))
self.assertTrue(ch.issue_excluded(self.issue(project_status="Rejected")))
self.assertTrue(ch.issue_excluded(self.issue(labels=["release blocker"])))
self.assertTrue(ch.issue_excluded(self.issue(labels=["no changelog"])))
self.assertFalse(ch.issue_excluded(self.issue(labels=["release blocker"])))
class RenderBoomEntryTests(unittest.TestCase):
@ -180,10 +180,18 @@ class ReplaceBoomSectionTests(unittest.TestCase):
once = ch.replace_boom_section(CHANGES, "2.19.0", [entry])
self.assertEqual(once, ch.replace_boom_section(once, "2.19.0", [entry]))
def test_empty_section_keeps_the_heading(self):
def test_empty_section_removes_the_heading(self):
updated = ch.replace_boom_section(CHANGES, "2.19.0", [])
self.assertIn(
"### :boom: Breaking changes & Deprecations\n\n### :rocket:", updated
self.assertNotIn("### :boom: Breaking changes & Deprecations", updated)
self.assertIn("### :rocket:", updated)
def test_empty_entries_do_not_insert_the_subsection(self):
without = CHANGES.replace(
"### :boom: Breaking changes & Deprecations\n\n- Old entry.\n\n", ""
)
self.assertEqual(
without,
ch.replace_boom_section(without, "2.19.0", []),
)
def test_inserts_the_subsection_when_missing(self):
@ -719,9 +727,11 @@ class FindDevOnlyBugsTests(unittest.TestCase):
{**bug(8, parent={"number": 10, "issue_type": "Feature", "milestone": "2.19.0"}),
"issue_type": "Enhancement"},
bug(9, body="### Affected versions\n\n2.18.2\n", labels=["regression"]),
bug(10, parent={"number": 10, "issue_type": "Feature", "milestone": "2.19.0"},
labels=["release blocker"]),
]
auto, suggested = ch.find_dev_only_bugs("2.19.0", issues)
self.assertEqual([e["issue"] for e in auto], [1, 2])
self.assertEqual([e["issue"] for e in auto], [1, 2, 10])
self.assertEqual([e["issue"] for e in suggested], [3, 5, 9])

View File

@ -191,6 +191,18 @@ class AdvisoriesTests(unittest.TestCase):
gh.advisory_fixed_in_version(self.advisory(" 2.19.1 "), "2.19.1")
)
@patch.object(gh, "run_gh_command")
def test_fetch_advisories_uses_cursor_pagination(self, run_gh_command):
first_page = [{"ghsa_id": "GHSA-first"}]
second_page = [{"ghsa_id": "GHSA-second"}]
run_gh_command.return_value = json.dumps([first_page, second_page])
self.assertEqual(gh.fetch_advisories(), first_page + second_page)
command = run_gh_command.call_args.args[0]
self.assertIn("--paginate", command)
self.assertIn("--slurp", command)
@patch.object(gh, "fetch_advisories")
def test_cmd_advisories_filters_by_patched_version(self, fetch_advisories):
matching = self.advisory("2.19.1", "GHSA-j4vc-cmf6-jhr7")