The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 19:30 UTC
fix(gitcafe): show line counts on linked and listed pull requests (#22633)
maria committed
Oct 22, 2026 at 01:20 UTC
8acbefefc51b4d281dcd04108c82baa1ab902b0e
2 files changed
+88
-15
packages/source-control-gitcafe/src/server/GitCafePullRequestProvider.test.ts
+42
@@ -504,6 +504,48 @@ describe("GitCafePullRequestProvider", () => {
504
}).pipe(Effect.provide(server.layer));
505
});
506
507
+ it.effect("recounts summary lines only when the compared commits move", () => {
508
+ const landedBase = "fedcba9876543210fedcba9876543210fedcba98";
509
+ let comparisonBaseOid = baseOid;
510
+ let pullReads = 0;
511
+ const server = fakeGitCafe({
512
+ // A comment moves the version without moving the compared commits.
513
+ "GET /repos/owner/repo/pulls/7": () => ({ ...pull, version: 4 + pullReads++ }),
514
+ "GET /repos/owner/repo/pulls/7/changes": () => ({
515
+ version: 4,
516
+ headOid,
517
+ comparisonBaseOid,
518
+ items: [{ path: "a.ts" }, { path: "b.ts" }],
519
+ next: null,
520
+ }),
521
+ "POST /repos/owner/repo/pulls/7/diff-files": (request: SentRequest) => ({
522
+ version: 4,
523
+ headOid,
524
+ comparisonBaseOid,
525
+ items: (request.body as { paths: ReadonlyArray<string> }).paths.map((path) => ({
526
+ path,
527
+ additions: comparisonBaseOid === baseOid ? 3 : 1,
528
+ deletions: 1,
529
+ })),
530
+ }),
531
+ });
532
+ const hunkReads = () =>
533
+ server.sent.filter((request) => request.path.endsWith("/diff-files")).length;
534
+ return Effect.gen(function* () {
535
+ const provider = yield* GitCafePullRequestProvider.make;
536
+ const first = yield* provider.getChangeRequestSummary!(target);
537
+ const second = yield* provider.getChangeRequestSummary!(target);
538
+ assert.deepInclude(first, { additions: 6, deletions: 2, changedFiles: 2 });
539
+ assert.deepInclude(second, { additions: 6, deletions: 2, changedFiles: 2 });
540
+ assert.strictEqual(hunkReads(), 1);
541
+ // A landed parent layer moves the comparison base under the same head.
542
+ comparisonBaseOid = landedBase;
543
+ const third = yield* provider.getChangeRequestSummary!(target);
544
+ assert.deepInclude(third, { additions: 2, deletions: 2, changedFiles: 2 });
545
+ assert.strictEqual(hunkReads(), 2);
546
+ }).pipe(Effect.provide(server.layer));
547
+ });
548
+
549
it.effect("fences a native merge on the target branch's current commit", () => {
550
const branchOid = "fedcba9876543210fedcba9876543210fedcba98";
551
const server = fakeGitCafe({
packages/source-control-gitcafe/src/server/GitCafePullRequestProvider.ts
+46
-15
@@ -53,6 +53,7 @@ const DIFF_FILES_BATCH = 64;
53
*/
54
const LINE_STATS_MAX_FILES = DIFF_FILES_BATCH * 4;
55
const MAX_CHANGE_PAGES = 20;
56
+const LINE_STATS_CACHE_SIZE = 256;
57
58
const chunk = <A>(items: ReadonlyArray<A>, size: number): Array<ReadonlyArray<A>> =>
59
Array.from({ length: Math.ceil(items.length / size) }, (_, index) =>
@@ -354,6 +355,11 @@ export const make = Effect.gen(function* () {
355
return yield* failure(operation, `GitCafe's stack operation ${outcome.state}.`);
356
});
357
358
+ // GitCafe's pulls carry no line totals, and linked pull requests are summarized every minute,
359
+ // so hunk totals are held per compared pair of commits. The file list that names the pair is
360
+ // cheap; a retarget or a landed parent layer moves the base without moving the head.
361
+ const lineTotals = new Map<string, { readonly additions: number; readonly deletions: number }>();
362
+
363
const readLineStats = Effect.fn("GitCafePullRequestProvider.readLineStats")(function* (
364
input: PullRef,
365
version: number,
@@ -381,21 +387,33 @@ export const make = Effect.gen(function* () {
387
after = batch.next;
388
if (after === null || after === previous || batch.items.length === 0) break;
389
}
384
- const counted =
385
- files.some((file) => file.additions !== undefined) ||
386
- files.length > LINE_STATS_MAX_FILES ||
387
- revision === undefined
388
- ? files
389
- : (yield* Effect.forEach(
390
+ if (revision === undefined) return { changedFiles: 0, additions: 0, deletions: 0 };
391
+ const key = `${input.host} ${input.repository.toLowerCase()} ${input.number} ${revision.baseOid} ${revision.headOid}`;
392
+ const held = lineTotals.get(key);
393
+ if (held !== undefined) return { changedFiles: files.length, ...held };
394
+ const details = files.some((file) => file.additions !== undefined)
395
+ ? Option.some(files)
396
+ : files.length > LINE_STATS_MAX_FILES
397
+ ? Option.none()
398
+ : yield* Effect.forEach(
399
chunk(detailablePaths(files), DIFF_FILES_BATCH),
400
(paths) => readDiffFiles(input, revision, paths),
401
{ concurrency: 4 },
393
- ).pipe(Effect.orElseSucceed(() => [[]]))).flat();
394
- return {
395
- changedFiles: files.length,
402
+ ).pipe(
403
+ Effect.map((batches) => batches.flat()),
404
+ Effect.option,
405
+ );
406
+ // Unread hunks leave the lines unknown rather than zero; the file count still stands.
407
+ if (Option.isNone(details)) return { changedFiles: files.length };
408
+ const counted = details.value;
409
+ const totals = {
410
additions: counted.reduce((total, file) => total + (file.additions ?? 0), 0),
411
deletions: counted.reduce((total, file) => total + (file.deletions ?? 0), 0),
412
};
413
+ if (lineTotals.size >= LINE_STATS_CACHE_SIZE)
414
+ lineTotals.delete(lineTotals.keys().next().value!);
415
+ lineTotals.set(key, totals);
416
+ return { changedFiles: files.length, ...totals };
417
});
418
419
const merge = Effect.fn("GitCafePullRequestProvider.merge")(function* (
@@ -525,14 +543,27 @@ export const make = Effect.gen(function* () {
543
};
544
},
545
),
528
- getChangeRequestSummary: (input) =>
529
- readPull("getChangeRequestSummary", input).pipe(
530
- Effect.map((pull) => ({
531
- ...Json.toChangeRequest(pull, input),
546
+ getChangeRequestSummary: Effect.fn("GitCafePullRequestProvider.getChangeRequestSummary")(
547
+ function* (input) {
548
+ const pull = yield* readPull("getChangeRequestSummary", input);
549
+ const changes =
550
+ pull.headOid === null
551
+ ? null
552
+ : yield* readLineStats(input, pull.version).pipe(Effect.orElseSucceed(() => null));
553
+ // A count that could not be read is absent rather than zero.
554
+ const {
555
+ additions: _additions,
556
+ deletions: _deletions,
557
+ ...summary
558
+ } = Json.toChangeRequest(pull, input);
559
+ return {
560
+ ...summary,
561
+ ...(changes === null ? {} : changes),
562
closedAt: pull.closedAt,
563
mergedAt: pull.mergedAt,
534
- })),
535
- ),
564
+ };
565
+ },
566
+ ),
567
getChangeRequest: Effect.fn("GitCafePullRequestProvider.getChangeRequest")(function* (input) {
568
const pull = yield* readPull("getChangeRequest", input);
569
const path = yield* pullPath("getChangeRequest", input);