The best way to control Claude Code, Codex and more from any computer or phone
fix(client): Linear issue links in messages open in the issue panel (#38854)
Julius Marminge committed
Nov 18, 2026 at 19:26 UTC
966bdc74f3ca3d96ed44a5feae6297cb58a01f89
17 files changed
+241
-27
apps/mobile/src/native/useOpenPullRequest.ts
+16
-2
@@ -1,5 +1,5 @@
1
import { useNavigation, useRoute, StackActions } from "@react-navigation/native";
2
-import { resolveIssueLinkTarget } from "@t3tools/client-runtime/issue-links";
2
+import { isStandaloneIssueLink, resolveIssueLinkTarget } from "@t3tools/client-runtime/issue-links";
3
import {
4
nativePullRequestDestination,
5
pullRequestCandidateForIssueLink,
@@ -10,6 +10,7 @@ import { useProjects, useThreadShell } from "../state/entities";
10
import { tryOpenExternalUrl } from "../lib/openExternalUrl";
11
import { appAtomRegistry } from "../state/atom-registry";
12
import { environmentServerConfigsAtom } from "../state/server";
13
+import { issueTrackerEnvironment } from "../state/issueTrackers";
14
import { composerPullRequests } from "../state/pull-requests";
15
import { useAtomQueryRunner } from "../state/use-atom-query-runner";
16
import { withKnownPullRequestSummary } from "../state/use-thread-pr";
@@ -28,6 +29,10 @@ export function useNavigateToPullRequest(options?: { readonly replace?: boolean
29
reportFailure: false,
30
reportDefect: false,
31
});
32
+ const readTrackerConnections = useAtomQueryRunner(issueTrackerEnvironment.connections, {
33
+ reportFailure: false,
34
+ reportDefect: false,
35
+ });
36
return async (url: string, context: PullRequestContext | null) => {
37
// Read at press time so a config push does not hand every link a new handler.
38
const serverConfigs = appAtomRegistry.get(environmentServerConfigsAtom);
@@ -37,12 +42,21 @@ export function useNavigateToPullRequest(options?: { readonly replace?: boolean
42
if (!destination) {
43
// An issue link from the same text opens the issue; anything else leaves for the browser.
44
const environmentId = context && EnvironmentId.make(context.environmentId);
45
+ const issuesEnabled =
46
+ environmentId !== null &&
47
+ serverConfigs.get(environmentId)?.environment.capabilities.issues === true;
48
+ // Only a standalone tracker's link needs the bindings, whose read probes the tracker.
49
+ const connections =
50
+ issuesEnabled && isStandaloneIssueLink(url)
51
+ ? await readTrackerConnections({ environmentId, input: {} })
52
+ : null;
53
const issue =
41
- environmentId && serverConfigs.get(environmentId)?.environment.capabilities.issues === true
54
+ issuesEnabled && context !== null
55
? resolveIssueLinkTarget({
56
url,
57
projects: projects.filter((project) => project.environmentId === environmentId),
58
preferredProjectId: context.projectId,
59
+ trackers: connections?._tag === "Success" ? connections.value : undefined,
60
})
61
: null;
62
if (!issue || !environmentId) return tryOpenExternalUrl(url, "pull-request");
apps/server/src/issue/IssueTrackerConnections.ts
+2
@@ -87,6 +87,7 @@ const make = Effect.gen(function* () {
87
connected: true,
88
account: probe.account,
89
detail: null,
90
+ ...(probe.workspace === undefined ? {} : { workspace: probe.workspace }),
91
scopes: probe.scopes,
92
})),
93
Effect.catch((error) =>
@@ -156,6 +157,7 @@ const make = Effect.gen(function* () {
157
connected: true,
158
account: probe.account,
159
detail: null,
160
+ ...(probe.workspace === undefined ? {} : { workspace: probe.workspace }),
161
scopes: probe.scopes,
162
};
163
});
apps/web/src/components/ChatMarkdown.tsx
+18
-2
@@ -164,6 +164,8 @@ import { cn } from "../lib/utils";
164
import { resolveRemoteOpenState, useRemoteOpenResolution } from "../remoteOpen";
165
import { useRightPanelStore } from "../rightPanelStore";
166
import { useOpenIssueLink } from "../lib/openIssueLink";
167
+import { issueTrackerEnvironment } from "../state/issueTrackers";
168
+import { useEnvironmentQuery } from "../state/query";
169
import { readThreadShell, useProjects } from "../state/entities";
170
import { serverEnvironment } from "../state/server";
171
import { shellEnvironment } from "../state/shell";
@@ -188,7 +190,10 @@ import {
190
workspaceLinkLookupQuery,
191
} from "@t3tools/client-runtime/workspace-basename-lookup";
192
import { resolvePullRequestPreviewTarget } from "@t3tools/client-runtime/change-request-links";
191
-import { resolveIssueLinkTarget } from "@t3tools/client-runtime/issue-links";
193
+import {
194
+ mayContainStandaloneIssueLink,
195
+ resolveIssueLinkTarget,
196
+} from "@t3tools/client-runtime/issue-links";
197
import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
198
import { useOpenChangeRequestLink } from "~/lib/openPullRequestLink";
199
import { textDirection } from "~/textDirection";
@@ -678,6 +683,13 @@ function useChatMarkdownState({
683
: revealInFileExplorerLabelForOs(revealInFileManager, messages);
684
const projects = useProjects();
685
const issueProjects = projects.filter((project) => project.environmentId === environmentId);
686
+ // Only text naming a standalone tracker asks for its bindings, whose read probes the tracker.
687
+ const issueTrackers =
688
+ useEnvironmentQuery(
689
+ issuesEnabled && environmentId !== null && mayContainStandaloneIssueLink(text)
690
+ ? issueTrackerEnvironment.connections({ environmentId, input: {} })
691
+ : null,
692
+ ).data ?? undefined;
693
const [preferredEditor] = usePreferredEditor(availableEditors);
694
const preferredEditorMenuLabel = openInEditorMenuLabel(preferredEditor, messages);
695
const openInPreferredEditor = useOpenInPreferredEditor(environmentId, availableEditors, cwd);
@@ -1027,6 +1039,7 @@ function useChatMarkdownState({
1039
openMarkdownMedia,
1040
projects,
1041
issueProjects,
1042
+ issueTrackers,
1043
linkedThreadPullRequestFor,
1044
resolveThreadPullRequest,
1045
resolvedTheme,
@@ -1198,6 +1211,7 @@ const CHAT_MARKDOWN_COMPONENTS = {
1211
openExternalLinkInPreview,
1212
projects,
1213
issueProjects,
1214
+ issueTrackers,
1215
linkedThreadPullRequestFor,
1216
resolveThreadPullRequest,
1217
pullRequestsEnabled,
@@ -1271,6 +1285,7 @@ const CHAT_MARKDOWN_COMPONENTS = {
1285
? resolveIssueLinkTarget({
1286
url: href,
1287
projects: issueProjects,
1288
+ trackers: issueTrackers,
1289
})
1290
: null;
1291
const issuePreviewTarget =
@@ -1322,7 +1337,7 @@ const CHAT_MARKDOWN_COMPONENTS = {
1337
if (
1338
!href ||
1339
openChangeRequestLink(event, href, undefined, environmentId ?? undefined) ||
1325
- openIssueLink(event, href, environmentId ?? undefined)
1340
+ openIssueLink(event, href, environmentId ?? undefined, issueTrackers)
1341
) {
1342
return;
1343
}
@@ -1463,6 +1478,7 @@ const CHAT_MARKDOWN_COMPONENTS = {
1478
},
1479
url,
1480
environmentId ?? undefined,
1481
+ issueTrackers,
1482
);
1483
if (!opened) await openDeferredMarkdownLink(url);
1484
}}
apps/web/src/lib/openIssueLink.ts
+8
-2
@@ -1,4 +1,8 @@
1
-import type { EnvironmentId, ScopedThreadRef } from "@t3tools/contracts";
1
+import type {
2
+ EnvironmentId,
3
+ IssueTrackerConnectionList,
4
+ ScopedThreadRef,
5
+} from "@t3tools/contracts";
6
import { resolveIssueLinkTarget } from "@t3tools/client-runtime/issue-links";
7
import { useNavigate } from "@tanstack/react-router";
8
import type { MouseEvent } from "react";
@@ -23,11 +27,12 @@ export function useOpenIssueLink(
27
>,
28
targetUrl: string,
29
targetEnvironmentId?: EnvironmentId,
30
+ trackers?: IssueTrackerConnectionList,
31
) => boolean {
32
const allProjects = useProjects();
33
const serverConfigs = useServerConfigs();
34
const navigate = useNavigate();
30
- return (event, targetUrl, targetEnvironmentId) => {
35
+ return (event, targetUrl, targetEnvironmentId, trackers) => {
36
if (event.metaKey || event.ctrlKey) return false;
37
const resolvedPanelRef = panelRef ?? threadRef;
38
// A list page's panel ref is a placeholder, not an environment; the link names its own.
@@ -37,6 +42,7 @@ export function useOpenIssueLink(
42
const target = resolveIssueLinkTarget({
43
url: targetUrl,
44
projects: allProjects.filter((project) => project.environmentId === environmentId),
45
+ trackers,
46
});
47
if (target === null) return false;
48
event.preventDefault();
packages/client-runtime/package.json
+1
@@ -635,6 +635,7 @@
635
"dependencies": {
636
"@pierre/diffs": "catalog:",
637
"@t3tools/contracts": "workspace:*",
638
+ "@t3tools/issue-tracker-linear": "workspace:*",
639
"@t3tools/provider-acp-registry": "workspace:*",
640
"@t3tools/provider-core": "workspace:*",
641
"@t3tools/provider-cursor": "workspace:*",
packages/client-runtime/src/issueLinks.test.ts
+48
-1
@@ -1,4 +1,9 @@
1
-import { EnvironmentId, ProjectId, SourceControlProviderKind } from "@t3tools/contracts";
1
+import {
2
+ EnvironmentId,
3
+ IssueTrackerKind,
4
+ ProjectId,
5
+ SourceControlProviderKind,
6
+} from "@t3tools/contracts";
7
import { describe, expect, it } from "vite-plus/test";
8
9
import { resolveIssueLinkTarget } from "./issueLinks.ts";
@@ -65,6 +70,48 @@ describe("resolveIssueLinkTarget", () => {
70
expect(custom?.ref).toMatchObject({ projectId: "custom", host: "code.acme.test", key: "7" });
71
});
72
73
+ it("reads a Linear link through the project bound to its team, else any bound to Linear", () => {
74
+ const trackers = {
75
+ trackers: [
76
+ {
77
+ tracker: IssueTrackerKind.make("linear"),
78
+ displayName: "Linear",
79
+ host: "linear.app",
80
+ scopeNoun: "team",
81
+ credential: { label: "Personal API key", helpUrl: null },
82
+ connected: true,
83
+ account: "julius",
84
+ detail: null,
85
+ workspace: "acme",
86
+ scopes: [],
87
+ },
88
+ ],
89
+ bindings: {
90
+ [ProjectId.make("p1")]: { tracker: IssueTrackerKind.make("linear"), scope: "API" },
91
+ [ProjectId.make("p2")]: { tracker: IssueTrackerKind.make("linear"), scope: "WEB" },
92
+ },
93
+ };
94
+ const resolve = (url: string) => resolveIssueLinkTarget({ url, projects, trackers });
95
+ expect(resolve("https://linear.app/acme/issue/WEB-17/fix-it")?.ref).toEqual({
96
+ projectId: "p2",
97
+ tracker: "linear",
98
+ host: "linear.app",
99
+ scope: "WEB",
100
+ key: "WEB-17",
101
+ });
102
+ expect(resolve("https://linear.app/acme/issue/OPS-3")?.ref).toMatchObject({
103
+ projectId: "p1",
104
+ scope: "OPS",
105
+ key: "OPS-3",
106
+ });
107
+ expect(resolve("https://linear.app.evil.example/acme/issue/WEB-17")).toBeNull();
108
+ // Team keys repeat across workspaces; only the connected one's links are its issues.
109
+ expect(resolve("https://linear.app/othercorp/issue/WEB-17")).toBeNull();
110
+ expect(
111
+ resolveIssueLinkTarget({ url: "https://linear.app/acme/issue/WEB-17", projects }),
112
+ ).toBeNull();
113
+ });
114
+
115
it.each([
116
"https://github.com.evil.example/acme/web/issues/7",
117
"https://github.com/acme/web/pull/7",
packages/client-runtime/src/issueLinks.ts
+77
-2
@@ -1,4 +1,9 @@
1
-import type { IssueRef } from "@t3tools/contracts";
1
+import type { IssueRef, IssueTrackerConnectionList } from "@t3tools/contracts";
2
+import {
3
+ LINEAR_HOST,
4
+ LINEAR_KIND,
5
+ parseLinearIssueUrl,
6
+} from "@t3tools/issue-tracker-linear/shared/issueUrl";
7
8
import { sourceControlClients } from "./sourceControlClients.ts";
9
import type { EnvironmentProject } from "./state/shell.ts";
@@ -48,6 +53,68 @@ function parseIssueLink(
53
return null;
54
}
55
56
+function parseStandaloneIssueLink(url: string) {
57
+ try {
58
+ const link = parseLinearIssueUrl(new URL(url));
59
+ return link === null ? null : { tracker: LINEAR_KIND, link };
60
+ } catch {
61
+ return null;
62
+ }
63
+}
64
+
65
+/** Whether `url` is a standalone tracker's issue link, which only bindings can resolve. */
66
+export function isStandaloneIssueLink(url: string): boolean {
67
+ return parseStandaloneIssueLink(url) !== null;
68
+}
69
+
70
+/** A cheap pre-check, so text without such a link never asks for the bindings. */
71
+export function mayContainStandaloneIssueLink(text: string): boolean {
72
+ return text.includes(`${LINEAR_HOST}/`);
73
+}
74
+
75
+/**
76
+ * A standalone tracker link resolves through the project bound to its scope, else any bound to
77
+ * the tracker, and only when it names the workspace the credential reaches: team keys repeat
78
+ * across workspaces, so a link elsewhere stays an ordinary link.
79
+ */
80
+function resolveStandaloneIssueLink<Project extends LinkProject>(
81
+ url: string,
82
+ projects: ReadonlyArray<Project>,
83
+ trackers: IssueTrackerConnectionList | undefined,
84
+ preferredProjectId: string | undefined,
85
+): { readonly project: Project; readonly ref: IssueRef } | null {
86
+ const parsed = trackers === undefined ? null : parseStandaloneIssueLink(url);
87
+ if (parsed === null || trackers === undefined) return null;
88
+ const { tracker, link } = parsed;
89
+ const workspace = trackers.trackers.find(
90
+ (connection) => connection.tracker === tracker && connection.account !== null,
91
+ )?.workspace;
92
+ if (workspace?.toLowerCase() !== link.workspace.toLowerCase()) return null;
93
+ const { bindings } = trackers;
94
+ const onTracker = projects.flatMap((project) => {
95
+ const binding = bindings[project.id];
96
+ return binding?.tracker === tracker ? [{ project, binding }] : [];
97
+ });
98
+ const preferFirst = (candidates: typeof onTracker) =>
99
+ candidates.find((candidate) => candidate.project.id === preferredProjectId) ?? candidates[0];
100
+ const scope = link.scope.toLowerCase();
101
+ const own = preferFirst(
102
+ onTracker.filter((candidate) => candidate.binding.scope.toLowerCase() === scope),
103
+ );
104
+ const lender = own ?? preferFirst(onTracker);
105
+ if (lender === undefined) return null;
106
+ return {
107
+ project: lender.project,
108
+ ref: {
109
+ projectId: lender.project.id,
110
+ tracker: lender.binding.tracker,
111
+ host: link.host,
112
+ scope: own === undefined ? link.scope : lender.binding.scope,
113
+ key: link.key,
114
+ },
115
+ };
116
+}
117
+
118
/**
119
* The reference an issue link resolves to, and the project it is read through: the project whose
120
* tracker binding is that host and scope, else any project on the same tracker and host lending
@@ -59,11 +126,19 @@ export function resolveIssueLinkTarget<Project extends LinkProject>(input: {
126
/** The projects of the environment the link is read in. */
127
readonly projects: ReadonlyArray<Project>;
128
readonly preferredProjectId?: string | undefined;
129
+ /** The environment's standalone trackers and bindings; without them only git-host links resolve. */
130
+ readonly trackers?: IssueTrackerConnectionList | undefined;
131
}): { readonly project: Project; readonly ref: IssueRef } | null {
132
// A link names its server's port; a binding does only when its remote or web URL did.
133
const authority = linkAuthority(input.url);
134
const parsed = parseIssueLink(input.url, authority, input.projects);
66
- if (parsed === null) return null;
135
+ if (parsed === null)
136
+ return resolveStandaloneIssueLink(
137
+ input.url,
138
+ input.projects,
139
+ input.trackers,
140
+ input.preferredProjectId,
141
+ );
142
const { definition, link } = parsed;
143
const onHost = input.projects.flatMap((project) => {
144
const binding = projectIssueBinding(project);
packages/contracts/src/issue.ts
+2
@@ -590,6 +590,8 @@ export const IssueTrackerConnection = Schema.Struct({
590
account: Schema.NullOr(TrimmedNonEmptyString),
591
/** Why a stored credential did not work, when it did not. */
592
detail: Schema.NullOr(TrimmedNonEmptyString),
593
+ /** The workspace the credential reaches, as its issue URLs name it; links elsewhere are foreign. */
594
+ workspace: Schema.optional(TrimmedNonEmptyString),
595
scopes: Schema.Array(IssueTrackerScope),
596
});
597
export type IssueTrackerConnection = typeof IssueTrackerConnection.Type;
packages/issue-tracker-linear/package.json
+4
@@ -3,6 +3,10 @@
3
"private": true,
4
"type": "module",
5
"exports": {
6
+ "./shared/issueUrl": {
7
+ "types": "./src/shared/issueUrl.ts",
8
+ "import": "./src/shared/issueUrl.ts"
9
+ },
10
"./server/driver": {
11
"types": "./src/server/driver.ts",
12
"import": "./src/server/driver.ts"
packages/issue-tracker-linear/src/server/LinearApi.graphql
+3
@@ -96,6 +96,9 @@ query T3Viewer {
96
viewer {
97
...LinearUser
98
}
99
+ organization {
100
+ urlKey
101
+ }
102
teams(first: 250) {
103
nodes {
104
id
packages/issue-tracker-linear/src/server/LinearApi.graphql.ts
+10
@@ -184,6 +184,13 @@ export const LinearPageInfo = Schema.Struct({
184
})
185
export interface LinearPageInfo extends Schema.Struct.Type<typeof LinearPageInfo.fields> {}
186
187
+/** A workspace (referred to as Organization in the API). Workspaces are the root-level container for all teams, users, projects, issues, and settings. Every user belongs to at least one workspace, and all data is scoped within a workspace boundary. */
188
+export const Organization = Schema.Struct({
189
+ /** The workspace's unique URL key, used in URLs to identify the workspace. */
190
+ urlKey: Schema.String
191
+})
192
+export interface Organization extends Schema.Struct.Type<typeof Organization.fields> {}
193
+
194
/** A team is the primary organizational unit in Linear. Issues belong to teams, and each team has its own workflow states, cycles, labels, and settings. Teams can be public (visible to all workspace members), private (visible only to team members), or restricted (visible only within an enclosing private-team boundary). Teams can also have sub-teams that inherit settings from their parent. */
195
export const T3ViewerTeamsNodesTeam = Schema.Struct({
196
/** The unique identifier of the entity. */
@@ -206,6 +213,7 @@ export const T3Viewer = GraphQL.query("T3Viewer", {
213
variables: [],
214
selections: [
215
{ name: "viewer", body: ["{...LinearUser}"] },
216
+ { name: "organization", body: ["{urlKey}"] },
217
{ name: "teams", body: ["(first:250){nodes{id key name}}"] }
218
],
219
fragments: [
@@ -215,6 +223,8 @@ export const T3Viewer = GraphQL.query("T3Viewer", {
223
result: Schema.Struct({
224
/** The currently authenticated user making the API request. */
225
viewer: LinearUser,
226
+ /** The authenticated user's workspace. */
227
+ organization: Organization,
228
/** All teams whose issues the user can access. This includes public teams and private teams the user is a member of. This may differ from `administrableTeams`, which returns teams whose settings the user can change but whose issues they don't necessarily have access to. */
229
teams: T3ViewerTeamsTeamConnection
230
})
packages/issue-tracker-linear/src/server/LinearApi.ts
+9
-3
@@ -18,7 +18,7 @@ import {
18
} from "effect/graphql";
19
import { HttpClient } from "effect/http";
20
import * as Headers from "effect/http/Headers";
21
-import { IssueTrackerKind } from "@t3tools/contracts";
21
+import { LINEAR_KIND } from "../shared/issueUrl.ts";
22
import { IssueTrackerError } from "@t3tools/source-control-core/server/IssueTracker";
23
import * as IssueTrackerHost from "@t3tools/source-control-core/server/IssueTrackerHost";
24
@@ -53,7 +53,7 @@ export type { LinearWorkflowState } from "./LinearApi.graphql.ts";
53
export type LinearAttachment = Attachment;
54
export type LinearHistoryEntry = IssueHistory;
55
56
-export const KIND = IssueTrackerKind.make("linear");
56
+export const KIND = LINEAR_KIND;
57
const DEFAULT_API_URL = "https://api.linear.app/graphql";
58
59
const LinearApiConfig = Config.all({
@@ -97,6 +97,8 @@ export class LinearApi extends Context.Service<
97
readonly viewer: (token?: string) => Effect.Effect<
98
{
99
readonly viewer: LinearUser;
100
+ /** The workspace's URL key, the first path segment of its issue links. */
101
+ readonly workspace: string;
102
readonly teams: ReadonlyArray<{
103
readonly id: string;
104
readonly key: string;
@@ -295,7 +297,11 @@ export const make = Effect.gen(function* () {
297
298
const viewer: LinearApi["Service"]["viewer"] = (token) =>
299
call("viewer", (linear) => linear.T3Viewer(), token).pipe(
298
- Effect.map((data) => ({ viewer: data.viewer, teams: data.teams.nodes })),
300
+ Effect.map((data) => ({
301
+ viewer: data.viewer,
302
+ workspace: data.organization.urlKey,
303
+ teams: data.teams.nodes,
304
+ })),
305
);
306
307
const listIssues: LinearApi["Service"]["listIssues"] = (input) =>
packages/issue-tracker-linear/src/server/LinearIssueTracker.test.ts
+16
-3
@@ -164,7 +164,11 @@ describe("LinearIssueTracker", () => {
164
it.effect("lists a team's issues as summaries keyed by identifier", () =>
165
Effect.gen(function* () {
166
const { tracker, requests } = fakeLinear({
167
- T3Viewer: () => ({ viewer: JULIUS, teams: { nodes: [] } }),
167
+ T3Viewer: () => ({
168
+ viewer: JULIUS,
169
+ organization: { urlKey: "acme" },
170
+ teams: { nodes: [] },
171
+ }),
172
T3Issues: (variables) => {
173
expect(variables.filter).toMatchObject({
174
team: { key: { eq: "ENG" } },
@@ -251,7 +255,11 @@ describe("LinearIssueTracker", () => {
255
const created: Array<unknown> = [];
256
const deleted: Array<unknown> = [];
257
const { tracker } = fakeLinear({
254
- T3Viewer: () => ({ viewer: JULIUS, teams: { nodes: [] } }),
258
+ T3Viewer: () => ({
259
+ viewer: JULIUS,
260
+ organization: { urlKey: "acme" },
261
+ teams: { nodes: [] },
262
+ }),
263
T3Issue: (variables) => {
264
// Linear refuses a page of zero comments, which fails the write that looked the issue up.
265
expect(variables.comments).toBeGreaterThan(0);
@@ -292,7 +300,11 @@ describe("LinearIssueTracker", () => {
300
it.effect("reads an issue with its comments, reactions, history and linked pull requests", () =>
301
Effect.gen(function* () {
302
const { tracker } = fakeLinear({
295
- T3Viewer: () => ({ viewer: JULIUS, teams: { nodes: [] } }),
303
+ T3Viewer: () => ({
304
+ viewer: JULIUS,
305
+ organization: { urlKey: "acme" },
306
+ teams: { nodes: [] },
307
+ }),
308
T3Issue: () => ({
309
issue: issue("ENG-7", {
310
comments: {
@@ -350,6 +362,7 @@ describe("LinearIssueTracker", () => {
362
const api = yield* tracker;
363
const detail = yield* api.getIssue({ ...target, key: "eng-7" });
364
expect(detail.viewer).toBe("julius");
365
+ expect((yield* api.probeCredential("token")).workspace).toBe("acme");
366
// The team's own workflow, in Linear's order, with the category each state falls in.
367
expect(detail.states.map((entry) => [entry.name, entry.category])).toEqual([
368
["Todo", "open"],
packages/issue-tracker-linear/src/server/LinearIssueTracker.ts
+4
-8
@@ -26,12 +26,13 @@ import {
26
type TrackerIssueSummary,
27
} from "@t3tools/source-control-core/server/IssueTracker";
28
29
+import { LINEAR_HOST, parseLinearIssueUrl } from "../shared/issueUrl.ts";
30
import * as LinearApi from "./LinearApi.ts";
31
32
const DESCRIPTOR: StandaloneIssueTrackerDescriptor = {
33
tracker: LinearApi.KIND,
34
displayName: "Linear",
34
- host: "linear.app",
35
+ host: LINEAR_HOST,
36
scopeNoun: "team",
37
credential: {
38
label: "Personal API key",
@@ -415,18 +416,13 @@ export const make: Effect.Effect<StandaloneIssueTrackerApi, never, LinearApi.Lin
416
kind: LinearApi.KIND,
417
capabilities: CAPABILITIES,
418
standalone: DESCRIPTOR,
418
- parseIssueUrl: (url) => {
419
- if (url.protocol !== "https:" || url.host.toLowerCase() !== DESCRIPTOR.host) return null;
420
- const [, workspace, resource, key] = url.pathname.split("/");
421
- if (!workspace || resource !== "issue" || key === undefined) return null;
422
- const scope = /^([A-Z][A-Z0-9_]*)-[1-9][0-9]*$/.exec(key)?.[1];
423
- return scope === undefined ? null : { host: DESCRIPTOR.host, workspace, scope, key };
424
- },
419
+ parseIssueUrl: parseLinearIssueUrl,
420
421
probeCredential: (token) =>
422
linear.viewer(token).pipe(
423
Effect.map((data) => ({
424
account: userName(data.viewer),
425
+ workspace: data.workspace,
426
scopes: data.teams.map((team) => ({ key: team.key, name: team.name })),
427
})),
428
),
packages/issue-tracker-linear/src/shared/issueUrl.ts
new
+13
@@ -0,0 +1,13 @@
1
+import { IssueTrackerKind } from "@t3tools/contracts";
2
+
3
+export const LINEAR_KIND = IssueTrackerKind.make("linear");
4
+export const LINEAR_HOST = "linear.app";
5
+
6
+/** `https://linear.app/<workspace>/issue/<TEAM>-<n>[/<slug>]`, keeping the workspace. */
7
+export function parseLinearIssueUrl(url: URL) {
8
+ if (url.protocol !== "https:" || url.host.toLowerCase() !== LINEAR_HOST) return null;
9
+ const [, workspace, resource, key] = url.pathname.split("/");
10
+ if (!workspace || resource !== "issue" || key === undefined) return null;
11
+ const scope = /^([A-Z][A-Z0-9_]*)-[1-9][0-9]*$/.exec(key)?.[1];
12
+ return scope === undefined ? null : { host: LINEAR_HOST, workspace, scope, key };
13
+}
packages/source-control-core/src/server/IssueTracker.ts
+7
-4
@@ -210,10 +210,13 @@ export interface StandaloneIssueTrackerApi extends IssueTrackerApi {
210
* Who a credential signs in as and which scopes it reaches, asked of the tracker itself. Run on
211
* a credential before it is stored, and on the stored one to report connection status.
212
*/
213
- readonly probeCredential: (
214
- token: string,
215
- ) => Effect.Effect<
216
- { readonly account: string; readonly scopes: ReadonlyArray<IssueTrackerScope> },
213
+ readonly probeCredential: (token: string) => Effect.Effect<
214
+ {
215
+ readonly account: string;
216
+ /** What the tracker's issue URLs name the credential's workspace by, where they name one. */
217
+ readonly workspace?: string | undefined;
218
+ readonly scopes: ReadonlyArray<IssueTrackerScope>;
219
+ },
220
IssueTrackerError
221
>;
222
}
pnpm-lock.yaml
+3
@@ -1525,6 +1525,9 @@ importers:
1525
'@t3tools/contracts':
1526
specifier: workspace:*
1527
version: link:../contracts
1528
+ '@t3tools/issue-tracker-linear':
1529
+ specifier: workspace:*
1530
+ version: link:../issue-tracker-linear
1531
'@t3tools/provider-acp-registry':
1532
specifier: workspace:*
1533
version: link:../provider-acp-registry