Skip to content

Commit 7f4f1dd

Browse files
TonybynMp4claude
andcommitted
fix(prs): drop stale host-search rows, flag a failed search, keep every GitLab reviewer id
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 133e414 commit 7f4f1dd

5 files changed

Lines changed: 42 additions & 9 deletions

File tree

‎apps/web/src/components/pullRequest/PullRequestReviewerPicker.tsx‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ export function PullRequestReviewerPicker({
3737
// Past the first page the host is asked, since what was loaded cannot answer for the rest.
3838
const searchQuery = useDebouncedValue(query.trim(), 250);
3939
const searchesHost = candidatesQuery.data?.truncated === true && searchQuery.length > 0;
40+
// Only once the debounce has caught up, or rows matching the previous text would linger.
41+
const searched = searchesHost && searchQuery === query.trim();
4042
const searchResult = useEnvironmentQuery(
4143
open && searchesHost
4244
? pullRequestEnvironment.reviewerSearch({
@@ -51,7 +53,7 @@ export function PullRequestReviewerPicker({
5153

5254
const candidates = mergeReviewerCandidates(
5355
candidatesQuery.data?.candidates ?? [],
54-
searchesHost ? (searchResult.data?.candidates ?? []) : [],
56+
searched ? (searchResult.data?.candidates ?? []) : [],
5557
query,
5658
);
5759

@@ -113,16 +115,23 @@ export function PullRequestReviewerPicker({
113115
error={
114116
candidatesQuery.data === null
115117
? candidatesQuery.error
116-
: searchesHost && candidates.length === 0
118+
: searched && candidates.length === 0
117119
? searchResult.error
118120
: null
119121
}
120122
candidates={candidates}
121123
emptyLabel="Nobody else has access to this repository."
122124
noMatchLabel="Nobody with access matches that."
123125
errorLabel="The people with access could not be read."
124-
truncated={candidatesQuery.data?.truncated === true && query.trim().length === 0}
125-
truncatedLabel="This repository has more people with access than are listed here. Search to find them."
126+
truncated={
127+
candidatesQuery.data?.truncated === true &&
128+
(query.trim().length === 0 || (searched && searchResult.error !== null))
129+
}
130+
truncatedLabel={
131+
searched && searchResult.error !== null
132+
? `Only the people already listed are matched: the host search failed. ${searchResult.error}`
133+
: "This repository has more people with access than are listed here. Search to find them."
134+
}
126135
candidateKey={(candidate) => `${candidate.kind}:${candidate.id}`}
127136
disabled={pending !== null}
128137
onSelect={(candidate) => void toggle(candidate)}

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,6 +1315,27 @@ layer("GitLabPullRequestCli.layer", (it) => {
13151315
}),
13161316
);
13171317

1318+
it.effect("keeps a reviewer it cannot show when writing the set back", () =>
1319+
Effect.gen(function* () {
1320+
mockedExecute
1321+
.mockReturnValueOnce(
1322+
Effect.succeed(output(mergeRequestJson({ reviewers: [{ id: 3, username: "" }] }))),
1323+
)
1324+
.mockReturnValueOnce(Effect.succeed(output("{}")));
1325+
const cli = yield* GitLabPullRequestCli.GitLabPullRequestCli;
1326+
1327+
yield* cli.setReviewerRequest({
1328+
cwd: "/w",
1329+
repository: "acme/web",
1330+
number: 7,
1331+
reviewers: [{ id: "9" }],
1332+
requested: true,
1333+
});
1334+
1335+
expect(JSON.parse(callAt(1).stdin ?? "")).toEqual({ reviewer_ids: [3, 9] });
1336+
}),
1337+
);
1338+
13181339
it.effect("takes a reviewer out of the set rather than clearing it", () =>
13191340
Effect.gen(function* () {
13201341
mockedExecute

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1268,7 +1268,7 @@ export const make = Effect.gen(function* () {
12681268
// GitLab has no endpoint that adds or removes one reviewer: `reviewer_ids` replaces the
12691269
// whole set, so the set that is already there is read first and the change applied to
12701270
// it.
1271-
const ids = new Set(mergeRequest.reviewerUsers.map((reviewer) => reviewer.id));
1271+
const ids = new Set(mergeRequest.reviewerIds);
12721272
for (const reviewer of input.reviewers) {
12731273
const id = Number(reviewer.id);
12741274
if (!Number.isSafeInteger(id) || id <= 0) continue;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ describe("getChangeRequest base freshness", () => {
7575
reviewers: [],
7676
checks: [],
7777
viewerCanMerge: true,
78+
reviewerIds: [],
7879
reviewerUsers: [],
7980
};
8081

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,9 @@ export interface GitLabMergeRequestDetail extends GitLabMergeRequestListItem {
198198
readonly reviewers: ReadonlyArray<PullRequestActor>;
199199
readonly checks: ReadonlyArray<PullRequestCheck>;
200200
readonly viewerCanMerge: boolean;
201-
/**
202-
* The reviewers with the ids GitLab writes the set back with. The candidate list leads with
203-
* them too, since one page of project users need not reach them.
204-
*/
201+
/** Every reviewer id, even one without a username to show, since writes replace the set. */
202+
readonly reviewerIds: ReadonlyArray<number>;
203+
/** The candidate list leads with these, since one page of project users need not reach them. */
205204
readonly reviewerUsers: ReadonlyArray<PullRequestActor & { readonly id: number }>;
206205
readonly autoMergeEnabled?: boolean;
207206
readonly autoMergeMethod?: PullRequestMergeMethod;
@@ -341,6 +340,9 @@ function toDetail(raw: Schema.Schema.Type<typeof RawMergeRequestSchema>): GitLab
341340
}),
342341
checks: toChecks(raw),
343342
viewerCanMerge: raw.user?.can_merge !== false,
343+
reviewerIds: (raw.reviewers ?? []).flatMap((reviewer) =>
344+
reviewer.id === undefined ? [] : [reviewer.id],
345+
),
344346
reviewerUsers: (raw.reviewers ?? []).flatMap((reviewer) => {
345347
const actor = toActor(reviewer);
346348
return actor === null || reviewer.id === undefined ? [] : [{ ...actor, id: reviewer.id }];

0 commit comments

Comments
 (0)