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
3 changes: 2 additions & 1 deletion actions/setup/js/create_pull_request_helpers.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ function generatePatchPreview(patchContent) {
}

const truncated = lineTruncated || charTruncated;
const summary = truncated ? `Show patch preview (${Math.min(maxLines, lines.length)} of ${lines.length} lines)` : `Show patch (${lines.length} lines)`;
const shownLines = preview.split("\n").length;
const summary = truncated ? `Show patch preview (${shownLines} of ${lines.length} lines)` : `Show patch (${lines.length} lines)`;

return `\n\n<details><summary>${summary}</summary>\n\n\`\`\`diff\n${preview}${truncated ? "\n... (truncated)" : ""}\n\`\`\`\n\n</details>`;
}
Expand Down
5 changes: 3 additions & 2 deletions actions/setup/js/create_pull_request_helpers.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -551,19 +551,20 @@ describe("generatePatchPreview", () => {
});

it("truncates and indicates truncation when over 500 lines", () => {
const patch = Array.from({ length: 600 }, (_, i) => `line${i}`).join("\n");
const patch = Array.from({ length: 600 }, (_, i) => (i === 500 ? "omitted-line" : "x")).join("\n");
const result = generatePatchPreview(patch);
expect(result).toContain("Show patch preview (500 of 600 lines)");
expect(result).toContain("... (truncated)");
// Content from line 500+ must not appear
expect(result).not.toContain("line500");
expect(result).not.toContain("omitted-line");
});

it("truncates and indicates truncation when over 2000 characters", () => {
// 3 lines totaling well over 2000 chars
const longLine = "x".repeat(1000);
const patch = `${longLine}\n${longLine}\n${longLine}`;
const result = generatePatchPreview(patch);
expect(result).toContain("Show patch preview (2 of 3 lines)");
expect(result).toContain("... (truncated)");
});

Expand Down
Loading