Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions scripts/commitRecords.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,13 @@ function changelog(base, tip) {
name,
git(["show", `${tip}:${f}`]),
);
const emoji =
/:\w+:/.exec(
categories[/** @type {keyof typeof categories} */ (category)],
)?.[0] ?? "";
return { category, emoji, text };
const heading =
categories[/** @type {keyof typeof categories} */ (category)];
return { category, heading, text };
} catch {
return {
category: "",
emoji: ":grey_question:",
heading: "#### :grey_question: Not a changelog fragment",
text: `- \`${name}\``,
};
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/commitRecords.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ test("the comment lists the changelog entries a range adds, breaking first", asy
const comment = await fs.readFile(md, "utf8");
has(
comment,
"### Changelog\n\n- :boom: Drop -x.\n- :bug: Recover the watcher.\n- :grey_question: `Bad Name.md`\n\n",
"### 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",
);
lacks(comment, "Old.");
lacks(comment, "Tmp.");
Expand Down
31 changes: 18 additions & 13 deletions scripts/recordMarkdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ import {

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

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

/**
* The changelog entries as a list, each bullet led by its entry's emoji, in
* at most `room` characters: the comment shortens commits to fit its
* budget but not the changelog, so entries past the room are counted, not
* drawn.
* The changelog entries grouped under their categories' headings, as the
* changelog groups them (the entries come in its order), in at most `room`
* characters: the comment shortens commits to fit its budget but not the
* changelog, so entries past the room are counted, not drawn.
* @param {ChangelogEntry[]} changelog
* @param {number} room
*/
function changelogList(changelog, room) {
if (!changelog.length) return "No changelog entry.";
const drawn = [];
let size = 0;
let heading = "";
let count = 0;
for (const e of changelog) {
const lines = unmentioned(e.text).replace(/^- /gm, `- ${e.emoji} `);
size += lines.length + 1;
const lines = `${e.heading === heading ? "" : `${e.heading}\n\n`}${unmentioned(e.text)}`;
size += lines.length + 2;
if (size > room) break;
drawn.push(lines);
drawn.push(e.heading === heading || !count ? lines : `\n${lines}`);
heading = e.heading;
count++;
}
const left = changelog.length - drawn.length;
const left = changelog.length - count;
if (left)
drawn.push(
`\n<sub>${left}${drawn.length ? " more" : ""} changelog entr${left === 1 ? "y" : "ies"} under \`changes/\`.</sub>`,
`\n<sub>${left}${count ? " more" : ""} changelog entr${left === 1 ? "y" : "ies"} under \`changes/\`.</sub>`,
);
return drawn.join("\n");
}
Expand All @@ -474,8 +479,8 @@ function changelogList(changelog, room) {
* last commits are left to the page. The commits the last push added or
* edited (`changes`) are marked.
*
* The changelog entries the pull request adds (`changelog`, each fragment's
* bullets led by its category's emoji) describe it as a whole, as its squash
* The changelog entries the pull request adds (`changelog`, grouped under
* the changelog's category headings) describe it as a whole, as its squash
* commit will; a commit's `Breaking:` sections describe that commit. They
* come first, under their own heading, which also notes a pull request
* whose commits break something while no entry is a breaking change, or
Expand Down
26 changes: 20 additions & 6 deletions scripts/recordMarkdown.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,13 @@ test("the heading lists the changelog entries and notes a breaking mismatch", ()
const plain = `Fix a typo\n\n${SIGNED}\n`;
const fix = {
category: "fix",
emoji: ":bug:",
heading: "#### :bug: Bug fix",
text: "- Recover @someone's `@raw` build.\n- Keep **watching**,\n after errors.",
};
const md = comment([plain], { changelog: [fix] });
has(
md,
"### 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",
"### 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",
);
has(
comment([plain], { changelog: [] }),
Expand All @@ -287,7 +287,17 @@ test("the heading lists the changelog entries and notes a breaking mismatch", ()
comment([breaking], { changelog: [fix] }),
"<sub>:boom: A commit says what it breaks (`Breaking:`), but no changelog entry is a breaking change.</sub>\n\n### Semantic Diff",
);
const boom = { category: "breaking", emoji: ":boom:", text: "- -x is gone." };
const boom = {
category: "breaking",
heading: "#### :boom: Breaking Change",
text: "- -x is gone.",
};
has(
comment([breaking], {
changelog: [boom, fix, { ...fix, text: "- More." }],
}),
"### 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",
);
const both = comment([breaking], { changelog: [boom] });
assert.ok(!both.includes("<sub>:boom:"));
has(
Expand All @@ -299,15 +309,15 @@ test("the heading lists the changelog entries and notes a breaking mismatch", ()
test("past a quarter of the budget, changelog entries are counted, not drawn", () => {
const entry = (/** @type {number} */ k) => ({
category: "fix",
emoji: ":bug:",
heading: "#### :bug: Bug fix",
text: `- Fix ${k}: ${"x".repeat(300)}`,
});
const md = comment([`Fix\n\n${SIGNED}\n`], {
budget: 4000,
changelog: Array.from({ length: 20 }, (_, k) => entry(k)),
});
assert.ok(md.length <= 4000, `${md.length}`);
has(md, "- :bug: Fix 0:");
has(md, "#### :bug: Bug fix\n\n- Fix 0:");
assert.ok(!md.includes("Fix 3:"));
has(
md,
Expand All @@ -316,7 +326,11 @@ test("past a quarter of the budget, changelog entries are counted, not drawn", (
const huge = comment([`Fix\n\n${SIGNED}\n`], {
budget: 4000,
changelog: [
{ category: "fix", emoji: ":bug:", text: `- ${"y".repeat(5000)}` },
{
category: "fix",
heading: "#### :bug: Bug fix",
text: `- ${"y".repeat(5000)}`,
},
],
});
assert.ok(huge.length <= 4000, `${huge.length}`);
Expand Down
Loading