Skip to content

Commit 08486bc

Browse files
cknittclaude
andcommitted
Date the comment and its commits, and link its heading
The one comment is edited in place, and GitHub marks an edit only as "edited", so the heading says which commit it is drawn up to and when, and its title links the page as well as "Full page". Each commit shows its author date to the minute in UTC, as the heading does, on the page too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AzPS5F8RDSGZ6dhfK6NdZp Signed-off-by: Christoph Knittel <ck@cca.io>
1 parent 291da39 commit 08486bc

4 files changed

Lines changed: 51 additions & 14 deletions

File tree

‎scripts/commitRecords.js‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,17 @@ const git = args =>
2929
stdio: ["ignore", "pipe", "ignore"],
3030
});
3131

32+
const MONTHS = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(" ");
33+
34+
/** A time as `Oct 23, 2026, 14:41 UTC`, as the cards and the comment print it. */
35+
const utc = (/** @type {Date} */ d) => {
36+
const two = (/** @type {number} */ n) => String(n).padStart(2, "0");
37+
return `${MONTHS[d.getUTCMonth()]} ${two(d.getUTCDate())}, ${d.getUTCFullYear()}, ${two(d.getUTCHours())}:${two(d.getUTCMinutes())} UTC`;
38+
};
39+
3240
/**
33-
* The record of one commit: its short hash, author, date and message.
41+
* The record of one commit: its short hash, author, author date (in UTC,
42+
* to the minute) and message.
3443
* @param {string} rev
3544
* @returns {CommitRecord}
3645
*/
@@ -40,7 +49,7 @@ function readRecord(rev) {
4049
return parseRecord({
4150
sha: show("--format=%h", "--abbrev=9").trim(),
4251
author: show("--format=%an").trim(),
43-
date: show("--format=%ad", "--date=format:%b %d, %Y").trim(),
52+
date: utc(new Date(show("--format=%aI").trim())),
4453
message: show("--format=%B"),
4554
});
4655
}
@@ -85,9 +94,14 @@ const heading = {
8594
const groups = targets.map(group);
8695
const body = pageBody(groups, heading);
8796
if (options.markdown) {
97+
const [base, tip] = targets[targets.length - 1].split("..");
8898
writeFileSync(
8999
options.markdown,
90-
commentMarkdown(groups, { url: options.url }),
100+
commentMarkdown(groups, {
101+
url: options.url,
102+
head: git(["rev-parse", "--short=9", tip ?? base]).trim(),
103+
updated: utc(new Date()),
104+
}),
91105
);
92106
console.log(options.markdown);
93107
}

‎scripts/commitRecords.test.js‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ test("a minimal record draws its identity and subject", async () => {
132132
has(html, "<h3>Fix a typo</h3>");
133133
assert.match(
134134
html,
135-
/<div class="meta"><code>[0-9a-f]{9}<\/code> · A Person \+ B Person · [A-Z][a-z]{2} \d{2}, \d{4} · <a href="https:\/\/github.com\/rescript-lang\/rescript\/pull\/7">#7<\/a><\/div>/,
135+
/<div class="meta"><code>[0-9a-f]{9}<\/code> · A Person \+ B Person · [A-Z][a-z]{2} \d{2}, \d{4}, \d{2}:\d{2} UTC · <a href="https:\/\/github.com\/rescript-lang\/rescript\/pull\/7">#7<\/a><\/div>/,
136136
);
137137
lacks(html, '<div class="below">');
138138
lacks(html, "Signed-off-by");
@@ -855,7 +855,13 @@ test("--markdown draws every commit into the comment, with the page's link", asy
855855
);
856856
assert.equal(r.status, 0, r.stderr);
857857
const comment = await fs.readFile(md, "utf8");
858-
has(comment, "2 commits · [Full page](https://cdn.example/pr-1/index.html)");
858+
const tip = git("rev-parse", "--short=9", "HEAD");
859+
assert.match(
860+
comment,
861+
new RegExp(
862+
`^### \\[Semantic Diff\\]\\(https://cdn\\.example/pr-1/index\\.html\\)\\n\\n2 commits · ${tip} · [A-Z][a-z]{2} \\d\\d, \\d{4}, \\d\\d:\\d\\d UTC · \\[Full page\\]\\(https://cdn\\.example/pr-1/index\\.html\\)\\n\\n<details`,
863+
),
864+
);
859865
has(comment, "First change");
860866
has(comment, "Second change");
861867
});

‎scripts/recordMarkdown.js‎

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -420,16 +420,29 @@ export function commitMarkdown(r, full) {
420420
}
421421

422422
/**
423-
* The comment: a heading linking the page, then each commit. Past the
424-
* budget, the commits with the most characters are drawn without their
425-
* forms, and if that is not enough, the last commits are left to the page.
423+
* The comment: a heading linking the page (`url`), in its title and as "Full
424+
* page", then each commit. Past the budget, the commits with the most
425+
* characters are drawn without their forms, and if that is not enough, the
426+
* last commits are left to the page. The heading names the commit drawn up
427+
* to (`head`, which GitHub links) and when (`updated`), since the comment is
428+
* edited in place on each push.
426429
* @param {Group[]} groups
427-
* @param {{ url?: string, budget?: number }} [options]
430+
* @param {{ url?: string, budget?: number, head?: string, updated?: string }} [options]
428431
*/
429-
export function commentMarkdown(groups, { url = "", budget = BUDGET } = {}) {
432+
export function commentMarkdown(
433+
groups,
434+
{ url = "", budget = BUDGET, head: tip = "", updated = "" } = {},
435+
) {
430436
const records = groups.flatMap(g => g.records);
431437
const n = records.length;
432-
const head = `### Semantic Diff\n\n${n} commit${n === 1 ? "" : "s"}${url ? ` · [Full page](${url})` : ""}`;
438+
const head = `### ${url ? `[Semantic Diff](${url})` : "Semantic Diff"}\n\n${[
439+
`${n} commit${n === 1 ? "" : "s"}`,
440+
tip,
441+
updated,
442+
url && `[Full page](${url})`,
443+
]
444+
.filter(Boolean)
445+
.join(" · ")}`;
433446
const drawn = records.map(r => commitMarkdown(r, true));
434447
const size = () => drawn.reduce((t, d) => t + d.length + 2, head.length);
435448
const order = drawn

‎scripts/recordMarkdown.test.js‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const SIGNED = "Signed-off-by: A Person <a@example.com>";
99
/**
1010
* The comment drawn from commit messages, one commit each.
1111
* @param {string[]} messages
12-
* @param {{ url?: string, budget?: number }} [options]
12+
* @param {Parameters<typeof commentMarkdown>[1]} [options]
1313
*/
1414
const comment = (messages, options) =>
1515
commentMarkdown(
@@ -65,11 +65,15 @@ Co-Authored-By: B Person <b@example.com>
6565
${SIGNED}
6666
`,
6767
],
68-
{ url: "https://cdn.example/pr-12/index.html?v=1" },
68+
{
69+
url: "https://cdn.example/pr-12/index.html?v=1",
70+
head: "aaaaaaaa0",
71+
updated: "Oct 23, 2026, 11:48 UTC",
72+
},
6973
);
7074
has(
7175
md,
72-
"### Semantic Diff\n\n1 commit · [Full page](https://cdn.example/pr-12/index.html?v=1)",
76+
"### [Semantic Diff](https://cdn.example/pr-12/index.html?v=1)\n\n1 commit · aaaaaaaa0 · Oct 23, 2026, 11:48 UTC · [Full page](https://cdn.example/pr-12/index.html?v=1)\n\n<details",
7377
);
7478
has(
7579
md,

0 commit comments

Comments
 (0)