diff --git a/apps/mobile/src/native/useOpenPullRequest.ts b/apps/mobile/src/native/useOpenPullRequest.ts
index d6da186b0f23a..f385432c52c19 100644
--- a/apps/mobile/src/native/useOpenPullRequest.ts
+++ b/apps/mobile/src/native/useOpenPullRequest.ts
@@ -1,15 +1,21 @@
import { useNavigation, useRoute, StackActions } from "@react-navigation/native";
-import { resolveIssueLinkTarget } from "@t3tools/client-runtime/issue-links";
+import {
+ isLinearIssueLink,
+ linksAnotherLinearWorkspace,
+ resolveIssueLinkTarget,
+} from "@t3tools/client-runtime/issue-links";
import {
nativePullRequestDestination,
pullRequestCandidateForIssueLink,
} from "../lib/pullRequestNavigation";
import { isAtomCommandInterrupted } from "@t3tools/client-runtime/state/runtime";
-import { EnvironmentId, ThreadId } from "@t3tools/contracts";
+import { EnvironmentId, type IssueTrackerConnectionList, ThreadId } from "@t3tools/contracts";
import { useProjects, useThreadShell } from "../state/entities";
import { tryOpenExternalUrl } from "../lib/openExternalUrl";
import { appAtomRegistry } from "../state/atom-registry";
import { environmentServerConfigsAtom } from "../state/server";
+import { issueEnvironment } from "../state/issues";
+import { issueTrackerEnvironment } from "../state/issueTrackers";
import { composerPullRequests } from "../state/pull-requests";
import { useAtomQueryRunner } from "../state/use-atom-query-runner";
import { withKnownPullRequestSummary } from "../state/use-thread-pr";
@@ -28,6 +34,14 @@ export function useNavigateToPullRequest(options?: { readonly replace?: boolean
reportFailure: false,
reportDefect: false,
});
+ const readTrackers = useAtomQueryRunner(issueTrackerEnvironment.connections, {
+ reportFailure: false,
+ reportDefect: false,
+ });
+ const readIssue = useAtomQueryRunner(issueEnvironment.detail, {
+ reportFailure: false,
+ reportDefect: false,
+ });
return async (url: string, context: PullRequestContext | null) => {
// Read at press time so a config push does not hand every link a new handler.
const serverConfigs = appAtomRegistry.get(environmentServerConfigsAtom);
@@ -37,14 +51,26 @@ export function useNavigateToPullRequest(options?: { readonly replace?: boolean
if (!destination) {
// An issue link from the same text opens the issue; anything else leaves for the browser.
const environmentId = context && EnvironmentId.make(context.environmentId);
- const issue =
- environmentId && serverConfigs.get(environmentId)?.environment.capabilities.issues === true
+ const issuesSupported =
+ environmentId !== null &&
+ serverConfigs.get(environmentId)?.environment.capabilities.issues === true;
+ const resolveIssue = (trackerBindings?: IssueTrackerConnectionList["bindings"]) =>
+ environmentId && issuesSupported
? resolveIssueLinkTarget({
url,
projects: projects.filter((project) => project.environmentId === environmentId),
preferredProjectId: context.projectId,
+ trackerBindings,
})
: null;
+ let issue = resolveIssue();
+ let standalone = false;
+ if (!issue && environmentId && issuesSupported && isLinearIssueLink(url)) {
+ // Linear links resolve through the projects bound to a team in Settings.
+ const trackers = await readTrackers({ environmentId, input: {} });
+ if (trackers._tag === "Success") issue = resolveIssue(trackers.value.bindings);
+ standalone = issue !== null;
+ }
if (!issue || !environmentId) return tryOpenExternalUrl(url, "pull-request");
const candidate = pullRequestCandidateForIssueLink(url, issue.ref);
if (candidate) {
@@ -64,6 +90,13 @@ export function useNavigateToPullRequest(options?: { readonly replace?: boolean
// A dropped connection says nothing about what the link names; the browser knows.
if (isAtomCommandInterrupted(preview)) return tryOpenExternalUrl(url, "pull-request");
}
+ if (standalone) {
+ // Team keys repeat across Linear workspaces; an issue whose workspace is unconfirmed goes to the browser.
+ const detail = await readIssue({ environmentId, input: issue.ref });
+ if (detail._tag !== "Success" || linksAnotherLinearWorkspace(url, detail.value.url)) {
+ return tryOpenExternalUrl(url, "pull-request");
+ }
+ }
const issueParams = {
environmentId,
projectId: issue.ref.projectId,
diff --git a/apps/web/src/components/chat/RightPanelSurfaceContent.tsx b/apps/web/src/components/chat/RightPanelSurfaceContent.tsx
index 80f27c8dce568..11d5b0450a425 100644
--- a/apps/web/src/components/chat/RightPanelSurfaceContent.tsx
+++ b/apps/web/src/components/chat/RightPanelSurfaceContent.tsx
@@ -199,6 +199,7 @@ export function RightPanelSurfaceContent(props: {
scope: surface.scope,
key: surface.key,
}}
+ linkUrl={surface.url}
threadRef={threadRef}
onSelectPullRequest={(reference) => {
useRightPanelStore.getState().openPullRequest(threadRef, {
diff --git a/apps/web/src/components/issue/IssueDetailPanel.tsx b/apps/web/src/components/issue/IssueDetailPanel.tsx
index e56a89c60f091..de77ff58e8a11 100644
--- a/apps/web/src/components/issue/IssueDetailPanel.tsx
+++ b/apps/web/src/components/issue/IssueDetailPanel.tsx
@@ -1,4 +1,5 @@
import { RegistryContext, useAtomValue } from "@effect/atom-react";
+import { linksAnotherLinearWorkspace } from "@t3tools/client-runtime/issue-links";
import { issueEventSentence, issueWriteAccess } from "@t3tools/client-runtime/issue-presentation";
import { createIssueCommentPager } from "@t3tools/client-runtime/state/issues";
import {
@@ -381,10 +382,13 @@ export function IssueDetailPanel({
reference,
threadRef = null,
listEntry = null,
+ linkUrl,
onSelectPullRequest,
}: {
environmentId: EnvironmentId;
reference: IssueRef;
+ /** The link this issue was opened from, when a click in text opened it. */
+ linkUrl?: string | undefined;
/** The list row this issue was opened from, shown until the detail arrives. */
listEntry?: IssueListEntry | null;
threadRef?: ScopedThreadRef | null;
@@ -426,6 +430,16 @@ export function IssueDetailPanel({
return ;
}
+ if (linkUrl !== undefined && linksAnotherLinearWorkspace(linkUrl, detail.url)) {
+ return (
+
+ );
+ }
+
const timeline: ReadonlyArray = [
...comments.map((c): TimelineItem => ({ kind: "comment", at: c.createdAt, comment: c })),
...detail.events.map((e): TimelineItem => ({ kind: "event", at: e.createdAt, event: e })),
diff --git a/apps/web/src/components/issue/IssuesPage.tsx b/apps/web/src/components/issue/IssuesPage.tsx
index 707cda40fb889..3ae0c53654740 100644
--- a/apps/web/src/components/issue/IssuesPage.tsx
+++ b/apps/web/src/components/issue/IssuesPage.tsx
@@ -812,6 +812,7 @@ export function IssuesPage() {
scope: renderedSurface.scope,
key: renderedSurface.key,
}}
+ linkUrl={renderedSurface.url}
onSelectPullRequest={(reference) => {
useRightPanelStore.getState().openPullRequest(rightPanelRef, {
projectId: reference.projectId,
diff --git a/apps/web/src/i18n/translations/de.json b/apps/web/src/i18n/translations/de.json
index 2f27960058ee6..5e596acc31487 100644
--- a/apps/web/src/i18n/translations/de.json
+++ b/apps/web/src/i18n/translations/de.json
@@ -5681,6 +5681,9 @@
"b8a884177afea13c": "Es gibt mehr Personen, als hier aufgeführt sind.",
"6081fdaabe34daf7": "Zugewiesen",
"2d9b7c42374ecd04": "Dieses Issue konnte nicht geladen werden",
+ "f4a2cf1e37b0f65c": "Dieses Issue ist in einem anderen Linear-Workspace",
+ "ccbf4f5267dde5b8": "Das verbundene Linear-Konto hat ein Issue mit demselben Schlüssel, aber nicht dieses.",
+ "8e8867deed70a6c1": "Auf Linear öffnen",
"217e1e7b60469736": "Issue-Status, {state}",
"a98a269e3061a069": "{issue} auf {provider} öffnen",
"c1ff5afd83b1e027": "Issue aktualisieren",
diff --git a/apps/web/src/i18n/translations/en.json b/apps/web/src/i18n/translations/en.json
index 7fed91e13a107..bba602c1201d9 100644
--- a/apps/web/src/i18n/translations/en.json
+++ b/apps/web/src/i18n/translations/en.json
@@ -5682,6 +5682,9 @@
"b8a884177afea13c": "More people exist than are listed here.",
"6081fdaabe34daf7": "Assigned",
"2d9b7c42374ecd04": "Could not load this issue",
+ "f4a2cf1e37b0f65c": "This issue is in another Linear workspace",
+ "ccbf4f5267dde5b8": "The connected Linear account has an issue with the same key, not this one.",
+ "8e8867deed70a6c1": "Open on Linear",
"217e1e7b60469736": "Issue state, {state}",
"a98a269e3061a069": "Open {issue} on {provider}",
"c1ff5afd83b1e027": "Refresh issue",
diff --git a/apps/web/src/i18n/translations/es.json b/apps/web/src/i18n/translations/es.json
index 2916e71511312..8dbd5d3117c51 100644
--- a/apps/web/src/i18n/translations/es.json
+++ b/apps/web/src/i18n/translations/es.json
@@ -5680,6 +5680,9 @@
"b8a884177afea13c": "Hay más personas de las que se muestran aquí.",
"6081fdaabe34daf7": "Asignado",
"2d9b7c42374ecd04": "No se pudo cargar esta issue",
+ "f4a2cf1e37b0f65c": "Esta issue está en otro espacio de trabajo de Linear",
+ "ccbf4f5267dde5b8": "La cuenta de Linear conectada tiene una issue con la misma clave, pero no esta.",
+ "8e8867deed70a6c1": "Abrir en Linear",
"217e1e7b60469736": "Estado de la issue, {state}",
"a98a269e3061a069": "Abrir {issue} en {provider}",
"c1ff5afd83b1e027": "Actualizar issue",
diff --git a/apps/web/src/i18n/translations/fr.json b/apps/web/src/i18n/translations/fr.json
index 332f6f419e0ef..569ed5c0a8909 100644
--- a/apps/web/src/i18n/translations/fr.json
+++ b/apps/web/src/i18n/translations/fr.json
@@ -5681,6 +5681,9 @@
"b8a884177afea13c": "Il existe plus de personnes que celles listées ici.",
"6081fdaabe34daf7": "Assigné",
"2d9b7c42374ecd04": "Impossible de charger ce ticket",
+ "f4a2cf1e37b0f65c": "Ce ticket se trouve dans un autre espace de travail Linear",
+ "ccbf4f5267dde5b8": "Le compte Linear connecté a un ticket avec la même clé, mais pas celui-ci.",
+ "8e8867deed70a6c1": "Ouvrir sur Linear",
"217e1e7b60469736": "État du ticket, {state}",
"a98a269e3061a069": "Ouvrir {issue} sur {provider}",
"c1ff5afd83b1e027": "Actualiser le ticket",
diff --git a/apps/web/src/i18n/translations/ja.json b/apps/web/src/i18n/translations/ja.json
index 191de35eadbc8..7fa758250fa6a 100644
--- a/apps/web/src/i18n/translations/ja.json
+++ b/apps/web/src/i18n/translations/ja.json
@@ -5663,6 +5663,9 @@
"b8a884177afea13c": "ここに表示されている以外にもユーザーがいます。",
"6081fdaabe34daf7": "割り当て済み",
"2d9b7c42374ecd04": "この Issue を読み込めませんでした",
+ "f4a2cf1e37b0f65c": "この Issue は別の Linear ワークスペースにあります",
+ "ccbf4f5267dde5b8": "接続中の Linear アカウントには同じキーの Issue がありますが、これとは別のものです。",
+ "8e8867deed70a6c1": "Linear で開く",
"217e1e7b60469736": "Issue の状態、{state}",
"a98a269e3061a069": "{provider} で {issue} を開く",
"c1ff5afd83b1e027": "Issue を更新",
diff --git a/apps/web/src/i18n/translations/ko.json b/apps/web/src/i18n/translations/ko.json
index ff2beb8085c53..0baa846dd09cb 100644
--- a/apps/web/src/i18n/translations/ko.json
+++ b/apps/web/src/i18n/translations/ko.json
@@ -5661,6 +5661,9 @@
"b8a884177afea13c": "여기에 표시된 것보다 사용자가 더 있습니다.",
"6081fdaabe34daf7": "지정됨",
"2d9b7c42374ecd04": "이 이슈를 불러올 수 없습니다",
+ "f4a2cf1e37b0f65c": "이 이슈는 다른 Linear 워크스페이스에 있습니다",
+ "ccbf4f5267dde5b8": "연결된 Linear 계정에 같은 키의 이슈가 있지만 이 이슈는 아닙니다.",
+ "8e8867deed70a6c1": "Linear에서 열기",
"217e1e7b60469736": "이슈 상태, {state}",
"a98a269e3061a069": "{provider}에서 {issue} 열기",
"c1ff5afd83b1e027": "이슈 새로 고침",
diff --git a/apps/web/src/i18n/translations/pt-BR.json b/apps/web/src/i18n/translations/pt-BR.json
index 052e06a9642cc..466ee5b262187 100644
--- a/apps/web/src/i18n/translations/pt-BR.json
+++ b/apps/web/src/i18n/translations/pt-BR.json
@@ -5680,6 +5680,9 @@
"b8a884177afea13c": "Há mais pessoas do que as listadas aqui.",
"6081fdaabe34daf7": "Atribuído",
"2d9b7c42374ecd04": "Não foi possível carregar esta issue",
+ "f4a2cf1e37b0f65c": "Esta issue está em outro workspace do Linear",
+ "ccbf4f5267dde5b8": "A conta do Linear conectada tem uma issue com a mesma chave, mas não esta.",
+ "8e8867deed70a6c1": "Abrir no Linear",
"217e1e7b60469736": "Estado da issue, {state}",
"a98a269e3061a069": "Abrir {issue} no {provider}",
"c1ff5afd83b1e027": "Atualizar issue",
diff --git a/apps/web/src/i18n/translations/ru.json b/apps/web/src/i18n/translations/ru.json
index 55baa13919c8c..19dcf49216fb8 100644
--- a/apps/web/src/i18n/translations/ru.json
+++ b/apps/web/src/i18n/translations/ru.json
@@ -5680,6 +5680,9 @@
"b8a884177afea13c": "Людей больше, чем показано здесь.",
"6081fdaabe34daf7": "Назначен",
"2d9b7c42374ecd04": "Не удалось загрузить этот issue",
+ "f4a2cf1e37b0f65c": "Этот issue находится в другом рабочем пространстве Linear",
+ "ccbf4f5267dde5b8": "В подключённом аккаунте Linear есть issue с тем же ключом, но не этот.",
+ "8e8867deed70a6c1": "Открыть в Linear",
"217e1e7b60469736": "Состояние issue: {state}",
"a98a269e3061a069": "Открыть {issue} в {provider}",
"c1ff5afd83b1e027": "Обновить issue",
diff --git a/apps/web/src/i18n/translations/sv.json b/apps/web/src/i18n/translations/sv.json
index df8f35cf81652..4d841dbbd5266 100644
--- a/apps/web/src/i18n/translations/sv.json
+++ b/apps/web/src/i18n/translations/sv.json
@@ -5681,6 +5681,9 @@
"b8a884177afea13c": "Det finns fler personer än som listas här.",
"6081fdaabe34daf7": "Tilldelad",
"2d9b7c42374ecd04": "Kunde inte läsa in det här ärendet",
+ "f4a2cf1e37b0f65c": "Det här ärendet finns i en annan Linear-arbetsyta",
+ "ccbf4f5267dde5b8": "Det anslutna Linear-kontot har ett ärende med samma nyckel, men inte det här.",
+ "8e8867deed70a6c1": "Öppna på Linear",
"217e1e7b60469736": "Ärendestatus, {state}",
"a98a269e3061a069": "Öppna {issue} på {provider}",
"c1ff5afd83b1e027": "Uppdatera ärende",
diff --git a/apps/web/src/i18n/translations/zh.json b/apps/web/src/i18n/translations/zh.json
index 70f7f30cfecbb..0655d810676dd 100644
--- a/apps/web/src/i18n/translations/zh.json
+++ b/apps/web/src/i18n/translations/zh.json
@@ -5687,6 +5687,9 @@
"b8a884177afea13c": "还有更多人员未在此列出。",
"6081fdaabe34daf7": "已分配",
"2d9b7c42374ecd04": "无法加载此 issue",
+ "f4a2cf1e37b0f65c": "此 issue 位于另一个 Linear 工作区",
+ "ccbf4f5267dde5b8": "已连接的 Linear 账户中有一个键相同的 issue,但不是这一个。",
+ "8e8867deed70a6c1": "在 Linear 上打开",
"217e1e7b60469736": "issue 状态,{state}",
"a98a269e3061a069": "在 {provider} 上打开 {issue}",
"c1ff5afd83b1e027": "刷新 issue",
diff --git a/apps/web/src/lib/openIssueLink.ts b/apps/web/src/lib/openIssueLink.ts
index 96d545827bbb9..ab8a9df53fd83 100644
--- a/apps/web/src/lib/openIssueLink.ts
+++ b/apps/web/src/lib/openIssueLink.ts
@@ -6,6 +6,8 @@ import type { MouseEvent } from "react";
import { readIssueListPreferences } from "../components/issue/issueListPreferences";
import { ISSUES_PANEL_REF, PULL_REQUESTS_PANEL_REF, useRightPanelStore } from "../rightPanelStore";
import { useProjects, useServerConfigs } from "../state/entities";
+import { issueTrackerEnvironment } from "../state/issueTrackers";
+import { useEnvironmentQuery } from "../state/query";
/**
* Opens an issue link beside the thread, and says whether it did. Anything else — a host no
@@ -27,6 +29,13 @@ export function useOpenIssueLink(
const allProjects = useProjects();
const serverConfigs = useServerConfigs();
const navigate = useNavigate();
+ const threadEnvironmentId = threadRef?.environmentId;
+ const trackers = useEnvironmentQuery(
+ threadEnvironmentId !== undefined &&
+ serverConfigs.get(threadEnvironmentId)?.environment.capabilities.issues === true
+ ? issueTrackerEnvironment.connections({ environmentId: threadEnvironmentId, input: {} })
+ : null,
+ );
return (event, targetUrl, targetEnvironmentId) => {
if (event.metaKey || event.ctrlKey) return false;
const resolvedPanelRef = panelRef ?? threadRef;
@@ -37,6 +46,7 @@ export function useOpenIssueLink(
const target = resolveIssueLinkTarget({
url: targetUrl,
projects: allProjects.filter((project) => project.environmentId === environmentId),
+ trackerBindings: environmentId === threadEnvironmentId ? trackers.data?.bindings : undefined,
});
if (target === null) return false;
event.preventDefault();
diff --git a/packages/client-runtime/package.json b/packages/client-runtime/package.json
index 21e592236c9dd..43a4a93e029b9 100644
--- a/packages/client-runtime/package.json
+++ b/packages/client-runtime/package.json
@@ -631,6 +631,7 @@
"dependencies": {
"@pierre/diffs": "catalog:",
"@t3tools/contracts": "workspace:*",
+ "@t3tools/issue-tracker-linear": "workspace:*",
"@t3tools/provider-acp-registry": "workspace:*",
"@t3tools/provider-core": "workspace:*",
"@t3tools/provider-cursor": "workspace:*",
diff --git a/packages/client-runtime/src/issueLinks.test.ts b/packages/client-runtime/src/issueLinks.test.ts
index eef7524db4f8b..4c20688e8c85e 100644
--- a/packages/client-runtime/src/issueLinks.test.ts
+++ b/packages/client-runtime/src/issueLinks.test.ts
@@ -1,7 +1,12 @@
-import { EnvironmentId, ProjectId, SourceControlProviderKind } from "@t3tools/contracts";
+import {
+ EnvironmentId,
+ IssueTrackerKind,
+ ProjectId,
+ SourceControlProviderKind,
+} from "@t3tools/contracts";
import { describe, expect, it } from "vite-plus/test";
-import { resolveIssueLinkTarget } from "./issueLinks.ts";
+import { linksAnotherLinearWorkspace, resolveIssueLinkTarget } from "./issueLinks.ts";
const project = (id: string, repository: string) =>
({
@@ -65,10 +70,61 @@ describe("resolveIssueLinkTarget", () => {
expect(custom?.ref).toMatchObject({ projectId: "custom", host: "code.acme.test", key: "7" });
});
+ it("reads a Linear issue through the project bound to its team, else lends a bound project", () => {
+ const trackerBindings = {
+ p1: { tracker: IssueTrackerKind.make("linear"), scope: "OPS" },
+ p2: { tracker: IssueTrackerKind.make("linear"), scope: "ENG" },
+ } as never;
+ const own = resolveIssueLinkTarget({
+ url: "https://linear.app/acme/issue/ENG-12/fix-the-thing",
+ projects,
+ trackerBindings,
+ });
+ expect(own?.ref).toEqual({
+ projectId: "p2",
+ tracker: "linear",
+ host: "linear.app",
+ scope: "ENG",
+ key: "ENG-12",
+ });
+
+ const lent = resolveIssueLinkTarget({
+ url: "https://linear.app/acme/issue/WEB-3",
+ projects,
+ trackerBindings,
+ preferredProjectId: ProjectId.make("p2"),
+ });
+ expect(lent?.ref).toMatchObject({ projectId: "p2", scope: "WEB", key: "WEB-3" });
+ });
+
it.each([
"https://github.com.evil.example/acme/web/issues/7",
"https://github.com/acme/web/pull/7",
+ "https://linear.app/acme/issue/ENG-12",
])("leaves %s an ordinary link", (url) => {
expect(resolveIssueLinkTarget({ url, projects })).toBeNull();
});
});
+
+describe("linksAnotherLinearWorkspace", () => {
+ it.each([
+ {
+ link: "https://linear.app/acme/issue/ENG-12",
+ issue: "https://linear.app/acme/issue/ENG-12/a-title",
+ expected: false,
+ },
+ {
+ link: "https://linear.app/other/issue/ENG-12",
+ issue: "https://linear.app/acme/issue/ENG-12/a-title",
+ expected: true,
+ },
+ { link: "https://linear.app/acme/issue/ENG-12", issue: "not a url", expected: true },
+ {
+ link: "https://github.com/acme/web/issues/7",
+ issue: "https://github.com/acme/web/issues/7",
+ expected: false,
+ },
+ ])("$link opening $issue is another workspace's: $expected", ({ link, issue, expected }) => {
+ expect(linksAnotherLinearWorkspace(link, issue)).toBe(expected);
+ });
+});
diff --git a/packages/client-runtime/src/issueLinks.ts b/packages/client-runtime/src/issueLinks.ts
index 44da23d9d85bf..e821e5cadb984 100644
--- a/packages/client-runtime/src/issueLinks.ts
+++ b/packages/client-runtime/src/issueLinks.ts
@@ -1,4 +1,8 @@
-import type { IssueRef } from "@t3tools/contracts";
+import type { IssueRef, IssueTrackerConnectionList } from "@t3tools/contracts";
+import {
+ LINEAR_TRACKER,
+ parseLinearIssueUrl,
+} from "@t3tools/issue-tracker-linear/shared/issue-url";
import { sourceControlClients } from "./sourceControlClients.ts";
import type { EnvironmentProject } from "./state/shell.ts";
@@ -59,11 +63,13 @@ export function resolveIssueLinkTarget(input: {
/** The projects of the environment the link is read in. */
readonly projects: ReadonlyArray;
readonly preferredProjectId?: string | undefined;
+ /** The environment's standalone tracker bindings; without them a Linear link stays plain. */
+ readonly trackerBindings?: IssueTrackerConnectionList["bindings"] | undefined;
}): { readonly project: Project; readonly ref: IssueRef } | null {
// A link names its server's port; a binding does only when its remote or web URL did.
const authority = linkAuthority(input.url);
const parsed = parseIssueLink(input.url, authority, input.projects);
- if (parsed === null) return null;
+ if (parsed === null) return resolveLinearIssueLink(input);
const { definition, link } = parsed;
const onHost = input.projects.flatMap((project) => {
const binding = projectIssueBinding(project);
@@ -94,3 +100,57 @@ export function resolveIssueLinkTarget(input: {
},
};
}
+
+/** A Linear link, read through the project bound to its team, else any project bound to Linear. */
+function resolveLinearIssueLink(input: {
+ readonly url: string;
+ readonly projects: ReadonlyArray;
+ readonly preferredProjectId?: string | undefined;
+ readonly trackerBindings?: IssueTrackerConnectionList["bindings"] | undefined;
+}): { readonly project: Project; readonly ref: IssueRef } | null {
+ const bindings = input.trackerBindings;
+ if (bindings === undefined || !URL.canParse(input.url)) return null;
+ const link = parseLinearIssueUrl(new URL(input.url));
+ if (link === null) return null;
+ const bound = input.projects.flatMap((project) => {
+ const binding = bindings[project.id];
+ return binding?.tracker === LINEAR_TRACKER ? [{ project, scope: binding.scope }] : [];
+ });
+ const preferFirst = (candidates: typeof bound) =>
+ candidates.find((candidate) => candidate.project.id === input.preferredProjectId) ??
+ candidates[0];
+ const own = preferFirst(
+ bound.filter((candidate) => candidate.scope.toLowerCase() === link.scope.toLowerCase()),
+ );
+ const lender = own ?? preferFirst(bound);
+ if (lender === undefined) return null;
+ return {
+ project: lender.project,
+ ref: {
+ projectId: lender.project.id,
+ tracker: LINEAR_TRACKER,
+ host: link.host,
+ scope: own === undefined ? link.scope : lender.scope,
+ key: link.key,
+ },
+ };
+}
+
+/** Whether a link names a Linear issue, so tracker bindings could open it. */
+export function isLinearIssueLink(url: string): boolean {
+ return URL.canParse(url) && parseLinearIssueUrl(new URL(url)) !== null;
+}
+
+/**
+ * Whether a Linear link names another workspace than the issue it opened. Team keys repeat across
+ * workspaces, so the connected one can hold an issue under the same key; only the issue's own
+ * URL says which workspace it is in, as in the server's `IssueService.resolveUrl`. Any link
+ * that is not a Linear issue link is never another workspace's.
+ */
+export function linksAnotherLinearWorkspace(linkUrl: string, issueUrl: string): boolean {
+ if (!URL.canParse(linkUrl)) return false;
+ const link = parseLinearIssueUrl(new URL(linkUrl));
+ if (link === null) return false;
+ const issue = URL.canParse(issueUrl) ? parseLinearIssueUrl(new URL(issueUrl)) : null;
+ return issue?.workspace !== link.workspace;
+}
diff --git a/packages/issue-tracker-linear/package.json b/packages/issue-tracker-linear/package.json
index b5d4d41b5222b..519fdc15dc74f 100644
--- a/packages/issue-tracker-linear/package.json
+++ b/packages/issue-tracker-linear/package.json
@@ -3,6 +3,10 @@
"private": true,
"type": "module",
"exports": {
+ "./shared/issue-url": {
+ "types": "./src/shared/issueUrl.ts",
+ "import": "./src/shared/issueUrl.ts"
+ },
"./server/driver": {
"types": "./src/server/driver.ts",
"import": "./src/server/driver.ts"
diff --git a/packages/issue-tracker-linear/src/server/LinearApi.ts b/packages/issue-tracker-linear/src/server/LinearApi.ts
index a89e0988b70c8..156430a668d00 100644
--- a/packages/issue-tracker-linear/src/server/LinearApi.ts
+++ b/packages/issue-tracker-linear/src/server/LinearApi.ts
@@ -18,10 +18,11 @@ import {
} from "effect/graphql";
import { HttpClient } from "effect/http";
import * as Headers from "effect/http/Headers";
-import { IssueTrackerKind } from "@t3tools/contracts";
import { IssueTrackerError } from "@t3tools/source-control-core/server/IssueTracker";
import * as IssueTrackerHost from "@t3tools/source-control-core/server/IssueTrackerHost";
+import { LINEAR_TRACKER } from "../shared/issueUrl.ts";
+
import type {
CommentCreateInput,
IssueCreateInput,
@@ -53,7 +54,7 @@ export type { LinearWorkflowState } from "./LinearApi.graphql.ts";
export type LinearAttachment = Attachment;
export type LinearHistoryEntry = IssueHistory;
-export const KIND = IssueTrackerKind.make("linear");
+export const KIND = LINEAR_TRACKER;
const DEFAULT_API_URL = "https://api.linear.app/graphql";
const LinearApiConfig = Config.all({
diff --git a/packages/issue-tracker-linear/src/server/LinearIssueTracker.ts b/packages/issue-tracker-linear/src/server/LinearIssueTracker.ts
index 885b016b23ebf..10cad7da67d12 100644
--- a/packages/issue-tracker-linear/src/server/LinearIssueTracker.ts
+++ b/packages/issue-tracker-linear/src/server/LinearIssueTracker.ts
@@ -26,12 +26,13 @@ import {
type TrackerIssueSummary,
} from "@t3tools/source-control-core/server/IssueTracker";
+import { LINEAR_HOST, parseLinearIssueUrl } from "../shared/issueUrl.ts";
import * as LinearApi from "./LinearApi.ts";
const DESCRIPTOR: StandaloneIssueTrackerDescriptor = {
tracker: LinearApi.KIND,
displayName: "Linear",
- host: "linear.app",
+ host: LINEAR_HOST,
scopeNoun: "team",
credential: {
label: "Personal API key",
@@ -415,13 +416,7 @@ export const make: Effect.Effect {
- if (url.protocol !== "https:" || url.host.toLowerCase() !== DESCRIPTOR.host) return null;
- const [, workspace, resource, key] = url.pathname.split("/");
- if (!workspace || resource !== "issue" || key === undefined) return null;
- const scope = /^([A-Z][A-Z0-9_]*)-[1-9][0-9]*$/.exec(key)?.[1];
- return scope === undefined ? null : { host: DESCRIPTOR.host, workspace, scope, key };
- },
+ parseIssueUrl: parseLinearIssueUrl,
probeCredential: (token) =>
linear.viewer(token).pipe(
diff --git a/packages/issue-tracker-linear/src/shared/issueUrl.ts b/packages/issue-tracker-linear/src/shared/issueUrl.ts
new file mode 100644
index 0000000000000..cf748e66e113f
--- /dev/null
+++ b/packages/issue-tracker-linear/src/shared/issueUrl.ts
@@ -0,0 +1,14 @@
+import { IssueTrackerKind } from "@t3tools/contracts";
+import type { IssueLink } from "@t3tools/source-control-core/shared/definition";
+
+export const LINEAR_TRACKER = IssueTrackerKind.make("linear");
+export const LINEAR_HOST = "linear.app";
+
+/** `https://linear.app//issue/-[/]`; the team key is the scope. */
+export function parseLinearIssueUrl(url: URL): (IssueLink & { readonly workspace: string }) | null {
+ if (url.protocol !== "https:" || url.host.toLowerCase() !== LINEAR_HOST) return null;
+ const [, workspace, resource, key] = url.pathname.split("/");
+ if (!workspace || resource !== "issue" || key === undefined) return null;
+ const scope = /^([A-Z][A-Z0-9_]*)-[1-9][0-9]*$/.exec(key)?.[1];
+ return scope === undefined ? null : { host: LINEAR_HOST, workspace, scope, key };
+}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index af0be20508e16..5e3028e7999d6 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -1525,6 +1525,9 @@ importers:
'@t3tools/contracts':
specifier: workspace:*
version: link:../contracts
+ '@t3tools/issue-tracker-linear':
+ specifier: workspace:*
+ version: link:../issue-tracker-linear
'@t3tools/provider-acp-registry':
specifier: workspace:*
version: link:../provider-acp-registry