Skip to content

Commit 50dcb62

Browse files
fix(pull-requests): only hosts that search users open the @ list
Adapters declare capabilities.mentions; web and mobile composers open the @ completion only when the pull request's host sets it, so Bitbucket and Azure DevOps no longer show a list that can never fill. GitLab's three-character user search floor moves into its CLI, so other hosts search from the first character. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 68fb8a0 commit 50dcb62

30 files changed

Lines changed: 132 additions & 103 deletions

‎apps/mobile/src/features/pull-requests/PullRequestDiscussionScreen.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ function Discussion({ params }: { params: PullRequestParams & { readonly discuss
6262
projectId: params.projectId,
6363
value: body,
6464
onChangeValue: setBody,
65+
enabled: detail.data?.capabilities.mentions === true,
6566
});
6667
const [extra, setExtra] = useState<readonly PullRequestThreadComment[]>([]);
6768
const [cursor, setCursor] = useState<string | null | undefined>();

‎apps/mobile/src/features/pull-requests/PullRequestEditScreen.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export function PullRequestEditScreen({ route }: StaticScreenProps<PullRequestEd
5656
projectId: params.projectId,
5757
value: value,
5858
onChangeValue: setDraft,
59-
enabled: params.field !== "title",
59+
enabled: params.field !== "title" && pr?.capabilities.mentions === true,
6060
});
6161
const [busy, setBusy] = useState(false);
6262
const [error, setError] = useState<string | null>(null);

‎apps/mobile/src/features/pull-requests/PullRequestInlineCommentScreen.tsx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@ export function PullRequestInlineCommentScreen({ route }: StaticScreenProps<Inli
3333
const saved = store.draft.comments.find((draft) => draft.id === params.draftId);
3434
const [editedBody, setBody] = useState<string | null>(null);
3535
const body = editedBody ?? saved?.body ?? "";
36+
const detail = useEnvironmentQuery(composerPullRequests.detail(pullRequestTarget(params)));
37+
const { refresh: refreshDetail } = detail;
3638
const mentions = usePullRequestMentions({
3739
environmentId: params.environmentId,
3840
projectId: params.projectId,
3941
value: body,
4042
onChangeValue: setBody,
43+
enabled: detail.data?.capabilities.mentions === true,
4144
});
42-
const detail = useEnvironmentQuery(composerPullRequests.detail(pullRequestTarget(params)));
43-
const { refresh: refreshDetail } = detail;
4445
useFocusEffect(refreshDetail);
4546
const permissions = usePullRequestPermissions(params, detail.data);
4647
const stale = detail.data && detail.data.headSha !== params.headSha;

‎apps/mobile/src/features/pull-requests/PullRequestReviewSheet.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export function PullRequestReviewSheet({
8888
projectId: params.projectId,
8989
value: body,
9090
onChangeValue: setBody,
91+
enabled: result.data?.capabilities.mentions === true,
9192
});
9293
const stale = store.draft.comments.some((comment) => comment.headSha !== result.data?.headSha);
9394
const [requestedVerdict, setRequestedVerdict] = useState<PullRequestReviewVerdict>("comment");

‎apps/mobile/src/features/pull-requests/usePullRequestMentions.ts‎

Lines changed: 24 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,61 @@
1-
import { useAtomValue } from "@effect/atom-react";
2-
import {
3-
EnvironmentId,
4-
ProjectId,
5-
type PullRequestActor,
6-
type PullRequestFilterOptionsInput,
7-
} from "@t3tools/contracts";
1+
import { EnvironmentId, ProjectId, type PullRequestActor } from "@t3tools/contracts";
82
import {
93
detectPullRequestMention,
104
insertPullRequestMention,
115
narrowPullRequestMentions,
12-
pullRequestMentionSearch,
136
} from "@t3tools/shared/pullRequestComposerTrigger";
14-
import * as Option from "effect/Option";
15-
import { AsyncResult, Atom } from "effect/reactivity";
167
import { useState } from "react";
178
import type { TextInputSelectionChangeEvent } from "react-native";
189

1910
import { composerPullRequests } from "../../state/pull-requests";
11+
import { useEnvironmentQuery } from "../../state/query";
2012
import { useDebouncedValue } from "../../state/queries";
2113

2214
const MENTION_SUGGESTION_LIMIT = 6;
2315

24-
const mentionOptionsFamily = Atom.family((key: string) => {
25-
const target: {
26-
readonly environmentId: EnvironmentId;
27-
readonly input: PullRequestFilterOptionsInput;
28-
} | null = JSON.parse(key);
29-
return Atom.make((get) => {
30-
if (target === null) return { authors: [], waiting: false, failed: false };
31-
const result = get(composerPullRequests.filterOptions(target));
32-
return {
33-
authors: Option.match(AsyncResult.value(result), {
34-
onNone: () => [] as ReadonlyArray<PullRequestActor>,
35-
onSome: (options) => options.authors,
36-
}),
37-
waiting: result.waiting,
38-
failed: AsyncResult.isFailure(result),
39-
};
40-
});
41-
});
42-
4316
/** Completes `@login` in a pull request text input from the repository's users. */
4417
export function usePullRequestMentions(input: {
4518
readonly environmentId: string;
4619
readonly projectId: string;
4720
readonly value: string;
4821
readonly onChangeValue: (value: string) => void;
49-
readonly enabled?: boolean;
22+
/** The pull request's host completes mentions (`capabilities.mentions`), and the field takes them. */
23+
readonly enabled: boolean;
5024
}) {
5125
const [selection, setSelection] = useState<{ start: number; end: number } | null>(null);
5226
// Set only right after an insertion, so the native input keeps its own caret otherwise.
5327
const [placed, setPlaced] = useState<{ start: number; end: number } | null>(null);
5428
const trigger =
55-
input.enabled === false || selection === null || selection.start !== selection.end
29+
!input.enabled || selection === null || selection.start !== selection.end
5630
? null
5731
: detectPullRequestMention(input.value, selection.start);
5832
const typed = trigger?.query ?? "";
59-
const search = pullRequestMentionSearch(typed);
33+
const search = typed === "" ? undefined : typed.slice(0, 100);
6034
const sent = useDebouncedValue(search, 250);
61-
const hosted = useAtomValue(
62-
mentionOptionsFamily(
63-
JSON.stringify(
64-
trigger === null
65-
? null
66-
: {
67-
environmentId: EnvironmentId.make(input.environmentId),
68-
input: {
69-
kind: "authors",
70-
projectId: ProjectId.make(input.projectId),
71-
...(sent ? { query: sent } : {}),
72-
},
73-
},
74-
),
75-
),
35+
const hosted = useEnvironmentQuery(
36+
trigger === null
37+
? null
38+
: composerPullRequests.filterOptions({
39+
environmentId: EnvironmentId.make(input.environmentId),
40+
input: {
41+
kind: "authors",
42+
projectId: ProjectId.make(input.projectId),
43+
...(sent ? { query: sent } : {}),
44+
},
45+
}),
7646
);
7747
// Older answers stay useful while the debounced search catches up, narrowed to what is typed now.
78-
const candidates = narrowPullRequestMentions(hosted.authors, typed, MENTION_SUGGESTION_LIMIT);
48+
const candidates = narrowPullRequestMentions(
49+
hosted.data?.authors ?? [],
50+
typed,
51+
MENTION_SUGGESTION_LIMIT,
52+
);
7953

8054
return {
8155
open: trigger !== null,
8256
candidates,
83-
isLoading: hosted.waiting || sent !== search,
84-
failed: hosted.failed,
57+
isLoading: hosted.isPending || sent !== search,
58+
failed: hosted.error !== null,
8559
selection: placed ?? undefined,
8660
onSelectionChange: (event: TextInputSelectionChangeEvent) => {
8761
setSelection(event.nativeEvent.selection);

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ import {
109109
ReviewThreadCard,
110110
toViewerSide,
111111
} from "./PullRequestReviewAnnotation";
112+
import { pullRequestMentionScope } from "./PullRequestMarkdownTextarea";
112113
import {
113114
getFileViewedRange,
114115
isFileDiffCollapsed,
@@ -550,6 +551,7 @@ function PullRequestCodeTab({
550551
commit,
551552
cacheKey: `pull-request:${referenceKey}:${detail.updatedAt}:${commit ?? "all"}`,
552553
});
554+
const mentionScope = pullRequestMentionScope(detail, environmentId, reference);
553555
const hostReview = detail.capabilities.review;
554556
const review = {
555557
inlineComment: hostReview.inlineComment && detail.viewerPermissions.comment,
@@ -960,6 +962,7 @@ function PullRequestCodeTab({
960962
canReact={detail.capabilities.reactions === true}
961963
environmentId={environmentId}
962964
reference={reference}
965+
mentionScope={mentionScope}
963966
pending={threadPending}
964967
fixPending={pendingFinding === pullRequestFindingKey({ kind: "thread", thread })}
965968
fixLabel={fixFindingLabel}
@@ -1031,9 +1034,7 @@ function PullRequestCodeTab({
10311034
kind="draft"
10321035
rangeLabel={`${draft.path}:${getReviewPositionAnchor(draft.position).line}`}
10331036
text=""
1034-
mentionScope={
1035-
canCommentOnLines ? { environmentId, projectId: reference.projectId } : null
1036-
}
1037+
mentionScope={canCommentOnLines ? mentionScope : null}
10371038
submitLabel={canCommentOnLines ? "Add to review" : "Add to agent"}
10381039
{...(canCommentOnLines && onAddToAgentSelection
10391040
? {

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ import { pullRequestEnvironment } from "~/state/pullRequests";
1010
import { Button } from "../ui/button";
1111
import { toastManager } from "../ui/toast";
1212
import { PullRequestGlyph } from "./pullRequestIcons";
13-
import { PullRequestMarkdownTextarea } from "./PullRequestMarkdownTextarea";
13+
import {
14+
PullRequestMarkdownTextarea,
15+
pullRequestMentionScope,
16+
} from "./PullRequestMarkdownTextarea";
1417
import { pullRequestReviewKey } from "./pullRequestReviewStore";
1518
import { useInlineActionConfirm } from "./useInlineActionConfirm";
1619

@@ -110,7 +113,7 @@ export function PullRequestCommentForm({
110113
<div className="space-y-2">
111114
<PullRequestMarkdownTextarea
112115
ref={textareaRef}
113-
mentionScope={{ environmentId, projectId: reference.projectId }}
116+
mentionScope={pullRequestMentionScope(detail, environmentId, reference)}
114117
// Lock while posting because success clears the draft.
115118
disabled={locked}
116119
readOnly={speech.freezesEditor}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
usePendingReviewComments,
1717
usePullRequestReviewStore,
1818
} from "./pullRequestReviewStore";
19+
import { pullRequestMentionScope } from "./PullRequestMarkdownTextarea";
1920

2021
export function PullRequestComposer({
2122
environmentId,
@@ -154,6 +155,7 @@ export function PullRequestComposer({
154155
active={open && mode === "review"}
155156
environmentId={environmentId}
156157
reference={reference}
158+
mentionScope={pullRequestMentionScope(detail, environmentId, reference)}
157159
term={term}
158160
verdicts={verdicts}
159161
requestChangesSummaryRequired={sourceControlClients

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ import { useLiveRefresh } from "~/hooks/useLiveRefresh";
6767
import { pullRequestEnvironment, usePullRequestTurnRefresh } from "~/state/pullRequests";
6868
import { useAtomCommand } from "~/state/use-atom-command";
6969
import { PullRequestStackMenu } from "./PullRequestStackMenu";
70+
import { pullRequestMentionScope } from "./PullRequestMarkdownTextarea";
7071
import { PullRequestChangeBreakdownStat } from "./PullRequestChangeBreakdownStat";
7172
import {
7273
capitalizeTerm,
@@ -1780,6 +1781,7 @@ export function PullRequestDetailPanel({
17801781
detail.capabilities.review.inlineComment && detail.viewerPermissions.comment
17811782
}
17821783
rangeComments={detail.capabilities.review.rangeComment === true}
1784+
mentionScope={pullRequestMentionScope(detail, environmentId, reference)}
17831785
onAskAboutLines={(comment, request) =>
17841786
addSelectionToAgent({ comment, request }, { keepGuide: true })
17851787
}

‎apps/web/src/components/pullRequest/PullRequestGuideTab.browser.test.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ it("keeps Try again inside a short panel when a failed guide has long diagnostic
5555
active
5656
canComment={false}
5757
rangeComments={false}
58+
mentionScope={null}
5859
onAskAboutLines={null}
5960
onAskAboutStop={null}
6061
onFinishReview={null}

0 commit comments

Comments
 (0)