Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

issueUrl.ts

13 lines676 Bytes

1import { IssueTrackerKind } from "@t3tools/contracts";
2​
3export const LINEAR_KIND = IssueTrackerKind.make("linear");
4export const LINEAR_HOST = "linear.app";
5​
6/** `https://linear.app/<workspace>/issue/<TEAM>-<n>[/<slug>]`, keeping the workspace. */
7export 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 };