1import { parsePullRequestAnchor } from "@t3tools/shared/pullRequestAnchor";
2import { resolveChangeRequestLinkTarget } from "@t3tools/client-runtime/change-request-links";
3import type { EnvironmentProject } from "@t3tools/client-runtime/state/shell";
4import { EnvironmentId, ProjectId } from "@t3tools/contracts";
5
6/** The PullRequest route for a change request link from a project, or null for the browser. */
7export function nativePullRequestDestination(
8 url: string,
9 context: { environmentId: string; projectId: string } | null,
10 projects: ReadonlyArray<Pick<EnvironmentProject, "id" | "environmentId" | "repositoryIdentity">>,
11 configLoaded: (environmentId: EnvironmentId) => boolean,
12) {
13 if (!context) return null;
14 const target = resolveChangeRequestLinkTarget({
15 url,
16 projects,
17 configLoaded,
18 environmentId: EnvironmentId.make(context.environmentId),
19 projectId: ProjectId.make(context.projectId),
20 lendHostProject: true,
21 });
22 if (target === null) return null;
23 return {
24 environmentId: context.environmentId,
25 projectId: String(target.project.id),
26 repository: target.repository,
27 number: target.number,
28 ...(parsePullRequestAnchor(url) ? { navigationUrl: url } : {}),
29 ...(target.host === undefined ? {} : { host: target.host }),
30 };
31}