Open History to see the last commit
1import { findProjectForChangeRequest } from "@t3tools/client-runtime/change-request-links";
2import type { EnvironmentProject } from "@t3tools/client-runtime/state/shell";
3import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
4
5/**
6 * Opens a change request in the app only under a project of the link's environment whose own
7 * repository holds it, preferring the one the link came from; anything else is the browser's.
8 */
9export function nativePullRequestDestination(
10 url: string,
11 context: { environmentId: string; projectId: string } | null,
12 projects: ReadonlyArray<Pick<EnvironmentProject, "id" | "environmentId" | "repositoryIdentity">>,
13) {
14 const parsed = sourceControlClients.parseChangeRequestUrl(url)?.link;
15 if (!parsed || !context) return null;
16 const candidates = projects.filter((project) => project.environmentId === context.environmentId);
17 const project = findProjectForChangeRequest(
18 [
19 ...candidates.filter((candidate) => candidate.id === context.projectId),
20 ...candidates.filter((candidate) => candidate.id !== context.projectId),
21 ],
22 parsed,
23 );
24 if (project === undefined) return null;
25 return {
26 environmentId: context.environmentId,
27 projectId: String(project.id),
28 repository: parsed.repository,
29 number: parsed.number,
30 host: parsed.authority ?? parsed.host,
31 };
32}