Skip to content

Commit ab67e5b

Browse files
cknittclaude
andcommitted
Keep one semantic diff comment per pull request
Each push, and above all each force push, added a comment of its own, so a pull request collected copies of its records. The workflow now edits one comment in place to hold every commit, and --since is gone. 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 c9a267c commit ab67e5b

5 files changed

Lines changed: 32 additions & 96 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ node scripts/commitRecords.js --out page.html [--pr <number>] [--title <text>] \
193193
- `--pr` and `--title` head the page with the pull request.
194194
`.github/workflows/semantic_diff.yml` renders each pull request's range
195195
and comments the records as Markdown (`--markdown <file> --url <page>`,
196-
scripts/recordMarkdown.js) with the page's link: after a push that keeps
197-
the previous head, only the commits it added (`--since <previous head>`).
196+
scripts/recordMarkdown.js) with the page's link, one comment that each
197+
push updates to hold every commit.
198198
- In prose, `#1234` and full pull request and issue URLs link as `#1234`,
199199
and the 9-character short sha of a commit on the page links to its card.
200200

‎.github/workflows/semantic_diff.yml‎

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: Semantic Diff
22

33
# Renders the commit records of each pull request (scripts/commitRecords.js)
44
# as a review page on the CDN, and comments them on the pull request as
5-
# Markdown (scripts/recordMarkdown.js) with the page's link. The page holds
6-
# every commit; the comment holds the commits a push added, or every commit
7-
# when the pull request is opened or reopened or its branch is force-pushed.
5+
# Markdown (scripts/recordMarkdown.js) with the page's link. A pull request
6+
# has one such comment, which each push updates in place to hold every
7+
# commit, so the pull request shows its current records in one place.
88
#
99
# A pull request from a branch of this repository runs on pull_request, with
1010
# the workflow and renderer of its merge into the base branch: GitHub takes
@@ -42,9 +42,6 @@ jobs:
4242
PR_NUMBER: ${{ github.event.pull_request.number }}
4343
PR_TITLE: ${{ github.event.pull_request.title }}
4444
BASE_SHA: ${{ github.event.pull_request.base.sha }}
45-
# The head before a push; empty when the pull request is opened or
46-
# reopened.
47-
BEFORE_SHA: ${{ github.event.action == 'synchronize' && github.event.before || '' }}
4845
steps:
4946
- name: Checkout renderer
5047
uses: actions/checkout@v7
@@ -55,25 +52,15 @@ jobs:
5552
persist-credentials: false
5653

5754
- name: Render semantic diff
58-
id: render
5955
run: |
6056
git fetch --no-tags --filter=blob:none origin "refs/pull/${PR_NUMBER}/head:refs/heads/pr-${PR_NUMBER}"
6157
base=$(git merge-base "$BASE_SHA" "pr-${PR_NUMBER}")
6258
head=$(git rev-parse --short=9 "pr-${PR_NUMBER}")
6359
# The query string names the rendered commit, so each push gets a
6460
# URL that no cache has seen.
6561
url="https://cdn.rescript-lang.org/semantic-diff/pr-${PR_NUMBER}/index.html?v=${head}"
66-
# A push that keeps the previous head adds commits on top of it:
67-
# the comment holds those. After a force push the previous head is
68-
# no ancestor (nor, from a fork, fetched), and the comment holds
69-
# every commit.
70-
since=()
71-
if [ -n "$BEFORE_SHA" ] && git merge-base --is-ancestor "$BEFORE_SHA" "pr-${PR_NUMBER}" 2>/dev/null; then
72-
since=(--since "$BEFORE_SHA")
73-
fi
7462
mkdir -p semantic-diff
75-
node scripts/commitRecords.js --out semantic-diff/index.html --markdown semantic-diff/comment.md "${since[@]}" --url "$url" --pr "$PR_NUMBER" --title "$PR_TITLE" "${base}..pr-${PR_NUMBER}"
76-
echo "head=${head}" >> "$GITHUB_OUTPUT"
63+
node scripts/commitRecords.js --out semantic-diff/index.html --markdown semantic-diff/comment.md --url "$url" --pr "$PR_NUMBER" --title "$PR_TITLE" "${base}..pr-${PR_NUMBER}"
7764
7865
- name: Setup Rclone
7966
uses: cometkim/rclone-actions/setup-rclone@8d9c6b95341f7698609deee65c3d62af42893288 # main, 2025-06-18
@@ -91,14 +78,12 @@ jobs:
9178
- name: Upload semantic diff
9279
run: rclone copyto --s3-no-check-bucket semantic-diff/index.html "rescript:cdn-assets/semantic-diff/pr-${PR_NUMBER}/index.html"
9380

94-
# A push that adds only merge commits writes no comment.
9581
- name: Comment semantic diff
96-
if: hashFiles('semantic-diff/comment.md') != ''
9782
uses: thollander/actions-comment-pull-request@v3
9883
with:
9984
pr-number: ${{ github.event.pull_request.number }}
100-
# Each push gets its own comment, so the comments of earlier pushes
101-
# stay; a re-run of the same head updates its comment.
102-
comment-tag: semantic-diff-${{ steps.render.outputs.head }}
85+
# The pull request's one comment, edited in place on each push;
86+
# edits notify no one.
87+
comment-tag: semantic-diff
10388
mode: upsert
10489
file-path: semantic-diff/comment.md

‎scripts/commitRecords.js‎

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
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
15-
* --since <rev>, the comment draws only the commits <rev> lacks, and is
16-
* not written when there are none.
14+
* (scripts/recordMarkdown.js), linking the page at --url <url>.
1715
*/
1816

1917
import { execFileSync } from "node:child_process";
@@ -67,9 +65,7 @@ const options = {};
6765
const targets = [];
6866
for (let i = 0; i < args.length; i++) {
6967
if (
70-
["--out", "--pr", "--title", "--markdown", "--url", "--since"].includes(
71-
args[i],
72-
) &&
68+
["--out", "--pr", "--title", "--markdown", "--url"].includes(args[i]) &&
7369
i + 1 < args.length
7470
)
7571
options[args[i].slice(2)] = args[++i];
@@ -78,7 +74,7 @@ for (let i = 0; i < args.length; i++) {
7874
const outFile = options.out;
7975
if (!outFile) {
8076
console.error(
81-
"usage: commitRecords.js --out <page.html> [--pr <number>] [--title <text>] [--markdown <comment.md> [--url <page url>] [--since <rev>]] <rev | base..tip>...",
77+
"usage: commitRecords.js --out <page.html> [--pr <number>] [--title <text>] [--markdown <comment.md> [--url <page url>]] <rev | base..tip>...",
8278
);
8379
process.exit(1);
8480
}
@@ -89,35 +85,11 @@ const heading = {
8985
const groups = targets.map(group);
9086
const body = pageBody(groups, heading);
9187
if (options.markdown) {
92-
const since = options.since;
93-
// The commits of the targets that `since` does not reach.
94-
const fresh = new Set(
95-
since
96-
? targets.flatMap(t =>
97-
git(["rev-list", "--abbrev-commit", "--abbrev=9", t, `^${since}`])
98-
.split("\n")
99-
.filter(Boolean),
100-
)
101-
: [],
88+
writeFileSync(
89+
options.markdown,
90+
commentMarkdown(groups, { url: options.url }),
10291
);
103-
const shown = since
104-
? groups.map(g => ({
105-
...g,
106-
records: g.records.filter(r => fresh.has(r.sha)),
107-
}))
108-
: groups;
109-
if (shown.some(g => g.records.length)) {
110-
writeFileSync(
111-
options.markdown,
112-
commentMarkdown(shown, {
113-
url: options.url,
114-
total: since
115-
? groups.reduce((n, g) => n + g.records.length, 0)
116-
: undefined,
117-
}),
118-
);
119-
console.log(options.markdown);
120-
}
92+
console.log(options.markdown);
12193
}
12294
const head = `<title>${esc(pageTitle(heading))}</title>
12395
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,600&family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;500&family=STIX+Two+Text:ital,wght@0,400;0,500;1,400&display=swap">

‎scripts/commitRecords.test.js‎

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ ${SIGNED}
832832
has(html, '<span class="ln del" style="--r:2;--c:1;--i:0">');
833833
});
834834

835-
test("--since leaves the comment the commits a push added, the page every commit", async () => {
835+
test("--markdown draws every commit into the comment, with the page's link", async () => {
836836
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "commit-records-"));
837837
const git = (/** @type {string[]} */ ...a) =>
838838
execFileSync("git", a, { cwd: dir, encoding: "utf8" }).trim();
@@ -841,36 +841,20 @@ test("--since leaves the comment the commits a push added, the page every commit
841841
git("config", "user.email", "a@example.com");
842842
await commit(git, dir, { "a.txt": "a\n" }, "base");
843843
await commit(git, dir, {}, `First change\n\n${SIGNED}`);
844-
const before = git("rev-parse", "HEAD");
845844
await commit(git, dir, {}, `Second change\n\n${SIGNED}`);
846-
const out = path.join(dir, "page.html");
847845
const md = path.join(dir, "comment.md");
848-
const run = (/** @type {string} */ since) => {
849-
const r = spawnSync(
850-
"node",
851-
[
852-
script,
853-
"--out",
854-
out,
855-
"--markdown",
856-
md,
857-
"--since",
858-
since,
859-
"HEAD~2..HEAD",
860-
],
861-
{ cwd: dir, encoding: "utf8" },
862-
);
863-
assert.equal(r.status, 0, r.stderr);
864-
};
865-
run(before);
846+
const r = spawnSync(
847+
"node",
848+
[
849+
script,
850+
...["--out", path.join(dir, "page.html"), "--markdown", md],
851+
...["--url", "https://cdn.example/pr-1/index.html", "HEAD~2..HEAD"],
852+
],
853+
{ cwd: dir, encoding: "utf8" },
854+
);
855+
assert.equal(r.status, 0, r.stderr);
866856
const comment = await fs.readFile(md, "utf8");
867-
has(comment, "1 new commit (2 total)");
857+
has(comment, "2 commits · [Full page](https://cdn.example/pr-1/index.html)");
858+
has(comment, "First change");
868859
has(comment, "Second change");
869-
lacks(comment, "First change");
870-
const html = await fs.readFile(out, "utf8");
871-
has(html, "First change");
872-
has(html, "Second change");
873-
await fs.rm(md);
874-
run("HEAD");
875-
await assert.rejects(fs.access(md));
876860
});

‎scripts/recordMarkdown.js‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -422,18 +422,13 @@ export function commitMarkdown(r, full) {
422422
* The comment: a heading linking the page, then each commit. Past the
423423
* budget, the commits with the most characters are drawn without their
424424
* forms, and if that is not enough, the last commits are left to the page.
425-
* With `total`, the commits are the new ones a push added to a pull request
426-
* of `total` commits.
427425
* @param {Group[]} groups
428-
* @param {{ url?: string, budget?: number, total?: number }} [options]
426+
* @param {{ url?: string, budget?: number }} [options]
429427
*/
430-
export function commentMarkdown(
431-
groups,
432-
{ url = "", budget = BUDGET, total } = {},
433-
) {
428+
export function commentMarkdown(groups, { url = "", budget = BUDGET } = {}) {
434429
const records = groups.flatMap(g => g.records);
435430
const n = records.length;
436-
const head = `### Semantic Diff\n\n${n}${total === undefined ? "" : " new"} commit${n === 1 ? "" : "s"}${total === undefined || total === n ? "" : ` (${total} total)`}${url ? ` · [Full page](${url})` : ""}`;
431+
const head = `### Semantic Diff\n\n${n} commit${n === 1 ? "" : "s"}${url ? ` · [Full page](${url})` : ""}`;
437432
const drawn = records.map(r => commitMarkdown(r, true));
438433
const size = () => drawn.reduce((t, d) => t + d.length + 2, head.length);
439434
const order = drawn

0 commit comments

Comments
 (0)