From eb0106e6fb100da60089129f77da7c84681ef708 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 23 Nov 2026 08:45:48 +0000 Subject: [PATCH] :sparkles: Simplify changelog review and report label edits Keep the release procedure in one place and separate review from GitHub writes. Clarify how to prepare and verify release highlights. Report each successful label edit so earlier changes remain visible if a later edit fails. AI-assisted-by: gpt-6.2-sol --- .agents/skills/update-changelog/SKILL.md | 64 ++----------------- .serena/memories/scripts/changelog.md | 2 +- .../memories/workflow/updating-changelog.md | 57 +++++++++++------ scripts/changelog.py | 28 ++++++-- scripts/test_changelog.py | 40 ++++++++++++ 5 files changed, 111 insertions(+), 80 deletions(-) diff --git a/.agents/skills/update-changelog/SKILL.md b/.agents/skills/update-changelog/SKILL.md index 97ba1bcd20..db876798f9 100644 --- a/.agents/skills/update-changelog/SKILL.md +++ b/.agents/skills/update-changelog/SKILL.md @@ -5,62 +5,12 @@ description: Update the project CHANGES.md with issues from a given GitHub miles # Skill: update-changelog -Entry point for all changelog work. All rules — sections, exclusions, entry -format, the `:boom:`, `:rocket:` and `:lock:` contracts, pre-flight, and the -anomaly report — live in `mem:workflow/updating-changelog` (file: -`.serena/memories/workflow/updating-changelog.md`). This skill routes to that -memory; it does not repeat it. +Use this skill to prepare, refresh, or audit a changelog version. -## When to Use +Read `mem:workflow/updating-changelog` for the rules and follow its **Flow**: +collect, review, write, verify. Start with `collect ` and keep its +JSON snapshot in a private temporary file. Reuse it for the review and checks; +collect again if the GitHub data changes. -- Before a new release, to populate the changelog with all fixed issues -- When new issues are added to an existing milestone and the changelog needs - to be refreshed -- To audit or repair an existing version section - -## Prerequisites - -- `gh` CLI authenticated (`gh auth status`) -- Python 3.8+ -- `scripts/gh.py` for GitHub queries, `scripts/changelog.py` for changelog - checks (run `python3 scripts/changelog.py --help` for usage) - -## What to Read - -1. `mem:workflow/updating-changelog` — the canonical flow: sources of truth, - layout, entry rules, the `## Breaking change note` comment contract, the - advisory (`:lock:`) contract, pre-flight checks, anomaly types, and pitfalls. -2. `mem:scripts/changelog` — `collect`, `boom`, `security`, `check-merged`, `cross-ref`, - `dev-only-bugs`, `report`. -3. `mem:scripts/gh` — `issues`, `issue`, `comments`, `prs`, `advisories`. - -## Commands - -```bash -snapshot=$(mktemp) -python3 scripts/changelog.py collect "" > "$snapshot" -``` - -Review the JSON before running any of these commands: - -```bash -python3 scripts/changelog.py dev-only-bugs "" --snapshot "$snapshot" --apply -python3 scripts/changelog.py boom "" --snapshot "$snapshot" --write -python3 scripts/changelog.py security "" --snapshot "$snapshot" --write -python3 scripts/changelog.py cross-ref "" --snapshot "$snapshot" -python3 scripts/changelog.py report "" --snapshot "$snapshot" -``` - -Keep the snapshot private: it can contain unpublished advisories and PR text. -Run `collect` first and use the JSON for review and -merge-state checks. Run `collect` again after any GitHub change, including -`dev-only-bugs --apply`. Use `--apply` only when there are sure cases. - -## Hard Rules - -- `CHANGES.md` is edited only on explicit request or during the release process. -- Only closed, non-excluded milestone issues are included; the issue is the changelog unit and the PR is inline. -- `:boom:` and `:rocket:` are label-generated and `:lock:` is advisory-generated: never hand-edit them; edit the label, the `## Breaking change note` comment or the advisory and re-run the command. -- Verify PR merge status before writing; only merged PRs are referenced. -- Bugs that never reached production stay out: `dev-only-bugs --apply` labels the sure ones; candidates are the user's call, never label them yourself. -- Fill `patched_versions` in the advisories before running `security`; unpublished advisories are valid. +Keep review read-only. Follow the separate `--apply` branch only when the +workflow calls for it. diff --git a/.serena/memories/scripts/changelog.md b/.serena/memories/scripts/changelog.md index 382cd983ce..d4a185d210 100644 --- a/.serena/memories/scripts/changelog.md +++ b/.serena/memories/scripts/changelog.md @@ -10,7 +10,7 @@ - `boom [--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 `#### ` 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 [--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 () (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 [--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 [--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. +- `dev-only-bugs [--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 and prints each successful edit to stdout with its issue URL and reason. On failure it exits nonzero and names the failed issue on stderr; earlier confirmations remain visible. 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. - `report [--changes CHANGES.md --output CHANGES-ISSUES.md]` — overwrite the anomaly report: A/B milestone mismatches, E `:boom:` entry without the label, F `:rocket:` sync, G `:boom:` sync, plus the C/D `:rocket:` gaps and the `dev-only-bugs` lists (warnings). `:boom:`/`:rocket:` rule violations are fixed by regenerating or relabelling, not by editing entries in place. ## Conventions diff --git a/.serena/memories/workflow/updating-changelog.md b/.serena/memories/workflow/updating-changelog.md index fcb8245761..c8b48b29b8 100644 --- a/.serena/memories/workflow/updating-changelog.md +++ b/.serena/memories/workflow/updating-changelog.md @@ -29,7 +29,7 @@ Editing `CHANGES.md` happens only on explicit request or as part of the release - **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`, `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). +- **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 flow finds these bugs and labels the sure cases `no changelog` (section 8, Review). - **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. @@ -140,7 +140,7 @@ Rules for the note: - Lists exactly the milestone issues with the `release highlight` label, and nothing else. Product decides highlights by labelling issues; a regeneration cannot undo that choice. - Every entry copies the text and references of the issue's regular entry and MUST carry both an issue link and a PR reference. - If no issue is labelled, leave the section out; do not pick highlights yourself. -- Never edit `:rocket:` by hand: add or remove the label and regenerate. +- No command generates `:rocket:` today. Build it from the eligible labelled issues in the snapshot, using their regular entries, and verify it with `report`. Change the label on GitHub to change which issues appear; do not pick highlights in the changelog. ## 7. `:lock:`: security fixes @@ -157,20 +157,41 @@ 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. **Collect the release inputs**: `python3 scripts/changelog.py collect "" > "$snapshot"`. Use a private temporary file because the JSON can contain unpublished advisories and PR text. It contains the milestone issues and PRs, batched related records, generated-section inputs, dev-only bug candidates and a comparison with the current changelog. Use `eligible_issues` for changelog candidates and `comparison` for pre-flight. Collection does not write to the changelog or GitHub. -3. **Keep out bugs that never reached production**: review `dev_only_bugs` in the snapshot. If `auto` has entries, run `python3 scripts/changelog.py dev-only-bugs "" --snapshot "$snapshot" --apply` to label the sure ones `no changelog` on GitHub, then repeat 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). -4. **Resolve PR links** using `prs` and `related_prs` in the snapshot. Look up a PR separately only if you discover a candidate not already in the snapshot. -5. **Categorize** by Issue Type and the two labels (section 2), and **build the descriptions** (section 4). -6. **Verify PR merge status** before writing: only include PRs with state `MERGED` in the snapshot or verified by `check-merged` if looked up separately. If a closing PR was closed unmerged, look for the PR that superseded it. -7. **Reconcile the existing text** (section 9). -8. **Generate `:boom:`**: `python3 scripts/changelog.py boom "" --snapshot "$snapshot"` prints the section; add `--write` to update just that subsection in `CHANGES.md`. If there are no entries, `--write` removes the subsection or leaves it absent. -9. **Generate `:rocket:`** from the `release highlight` label (section 6). -10. **Generate `:lock:`**: `python3 scripts/changelog.py security "" --snapshot "$snapshot"` prints the section; add `--write` to replace it in `CHANGES.md`. The contract lives in section 7. -11. **Cross-check PRs**: `python3 scripts/changelog.py cross-ref "" --snapshot "$snapshot"`. It compares the snapshot against the updated changelog, lists missing merged PRs and warns about closed (unmerged) PRs. PRs linked from `:lock:` count as referenced; an advisory with no PR is invisible here by design. -12. **Generate the anomaly report**: `python3 scripts/changelog.py report "" --snapshot "$snapshot"`. It reads the updated changelog and overwrites `CHANGES-ISSUES.md` (section 10). If you need the report to resolve a new reference not known to the snapshot, collect again first. +### Collect + +- Confirm the version if unclear. Use an authenticated `gh` CLI and a private temporary file: the snapshot can contain unpublished advisories and PR text. + +```bash +snapshot=$(mktemp) +python3 scripts/changelog.py collect "" > "$snapshot" +``` + +- Use the same snapshot throughout. Collect again if GitHub data changes or if the final report needs to resolve a new reference absent from the snapshot. + +### Review + +- Use `eligible_issues` to select entries, `comparison` to reconcile the current text (section 9), and `prs` and `related_prs` to verify links. Reference only `MERGED` PRs. If a closing PR was closed unmerged, look for its replacement; use `check-merged` for PRs looked up outside the snapshot. +- Review `dev_only_bugs`. A bug with a `Feature` or `Enhancement` parent in the same milestone is a sure case (`auto`). An epic parent in the same milestone, a `regression` label, or an unreleased-only environment is only a hint (`suggested`). Show candidates to the user, who labels the ones they confirm. +- **Separate GitHub write, only if there are sure cases:** `python3 scripts/changelog.py dev-only-bugs "" --snapshot "$snapshot" --apply` adds `no changelog` to `auto` issues and prints each successful edit to stdout. If a later edit fails, earlier edits still stand. Collect again after applying labels before proceeding. + +### Write + +- Update only on explicit request or during a release. Categorize and draft entries using sections 2–4. Build `:rocket:` from `release highlight` as described in section 6. +- Use the generators for `:boom:` and `:lock:` (sections 5 and 7). Omit `--write` to preview; use it only after the version header exists. + +```bash +python3 scripts/changelog.py boom "" --snapshot "$snapshot" --write +python3 scripts/changelog.py security "" --snapshot "$snapshot" --write +``` + +### Verify + +- `cross-ref` shows missing merged PRs and warns about closed, unmerged PRs. `report` checks the updated changelog and overwrites `CHANGES-ISSUES.md` (section 10). + +```bash +python3 scripts/changelog.py cross-ref "" --snapshot "$snapshot" +python3 scripts/changelog.py report "" --snapshot "$snapshot" +``` ## 9. Pre-flight: reconcile before writing @@ -198,7 +219,7 @@ Start from a fresh `collect` snapshot. Refresh it if GitHub changes during revie - **C — released X.Y.0 version without a `:rocket:` section** (gap; patches never carry highlights). - **D — `:rocket:` entry without issue AND PR references** (gap). -**Bugs that may never have reached production** are warnings too (section 8, step 3): sub-issues of a milestone feature still unlabelled (run `dev-only-bugs --apply`) and candidates for the user to confirm. They never count toward the total. +**Bugs that may never have reached production** are warnings too (section 8, Review): sure cases still unlabelled and candidates for the user to confirm. They never count toward the total. Anything else is a rule violation, not a report item: fix it in the pre-flight and re-run. @@ -208,7 +229,7 @@ Anything else is a rule violation, not a report item: fix it in the pre-flight a - **Labels, not emoji**: title prefixes are cosmetic and often missing; the section comes from Issue Type and the two labels. - **Taiga references**: old entries link to Taiga. Resolve them to the GitHub issue via the description text or the PRs that mention the Taiga URL, then link issue and PR. - **Long-lived links only**: runbooks and docs referenced from a note must point to `staging` or `main`, never to a feature branch that will be deleted. -- **Generated sections**: `:boom:`, `:rocket:` and `:lock:` are generated. Never patch them by hand; edit the label, the note comment or the advisory and re-run. +- **Generated sections**: use `boom` and `security` for `:boom:` and `:lock:`. Change the label, note or advisory on GitHub rather than patching their output. For `:rocket:`, follow the label-driven workflow in section 6. - **Deleted or transferred issues**: an issue referenced in the changelog that returns 410/404 (deleted or moved out of the repo) must lose its entry in the pre-flight. Its security fixes, if any, stay in `:lock:` through the advisory. ## 12. Where the code is diff --git a/scripts/changelog.py b/scripts/changelog.py index 6c7dc84952..dd3ccd9560 100644 --- a/scripts/changelog.py +++ b/scripts/changelog.py @@ -765,10 +765,30 @@ def cmd_dev_only_bugs(args: argparse.Namespace) -> None: if args.apply: for e in auto: - subprocess.run( - ["gh", "issue", "edit", str(e["issue"]), "--repo", REPO, - "--add-label", "no changelog"], - check=True, capture_output=True, + url = issue_url(e["issue"]) + try: + subprocess.run( + [ + "gh", + "issue", + "edit", + str(e["issue"]), + "--repo", + REPO, + "--add-label", + "no changelog", + ], + check=True, + capture_output=True, + text=True, + ) + except subprocess.CalledProcessError as err: + detail = (err.stderr or "").strip() + detail = detail or f"gh exited with status {err.returncode}" + sys.exit(f"ERROR: could not apply `no changelog` to {url}: {detail}") + print( + f"Applied `no changelog`: {url} ({e['reason']})", + flush=True, ) print(f"Labelled {len(auto)} issues `no changelog`", file=sys.stderr) diff --git a/scripts/test_changelog.py b/scripts/test_changelog.py index 6c6d2aaab9..2d31e6e8ec 100644 --- a/scripts/test_changelog.py +++ b/scripts/test_changelog.py @@ -844,5 +844,45 @@ class FindDevOnlyBugsTests(unittest.TestCase): self.assertEqual([e["issue"] for e in suggested], [3, 5, 9]) +class DevOnlyBugsApplyTests(unittest.TestCase): + def test_reports_only_successful_edits_if_a_later_edit_fails(self): + snapshot = { + "dev_only_bugs": { + "auto": [ + { + "issue": 1, + "issue_title": "First bug", + "reason": "Same milestone", + }, + { + "issue": 2, + "issue_title": "Second bug", + "reason": "Same milestone", + }, + ], + "suggested": [], + } + } + args = argparse.Namespace(milestone="2.19.0", apply=True) + out = io.StringIO() + with ( + patch.object(ch, "load_snapshot", return_value=snapshot), + patch.object( + ch.subprocess, + "run", + side_effect=[None, ch.subprocess.CalledProcessError(1, "gh")], + ), + contextlib.redirect_stdout(out), + self.assertRaisesRegex(SystemExit, r"could not apply .*issues/2"), + ): + ch.cmd_dev_only_bugs(args) + + self.assertIn( + "Applied `no changelog`: https://github.com/penpot/penpot/issues/1", + out.getvalue(), + ) + self.assertNotIn("https://github.com/penpot/penpot/issues/2", out.getvalue()) + + if __name__ == "__main__": unittest.main(verbosity=2)