Open History to see the last commit
1// The weight client-metrics and mobile-metrics seed: a branch changing many files, and its pull
2// request on the fake GitHub with a long body, files, commits and comments.
3import type { FakePullRequestDetail } from "./forge.ts";
4
5/** Many files with many lines, so the Diff panel and the PR's files have real weight. */
6export const DIFF_FILES = 40;
7const DIFF_LINES = 60;
8export const sourceFile = (index: number, variant: "before" | "after") =>
9 Array.from({ length: DIFF_LINES }, (_, line) =>
10 line % 10 === 0
11 ? `export function helper${index}_${line}(input: ReadonlyArray<number>) {`
12 : line % 10 === 9
13 ? "}"
14 : variant === "after" && line % 3 === 0
15 ? ` const value${line} = input.map((entry) => entry ** ${line}).filter(Boolean); // changed`
16 : ` const value${line} = input.map((entry) => entry * ${line}).filter(Boolean);`,
17 ).join("\n") + "\n";
18
19export const pullRequestDetail = (): FakePullRequestDetail => {
20 const files = Array.from({ length: DIFF_FILES }, (_, index) => {
21 const changed = Array.from({ length: DIFF_LINES }, (_, line) => line).filter(
22 (line) => line % 10 !== 0 && line % 10 !== 9 && line % 3 === 0,
23 );
24 const patch = [
25 `@@ -1,${DIFF_LINES} +1,${DIFF_LINES} @@`,
26 ...changed.flatMap((line) => [
27 `- const value${line} = input.map((entry) => entry * ${line}).filter(Boolean);`,
28 `+ const value${line} = input.map((entry) => entry ** ${line}).filter(Boolean); // changed`,
29 ]),
30 ].join("\n");
31 return {
32 path: `src/module${index}.ts`,
33 additions: changed.length,
34 deletions: changed.length,
35 patch,
36 };
37 });
38 const section = (title: string) =>
39 `## ${title}\n\nThis part of the change moves the helpers behind one entry point. Callers keep their signatures; each module now **squares** its inputs before filtering, and the filters skip falsy values.\n\n- \`src/module0.ts\` through \`src/module9.ts\` read the new helpers\n- the tests cover the empty input and the largest one\n- nothing outside \`src/\` moves\n\n\`\`\`ts\nexport function helper0_0(input: ReadonlyArray<number>) {\n return input.map((entry) => entry ** 2).filter(Boolean);\n}\n\`\`\`\n`;
40 return {
41 body: [
42 "Squares every helper's input and moves them behind one entry point.",
43 ...["Why", "What changed", "How it was tested", "Follow-ups", "Risks"].map(section),
44 "| module | before | after |\n| :-- | --: | --: |\n" +
45 Array.from(
46 { length: 12 },
47 (_, index) => `| module${index} | ${index * 3} ms | ${index * 2} ms |`,
48 ).join("\n"),
49 ].join("\n\n"),
50 files,
51 comments: Array.from(
52 { length: 12 },
53 (_, index) =>
54 `Comment ${index + 1}: the helper in \`src/module${index}.ts\` reads better now. Could the filter keep zero?\n\n> ${"Quoted context from the review. ".repeat(3)}`,
55 ),
56 commits: 8,
57 };
58};