Skip to content

Commit 1fe6b54

Browse files
fix(gitcafe): diffs still load for pulls that report no head yet
The shared changes-page reader pinned the first page to the pull's headOid, which GitCafe may report as null, so every diff for such a pull failed. Pin the head only when the pull names one; version, cursor revision, and repeated-cursor checks are unchanged. Name the 500-path changes page size. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent d135b90 commit 1fe6b54

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

‎packages/source-control-gitcafe/src/server/GitCafePullRequestProvider.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,21 @@ describe("GitCafePullRequestProvider changed paths", () => {
247247
},
248248
);
249249

250+
it.effect.each(["getDiff", "getDiffFilePaths"] as const)(
251+
"%s reads a pull that reports no head yet",
252+
(method) => {
253+
const server = fakeGitCafe({
254+
"GET /repos/owner/repo/pulls/7": { ...pull, headOid: null },
255+
"GET /repos/owner/repo/pulls/7/changes": { ...snapshot, items: [], next: null },
256+
});
257+
return Effect.gen(function* () {
258+
const provider = yield* GitCafePullRequestProvider.make;
259+
const result = yield* provider[method]!(target);
260+
assert.isNull(result.nextCursor);
261+
}).pipe(Effect.provide(server.layer));
262+
},
263+
);
264+
250265
it.effect.each([{ version: 5 }, { headOid: baseOid }])(
251266
"refuses initial changed paths from a different pull revision (%j)",
252267
(changed) => {

‎packages/source-control-gitcafe/src/server/GitCafePullRequestProvider.ts‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ const AUTHOR_DISCOVERY_PAGES = 5;
5656
const KNOWN_AUTHORS_LIMIT = 10_000;
5757
/** GitCafe's cap on paths per `/diff-files` read, and so one diff page. */
5858
const DIFF_FILES_BATCH = 64;
59+
/** Changed-path pages carry no hunks, so they can be read in larger pages. */
60+
const CHANGES_PAGE_LIMIT = 500;
5961
/** Line totals require hunk reads; omit them for large PRs. */
6062
const LINE_STATS_MAX_FILES = DIFF_FILES_BATCH * 4;
6163
const MAX_CHANGE_PAGES = 20;
@@ -535,16 +537,16 @@ export const make = Effect.gen(function* () {
535537
: yield* decodeDiffCursor(input.cursor).pipe(
536538
Effect.mapError((cause) => failure(operation, "Invalid GitCafe diff cursor.", cause)),
537539
);
538-
const pull = cursor === null ? yield* readPull(operation, input) : null;
539-
const version = cursor?.version ?? pull!.version;
540-
const headOid = cursor?.headOid ?? pull!.headOid;
540+
// A pull without a head yet has nothing to pin; its version still is.
541+
const expected = cursor ?? (yield* readPull(operation, input));
542+
const version = expected.version;
541543
const path = yield* pullPath(operation, input);
542544
const query = new URLSearchParams({ expectedVersion: String(version), limit: String(limit) });
543545
if (cursor !== null) query.set("after", cursor.after);
544546
const page = yield* read(operation, input, { path: `${path}/changes?${query}` }, Changes);
545547
if (
546548
page.version !== version ||
547-
page.headOid !== headOid ||
549+
(expected.headOid !== null && page.headOid !== expected.headOid) ||
548550
(cursor !== null && cursor.baseOid !== page.comparisonBaseOid)
549551
)
550552
return yield* failure(
@@ -644,7 +646,10 @@ export const make = Effect.gen(function* () {
644646
let revision: { version: number; headOid: string; baseOid: string } | undefined;
645647
let after: string | null = null;
646648
for (let page = 0; page < MAX_CHANGE_PAGES; page++) {
647-
const query = new URLSearchParams({ expectedVersion: String(version), limit: "500" });
649+
const query = new URLSearchParams({
650+
expectedVersion: String(version),
651+
limit: String(CHANGES_PAGE_LIMIT),
652+
});
648653
if (after !== null) query.set("after", after);
649654
const batch: typeof Changes.Type = yield* read(
650655
"getChangeRequest",
@@ -1013,7 +1018,7 @@ export const make = Effect.gen(function* () {
10131018
};
10141019
}),
10151020
getDiffFilePaths: Effect.fn("GitCafePullRequestProvider.getDiffFilePaths")(function* (input) {
1016-
const page = yield* readDiffPage("getDiffFilePaths", input, 500);
1021+
const page = yield* readDiffPage("getDiffFilePaths", input, CHANGES_PAGE_LIMIT);
10171022
return {
10181023
files: page.items.map((file) => ({
10191024
oldPath: file.oldPath ?? file.path,

0 commit comments

Comments
 (0)