Skip to content

Commit e6b89eb

Browse files
cknittclaude
andauthored
Group the semantic diff comment's changelog entries as the changelog does (#9007)
Group the comment's changelog entries as the changelog does A flat list led by emojis read unlike the changelog the entries end up in. The entries are now grouped under the changelog's category headings, in its order. Claude-Session: https://claude.ai/code/session_01AzPS5F8RDSGZ6dhfK6NdZp Signed-off-by: Christoph Knittel <ck@cca.io> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent a42a937 commit e6b89eb

4 files changed

Lines changed: 43 additions & 26 deletions

File tree

‎scripts/commitRecords.js‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,13 @@ function changelog(base, tip) {
6565
name,
6666
git(["show", `${tip}:${f}`]),
6767
);
68-
const emoji =
69-
/:\w+:/.exec(
70-
categories[/** @type {keyof typeof categories} */ (category)],
71-
)?.[0] ?? "";
72-
return { category, emoji, text };
68+
const heading =
69+
categories[/** @type {keyof typeof categories} */ (category)];
70+
return { category, heading, text };
7371
} catch {
7472
return {
7573
category: "",
76-
emoji: ":grey_question:",
74+
heading: "#### :grey_question: Not a changelog fragment",
7775
text: `- \`${name}\``,
7876
};
7977
}

‎scripts/commitRecords.test.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ test("the comment lists the changelog entries a range adds, breaking first", asy
933933
const comment = await fs.readFile(md, "utf8");
934934
has(
935935
comment,
936-
"### Changelog\n\n- :boom: Drop -x.\n- :bug: Recover the watcher.\n- :grey_question: `Bad Name.md`\n\n",
936+
"### Changelog\n\n#### :boom: Breaking Change\n\n- Drop -x.\n\n#### :bug: Bug fix\n\n- Recover the watcher.\n\n#### :grey_question: Not a changelog fragment\n\n- `Bad Name.md`\n\n",
937937
);
938938
lacks(comment, "Old.");
939939
lacks(comment, "Tmp.");

‎scripts/recordMarkdown.js‎

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ import {
3838

3939
/**
4040
* A changelog fragment the pull request adds: its category, the category's
41-
* emoji as the changelog heads it (`:boom:`), and its Markdown bullets.
42-
* @typedef {{ category: string, emoji: string, text: string }} ChangelogEntry
41+
* heading as the changelog has it (`#### :boom: Breaking Change`), and its
42+
* Markdown bullets.
43+
* @typedef {{ category: string, heading: string, text: string }} ChangelogEntry
4344
*/
4445

4546
/** The characters a comment holds at most, with room for the action's tag. */
@@ -442,27 +443,31 @@ export function commitMarkdown(r, full, change = "") {
442443
}
443444

444445
/**
445-
* The changelog entries as a list, each bullet led by its entry's emoji, in
446-
* at most `room` characters: the comment shortens commits to fit its
447-
* budget but not the changelog, so entries past the room are counted, not
448-
* drawn.
446+
* The changelog entries grouped under their categories' headings, as the
447+
* changelog groups them (the entries come in its order), in at most `room`
448+
* characters: the comment shortens commits to fit its budget but not the
449+
* changelog, so entries past the room are counted, not drawn.
449450
* @param {ChangelogEntry[]} changelog
450451
* @param {number} room
451452
*/
452453
function changelogList(changelog, room) {
453454
if (!changelog.length) return "No changelog entry.";
454455
const drawn = [];
455456
let size = 0;
457+
let heading = "";
458+
let count = 0;
456459
for (const e of changelog) {
457-
const lines = unmentioned(e.text).replace(/^- /gm, `- ${e.emoji} `);
458-
size += lines.length + 1;
460+
const lines = `${e.heading === heading ? "" : `${e.heading}\n\n`}${unmentioned(e.text)}`;
461+
size += lines.length + 2;
459462
if (size > room) break;
460-
drawn.push(lines);
463+
drawn.push(e.heading === heading || !count ? lines : `\n${lines}`);
464+
heading = e.heading;
465+
count++;
461466
}
462-
const left = changelog.length - drawn.length;
467+
const left = changelog.length - count;
463468
if (left)
464469
drawn.push(
465-
`\n<sub>${left}${drawn.length ? " more" : ""} changelog entr${left === 1 ? "y" : "ies"} under \`changes/\`.</sub>`,
470+
`\n<sub>${left}${count ? " more" : ""} changelog entr${left === 1 ? "y" : "ies"} under \`changes/\`.</sub>`,
466471
);
467472
return drawn.join("\n");
468473
}
@@ -474,8 +479,8 @@ function changelogList(changelog, room) {
474479
* last commits are left to the page. The commits the last push added or
475480
* edited (`changes`) are marked.
476481
*
477-
* The changelog entries the pull request adds (`changelog`, each fragment's
478-
* bullets led by its category's emoji) describe it as a whole, as its squash
482+
* The changelog entries the pull request adds (`changelog`, grouped under
483+
* the changelog's category headings) describe it as a whole, as its squash
479484
* commit will; a commit's `Breaking:` sections describe that commit. They
480485
* come first, under their own heading, which also notes a pull request
481486
* whose commits break something while no entry is a breaking change, or

‎scripts/recordMarkdown.test.js‎

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,13 @@ test("the heading lists the changelog entries and notes a breaking mismatch", ()
270270
const plain = `Fix a typo\n\n${SIGNED}\n`;
271271
const fix = {
272272
category: "fix",
273-
emoji: ":bug:",
273+
heading: "#### :bug: Bug fix",
274274
text: "- Recover @someone's `@raw` build.\n- Keep **watching**,\n after errors.",
275275
};
276276
const md = comment([plain], { changelog: [fix] });
277277
has(
278278
md,
279-
"### Changelog\n\n- :bug: Recover `@someone`'s `@raw` build.\n- :bug: Keep **watching**,\n after errors.\n\n### Semantic Diff\n\n1 commit\n\n<details",
279+
"### Changelog\n\n#### :bug: Bug fix\n\n- Recover `@someone`'s `@raw` build.\n- Keep **watching**,\n after errors.\n\n### Semantic Diff\n\n1 commit\n\n<details",
280280
);
281281
has(
282282
comment([plain], { changelog: [] }),
@@ -287,7 +287,17 @@ test("the heading lists the changelog entries and notes a breaking mismatch", ()
287287
comment([breaking], { changelog: [fix] }),
288288
"<sub>:boom: A commit says what it breaks (`Breaking:`), but no changelog entry is a breaking change.</sub>\n\n### Semantic Diff",
289289
);
290-
const boom = { category: "breaking", emoji: ":boom:", text: "- -x is gone." };
290+
const boom = {
291+
category: "breaking",
292+
heading: "#### :boom: Breaking Change",
293+
text: "- -x is gone.",
294+
};
295+
has(
296+
comment([breaking], {
297+
changelog: [boom, fix, { ...fix, text: "- More." }],
298+
}),
299+
"### Changelog\n\n#### :boom: Breaking Change\n\n- -x is gone.\n\n#### :bug: Bug fix\n\n- Recover `@someone`'s `@raw` build.\n- Keep **watching**,\n after errors.\n- More.\n\n### Semantic Diff",
300+
);
291301
const both = comment([breaking], { changelog: [boom] });
292302
assert.ok(!both.includes("<sub>:boom:"));
293303
has(
@@ -299,15 +309,15 @@ test("the heading lists the changelog entries and notes a breaking mismatch", ()
299309
test("past a quarter of the budget, changelog entries are counted, not drawn", () => {
300310
const entry = (/** @type {number} */ k) => ({
301311
category: "fix",
302-
emoji: ":bug:",
312+
heading: "#### :bug: Bug fix",
303313
text: `- Fix ${k}: ${"x".repeat(300)}`,
304314
});
305315
const md = comment([`Fix\n\n${SIGNED}\n`], {
306316
budget: 4000,
307317
changelog: Array.from({ length: 20 }, (_, k) => entry(k)),
308318
});
309319
assert.ok(md.length <= 4000, `${md.length}`);
310-
has(md, "- :bug: Fix 0:");
320+
has(md, "#### :bug: Bug fix\n\n- Fix 0:");
311321
assert.ok(!md.includes("Fix 3:"));
312322
has(
313323
md,
@@ -316,7 +326,11 @@ test("past a quarter of the budget, changelog entries are counted, not drawn", (
316326
const huge = comment([`Fix\n\n${SIGNED}\n`], {
317327
budget: 4000,
318328
changelog: [
319-
{ category: "fix", emoji: ":bug:", text: `- ${"y".repeat(5000)}` },
329+
{
330+
category: "fix",
331+
heading: "#### :bug: Bug fix",
332+
text: `- ${"y".repeat(5000)}`,
333+
},
320334
],
321335
});
322336
assert.ok(huge.length <= 4000, `${huge.length}`);

0 commit comments

Comments
 (0)