Skip to content

Commit de0de10

Browse files
peter-mdfclaude
andcommitted
ci: stop crediting the maintainer, and stop overwriting edited release notes
Two problems with the release PR, both found on ha-swiss-post 0.13.1. The maintainer was credited for reporting their own tester-request issue. The filter checks `author_association`, which only reads MEMBER for a viewer that can see the org membership — and this org's memberships are private, so the release token saw an owner as NONE. Repo permission is visible to that token and settles it: admin, maintain or write is never credited. If the permission check itself is refused, the login is still credited, but with a warning in the run log rather than in silence. An edited PR body was thrown away by the next feat:/fix: push. The house style asks a maintainer to edit the body before merging, so regenerating over it destroyed exactly the work it asks for. The generator now stamps what it wrote with a fingerprint, and on a later run a body that no longer matches is left alone, with the regenerated notes posted as a PR comment instead. The fingerprint is taken over a normalised body, because GitHub returns CRLF and its own trailing whitespace, and the marker is stripped from the published release notes. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 4ddcf0e commit de0de10

4 files changed

Lines changed: 131 additions & 13 deletions

File tree

‎.github/scripts/ai_release_notes.js‎

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,29 +39,64 @@ async function accessToken(core) {
3939
// the commenters. Who tested a fix elsewhere (PRs, chat) isn't attributable,
4040
// so that stays a human's call.
4141
const MAINTAINER_ASSOCIATIONS = new Set(["OWNER", "MEMBER", "COLLABORATOR"]);
42+
const MAINTAINER_PERMISSIONS = new Set(["admin", "maintain", "write"]);
4243

4344
function earnsCredit(user, association) {
4445
return Boolean(user?.login) && user.type !== "Bot" && !MAINTAINER_ASSOCIATIONS.has(association);
4546
}
4647

47-
async function issueAuthors(changes, github, context) {
48+
// `author_association` is not enough on its own. It only reads MEMBER for a
49+
// viewer who can *see* the org membership, and this org's memberships are
50+
// private, so the release token sees the maintainer as NONE and credited them
51+
// for reporting their own tester-request issue. Repo permission is visible to
52+
// the token and settles it.
53+
async function isMaintainer(login, { github, context, core }, cache) {
54+
if (cache.has(login)) return cache.get(login);
55+
let maintainer = false;
56+
try {
57+
const { data } = await github.rest.repos.getCollaboratorPermissionLevel({
58+
owner: context.repo.owner,
59+
repo: context.repo.repo,
60+
username: login,
61+
});
62+
maintainer = MAINTAINER_PERMISSIONS.has(data.permission);
63+
} catch (error) {
64+
if (error.status === 401 || error.status === 403) {
65+
// The token cannot read permissions at all, so every login looks like an
66+
// outside reporter. Credit them rather than dropping a real one, but say
67+
// so: a wrong credit in the log beats a silent one in the release.
68+
core.warning(`Could not check whether @${login} is a maintainer (${error.status}); crediting them — check the release PR.`);
69+
}
70+
// Anything else (a 404 for someone with no access) is simply not a
71+
// maintainer, which is the common case.
72+
}
73+
cache.set(login, maintainer);
74+
return maintainer;
75+
}
76+
77+
async function issueAuthors(changes, { github, context, core }) {
4878
const numbers = [...new Set(changes.flatMap((change) => change.issues || []))];
49-
const logins = [];
50-
const add = (user, association) => {
51-
if (earnsCredit(user, association) && !logins.includes(user.login)) logins.push(user.login);
79+
const candidates = [];
80+
const consider = (user, association) => {
81+
if (earnsCredit(user, association) && !candidates.includes(user.login)) candidates.push(user.login);
5282
};
5383
for (const number of numbers) {
5484
const params = { owner: context.repo.owner, repo: context.repo.repo, issue_number: Number(number) };
5585
try {
5686
const { data: issue } = await github.rest.issues.get(params);
5787
if (issue.pull_request) continue;
58-
add(issue.user, issue.author_association);
88+
consider(issue.user, issue.author_association);
5989
const comments = await github.paginate(github.rest.issues.listComments, { ...params, per_page: 100 });
60-
for (const comment of comments) add(comment.user, comment.author_association);
90+
for (const comment of comments) consider(comment.user, comment.author_association);
6191
} catch {
6292
// Deleted or inaccessible issue: no credit to give.
6393
}
6494
}
95+
const cache = new Map();
96+
const logins = [];
97+
for (const login of candidates) {
98+
if (!(await isMaintainer(login, { github, context, core }, cache))) logins.push(login);
99+
}
65100
return logins;
66101
}
67102

@@ -204,7 +239,10 @@ function render(sections, helpWanted, credits, repo) {
204239
// publishing something malformed or hallucinated.
205240
async function aiReleaseNotes(changes, helpWanted, repo, { github, context, core, suitePath }) {
206241
const houseStyle = fs.readFileSync(path.join(suitePath, "RELEASE_NOTES.md"), "utf8");
207-
const [token, credits] = await Promise.all([accessToken(core), issueAuthors(changes, github, context)]);
242+
const [token, credits] = await Promise.all([
243+
accessToken(core),
244+
issueAuthors(changes, { github, context, core }),
245+
]);
208246
const result = await callClaude(token, changes, houseStyle);
209247

210248
if (!isBulletArray(result.new_features) || !isBulletArray(result.bug_fixes)) {

‎.github/scripts/publish_release.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ module.exports = async ({ github, context, core }) => {
7676
tag_name: version,
7777
target_commitish: sha,
7878
name: version,
79-
body: (releasePr.body || "").trim(),
79+
// The generator's fingerprint marker (see release_manager.js) belongs to
80+
// the PR, not to the published notes.
81+
body: (releasePr.body || "").replace(/\n*<!-- notes-sha: [0-9a-f]{64} -->\s*$/, "").trim(),
8082
draft: true,
8183
}));
8284
}

‎.github/scripts/release_manager.js‎

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const crypto = require("crypto");
12
const fs = require("fs");
23
const path = require("path");
34
const { aiReleaseNotes } = require("./ai_release_notes.js");
@@ -151,6 +152,76 @@ async function openHelpWanted(github, context) {
151152
return issues.filter((issue) => !issue.pull_request).length;
152153
}
153154

155+
// The release PR body is the release, and the house style asks a maintainer to
156+
// edit it before merging — but every later feat:/fix: push regenerates it and
157+
// used to throw that editing away. A fingerprint of what the generator last
158+
// wrote tells the two apart: body still matching it, overwrite freely; body
159+
// changed, a human has been here.
160+
const NOTES_FINGERPRINT = /\n*<!-- notes-sha: ([0-9a-f]{64}) -->\s*$/;
161+
162+
// GitHub hands a PR body back with CRLF line endings and its own trailing
163+
// whitespace, so the fingerprint is taken over a normalised form. Without
164+
// this, a body nobody touched reads as edited and the notes would never
165+
// regenerate again.
166+
function canonical(notes) {
167+
return notes.replace(/\r\n/g, "\n").replace(/\s+$/, "");
168+
}
169+
170+
function fingerprint(notes) {
171+
return crypto.createHash("sha256").update(canonical(notes)).digest("hex");
172+
}
173+
174+
function stamp(notes) {
175+
return `${canonical(notes)}\n\n<!-- notes-sha: ${fingerprint(notes)} -->`;
176+
}
177+
178+
function editedByHand(body) {
179+
const normalised = (body || "").replace(/\r\n/g, "\n");
180+
const match = NOTES_FINGERPRINT.exec(normalised);
181+
// No stamp at all means it predates this check or was written by hand; either
182+
// way, keeping it is the safe choice.
183+
if (!match) return true;
184+
return fingerprint(normalised.slice(0, match.index)) !== match[1];
185+
}
186+
187+
async function openReleasePr(github, context) {
188+
const { data: pulls } = await github.rest.pulls.list({
189+
owner: context.repo.owner,
190+
repo: context.repo.repo,
191+
state: "open",
192+
head: `${context.repo.owner}:automation/release`,
193+
per_page: 1,
194+
});
195+
return pulls[0] || null;
196+
}
197+
198+
// Returns the body to hand to create-pull-request: the freshly stamped notes,
199+
// or the maintainer's own edited body with the regenerated notes posted as a
200+
// comment instead of silently replacing their work.
201+
async function bodyPreservingEdits(notes, { github, context, core }) {
202+
let existing;
203+
try {
204+
existing = await openReleasePr(github, context);
205+
} catch (error) {
206+
core.warning(`Could not read the open release PR (${error.message}); writing the generated notes.`);
207+
return stamp(notes);
208+
}
209+
if (!existing || !editedByHand(existing.body)) return stamp(notes);
210+
211+
try {
212+
await github.rest.issues.createComment({
213+
owner: context.repo.owner,
214+
repo: context.repo.repo,
215+
issue_number: existing.number,
216+
body: `This PR's body was edited by hand, so it was left alone. Here are the regenerated notes, including the change that just landed — fold in whatever is worth keeping.\n\n---\n\n${notes}`,
217+
});
218+
core.notice(`Release PR #${existing.number} was edited by hand; kept it and posted the regenerated notes as a comment.`);
219+
} catch (error) {
220+
core.warning(`Could not post the regenerated notes as a comment (${error.message}); the PR body was still left as edited.`);
221+
}
222+
return existing.body;
223+
}
224+
154225
function writeManifestVersion(version) {
155226
const path = process.env.MANIFEST_PATH;
156227
const original = fs.readFileSync(path, "utf8");
@@ -204,9 +275,11 @@ module.exports = async ({ github, context, core }) => {
204275
notes = releaseNotes(changes, helpWanted, repo);
205276
}
206277

278+
const body = await bodyPreservingEdits(notes, { github, context, core });
279+
207280
core.setOutput("has_release", "true");
208281
core.setOutput("version", version);
209-
core.setOutput("notes", notes);
282+
core.setOutput("notes", body);
210283
core.notice(`Proposing ${version} (${tag} + ${changes.length} change(s)).`);
211284
core.info(`Release notes:\n${notes}`);
212285
};

‎RELEASE_NOTES.md‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,21 @@ release notes for one (see `.github/scripts/ai_release_notes.js`).
6161
- **The release PR body is the release, verbatim — edit it before merging.**
6262
That is where the judgement a rule cannot make belongs: naming who reported an
6363
issue, merging two commits into one clearer bullet, adding context a subject
64-
had no room for. A later `feat:`/`fix:` push regenerates the body, so edit it
65-
shortly before merging.
64+
had no room for. **An edited body is never overwritten:** a later
65+
`feat:`/`fix:` push notices the edit, leaves the body alone and posts the
66+
regenerated notes as a PR comment instead, so the new change is still
67+
visible and folding it in stays a human decision. An unedited body is
68+
regenerated in place as before.
6669
- **Release notes are user-facing only.** Use the shared `##` house style
6770
(`New features`, `Bug fixes`, `Other improvements`, `Credits`) and never
6871
cross-reference other repos. A bullet is one line, optionally followed by
6972
indented paragraphs that expand it — that indentation is what keeps them
7073
inside the bullet, so don't hard-wrap a bullet's own first line.
7174
A section with nothing to say is omitted rather than filled with a placeholder
72-
sentence; `Credits` in particular is worth adding by hand whenever someone
73-
reported or tested the change.
75+
sentence; `Credits` is generated from the reporters and commenters on every
76+
issue a commit references, and is still worth extending by hand for anyone
77+
who tested outside an issue. Maintainers are never credited — the
78+
tester-request issues are opened by one, so the reporters are the commenters.
7479
- **A bullet's first line stays short, and the detail goes underneath it.**
7580
Both renderers — the mechanical one and the AI one in
7681
`.github/scripts/ai_release_notes.js` — emit exactly that shape, and

0 commit comments

Comments
 (0)