Repository navigation
ci: start notes at the first release - #225
Conversation
Without a previous published release, GitHub's generate-notes API starts at an older tag of its choice, even one without a release (as for v0.4.0, whose list started at v0.3.0). For a first release, the workflow now lists all merged pull requests in the history of the release commit itself, in GitHub's format, with "scripts/release_notes.py first"; the job may read pull requests for it. Closes #221 Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Skip merged pull requests without a merge commit, so that they can't fail the release after the image is published. - Keep titles on one line, and split generated notes at line breaks only, so that a title can't add a heading to the release body. - Pin the output of `first` in its CLI test, test non-UTF-8 input, and document the inputs, the permission and how to preview the notes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideThe release workflow now handles a first release by collecting closed pull requests and the release commit history, then using a new Python command to produce GitHub-format notes from merged pull requests reachable from that release. Existing releases continue using GitHub's generated-notes API, while parsing, documentation, permissions, and comprehensive tests are updated to cover the new path and edge cases. Sequence diagram for first-release note generationsequenceDiagram
participant Workflow as Release workflow
participant GitHub as GitHub API
participant Git as Git history
participant Script as release_notes.py
participant Release as GitHub release
Workflow->>GitHub: List closed pull requests
GitHub-->>Workflow: Paginated pull request pages
Workflow->>Git: git rev-list HEAD
Git-->>Workflow: Release commit SHAs
Workflow->>Script: first tag --repository --pulls --commits
Script->>Script: merged_pull_requests(pages)
Script->>Script: first_release_notes(tag, repository, pulls, commits)
Script-->>Workflow: GitHub-format generated notes
Workflow->>Release: Create release with generated notes
Flow diagram for first versus subsequent release notesflowchart TD
Start[Create release] --> Previous{Previous published release?}
Previous -->|Yes| API[GitHub generate-notes API with previous_tag_name]
Previous -->|No| Inputs[Collect closed pull requests and git rev-list HEAD]
Inputs --> First[release_notes.py first]
First --> Filter[Keep merged pull requests in release history]
Filter --> Notes[Build changed, new contributors, and full changelog sections]
API --> Body[Combine generated notes with curated notes]
Notes --> Body
Body --> Publish[Publish release]
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #225 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 16 16
Lines 1296 1362 +66
=========================================
+ Hits 1296 1362 +66 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey - I've found 4 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="scripts/release_notes.py" line_range="531" />
<code_context>
+ lines.append(WHATS_CHANGED)
+ lines += [
+ f"* {pull.title} by @{pull.author} in {pull.url}" for pull in released
+ ]
+ new = [pull for pull in released if first[pull.author] == pull.number]
+ if new:
</code_context>
<issue_to_address>
**Pull request titles inject release links**
When a merged PR author sets its title to Markdown containing a misleading link or other formatted content, the title is whitespace-normalized but not Markdown-escaped before `first_release_notes` inserts it into the release body, so readers can be shown attacker-controlled links or misleading release-note text as project-published content.
Escape Markdown syntax in PR titles before inserting them into generated notes, or otherwise render titles as plain text.
</issue_to_address>
### Comment 2
<location path=".github/workflows/release.yaml" line_range="464-472" />
<code_context>
+ gh api "repos/${GH_REPO}/releases/generate-notes" \
+ -f "tag_name=${TAG}" -f "previous_tag_name=${PREVIOUS}" \
+ --jq .body > "${notes_file}"
+ else
+ pulls="$(mktemp)"
+ commits="$(mktemp)"
+ gh api --paginate --slurp \
+ "repos/${GH_REPO}/pulls?state=closed&per_page=100" > "${pulls}"
+ git rev-list HEAD > "${commits}"
+ python scripts/release_notes.py first "${TAG}" \
+ --repository "${GH_REPO}" --pulls "${pulls}" \
+ --commits "${commits}" > "${notes_file}"
fi
- notes_file="$(mktemp)"
</code_context>
<issue_to_address>
**Concurrent releases repeat earlier notes**
When two release runs for different tags determine the previous release before either has published, two different tag runs can both read an empty published-release list before either publishes. Since concurrency is keyed by ref, both take this first-release branch and include the full history, so the later release repeats pull requests already listed in the earlier release.
Serialize release publication across tags, or coordinate the previous-release check and notes generation so concurrent runs cannot both use the first-release history.
</issue_to_address>
### Comment 3
<location path="scripts/release_notes.py" line_range="521" />
<code_context>
+ The notes, as the `body` of a `generate-notes` response.
+ """
+ history = set(commits)
+ ordered = sorted(pulls, key=lambda pull: (pull.merged_at, pull.number))
+ first: dict[str, int] = {}
+ for pull in ordered:
</code_context>
<issue_to_address>
**Pull requests appear in wrong merge order**
When two pull requests share a `merged_at` timestamp and their merge order differs from their pull-request-number order, `ordered` sorts tied pulls by `pull.number`, so `first_release_notes` lists them out of merge order and can choose the wrong first-contribution entry for an author.
`ordered` must use the actual merge sequence to break `merged_at` ties instead of `pull.number`.
</issue_to_address>
### Comment 4
<location path=".github/workflows/release.yaml" line_range="467-469" />
<code_context>
+ else
+ pulls="$(mktemp)"
+ commits="$(mktemp)"
+ gh api --paginate --slurp \
+ "repos/${GH_REPO}/pulls?state=closed&per_page=100" > "${pulls}"
+ git rev-list HEAD > "${commits}"
+ python scripts/release_notes.py first "${TAG}" \
+ --repository "${GH_REPO}" --pulls "${pulls}" \
</code_context>
<issue_to_address>
**Pagination repeats pull requests**
When the closed-pull-request list changes while a first-release run is fetching multiple pages, a closed pull request entering the paginated result between page requests shifts the page boundaries. `merged_pull_requests` keeps repeated records, so `first_release_notes` emits the affected pull request more than once in the release notes.
Deduplicate paginated results by pull-request number and reconcile the pages against a stable complete result before generating notes.
Also at `scripts/release_notes.py:468`.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 4 findings to address first, and the release job gains permission to read closed pull requests, and its first-release notes are published from that data. If the commit matching or PR selection is wrong, readers may see an incorrect public release note; the release text can be edited, but that cannot undo what was already seen.
Blocking findings: scripts/release_notes.py:531, .github/workflows/release.yaml:472, scripts/release_notes.py:521, .github/workflows/release.yaml:469
Pages of closed pull requests fetched while pull requests are closed may repeat one; list each pull request once. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Without a previous published release, GitHub's
generate-notesAPI picks an older tag itself, even one that has no release. That is why the generated list of v0.4.0 started at the tag v0.3.0. For a first release, the "Create release" step now builds the generated notes itself:scripts/release_notes.py first <tag> --repository <owner/repo> --pulls <file> --commits <file>prints notes in GitHub's format: "What's Changed", "New Contributors" and**Full Changelog**: …/commits/<tag>. The inputs are the closed pull requests (gh api --paginate --slurp "repos/…/pulls?state=closed&per_page=100") and the release's commits (git rev-list HEADat the release commit).previous_tag_name). The job getspull-requests: read.body()now splits generated notes only at line breaks (LF, CRLF, CR). Before, it also split at other separators such as U+2028, which would let a pull request title add a heading.docs/development.mddescribes how a first release works and how to preview its notes.Builds on the draft → upload → publish step of #219.
Closes #221
How it was verified
coverage run --source scripts -m pytest tests/test_release_notes.py tests/test_release_version.py tests/test_release_assets.py: all pass, andscripts/release_notes.pyhas 100% coverage. After mergingdev, the release-notes, version-guard and docs-hook tests pass (153 passed).pre-commit run --all-filespasses, including actionlint.I ran
firston real data:v0.4.0, the repository's 110 closed pull requests andgit rev-list v0.4.0. The output matches the "Commits" section of the published v0.4.0 notes, including the order,@dependabot[bot]and the order of "New Contributors". It also lists feat: controllers for adding & deleting services #10, feat(helm)!: pin MongoDB, add DB auth and probes #99, feat!: add owner-based access control #106 and feat!: serve service info from config only #107, which the published list lacks, so@uniqueg's first contribution becomes feat: controllers for adding & deleting services #10 instead of feat: add support for JWT-based authZ & validation #16. Their merge commits are in the history of v0.4.0, and GitHub associates them with those pull requests, so the published list is incomplete there.Review: two rounds of adversarial and quality reviewer subagents. No high findings. The medium ones are fixed: a literal expected output in the CLI test, the parser description, and the docs. The low ones that affect behaviour are fixed too: skipping pull requests without a merge commit, one-line titles, and splitting only at line breaks.
CI: all checks pass.
Declined review findings
An end-to-end test of the workflow step: that step only runs at a real first release. The Python parts are tested, and the docs give the commands to preview the notes locally.
First contributions ignore merged pull requests without a merge commit: this is a rare edge case. The approximation is accepted.
Sourcery: Markdown in titles (not escaped): GitHub's generated notes keep titles as they are too, and titles stay on one line.
Sourcery: concurrent releases repeating notes: the previous-release logic is unchanged by this PR; releases wait for the approval of the
releaseenvironment one at a time.Sourcery: ties of
merged_at: the API has no finer merge order; the number is a stable tie-breaker.Fixed from Sourcery: pull requests repeated across pages are listed once.
Open questions
None (whether to correct the published v0.4.0 notes is outside this PR).
🤖 Generated with Claude Code