Skip to content

Commit 8b14387

Browse files
cknittclaude
andcommitted
Draw a pull request's commit authors by their GitHub login
A login is shorter than a name and leads to the person. The workflow asks GitHub's API for the account each commit's email belongs to, and the page and comment link the login to the profile (a link, not a mention, which would notify); a commit without an account keeps the author's name. 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 f26ccd0 commit 8b14387

6 files changed

Lines changed: 99 additions & 14 deletions

File tree

‎.claude/skills/records/SKILL.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,9 @@ node scripts/commitRecords.js --out page.html [--pr <number>] [--title <text>] \
202202
## What the page shows
203203

204204
The page is the heading, then a card per commit. A card shows the commit's
205-
short sha, author and co-authors (an AI assistant by its short name, such
206-
as Claude), date, the pull request a `(#1234)` at the end of the subject
205+
short sha, author (in a pull request's page and comment, the GitHub login
206+
linking the profile) and co-authors (an AI assistant by its short name,
207+
such as Claude), date, the pull request a `(#1234)` at the end of the subject
207208
names, and the message drawn: the subject, the prose, each object block
208209
with its example and forms, the `Breaking:` sections as banners, and the
209210
`Review:` sections as a list.

‎.github/workflows/semantic_diff.yml‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ jobs:
5656
persist-credentials: false
5757

5858
- name: Render semantic diff
59+
env:
60+
GH_TOKEN: ${{ github.token }}
5961
run: |
6062
git fetch --no-tags --filter=blob:none origin "refs/pull/${PR_NUMBER}/head:refs/heads/pr-${PR_NUMBER}"
6163
base=$(git merge-base "$BASE_SHA" "pr-${PR_NUMBER}")
@@ -72,7 +74,13 @@ jobs:
7274
previous=(--previous "$BEFORE_SHA")
7375
fi
7476
mkdir -p semantic-diff
75-
node scripts/commitRecords.js --out semantic-diff/index.html --markdown semantic-diff/comment.md "${previous[@]}" --url "$url" --pr "$PR_NUMBER" --title "$PR_TITLE" "${base}..pr-${PR_NUMBER}"
77+
# The authors' GitHub logins, which git doesn't know; the API links
78+
# a commit to the account its email belongs to. Without them, the
79+
# authors are drawn by name.
80+
gh api --paginate "repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/commits?per_page=100" \
81+
--jq '.[] | select(.author != null) | "\(.sha) \(.author.login)"' > semantic-diff/logins.txt ||
82+
: > semantic-diff/logins.txt
83+
node scripts/commitRecords.js --out semantic-diff/index.html --markdown semantic-diff/comment.md "${previous[@]}" --logins semantic-diff/logins.txt --url "$url" --pr "$PR_NUMBER" --title "$PR_TITLE" "${base}..pr-${PR_NUMBER}"
7684
7785
- name: Setup Rclone
7886
uses: cometkim/rclone-actions/setup-rclone@8d9c6b95341f7698609deee65c3d62af42893288 # main, 2025-06-18

‎scripts/commitRecords.js‎

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111
* node scripts/commitRecords.js --out review.html <base>..<tip>...
1212
* --pr <number> and --title <text> head the page with the pull request.
1313
* --markdown <file> also draws the records as the pull request's comment
14-
* (scripts/recordMarkdown.js), linking the page at --url <url>. With
14+
* (scripts/recordMarkdown.js), linking the page at --url <url>.
15+
* --logins <file>, lines `<sha> <login>`, names the GitHub accounts of
16+
* the commits' authors, drawn in place of their names. With
1517
* --previous <rev>, the pull request's head before the last push, the
1618
* comment marks the commits that push added or whose message it edited.
1719
*/
1820

1921
import { execFileSync } from "node:child_process";
20-
import { writeFileSync } from "node:fs";
22+
import { readFileSync, writeFileSync } from "node:fs";
2123
import { commentMarkdown } from "./recordMarkdown.js";
2224
import { CSS, esc, pageBody, pageTitle, parseRecord } from "./recordRender.js";
2325

@@ -57,6 +59,7 @@ function readRecord(rev) {
5759
const record = parseRecord({
5860
sha: show("--format=%h", "--abbrev=9").trim(),
5961
author: show("--format=%an").trim(),
62+
login: logins.get(show("--format=%H").trim()),
6063
date: utc(new Date(show("--format=%aI").trim())),
6164
message: show("--format=%B"),
6265
});
@@ -131,9 +134,15 @@ const options = {};
131134
const targets = [];
132135
for (let i = 0; i < args.length; i++) {
133136
if (
134-
["--out", "--pr", "--title", "--markdown", "--url", "--previous"].includes(
135-
args[i],
136-
) &&
137+
[
138+
"--out",
139+
"--pr",
140+
"--title",
141+
"--markdown",
142+
"--url",
143+
"--previous",
144+
"--logins",
145+
].includes(args[i]) &&
137146
i + 1 < args.length
138147
)
139148
options[args[i].slice(2)] = args[++i];
@@ -142,10 +151,18 @@ for (let i = 0; i < args.length; i++) {
142151
const outFile = options.out;
143152
if (!outFile) {
144153
console.error(
145-
"usage: commitRecords.js --out <page.html> [--pr <number>] [--title <text>] [--markdown <comment.md> [--url <page url>] [--previous <rev>]] <rev | base..tip>...",
154+
"usage: commitRecords.js --out <page.html> [--pr <number>] [--title <text>] [--markdown <comment.md> [--url <page url>] [--previous <rev>]] [--logins <file>] <rev | base..tip>...",
146155
);
147156
process.exit(1);
148157
}
158+
/** The GitHub logins of the commits' authors, by full sha. */
159+
const logins = new Map(
160+
(options.logins ? readFileSync(options.logins, "utf8") : "")
161+
.split("\n")
162+
.map(l => l.trim().split(/\s+/))
163+
.filter(f => f.length === 2)
164+
.map(([sha, login]) => [sha, login]),
165+
);
149166
const heading = {
150167
pr: (options.pr ?? "").replace(/\D/g, ""),
151168
title: options.title ?? "",

‎scripts/commitRecords.test.js‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,52 @@ test("--markdown draws every commit into the comment, with the page's link", asy
866866
has(comment, "Second change");
867867
});
868868

869+
test("--logins draws an author by the GitHub login, linked, others by name", async () => {
870+
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "commit-records-"));
871+
const git = (/** @type {string[]} */ ...a) =>
872+
execFileSync("git", a, { cwd: dir, encoding: "utf8" }).trim();
873+
git("init", "-q", "-b", "main");
874+
git("config", "user.name", "A Person");
875+
git("config", "user.email", "a@example.com");
876+
await commit(git, dir, { "a.txt": "a\n" }, "base");
877+
await commit(
878+
git,
879+
dir,
880+
{},
881+
`Known\n\nCo-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>\n${SIGNED}`,
882+
);
883+
const known = git("rev-parse", "HEAD");
884+
await commit(git, dir, {}, `Unknown\n\n${SIGNED}`);
885+
await commit(git, dir, {}, `Odd login\n\n${SIGNED}`);
886+
const odd = git("rev-parse", "HEAD");
887+
const logins = path.join(dir, "logins.txt");
888+
await fs.writeFile(logins, `${known} a-person\n${odd} bot[bot]\n`);
889+
const out = path.join(dir, "page.html");
890+
const md = path.join(dir, "comment.md");
891+
const r = spawnSync(
892+
"node",
893+
[
894+
script,
895+
...["--out", out, "--markdown", md, "--logins", logins],
896+
"HEAD~3..HEAD",
897+
],
898+
{ cwd: dir, encoding: "utf8" },
899+
);
900+
assert.equal(r.status, 0, r.stderr);
901+
const html = await fs.readFile(out, "utf8");
902+
has(
903+
html,
904+
'</code> · <a href="https://github.com/a-person">a-person</a> + Claude · ',
905+
);
906+
const comment = await fs.readFile(md, "utf8");
907+
has(comment, " · [a-person](https://github.com/a-person) + Claude · ");
908+
const card = (/** @type {string} */ subject) =>
909+
comment.split("<details").find(d => d.includes(`<b>${subject}</b>`)) ?? "";
910+
has(card("Unknown"), " · A Person · ");
911+
has(card("Odd login"), " · A Person · ");
912+
lacks(comment, "@a-person");
913+
});
914+
869915
test("--previous marks the commits the last push added or edited", async () => {
870916
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "commit-records-"));
871917
const git = (/** @type {string[]} */ ...a) =>

‎scripts/recordMarkdown.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ export function commitMarkdown(r, full, change = "") {
406406
[...s.text, ...s.block.map(l => l.trim())].join(" ").trim();
407407
const out = [
408408
`<details open><summary>${change ? `${SIGNS[/** @type {keyof typeof SIGNS} */ (change)] ?? ""} ` : ""}<b>${inlineHtml(subject)}</b></summary>`,
409-
`<sub>${esc(r.sha)} · ${inline(byline(r))}${r.date ? ` · ${esc(r.date)}` : ""}${pr ? ` · #${pr}` : ""}${change ? ` · ${esc(change)}` : ""}</sub>`,
409+
`<sub>${esc(r.sha)} · ${byline(r, inline, (login, url) => `[${login}](${url})`)}${r.date ? ` · ${esc(r.date)}` : ""}${pr ? ` · #${pr}` : ""}${change ? ` · ${esc(change)}` : ""}</sub>`,
410410
...sectionGroups(r.sections.filter(s => !BELOW.has(s.name))).map(g =>
411411
section(g.section, g.parts, full),
412412
),

‎scripts/recordRender.js‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ export const PART = /^(?:Example|(Before|After) \(([a-z]+)\))$/;
6666

6767
/**
6868
* @typedef {{ name: string, text: string[], block: string[] }} Section
69-
* @typedef {{ sha: string, author: string, date: string, message: string }} CommitInfo
69+
* @typedef {{
70+
* sha: string, author: string, login?: string, date: string, message: string
71+
* }} CommitInfo
7072
* @typedef {CommitInfo & {
7173
* subject: string, sections: Section[], coauthors: string[]
7274
* }} CommitRecord
@@ -192,10 +194,21 @@ export function parseRecord(commit) {
192194
}
193195

194196
/**
195-
* Who made a commit: its author and co-authors, as `A Person + Claude`.
197+
* Who made a commit, as `A Person + Claude`: its author, by the GitHub login
198+
* when known, and its co-authors, each name drawn by `name` and the login
199+
* as a link to the profile by `profile` (a link, not an `@` mention, which
200+
* would notify the user).
196201
* @param {CommitRecord} r
202+
* @param {(name: string) => string} name
203+
* @param {(login: string, url: string) => string} profile
197204
*/
198-
export const byline = r => [r.author, ...r.coauthors].join(" + ");
205+
export const byline = (r, name, profile) =>
206+
[
207+
r.login && /^[A-Za-z0-9-]+$/.test(r.login)
208+
? profile(r.login, `https://github.com/${r.login}`)
209+
: name(r.author),
210+
...r.coauthors.map(name),
211+
].join(" + ");
199212

200213
// ---------------------------------------------------------------------------
201214
// Code, highlighted by token
@@ -1530,7 +1543,7 @@ function card(r) {
15301543
[...s.text, ...s.block.map(l => l.trim())].join(" ").trim();
15311544
const out = [
15321545
`<article class="card${breaking.length ? " breaking" : ""}" id="c-${esc(r.sha)}">`,
1533-
`<header><div class="meta"><code>${esc(r.sha)}</code> · ${esc(byline(r))}${r.date ? ` · ${esc(r.date)}` : ""}${
1546+
`<header><div class="meta"><code>${esc(r.sha)}</code> · ${byline(r, esc, (login, url) => `<a href="${url}">${login}</a>`)}${r.date ? ` · ${esc(r.date)}` : ""}${
15341547
pr ? ` · <a href="${REPO_URL}/pull/${pr}">#${pr}</a>` : ""
15351548
}</div><h3>${inline(subject)}</h3></header>`,
15361549
];

0 commit comments

Comments
 (0)