Skip to content

Commit 78bf2b8

Browse files
TonybynMp4claude
andcommitted
fix(pull-requests): address reference completion review findings
- Debounce the first burst of typing by asking for the unsearched list until the key settles. - Decode a missing references key from older servers as an empty list. - Send a valid GraphQL Int for long numeric queries on GitHub. - Search GitLab titles only, and keep merge requests when the issue search fails. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent f161106 commit 78bf2b8

6 files changed

Lines changed: 54 additions & 13 deletions

File tree

‎packages/contracts/src/pullRequest.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,10 @@ export type PullRequestReferenceCandidate = typeof PullRequestReferenceCandidate
541541
export const PullRequestFilterOptions = Schema.Struct({
542542
labels: Schema.Array(PullRequestLabel),
543543
authors: Schema.Array(PullRequestActor),
544-
references: Schema.Array(PullRequestReferenceCandidate),
544+
// Servers from before reference completion send no key.
545+
references: Schema.Array(PullRequestReferenceCandidate).pipe(
546+
Schema.withDecodingDefault(Effect.succeed([])),
547+
),
545548
truncated: Schema.Boolean,
546549
});
547550
export type PullRequestFilterOptions = typeof PullRequestFilterOptions.Type;

‎packages/shared/src/pullRequestComposerTrigger.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ describe("debouncedPullRequestCompletionSearch", () => {
8787
["a settled short query", { kind: "reference", query: "zz" }, "reference:", undefined],
8888
["a settled bare sigil", { kind: "mention", query: "" }, "mention:", undefined],
8989
["a lagging search", { kind: "reference", query: "crash" }, "reference:cra", "cra"],
90-
["the other kind's key", { kind: "mention", query: "jul" }, "reference:12", "jul"],
91-
["no key yet", { kind: "reference", query: "12" }, null, "12"],
90+
["the other kind's key", { kind: "mention", query: "jul" }, "reference:12", undefined],
91+
["no key yet", { kind: "reference", query: "12" }, null, undefined],
9292
] as const)("sends %s as the host search", (_, trigger, key, sent) => {
9393
expect(debouncedPullRequestCompletionSearch(trigger, key)).toBe(sent);
9494
});

‎packages/shared/src/pullRequestComposerTrigger.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ export function pullRequestCompletionKey(
6565
}
6666

6767
/**
68-
* The search to send for `trigger` given a debounced key. A key for the other kind is stale, so
69-
* switching between `@` and `#` sends the current search at once.
68+
* The search to send for `trigger` given a debounced key. Until a key for this kind settles, the
69+
* host is asked for its unsearched list, which narrows locally, so a burst of typing sends one query.
7070
*/
7171
export function debouncedPullRequestCompletionSearch(
7272
trigger: Pick<PullRequestComposerTrigger, "kind" | "query">,
@@ -75,7 +75,7 @@ export function debouncedPullRequestCompletionSearch(
7575
const prefix = `${trigger.kind}:`;
7676
return debouncedKey?.startsWith(prefix)
7777
? debouncedKey.slice(prefix.length) || undefined
78-
: pullRequestCompletionSearch(trigger);
78+
: undefined;
7979
}
8080

8181
export function narrowPullRequestMentions<A extends { login: string; name: string | null }>(

‎packages/source-control-github/src/server/GitHubPullRequestApi.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2356,14 +2356,16 @@ export const make = Effect.gen(function* () {
23562356
searchRepositoryReferences: Effect.fn("GitHubPullRequestApi.searchRepositoryReferences")(
23572357
function (input) {
23582358
const { owner, name } = parseRepositorySelector(input.repository);
2359-
const number = /^\d+$/.test(input.query ?? "") ? Number(input.query) : 0;
2359+
const parsed = /^\d+$/.test(input.query ?? "") ? Number(input.query) : 0;
2360+
// GraphQL validates `$number: Int!` even when `@include` skips the lookup.
2361+
const exact = parsed > 0 && parsed <= 2_147_483_647;
23602362
return client
23612363
.RepositoryReferences({
23622364
owner,
23632365
name,
23642366
q: referenceSearchQuery(input.repository, input.query),
2365-
number,
2366-
exact: number > 0 && number <= 2_147_483_647,
2367+
number: exact ? parsed : 0,
2368+
exact,
23672369
})
23682370
.pipe(
23692371
graphql({ ...input, operation: "searchRepositoryReferences", allowReserve: true }),

‎packages/source-control-gitlab/src/server/GitLabPullRequestCli.test.ts‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,6 +1440,26 @@ layer("GitLabPullRequestCli.layer", (it) => {
14401440
expect(result).toMatchObject({ _tag: "Failure", failure: error });
14411441
}),
14421442
);
1443+
1444+
it.effect("keeps merge request references when the issue search fails", () =>
1445+
Effect.gen(function* () {
1446+
mockedExecute.mockImplementation((input) =>
1447+
JSON.stringify(input).includes("/issues?")
1448+
? Effect.fail(
1449+
new GitLabCli.GitLabCliCommandError({
1450+
operation: "execute",
1451+
command: "glab",
1452+
cwd: "/w",
1453+
cause: null,
1454+
}),
1455+
)
1456+
: Effect.succeed(output(JSON.stringify([{ iid: 5, title: "Ship it", state: "opened" }]))),
1457+
);
1458+
const cli = yield* GitLabPullRequestCli.GitLabPullRequestCli;
1459+
const page = yield* cli.searchProjectReferences({ cwd: "/w", repository: "acme/web" });
1460+
expect(page.items.map((item) => item.reference)).toEqual(["!5"]);
1461+
}),
1462+
);
14431463
});
14441464

14451465
it("asks for a numeric reference's iid besides the recent issues and merge requests", () => {
@@ -1454,7 +1474,7 @@ it("asks for a numeric reference's iid besides the recent issues and merge reque
14541474
{ kind: "change-request", params: recent },
14551475
]);
14561476
expect(GitLabPullRequestCli.referenceSearches("crash")).toEqual([
1457-
{ kind: "issue", params: [...recent, ["search", "crash"]] },
1458-
{ kind: "change-request", params: [...recent, ["search", "crash"]] },
1477+
{ kind: "issue", params: [...recent, ["search", "crash"], ["in", "title"]] },
1478+
{ kind: "change-request", params: [...recent, ["search", "crash"], ["in", "title"]] },
14591479
]);
14601480
});

‎packages/source-control-gitlab/src/server/GitLabPullRequestCli.ts‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ export function referenceSearches(search: string | undefined): ReadonlyArray<{
589589
const recent: ReadonlyArray<readonly [string, string]> = [
590590
["order_by", "updated_at"],
591591
["sort", "desc"],
592-
...(numeric ? [] : searchParams(text)),
592+
...(numeric || text.length === 0 ? [] : ([...searchParams(text), ["in", "title"]] as const)),
593593
];
594594
const kinds = ["issue", "change-request"] as const;
595595
return [
@@ -1684,7 +1684,23 @@ export const make = Effect.gen(function* () {
16841684
function (input) {
16851685
return Effect.forEach(
16861686
referenceSearches(input.search),
1687-
({ kind, params }) => projectReferences({ ...input, kind, params }),
1687+
({ kind, params }) =>
1688+
projectReferences({ ...input, kind, params }).pipe(
1689+
// A project with issues turned off answers 403 for issues; its merge requests still
1690+
// complete. An unusable CLI or account still reaches the caller.
1691+
Effect.catchIf(
1692+
(cause) =>
1693+
cause._tag !== "GitLabCliUnavailableError" &&
1694+
cause._tag !== "GitLabCliAuthenticationError" &&
1695+
cause._tag !== "GitLabCliRateLimitError",
1696+
(cause) =>
1697+
Effect.logWarning("GitLab reference search failed", {
1698+
repository: input.repository,
1699+
kind,
1700+
reason: cause._tag,
1701+
}).pipe(Effect.as({ items: [], rawCount: 0 })),
1702+
),
1703+
),
16881704
{ concurrency: "unbounded" },
16891705
).pipe(Effect.map(mergeReferencePages));
16901706
},

0 commit comments

Comments
 (0)