@@ -6,6 +6,7 @@ import type {
66 ThreadLinkedPullRequest ,
77 ThreadPullRequestLink ,
88} from "@t3tools/contracts" ;
9+ import type { EnvironmentProject } from "@t3tools/client-runtime/state/shell" ;
910import {
1011 isAtomCommandInterrupted ,
1112 squashAtomCommandFailure ,
@@ -20,14 +21,32 @@ import {
2021} from "@t3tools/shared/threadPullRequests" ;
2122import {
2223 findProjectForChangeRequest ,
23- findProjectOnChangeRequestHost ,
2424 matchesLinkedPullRequestUrl ,
2525 parseChangeRequestUrl ,
26+ type ChangeRequestLink ,
2627} from "~/lib/openPullRequestLink" ;
2728import { useProjects , useServerConfigs } from "~/state/entities" ;
2829import { threadEnvironment } from "~/state/threads" ;
2930import { useAtomCommand } from "~/state/use-atom-command" ;
3031
32+ /**
33+ * Whether a parsed change-request link can be linked to a thread. `multiple` mode (the
34+ * `threadPullRequests` capability) stores a link's host, repository and number on the thread
35+ * directly and needs no project at all; a freshly linked pull request already starts with a
36+ * null snapshot until some project can sync it, so a host nothing here is checked out from is
37+ * the same case, not a reason to refuse the link. `single` mode still needs a matching project,
38+ * since that is where its required `projectId` comes from.
39+ */
40+ export function canLinkChangeRequest (
41+ mode : ReturnType < typeof threadPullRequestLinkMode > ,
42+ projects : ReadonlyArray < EnvironmentProject > ,
43+ parsed : ChangeRequestLink ,
44+ ) : boolean {
45+ if ( mode === "unsupported" ) return false ;
46+ if ( mode === "multiple" ) return true ;
47+ return findProjectForChangeRequest ( projects , parsed ) !== undefined ;
48+ }
49+
3150/** Routes link actions through the command advertised by this environment. */
3251export function usePullRequestLinking ( environmentId : EnvironmentId | null | undefined ) {
3352 const configs = useServerConfigs ( ) ;
@@ -44,13 +63,7 @@ export function usePullRequestLinking(environmentId: EnvironmentId | null | unde
4463 ) ;
4564 const canLink = ( url : string ) => {
4665 const parsed = parseChangeRequestUrl ( url ) ;
47- if ( parsed === null || mode === "unsupported" ) return false ;
48- return (
49- ( mode === "multiple" ? findProjectOnChangeRequestHost : findProjectForChangeRequest ) (
50- environmentProjects ,
51- parsed ,
52- ) !== undefined
53- ) ;
66+ return parsed !== null && canLinkChangeRequest ( mode , environmentProjects , parsed ) ;
5467 } ;
5568 const isLinked = (
5669 thread : {
0 commit comments