Skip to content

Commit 0acc992

Browse files
fix(gitcafe): fence label and reviewer toggles on a version read first
A toggle read the pull request's version and its list at the same time, so a change landing between the two could be overwritten without a conflict. The version is now read first. The detail view no longer fails for a token without `pr:review:read`: it shows no reviewers instead. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 63c0d76 commit 0acc992

2 files changed

Lines changed: 30 additions & 6 deletions

File tree

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,23 @@ describe("GitCafePullRequestProvider", () => {
512512
}).pipe(Effect.provide(server.layer));
513513
});
514514

515+
it.effect("still reads a pull request whose reviewers the token may not see", () => {
516+
const server = fakeGitCafe({
517+
"GET /repos/owner/repo/pulls/7": { ...pull, headOid: null },
518+
"GET /repos/owner/repo/pulls/7/labels": { items: [labels[0]], next: null },
519+
"GET /repos/owner/repo/pulls/7/status": {
520+
merge: { conflicts: "unknown", fastForward: null, strategies: [] },
521+
checks: { pending: 0, failing: 0, total: 0 },
522+
},
523+
});
524+
return Effect.gen(function* () {
525+
const provider = yield* GitCafePullRequestProvider.make;
526+
const detail = yield* provider.getChangeRequest(target);
527+
assert.deepStrictEqual(detail.reviewers, []);
528+
assert.deepStrictEqual(detail.labels, [{ name: "bug", color: "#d73a4a" }]);
529+
}).pipe(Effect.provide(server.layer));
530+
});
531+
515532
it.effect("requests and withdraws reviewers by rewriting the whole list", () => {
516533
const bob = { ...actor, actorId: "act_two", handle: "bob" };
517534
let requested = [{ id: "act_two", actor: bob }];

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,9 @@ export const make = Effect.gen(function* () {
260260

261261
/**
262262
* GitCafe replaces a pull request's whole reviewer or label list, so one toggle reads the
263-
* list, changes it, and writes it back fenced on the pull request's version.
263+
* list, changes it, and writes it back fenced on the pull request's version. The version is
264+
* read first: a change landing between the two reads then fails the fence instead of being
265+
* overwritten.
264266
*/
265267
const toggleListed = Effect.fn("GitCafePullRequestProvider.toggleListed")(function* (
266268
operation: string,
@@ -270,10 +272,8 @@ export const make = Effect.gen(function* () {
270272
on: boolean,
271273
) {
272274
const path = yield* pullPath(operation, input);
273-
const [pull, listed] = yield* Effect.all(
274-
[readPull(operation, input), readPages(operation, input, `${path}/${list.name}`, Listed)],
275-
{ concurrency: 2 },
276-
);
275+
const pull = yield* readPull(operation, input);
276+
const listed = yield* readPages(operation, input, `${path}/${list.name}`, Listed);
277277
const current = listed.items.map((item) => item.id);
278278
const next = on
279279
? [...new Set([...current, ...ids])]
@@ -589,7 +589,14 @@ export const make = Effect.gen(function* () {
589589
pull.headOid === null
590590
? Effect.succeed(null)
591591
: readLineStats(input, pull.version).pipe(Effect.orElseSucceed(() => null)),
592-
readPages("getChangeRequest", input, `${path}/reviewers`, Json.GitCafeActorEntries),
592+
// Reviewers need `pr:review:read`, which a contents-only token lacks.
593+
readPages("getChangeRequest", input, `${path}/reviewers`, Json.GitCafeActorEntries).pipe(
594+
Effect.catch((error) =>
595+
error.reason === "unauthenticated" || error.reason === "rate-limited"
596+
? Effect.fail(error)
597+
: Effect.succeed({ items: [], next: null }),
598+
),
599+
),
593600
readPages("getChangeRequest", input, `${path}/labels`, Json.GitCafeLabels),
594601
],
595602
{ concurrency: 5 },

0 commit comments

Comments
 (0)