Skip to content

Commit c76b2cd

Browse files
theCodeDriftclaude
andcommitted
fix(ci): Preserve leading prose indentation in ownDescription
canonicalizeBody derives the description via ownDescription, which used .trim() — stripping leading indentation from a managed PR's prose, so a description opening with an indented Markdown code block could be silently reflowed. Tidy only the whitespace the region surgery introduces: collapse seams, drop leading blank lines, and trim trailing whitespace, leaving the first line's indentation intact. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 5a41c58 commit c76b2cd

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

‎.github/scripts/stack-breadcrumb.cjs‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,23 @@ function extractCarriedRegions(body) {
201201

202202
/**
203203
* A body's own description — the human-written part, with the managed regions
204-
* (the stack tree and any carried `<!-- PR:N -->` regions) removed and spacing
205-
* tidied.
204+
* (the stack tree and any carried `<!-- PR:N -->` regions) removed and the
205+
* spacing their removal left behind tidied.
206+
*
207+
* Only whitespace introduced by the surgery is touched: 3+ newline runs (a seam
208+
* where a region was cut from the middle) collapse to a blank line, leading
209+
* blank lines (left when a region sat at the very top) are dropped, and trailing
210+
* whitespace is trimmed. The prose is otherwise preserved verbatim — crucially,
211+
* leading indentation on the first line survives, so a description that opens
212+
* with an indented Markdown code block is not silently reflowed.
206213
*/
207214
function ownDescription(body) {
208215
return body
209216
.replace(REGION_PATTERN, "")
210217
.replace(ANY_PR_REGION_PATTERN, "")
211218
.replace(/\n{3,}/g, "\n\n")
212-
.trim();
219+
.replace(/^\n+/, "")
220+
.trimEnd();
213221
}
214222

215223
/** Wrap a description as a carried region for `number_`. */

‎.github/scripts/stack-breadcrumb.test.cjs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,14 @@ test("ownDescription: strips the stack tree and carried regions", () => {
581581
assert.equal(ownDescription(body), "My description.");
582582
});
583583

584+
test("ownDescription: preserves leading indentation after a top region", () => {
585+
// A breadcrumb at the very top must not cost the prose its leading indent —
586+
// otherwise a description opening with an indented code block gets reflowed.
587+
const body =
588+
"<!-- stack root=1 pr=1,2:1 -->\n(tree)\n<!-- /stack -->\n\n const x = 1;\nplain line";
589+
assert.equal(ownDescription(body), " const x = 1;\nplain line");
590+
});
591+
584592
test("upsertCarriedRegion: appends when absent, replaces in place when present", () => {
585593
const appended = upsertCarriedRegion("Body.", 85, P85);
586594
assert.equal(appended, `Body.\n\n${P85}`);

0 commit comments

Comments
 (0)