Skip to content

Commit 21b0b7a

Browse files
fix(composer): keep reviews from different Git hosts in suggestions (#36104)
Co-authored-by: Julius Marminge <[email protected]>
1 parent 10fbff5 commit 21b0b7a

7 files changed

Lines changed: 96 additions & 19 deletions

File tree

‎apps/mobile/src/features/threads/use-composer-command-menu.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { threadPullRequestKeyOf } from "@t3tools/client-runtime/thread-pull-requests";
12
import * as Dialog from "../../components/ui/Dialog";
23
import type {
34
EnvironmentId,
@@ -358,7 +359,7 @@ export function useComposerCommandMenu({
358359

359360
if (trigger.kind === "pull-request") {
360361
return pullRequestSearch.entries.map((entry) => ({
361-
id: `pr:${entry.projectId}:${entry.repository}:${entry.number}`,
362+
id: `pr:${entry.projectId}:${threadPullRequestKeyOf(entry)}`,
362363
type: "pull-request",
363364
pullRequest: {
364365
number: entry.number,

‎apps/mobile/src/state/queries.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import { threadPullRequestKeyOf } from "@t3tools/client-runtime/thread-pull-requests";
12
import { filterComposerPullRequestMatches } from "@t3tools/shared/composerPullRequestMatches";
23
import { expect, it } from "@effect/vitest";
34

45
it("keeps an older exact PR in the mobile menu ahead of twenty newer substring matches", () => {
56
const exact = {
7+
host: "github.com",
68
number: 42,
79
projectId: "project",
810
repository: "example/repo",
@@ -14,6 +16,7 @@ it("keeps an older exact PR in the mobile menu ahead of twenty newer substring m
1416
updatedAt: "2026-01-01",
1517
}));
1618
const matches = filterComposerPullRequestMatches({
19+
keyOf: threadPullRequestKeyOf,
1720
entries: [exact, ...recent, exact],
1821
projectId: exact.projectId,
1922
repository: exact.repository,

‎apps/mobile/src/state/queries.ts‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import {
2+
legacyThreadPullRequestKey,
3+
threadPullRequestKeyOf,
4+
} from "@t3tools/client-runtime/thread-pull-requests";
15
import {
26
composerPullRequestsFromLinks,
37
filterComposerPullRequestMatches,
@@ -148,11 +152,16 @@ export function useComposerPullRequestSearch(input: {
148152
})
149153
: null,
150154
);
155+
// Only the host: the URL's full repository path would not match the project's selector.
156+
const exactEntry = exact.data
157+
? { ...exact.data, host: legacyThreadPullRequestKey(exact.data).host }
158+
: null;
151159
const entries = (() => {
152160
if (input.query === null || input.projectId === null || input.repository === null) return [];
153161
if (/^\d*$/.test(input.query)) {
154162
return filterComposerPullRequestMatches({
155-
entries: ready ? [...(exact.data ? [exact.data] : []), ...(list.data?.entries ?? [])] : [],
163+
keyOf: threadPullRequestKeyOf,
164+
entries: ready ? [...(exactEntry ? [exactEntry] : []), ...(list.data?.entries ?? [])] : [],
156165
linked,
157166
projectId: input.projectId,
158167
repository: input.repository,
@@ -162,24 +171,29 @@ export function useComposerPullRequestSearch(input: {
162171
}
163172
if (!ready) {
164173
return withLinkedComposerPullRequestsFirst({
174+
keyOf: threadPullRequestKeyOf,
165175
matches: [],
166176
linked,
167177
query: input.query,
168178
limit: 20,
169179
});
170180
}
171181
const words = (query ?? "").toLowerCase().split(/\s+/).filter(Boolean);
172-
const found = [...(exact.data ? [exact.data] : []), ...(list.data?.entries ?? [])].filter(
182+
const found = [...(exactEntry ? [exactEntry] : []), ...(list.data?.entries ?? [])].filter(
173183
(entry) =>
174184
entry.projectId === input.projectId &&
175185
entry.repository.toLowerCase() === input.repository?.toLowerCase() &&
176186
words.every((word) =>
177187
`${entry.title} ${entry.headBranch} ${entry.baseBranch}`.toLowerCase().includes(word),
178188
),
179189
);
180-
const unique = new Map<number, (typeof found)[number]>();
181-
for (const entry of found) if (!unique.has(entry.number)) unique.set(entry.number, entry);
190+
const unique = new Map<string, (typeof found)[number]>();
191+
for (const entry of found) {
192+
const key = threadPullRequestKeyOf(entry);
193+
if (!unique.has(key)) unique.set(key, entry);
194+
}
182195
return withLinkedComposerPullRequestsFirst({
196+
keyOf: threadPullRequestKeyOf,
183197
matches: [...unique.values()].sort((left, right) =>
184198
right.updatedAt.localeCompare(left.updatedAt),
185199
),

‎apps/web/src/components/chat/useComposerMenuItems.ts‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import {
2+
legacyThreadPullRequestKey,
3+
threadPullRequestKeyOf,
4+
} from "@t3tools/client-runtime/thread-pull-requests";
15
import {
26
matchComposerEnvironmentItems,
37
matchComposerThreadItems,
@@ -327,10 +331,17 @@ export function useComposerMenuItems({
327331
) {
328332
const exactPullRequest =
329333
exactPullRequestLookup.data?.number === pullRequestTriggerNumber
330-
? [exactPullRequestLookup.data]
334+
? [
335+
{
336+
...exactPullRequestLookup.data,
337+
// Only the host: the URL's full repository path would not match the project's selector.
338+
host: legacyThreadPullRequestKey(exactPullRequestLookup.data).host,
339+
},
340+
]
331341
: [];
332342
const matches = /^\d*$/u.test(composerTrigger.query)
333343
? filterComposerPullRequestMatches({
344+
keyOf: threadPullRequestKeyOf,
334345
entries: [...exactPullRequest, ...(pullRequestLookup.data?.entries ?? [])],
335346
linked: linkedPullRequests,
336347
projectId: pullRequestProjectId,
@@ -339,6 +350,7 @@ export function useComposerMenuItems({
339350
limit: COMPOSER_PULL_REQUEST_RESULT_LIMIT,
340351
})
341352
: withLinkedComposerPullRequestsFirst({
353+
keyOf: threadPullRequestKeyOf,
342354
matches: rankPullRequestMatches(
343355
(pullRequestLookup.data?.entries ?? []).filter((entry) => {
344356
if (
@@ -363,7 +375,7 @@ export function useComposerMenuItems({
363375
limit: COMPOSER_PULL_REQUEST_RESULT_LIMIT,
364376
});
365377
return matches.map((pullRequest) => ({
366-
id: `pull-request:${pullRequest.projectId}:${pullRequest.repository}:${pullRequest.number}`,
378+
id: `pull-request:${pullRequest.projectId}:${threadPullRequestKeyOf(pullRequest)}`,
367379
type: "pull-request",
368380
pullRequest: {
369381
number: pullRequest.number,

‎apps/web/src/composer-logic.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { threadPullRequestKeyOf } from "@t3tools/client-runtime/thread-pull-requests";
12
import { filterComposerPullRequestMatches } from "@t3tools/shared/composerPullRequestMatches";
23
import { EnvironmentId, MessageId, ThreadId, type AssistantCitation } from "@t3tools/contracts";
34
import {
@@ -331,30 +332,35 @@ describe("detectComposerTrigger", () => {
331332
describe("filterComposerPullRequestMatches", () => {
332333
const entries = [
333334
{
335+
host: "github.com",
334336
number: 7,
335337
projectId: "project-1",
336338
repository: "t3tools/t3code",
337339
updatedAt: "2026-09-01T12:00:00.000Z",
338340
},
339341
{
342+
host: "github.com",
340343
number: 8987,
341344
projectId: "project-1",
342345
repository: "T3Tools/T3Code",
343346
updatedAt: "2026-09-03T12:00:00.000Z",
344347
},
345348
{
349+
host: "github.com",
346350
number: 27,
347351
projectId: "project-1",
348352
repository: "t3tools/t3code",
349353
updatedAt: "2026-09-02T12:00:00.000Z",
350354
},
351355
{
356+
host: "github.com",
352357
number: 27,
353358
projectId: "project-1",
354359
repository: "t3tools/t3code",
355360
updatedAt: "2026-09-01T13:00:00.000Z",
356361
},
357362
{
363+
host: "github.com",
358364
number: 70,
359365
projectId: "project-2",
360366
repository: "t3tools/other",
@@ -365,6 +371,7 @@ describe("filterComposerPullRequestMatches", () => {
365371
it("matches and de-duplicates number fragments within one repository, exact match first", () => {
366372
expect(
367373
filterComposerPullRequestMatches({
374+
keyOf: threadPullRequestKeyOf,
368375
entries,
369376
projectId: "project-1",
370377
repository: "t3tools/t3code",
@@ -376,18 +383,21 @@ describe("filterComposerPullRequestMatches", () => {
376383

377384
it("keeps an older exact match when newer substring matches would fill the limit", () => {
378385
const exact = {
386+
host: "github.com",
379387
number: 7,
380388
projectId: "project-1",
381389
repository: "t3tools/t3code",
382390
updatedAt: "2020-01-01T00:00:00.000Z",
383391
};
384392
const newerSubstringMatches = Array.from({ length: 12 }, (_unused, index) => ({
393+
host: "github.com",
385394
number: 700 + index,
386395
projectId: "project-1",
387396
repository: "t3tools/t3code",
388397
updatedAt: `2026-09-${String(index + 1).padStart(2, "0")}T12:00:00.000Z`,
389398
}));
390399
const matches = filterComposerPullRequestMatches({
400+
keyOf: threadPullRequestKeyOf,
391401
entries: [...newerSubstringMatches, exact],
392402
projectId: "project-1",
393403
repository: "t3tools/t3code",

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

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
import { describe, expect, it } from "vite-plus/test";
22

3-
import type { ThreadPullRequestLink } from "@t3tools/contracts";
3+
import type { ThreadPullRequestKey, ThreadPullRequestLink } from "@t3tools/contracts";
44

55
import {
66
composerPullRequestsFromLinks,
77
filterComposerPullRequestMatches,
88
withLinkedComposerPullRequestsFirst,
99
} from "./composerPullRequestMatches.ts";
1010

11+
const keyOf = (entry: ThreadPullRequestKey) =>
12+
`${entry.host.trim().toLowerCase()}/${entry.repository.trim().toLowerCase()}#${entry.number}`;
13+
1114
const entry = (number: number, updatedAt: string) => ({
1215
number,
16+
host: "github.com",
1317
projectId: "p1",
1418
repository: "owner/repo",
1519
updatedAt,
@@ -18,6 +22,7 @@ const entry = (number: number, updatedAt: string) => ({
1822
describe("filterComposerPullRequestMatches", () => {
1923
it("ranks the exact number above newer substring matches", () => {
2024
const result = filterComposerPullRequestMatches({
25+
keyOf,
2126
entries: [entry(1234, "2026-01-03"), entry(123, "2026-01-01"), entry(1230, "2026-01-02")],
2227
projectId: "p1",
2328
repository: "owner/repo",
@@ -29,6 +34,7 @@ describe("filterComposerPullRequestMatches", () => {
2934

3035
it("orders by update instant when timestamps carry different UTC offsets", () => {
3136
const result = filterComposerPullRequestMatches({
37+
keyOf,
3238
entries: [entry(401, "2026-10-25T02:50:00+02:00"), entry(499, "2026-10-25T02:10:00+01:00")],
3339
projectId: "p1",
3440
repository: "owner/repo",
@@ -66,6 +72,7 @@ describe("linked pull requests", () => {
6672

6773
it("offers a linked pull request from another repository above the project's own", () => {
6874
const result = filterComposerPullRequestMatches({
75+
keyOf,
6976
entries: [entry(4, "2026-01-03"), { ...entry(4, "2026-01-04"), repository: "owner/other" }],
7077
linked: composerPullRequestsFromLinks([link("owner/repo-b", 4)], "p1"),
7178
projectId: "p1",
@@ -79,8 +86,27 @@ describe("linked pull requests", () => {
7986
]);
8087
});
8188

89+
it("keeps linked reviews with the same repository and number on different hosts", () => {
90+
const github = link("wireshark/wireshark", 1);
91+
const gitlab = link("wireshark/wireshark", 1, {
92+
host: "gitlab.com",
93+
url: "https://gitlab.com/wireshark/wireshark/-/merge_requests/1",
94+
});
95+
const result = filterComposerPullRequestMatches({
96+
keyOf,
97+
entries: [],
98+
linked: composerPullRequestsFromLinks([github, gitlab], "p1"),
99+
projectId: "p1",
100+
repository: "wireshark/wireshark",
101+
query: "1",
102+
limit: 10,
103+
});
104+
expect(result.map((match) => match.url)).toEqual([github.url, gitlab.url]);
105+
});
106+
82107
it("keeps one row for a linked pull request the project listing already has", () => {
83108
const result = filterComposerPullRequestMatches({
109+
keyOf,
84110
entries: [entry(4, "2026-01-03")],
85111
linked: composerPullRequestsFromLinks([link("Owner/Repo", 4)], "p1"),
86112
projectId: "p1",
@@ -98,22 +124,34 @@ describe("linked pull requests", () => {
98124
snapshot: { ...link("owner/repo", 7).snapshot!, title: "Fix login" },
99125
}),
100126
link("owner/repo", 8),
127+
link("owner/repo", 8, {
128+
host: "gitlab.com",
129+
url: "https://gitlab.com/owner/repo/-/merge_requests/8",
130+
snapshot: { ...link("owner/repo", 8).snapshot!, title: "Fix CI" },
131+
}),
101132
],
102133
"p1",
103134
);
104135
const searching = withLinkedComposerPullRequestsFirst({
136+
keyOf,
105137
matches: [],
106138
linked,
107139
query: "fix",
108140
limit: 10,
109141
});
110-
expect(searching.map((match) => match.number)).toEqual([7]);
142+
expect(searching.map((match) => match.number)).toEqual([7, 8]);
111143
const searched = withLinkedComposerPullRequestsFirst({
144+
keyOf,
112145
matches: [entry(9, "2026-01-05"), entry(8, "2026-01-03")],
113146
linked,
114147
query: "fix",
115148
limit: 10,
116149
});
117-
expect(searched).toEqual([linked[0], entry(8, "2026-01-03"), entry(9, "2026-01-05")]);
150+
expect(searched).toEqual([
151+
linked[0],
152+
entry(8, "2026-01-03"),
153+
linked[2],
154+
entry(9, "2026-01-05"),
155+
]);
118156
});
119157
});

‎packages/shared/src/composerPullRequestMatches.ts‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import type { ThreadPullRequestLink } from "@t3tools/contracts";
1+
import type { ThreadPullRequestKey, ThreadPullRequestLink } from "@t3tools/contracts";
22

33
import { visibleThreadPullRequests } from "./threadPullRequests.ts";
44

5-
export interface ComposerPullRequestMatch {
6-
readonly number: number;
5+
export interface ComposerPullRequestMatch extends ThreadPullRequestKey {
76
readonly projectId: string;
8-
readonly repository: string;
97
readonly updatedAt: string;
108
}
119

@@ -19,6 +17,7 @@ export function composerPullRequestsFromLinks(
1917
: [
2018
{
2119
projectId,
20+
host: link.host,
2221
repository: link.repository,
2322
number: link.number,
2423
url: link.url,
@@ -43,10 +42,10 @@ export function filterComposerPullRequestMatches<
4342
readonly repository: string;
4443
readonly query: string;
4544
readonly limit: number;
45+
readonly keyOf: (entry: Entry | Linked) => string;
4646
}): ReadonlyArray<Entry | Linked> {
4747
const repository = input.repository.trim().toLowerCase();
48-
const keyOf = (entry: ComposerPullRequestMatch) =>
49-
`${entry.repository.trim().toLowerCase()}#${entry.number}`;
48+
const { keyOf } = input;
5049
const linked = (input.linked ?? []).filter((entry) => String(entry.number).includes(input.query));
5150
const linkedKeys = new Set(linked.map(keyOf));
5251
const matchingEntries = input.entries.filter(
@@ -62,7 +61,7 @@ export function filterComposerPullRequestMatches<
6261
}
6362
}
6463
const isExactMatch = (entry: ComposerPullRequestMatch) => String(entry.number) === input.query;
65-
const isLinked = (entry: ComposerPullRequestMatch) => linkedKeys.has(keyOf(entry));
64+
const isLinked = (entry: Entry | Linked) => linkedKeys.has(keyOf(entry));
6665
const updatedAtMs = (entry: ComposerPullRequestMatch) => Date.parse(entry.updatedAt) || 0;
6766
// Hermes has no ES2023 array methods, so sort a fresh array.
6867
return [...uniqueEntries.values()]
@@ -87,9 +86,9 @@ export function withLinkedComposerPullRequestsFirst<
8786
readonly linked: ReadonlyArray<Linked>;
8887
readonly query: string;
8988
readonly limit: number;
89+
readonly keyOf: (entry: Entry | Linked) => string;
9090
}): ReadonlyArray<Entry | Linked> {
91-
const keyOf = (entry: ComposerPullRequestMatch) =>
92-
`${entry.repository.trim().toLowerCase()}#${entry.number}`;
91+
const { keyOf } = input;
9392
const matchesByKey = new Map(input.matches.map((entry) => [keyOf(entry), entry]));
9493
const words = input.query.toLowerCase().split(/\s+/u).filter(Boolean);
9594
const linked = input.linked.flatMap((entry): Array<Entry | Linked> => {

0 commit comments

Comments
 (0)