Skip to content

Commit 09a453e

Browse files
committed
fix(source-control): keep Origin branch references and truncated checks honest
1 parent 5586b3f commit 09a453e

2 files changed

Lines changed: 16 additions & 8 deletions

File tree

‎packages/source-control-cursor-origin/src/server/OriginPullRequestProvider.ts‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,9 @@ export const make = Effect.gen(function* () {
318318
},
319319
OriginCheckRunListSchema,
320320
(page) => page.checkRuns,
321-
).pipe(Effect.map((page) => page.items.map(originCheck)));
321+
).pipe(
322+
Effect.map((page) => ({ checks: page.items.map(originCheck), truncated: page.truncated })),
323+
);
322324
},
323325
{ capacity: 256, timeToLive: (exit) => (Exit.isSuccess(exit) ? "1 second" : 0) },
324326
);
@@ -327,7 +329,7 @@ export const make = Effect.gen(function* () {
327329
) =>
328330
input.sha
329331
? Cache.get(checkRuns, `${input.cwd}\n${input.repository}\n${input.sha}`)
330-
: Effect.succeed([]);
332+
: Effect.succeed({ checks: [], truncated: false });
331333

332334
const readPatch = (cwd: string, path: string) =>
333335
readPages({ cwd, operation: "getDiff", path }, OriginFileListSchema, (page) => page.files).pipe(
@@ -702,18 +704,21 @@ export const make = Effect.gen(function* () {
702704

703705
getChangeRequestChecks: (input) =>
704706
withPull(input, (pullRequest) => listChecks({ ...input, sha: pullRequest.head.sha })).pipe(
705-
Effect.map(([pullRequest, checks]) => ({ state: originState(pullRequest), checks })),
707+
Effect.map(([pullRequest, { checks }]) => ({ state: originState(pullRequest), checks })),
706708
Effect.mapError(fail("getChangeRequestChecks")),
707709
),
708710

709711
getChangeRequest: Effect.fn("OriginPullRequestProvider.getChangeRequest")(
710712
function* (input) {
711-
const [[pullRequest, [checks, avatars, mergeability]], repository] = yield* Effect.all(
713+
const [[pullRequest, [checkRead, avatars, mergeability]], repository] = yield* Effect.all(
712714
[
713715
withPull(input, (pullRequest) =>
714716
Effect.all(
715717
[
716-
recover(listChecks({ ...input, sha: pullRequest.head.sha }), []),
718+
recover(listChecks({ ...input, sha: pullRequest.head.sha }), {
719+
checks: [],
720+
truncated: false,
721+
}),
717722
avatarsFor(input.cwd, [pullRequest.author], viewArgs(input, "author")),
718723
mergeabilityOf(input, pullRequest),
719724
],
@@ -724,10 +729,13 @@ export const make = Effect.gen(function* () {
724729
],
725730
{ concurrency: "unbounded" },
726731
);
732+
const { checks, truncated } = checkRead;
733+
const rollup = checksState(checks);
727734
const detail: ProviderChangeRequestDetail = {
728735
...toProviderChangeRequest(pullRequest, avatars),
729736
mergeability,
730-
checksState: checksState(checks),
737+
// Checks past the last page read are unknown, so all-green ones read are not a pass.
738+
checksState: truncated && rollup === "passing" ? "pending" : rollup,
731739
headSha: pullRequest.head.sha ?? null,
732740
body: pullRequest.body ?? "",
733741
changedFiles: pullRequest.changedFiles ?? 0,

‎packages/source-control-cursor-origin/src/server/OriginSourceControlProvider.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ export const makeDiscovery = Effect.gen(function* () {
7373
} satisfies SourceControlManagedCliDiscoverySpec;
7474
});
7575

76-
/** `42`, `#42`, or a `cursor.com/codebase/…/pull/42` URL. */
76+
/** `42` or `#42`; anything else, such as `123/fix`, is a branch. */
7777
function originPullNumber(reference: string): number | null {
78-
const match = /(?:^#?|\/pull\/)(\d+)(?:\/[^?#]*)?(?:[?#].*)?$/u.exec(reference.trim());
78+
const match = /^#?(\d+)$/u.exec(reference.trim());
7979
const number = Number(match?.[1]);
8080
return Number.isSafeInteger(number) && number > 0 ? number : null;
8181
}

0 commit comments

Comments
 (0)