OPE-296: Add linear integration for starting sessions from issues (#3235)
* feat(linear): start sessions from Linear issues Authorize a Linear workspace on this OpenChamber server, map teams to projects, attach an issue from chat, start a session or worktree from an issue, and post started/completed/failed comments that open the session. Hidden in VS Code. * feat(linear): connect more than one Linear workspace Store each OAuth grant on this OpenChamber server and keep one current, so Settings can add and switch workspaces without dropping the others. Project mapping is per workspace. Remove the Linear button next to New Chat; start-from-issue stays on New Worktree. * feat(linear): add a right-hand issues panel Browse and filter issues in the rail, open a card to change status or start a session, and collapse search plus most filters to icons on a narrow panel. * feat(linear): open issues in the rail and filter by Linear status The rail icon only shows after Linear is connected. Clicking a Linear row on work status opens the panel. Status options match the card, including Done, Canceled, and Duplicate. The Integrations experimental warning sits under Third-party integrations. * fix(linear): use stable OAuth callback broker * fix(chat): preview Linear issue attachments The context switch missed linear-issue, so tsc treated the preview helpers as incomplete. * fix(ui): restore Linear i18n parity and the #2903 sync harness Turkish was missing the Linear dictionaries, and the subagent test still wrapped only SyncContext after reads moved to SyncRuntimeContext. * fix(linear): drop changelog hunks and close review races Keep changelogs out of this PR, restore CodeMirror ranges, ignore stale Linear list pages, and leave a persisted Linear tab open until auth has actually resolved. * fix(linear): tint active issue filters and clear them in one click * fix(markdown): read escaped brackets as text, not display math `\[...\]` is display math in LaTeX and an escaped bracket pair in CommonMark. The block tokenizer claimed every `\[`, so prose like `[title \[Bug\] more](url)` was handed to KaTeX: "Bug" rendered as a centered formula and the block token split the paragraph, tearing the link into three pieces. Linear, GitHub and any other source that escapes brackets the way CommonMark requires hit this. Display math now has to own its line — `\[` starts one and `\]` ends one. A formula on its own line still renders; `\[` mid-sentence stays an escape, which is what CommonMark says it is and what prose almost always means. Inline `\(...\)` keeps the same ambiguity, but inline math is legitimately mid-sentence, so there is no position to judge it by. Covered by regression tests, including the verbatim comment body that surfaced this. * feat(linear): make session status comments opt-in and public-only A status comment lands in a Linear workspace the whole team reads, and the link it carried pointed at whatever origin started the session — usually loopback or a LAN address. Everyone but its author got a dead link, and nobody had agreed to the comments in the first place. Comments are now off until the user turns them on in Settings -> Integrations -> Linear, and the check lives on the server: the event hub posts completed and failure without going through the interface, so a client-side gate would not hold. When the resolved origin is not publicly reachable the server posts nothing at all rather than a link only its author can open; `isPublicSessionOrigin` rejects loopback, private LAN, carrier-grade NAT, link-local and single-label hosts. The desktop deep-link origin is gone with it, since no one else can follow one either. The comment body also dropped the session title. It repeated the issue the comment already sits on, and issue titles routinely carry brackets ("[Bug] ...") that broke the markdown link. The body is now one short link, and `sessionTitle` is gone from the route, client and types. Also caps the dedupe file at the newest 500 sessions; it grew forever. * fix(linear): match the pull request panel and clear review findings Comments in the Linear panel now render as the same avatar timeline the pull request panel uses, with the shared time-format preference instead of a raw locale string. Comment authors carry `avatarUrl`, which the GraphQL selection was not requesting. Review findings from the same pass: - `status-runtime.js` hand-rolled `typeof` narrowing and failed the vendored anti-slop lint; it now parses through `parse.js` like every other file in the module. - `useLinearAuthStore` turned any failed request into `connected: false` with `hasChecked: true`. Since the rail icon, the composer entry and the worktree option all gate on `connected === true`, one network blip hid Linear for the rest of the session, and Settings only re-checked when it had never checked. It now keeps the last known status and leaves `hasChecked` false so the next caller retries. - `LinearIssuesView` (1096 lines) was a static import in `ContextPanel`, shipping in the main bundle although its rail icon stays hidden until a workspace is connected. It is lazy now, like `GitView`. - Dropped dead code: the unused port helpers left over from the loopback callback, two re-exported default values nothing read, and a redundant export in `linkedIssues`. - Integrations is no longer badged beta.
This commit is contained in:
@@ -15,6 +15,7 @@ import { createWebNotificationsAPI } from './notifications';
|
||||
import { createWebToolsAPI } from './tools';
|
||||
import { createWebPushAPI } from './push';
|
||||
import { createWebGitHubAPI } from './github';
|
||||
import { createWebLinearAPI } from './linear';
|
||||
import { createWebClientAuthAPI } from './clientAuth';
|
||||
|
||||
export interface WebAPIsOptions {
|
||||
@@ -45,6 +46,7 @@ export const createWebAPIs = (options: WebAPIsOptions = {}): RuntimeAPIs => {
|
||||
permissions: createWebPermissionsAPI(),
|
||||
notifications: createWebNotificationsAPI(),
|
||||
github: createWebGitHubAPI({ urls: activeUrls }),
|
||||
linear: createWebLinearAPI(),
|
||||
push: createWebPushAPI(),
|
||||
clientAuth: createWebClientAuthAPI(),
|
||||
tools: createWebToolsAPI(),
|
||||
|
||||
@@ -0,0 +1,609 @@
|
||||
import type {
|
||||
LinearAPI,
|
||||
LinearAuthOrigin,
|
||||
LinearAuthStart,
|
||||
LinearAuthStatus,
|
||||
LinearIssue,
|
||||
LinearIssueAssignee,
|
||||
LinearIssueComment,
|
||||
LinearIssueLabel,
|
||||
LinearIssuePriority,
|
||||
LinearIssueGetResult,
|
||||
LinearIssueState,
|
||||
LinearIssueStatesResult,
|
||||
LinearIssueUpdateInput,
|
||||
LinearIssueUpdateResult,
|
||||
LinearIssueSummary,
|
||||
LinearIssueTeam,
|
||||
LinearIssuesListOptions,
|
||||
LinearIssuesListResult,
|
||||
LinearMappingResult,
|
||||
LinearMappingWrite,
|
||||
LinearOrganizationSummary,
|
||||
LinearPreferences,
|
||||
LinearSessionStatusPostInput,
|
||||
LinearSessionStatusPostResult,
|
||||
LinearTeamMapping,
|
||||
LinearWorkflowState,
|
||||
LinearUserSummary,
|
||||
LinearWorkspaceSummary,
|
||||
} from '@openchamber/ui/lib/api/types';
|
||||
import { runtimeFetch } from '@openchamber/ui/lib/runtime-fetch';
|
||||
|
||||
type LinearJson = {
|
||||
connected?: boolean;
|
||||
user?: LinearUserSummary | null;
|
||||
organization?: LinearOrganizationSummary | null;
|
||||
scope?: string;
|
||||
workspaces?: LinearWorkspaceSummary[];
|
||||
authorizationUrl?: string;
|
||||
expiresIn?: number;
|
||||
removed?: boolean;
|
||||
error?: string;
|
||||
issues?: LinearIssueSummary[];
|
||||
cursor?: string | null;
|
||||
hasMore?: boolean;
|
||||
issue?: LinearIssue | null;
|
||||
states?: LinearWorkflowState[];
|
||||
defaultProjectPath?: string | null;
|
||||
teams?: LinearTeamMapping[];
|
||||
posted?: boolean;
|
||||
skipped?: string;
|
||||
commentId?: string | null;
|
||||
sessionComments?: boolean;
|
||||
};
|
||||
|
||||
async function readLinearJson(response: Response): Promise<LinearJson | null> {
|
||||
try {
|
||||
return await response.json();
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function readErrorMessage(payload: LinearJson | null, fallback: string): string {
|
||||
const error = payload?.error?.trim();
|
||||
return error || fallback;
|
||||
}
|
||||
|
||||
function readFiniteNumber(value: number | null | undefined): number | null {
|
||||
return Number.isFinite(value) ? (value ?? null) : null;
|
||||
}
|
||||
|
||||
function readRawString(value: string | null | undefined): string | null {
|
||||
return Object.prototype.toString.call(value) === '[object String]' ? `${value}` : null;
|
||||
}
|
||||
|
||||
function parseUser(payload: LinearUserSummary | null | undefined): LinearUserSummary | null {
|
||||
const id = payload?.id?.trim();
|
||||
if (!id) return null;
|
||||
return {
|
||||
id,
|
||||
name: payload?.name?.trim() || null,
|
||||
displayName: payload?.displayName?.trim() || null,
|
||||
email: payload?.email?.trim() || null,
|
||||
avatarUrl: payload?.avatarUrl?.trim() || null,
|
||||
};
|
||||
}
|
||||
|
||||
function parseOrganization(payload: LinearOrganizationSummary | null | undefined): LinearOrganizationSummary | null {
|
||||
const id = payload?.id?.trim();
|
||||
const name = payload?.name?.trim();
|
||||
if (!id || !name) return null;
|
||||
return {
|
||||
id,
|
||||
name,
|
||||
urlKey: payload?.urlKey?.trim() || null,
|
||||
};
|
||||
}
|
||||
|
||||
function parseWorkspace(payload: LinearWorkspaceSummary | null | undefined): LinearWorkspaceSummary | null {
|
||||
const id = payload?.id?.trim();
|
||||
if (!id) return null;
|
||||
const authorizedAt = payload?.authorizedAt;
|
||||
return {
|
||||
id,
|
||||
name: payload?.name?.trim() || null,
|
||||
urlKey: payload?.urlKey?.trim() || null,
|
||||
current: payload?.current === true,
|
||||
user: parseUser(payload?.user),
|
||||
authorizedAt: readFiniteNumber(authorizedAt),
|
||||
};
|
||||
}
|
||||
|
||||
function toAuthStatus(payload: LinearJson | null): LinearAuthStatus | null {
|
||||
if (payload?.connected !== true && payload?.connected !== false) {
|
||||
return null;
|
||||
}
|
||||
const workspaces = Array.isArray(payload.workspaces)
|
||||
? payload.workspaces.map(parseWorkspace).filter((entry): entry is LinearWorkspaceSummary => entry != null)
|
||||
: [];
|
||||
return {
|
||||
connected: payload.connected,
|
||||
user: parseUser(payload.user),
|
||||
organization: parseOrganization(payload.organization),
|
||||
scope: payload.scope?.trim() || undefined,
|
||||
workspaces: payload.connected ? workspaces : undefined,
|
||||
};
|
||||
}
|
||||
|
||||
function toAuthStart(payload: LinearJson | null): LinearAuthStart | null {
|
||||
const authorizationUrl = payload?.authorizationUrl?.trim();
|
||||
const expiresIn = payload?.expiresIn;
|
||||
const scope = payload?.scope?.trim();
|
||||
if (!authorizationUrl || !Number.isFinite(expiresIn) || expiresIn == null || !scope) {
|
||||
return null;
|
||||
}
|
||||
return { authorizationUrl, expiresIn, scope };
|
||||
}
|
||||
|
||||
function parseState(payload: LinearIssueState | null | undefined): LinearIssueState | null {
|
||||
const id = payload?.id?.trim() || null;
|
||||
const name = payload?.name?.trim() || null;
|
||||
const type = payload?.type?.trim() || null;
|
||||
if (!id && !name && !type) return null;
|
||||
return { id, name, type };
|
||||
}
|
||||
|
||||
function parseWorkflowState(payload: LinearWorkflowState | null | undefined): LinearWorkflowState | null {
|
||||
const id = payload?.id?.trim();
|
||||
const name = payload?.name?.trim();
|
||||
if (!id || !name) return null;
|
||||
const position = payload?.position;
|
||||
return {
|
||||
id,
|
||||
name,
|
||||
type: payload?.type?.trim() || null,
|
||||
position: readFiniteNumber(position) ?? 0,
|
||||
};
|
||||
}
|
||||
|
||||
function parseAssignee(payload: LinearIssueAssignee | null | undefined): LinearIssueAssignee | null {
|
||||
const name = payload?.name?.trim() || null;
|
||||
const displayName = payload?.displayName?.trim() || null;
|
||||
const avatarUrl = payload?.avatarUrl?.trim() || null;
|
||||
if (!name && !displayName && !avatarUrl) return null;
|
||||
return { name, displayName, avatarUrl };
|
||||
}
|
||||
|
||||
function parseTeam(payload: LinearIssueTeam | null | undefined): LinearIssueTeam | null {
|
||||
const id = payload?.id?.trim();
|
||||
const key = payload?.key?.trim();
|
||||
const name = payload?.name?.trim();
|
||||
if (!id || !key || !name) return null;
|
||||
return { id, key, name };
|
||||
}
|
||||
|
||||
function parsePriority(value: LinearIssueSummary['priority']): LinearIssuePriority | null {
|
||||
if (value !== 0 && value !== 1 && value !== 2 && value !== 3 && value !== 4) {
|
||||
return null;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function parseLabelColor(value: string | null | undefined): string | null {
|
||||
const raw = value?.trim();
|
||||
if (!raw) return null;
|
||||
const hex = raw.startsWith('#') ? raw.slice(1) : raw;
|
||||
if (!/^[0-9A-Fa-f]{6}$/.test(hex)) return null;
|
||||
return `#${hex.toLowerCase()}`;
|
||||
}
|
||||
|
||||
function parseLabel(payload: LinearIssueLabel | null | undefined): LinearIssueLabel | null {
|
||||
if (!payload) return null;
|
||||
const id = payload?.id?.trim();
|
||||
const name = payload?.name?.trim();
|
||||
if (!id || !name) return null;
|
||||
return {
|
||||
id,
|
||||
name,
|
||||
color: parseLabelColor(payload.color),
|
||||
};
|
||||
}
|
||||
|
||||
function parseLabels(payload: LinearIssueSummary['labels']): LinearIssueLabel[] {
|
||||
if (!Array.isArray(payload)) return [];
|
||||
return payload.map(parseLabel).filter((label): label is LinearIssueLabel => label != null);
|
||||
}
|
||||
|
||||
function parseIssueSummary(payload: LinearIssueSummary | null | undefined): LinearIssueSummary | null {
|
||||
if (!payload) return null;
|
||||
const id = payload?.id?.trim();
|
||||
const identifier = payload?.identifier?.trim();
|
||||
const title = payload?.title?.trim();
|
||||
const url = payload?.url?.trim();
|
||||
if (!id || !identifier || !title || !url) return null;
|
||||
return {
|
||||
id,
|
||||
identifier,
|
||||
title,
|
||||
url,
|
||||
state: parseState(payload.state),
|
||||
assignee: parseAssignee(payload.assignee),
|
||||
team: parseTeam(payload.team),
|
||||
priority: parsePriority(payload.priority),
|
||||
labels: parseLabels(payload.labels),
|
||||
};
|
||||
}
|
||||
|
||||
function parseComment(payload: LinearIssueComment | null | undefined): LinearIssueComment | null {
|
||||
const id = payload?.id?.trim();
|
||||
if (!id) return null;
|
||||
const body = payload?.body;
|
||||
return {
|
||||
id,
|
||||
body: readRawString(body) ?? '',
|
||||
createdAt: payload?.createdAt?.trim() || null,
|
||||
user: payload?.user
|
||||
? {
|
||||
name: payload.user.name?.trim() || null,
|
||||
displayName: payload.user.displayName?.trim() || null,
|
||||
avatarUrl: payload.user.avatarUrl?.trim() || null,
|
||||
}
|
||||
: null,
|
||||
};
|
||||
}
|
||||
|
||||
function parseIssue(payload: LinearIssue | null | undefined): LinearIssue | null {
|
||||
const summary = parseIssueSummary(payload);
|
||||
if (!summary) return null;
|
||||
const comments = Array.isArray(payload?.comments)
|
||||
? payload.comments.map(parseComment).filter((comment): comment is LinearIssueComment => comment != null)
|
||||
: [];
|
||||
const description = payload?.description;
|
||||
return {
|
||||
...summary,
|
||||
description: readRawString(description),
|
||||
comments,
|
||||
};
|
||||
}
|
||||
|
||||
function toIssuesList(payload: LinearJson | null): LinearIssuesListResult | null {
|
||||
if (payload?.connected !== true && payload?.connected !== false) {
|
||||
return null;
|
||||
}
|
||||
if (payload.connected === false) {
|
||||
return { connected: false };
|
||||
}
|
||||
const issues = Array.isArray(payload.issues)
|
||||
? payload.issues.map(parseIssueSummary).filter((issue): issue is LinearIssueSummary => issue != null)
|
||||
: [];
|
||||
return {
|
||||
connected: true,
|
||||
issues,
|
||||
cursor: payload.cursor?.trim() || null,
|
||||
hasMore: payload.hasMore === true,
|
||||
};
|
||||
}
|
||||
|
||||
function toIssueGet(payload: LinearJson | null): LinearIssueGetResult | null {
|
||||
if (payload?.connected !== true && payload?.connected !== false) {
|
||||
return null;
|
||||
}
|
||||
if (payload.connected === false) {
|
||||
return { connected: false };
|
||||
}
|
||||
return {
|
||||
connected: true,
|
||||
issue: parseIssue(payload.issue),
|
||||
};
|
||||
}
|
||||
|
||||
function toIssueStates(payload: LinearJson | null): LinearIssueStatesResult | null {
|
||||
if (payload?.connected !== true && payload?.connected !== false) {
|
||||
return null;
|
||||
}
|
||||
if (payload.connected === false) {
|
||||
return { connected: false };
|
||||
}
|
||||
const states = Array.isArray(payload.states)
|
||||
? payload.states.map(parseWorkflowState).filter((state): state is LinearWorkflowState => state != null)
|
||||
: [];
|
||||
return { connected: true, states };
|
||||
}
|
||||
|
||||
function toIssueUpdate(payload: LinearJson | null): LinearIssueUpdateResult | null {
|
||||
if (payload?.connected !== true && payload?.connected !== false) {
|
||||
return null;
|
||||
}
|
||||
if (payload.connected === false) {
|
||||
return { connected: false };
|
||||
}
|
||||
return {
|
||||
connected: true,
|
||||
issue: parseIssue(payload.issue),
|
||||
};
|
||||
}
|
||||
|
||||
function parseTeamMapping(payload: LinearTeamMapping | null | undefined): LinearTeamMapping | null {
|
||||
const id = payload?.id?.trim();
|
||||
const key = payload?.key?.trim();
|
||||
const name = payload?.name?.trim();
|
||||
if (!id || !key || !name) return null;
|
||||
const projectPath = payload?.projectPath?.trim() || null;
|
||||
return { id, key, name, projectPath };
|
||||
}
|
||||
|
||||
function toMapping(payload: LinearJson | null): LinearMappingResult | null {
|
||||
if (payload?.connected !== true && payload?.connected !== false) {
|
||||
return null;
|
||||
}
|
||||
if (payload.connected === false) {
|
||||
return { connected: false };
|
||||
}
|
||||
const teams = Array.isArray(payload.teams)
|
||||
? payload.teams.map(parseTeamMapping).filter((team): team is LinearTeamMapping => team != null)
|
||||
: [];
|
||||
return {
|
||||
connected: true,
|
||||
defaultProjectPath: payload.defaultProjectPath?.trim() || null,
|
||||
teams,
|
||||
};
|
||||
}
|
||||
|
||||
type LinearSessionStatusSkipped = Extract<
|
||||
LinearSessionStatusPostResult,
|
||||
{ posted: false }
|
||||
>['skipped'];
|
||||
|
||||
const SESSION_STATUS_SKIPPED: readonly LinearSessionStatusSkipped[] = [
|
||||
'already-posted',
|
||||
'issue-not-found',
|
||||
'not-started',
|
||||
'disabled',
|
||||
'origin-not-public',
|
||||
];
|
||||
|
||||
function parseSkipped(value: string | undefined): LinearSessionStatusSkipped | null {
|
||||
return SESSION_STATUS_SKIPPED.find((entry) => entry === value) ?? null;
|
||||
}
|
||||
|
||||
function toPreferences(payload: LinearJson | null): LinearPreferences | null {
|
||||
if (payload?.sessionComments !== true && payload?.sessionComments !== false) {
|
||||
return null;
|
||||
}
|
||||
return { sessionComments: payload.sessionComments };
|
||||
}
|
||||
|
||||
function toSessionStatusPost(payload: LinearJson | null): LinearSessionStatusPostResult | null {
|
||||
if (payload?.connected !== true && payload?.connected !== false) {
|
||||
return null;
|
||||
}
|
||||
if (payload.connected === false) {
|
||||
return { connected: false };
|
||||
}
|
||||
if (payload.posted === true) {
|
||||
return {
|
||||
connected: true,
|
||||
posted: true,
|
||||
commentId: payload.commentId?.trim() || null,
|
||||
};
|
||||
}
|
||||
const skipped = parseSkipped(payload.skipped);
|
||||
if (payload.posted === false && skipped) {
|
||||
return { connected: true, posted: false, skipped };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export const createWebLinearAPI = (): LinearAPI => ({
|
||||
async authStatus(): Promise<LinearAuthStatus> {
|
||||
const response = await runtimeFetch('/api/linear/auth/status', {
|
||||
method: 'GET',
|
||||
headers: { Accept: 'application/json' },
|
||||
});
|
||||
const payload = await readLinearJson(response);
|
||||
const status = toAuthStatus(payload);
|
||||
if (!response.ok || !status) {
|
||||
throw new Error(readErrorMessage(payload, response.statusText || 'Failed to load Linear status'));
|
||||
}
|
||||
return status;
|
||||
},
|
||||
|
||||
async authStart(origin?: LinearAuthOrigin): Promise<LinearAuthStart> {
|
||||
const response = await runtimeFetch('/api/linear/auth/start', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Accept: 'application/json',
|
||||
},
|
||||
body: JSON.stringify(origin ? { origin } : {}),
|
||||
});
|
||||
const payload = await readLinearJson(response);
|
||||
const started = toAuthStart(payload);
|
||||
if (!response.ok || !started) {
|
||||
throw new Error(readErrorMessage(payload, response.statusText || 'Failed to start Linear auth'));
|
||||
}
|
||||
return started;
|
||||
},
|
||||
|
||||
async authDisconnect(): Promise<{ removed: boolean }> {
|
||||
const response = await runtimeFetch('/api/linear/auth', {
|
||||
method: 'DELETE',
|
||||
headers: { Accept: 'application/json' },
|
||||
});
|
||||
const payload = await readLinearJson(response);
|
||||
if (!response.ok) {
|
||||
throw new Error(readErrorMessage(payload, response.statusText || 'Failed to disconnect Linear'));
|
||||
}
|
||||
return { removed: payload?.removed === true };
|
||||
},
|
||||
|
||||
async authActivate(organizationId: string): Promise<LinearAuthStatus> {
|
||||
const response = await runtimeFetch('/api/linear/auth/activate', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Accept: 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ organizationId }),
|
||||
});
|
||||
const payload = await readLinearJson(response);
|
||||
const status = toAuthStatus(payload);
|
||||
if (!response.ok || !status) {
|
||||
throw new Error(readErrorMessage(payload, response.statusText || 'Failed to switch Linear workspace'));
|
||||
}
|
||||
return status;
|
||||
},
|
||||
|
||||
async issuesList(options?: LinearIssuesListOptions): Promise<LinearIssuesListResult> {
|
||||
const params = new URLSearchParams();
|
||||
const query = options?.query?.trim();
|
||||
const cursor = options?.cursor?.trim();
|
||||
const status = options?.status?.trim();
|
||||
const assignee = options?.assignee?.trim();
|
||||
const teamId = options?.teamId?.trim();
|
||||
const priority = options?.priority?.trim();
|
||||
if (query) params.set('query', query);
|
||||
if (cursor) params.set('cursor', cursor);
|
||||
if (status) params.set('status', status);
|
||||
if (assignee) params.set('assignee', assignee);
|
||||
if (teamId) params.set('teamId', teamId);
|
||||
if (priority) params.set('priority', priority);
|
||||
const queryString = params.toString();
|
||||
const suffix = queryString ? `?${queryString}` : '';
|
||||
const response = await runtimeFetch(`/api/linear/issues/list${suffix}`, {
|
||||
method: 'GET',
|
||||
headers: { Accept: 'application/json' },
|
||||
});
|
||||
const payload = await readLinearJson(response);
|
||||
const result = toIssuesList(payload);
|
||||
if (!response.ok || !result) {
|
||||
throw new Error(readErrorMessage(payload, response.statusText || 'Failed to load Linear issues'));
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
async issueGet(id: string): Promise<LinearIssueGetResult> {
|
||||
const params = new URLSearchParams({ id });
|
||||
const response = await runtimeFetch(`/api/linear/issues/get?${params.toString()}`, {
|
||||
method: 'GET',
|
||||
headers: { Accept: 'application/json' },
|
||||
});
|
||||
const payload = await readLinearJson(response);
|
||||
const result = toIssueGet(payload);
|
||||
if (!response.ok || !result) {
|
||||
throw new Error(readErrorMessage(payload, response.statusText || 'Failed to load Linear issue'));
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
async issueStates(teamId: string): Promise<LinearIssueStatesResult> {
|
||||
const params = new URLSearchParams({ teamId });
|
||||
const response = await runtimeFetch(`/api/linear/issues/states?${params.toString()}`, {
|
||||
method: 'GET',
|
||||
headers: { Accept: 'application/json' },
|
||||
});
|
||||
const payload = await readLinearJson(response);
|
||||
const result = toIssueStates(payload);
|
||||
if (!response.ok || !result) {
|
||||
throw new Error(readErrorMessage(payload, response.statusText || 'Failed to load Linear workflow states'));
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
async issueUpdate(input: LinearIssueUpdateInput): Promise<LinearIssueUpdateResult> {
|
||||
const response = await runtimeFetch('/api/linear/issues/update', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Accept: 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
id: input.id,
|
||||
stateId: input.stateId,
|
||||
}),
|
||||
});
|
||||
const payload = await readLinearJson(response);
|
||||
const result = toIssueUpdate(payload);
|
||||
if (!response.ok || !result) {
|
||||
throw new Error(readErrorMessage(payload, response.statusText || 'Failed to update Linear issue'));
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
async mappingGet(): Promise<LinearMappingResult> {
|
||||
const response = await runtimeFetch('/api/linear/mapping', {
|
||||
method: 'GET',
|
||||
headers: { Accept: 'application/json' },
|
||||
});
|
||||
const payload = await readLinearJson(response);
|
||||
const result = toMapping(payload);
|
||||
if (!response.ok || !result) {
|
||||
throw new Error(readErrorMessage(payload, response.statusText || 'Failed to load Linear mapping'));
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
async mappingSet(mapping: LinearMappingWrite): Promise<LinearMappingResult> {
|
||||
const response = await runtimeFetch('/api/linear/mapping', {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Accept: 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
defaultProjectPath: mapping.defaultProjectPath,
|
||||
teamProjectPaths: mapping.teamProjectPaths,
|
||||
}),
|
||||
});
|
||||
const payload = await readLinearJson(response);
|
||||
const result = toMapping(payload);
|
||||
if (!response.ok || !result) {
|
||||
throw new Error(readErrorMessage(payload, response.statusText || 'Failed to save Linear mapping'));
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
async sessionStatusPost(input: LinearSessionStatusPostInput): Promise<LinearSessionStatusPostResult> {
|
||||
const response = await runtimeFetch('/api/linear/session-status', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Accept: 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
kind: input.kind,
|
||||
sessionId: input.sessionId,
|
||||
issueIdentifier: input.issueIdentifier,
|
||||
sessionOrigin: input.sessionOrigin,
|
||||
}),
|
||||
});
|
||||
const payload = await readLinearJson(response);
|
||||
const result = toSessionStatusPost(payload);
|
||||
if (!response.ok || !result) {
|
||||
throw new Error(readErrorMessage(payload, response.statusText || 'Failed to post Linear session status'));
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
async preferencesGet(): Promise<LinearPreferences> {
|
||||
const response = await runtimeFetch('/api/linear/preferences', {
|
||||
method: 'GET',
|
||||
headers: { Accept: 'application/json' },
|
||||
});
|
||||
const payload = await readLinearJson(response);
|
||||
const result = toPreferences(payload);
|
||||
if (!response.ok || !result) {
|
||||
throw new Error(readErrorMessage(payload, response.statusText || 'Failed to load Linear preferences'));
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
async preferencesSet(preferences: LinearPreferences): Promise<LinearPreferences> {
|
||||
const response = await runtimeFetch('/api/linear/preferences', {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Accept: 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ sessionComments: preferences.sessionComments }),
|
||||
});
|
||||
const payload = await readLinearJson(response);
|
||||
const result = toPreferences(payload);
|
||||
if (!response.ok || !result) {
|
||||
throw new Error(readErrorMessage(payload, response.statusText || 'Failed to save Linear preferences'));
|
||||
}
|
||||
return result;
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user