Open History to see the last commit
1import type { ThreadPullRequestLink } from "@t3tools/contracts";
2
3import { resolveThreadCurrentPullRequestLink } from "./threadPullRequests.ts";
4
5export interface ThreadReferenceCopyTarget {
6 readonly kind: "pull-request" | "thread";
7 readonly value: string;
8 readonly clipboardTarget: string;
9 readonly successTitle: string;
10 readonly failureTitle: string;
11}
12
13export function threadHandoverSourceKey(environmentId: string, threadId: string): string {
14 return `handover:${JSON.stringify([environmentId, threadId])}`;
15}
16
17export function resolveThreadReferenceCopyTarget(input: {
18 readonly threadId: string;
19 /** Undefined means no PR panel; null means its URL is not available yet. */
20 readonly openPanelPullRequestUrl?: string | null | undefined;
21 readonly pullRequests?: ReadonlyArray<ThreadPullRequestLink> | undefined;
22 readonly linkedPullRequestUrl?: string | null;
23}): ThreadReferenceCopyTarget | null {
24 if (input.openPanelPullRequestUrl === null) return null;
25 const pullRequestUrl =
26 input.openPanelPullRequestUrl ??
27 resolveThreadCurrentPullRequestLink(input.pullRequests ?? [])?.url ??
28 input.linkedPullRequestUrl;
29 return pullRequestUrl
30 ? {
31 kind: "pull-request",
32 value: pullRequestUrl,
33 clipboardTarget: "pull request link",
34 successTitle: "PR link copied",
35 failureTitle: "Failed to copy PR link",
36 }
37 : {
38 kind: "thread",
39 value: input.threadId,
40 clipboardTarget: "thread ID",
41 successTitle: "Thread ID copied",
42 failureTitle: "Failed to copy thread ID",
43 };
44}