Open History to see the last commit
1import type { PullRequestAssigneeCandidate } from "@t3tools/contracts";
2
3/**
4 * The assignee menu's rows: the people the menu first loaded, narrowed to what was typed, then
5 * whoever the host's own search found beyond them. Anybody in both comes from the first list,
6 * since that is the one an assignment updates.
7 */
8export function mergeAssigneeCandidates(
9 loaded: ReadonlyArray<PullRequestAssigneeCandidate>,
10 searched: ReadonlyArray<PullRequestAssigneeCandidate>,
11 query: string,
12): ReadonlyArray<PullRequestAssigneeCandidate> {
13 const needle = query.trim().toLowerCase();
14 const known = new Set(loaded.map((candidate) => candidate.id));
15 return [
16 ...loaded.filter(
17 (candidate) =>
18 needle.length === 0 ||
19 candidate.login.toLowerCase().includes(needle) ||
20 (candidate.name ?? "").toLowerCase().includes(needle),
21 ),
22 // The host matched these on its own terms, an email for one, so they are not narrowed again.
23 ...searched.filter((candidate) => !known.has(candidate.id)),
24 ];
25}