feat(issues): make issues page writable with inline editing (#1017)
This commit is contained in:
@@ -13,7 +13,15 @@ import { sortWorkItemsByUpdatedAt } from '../../shared/work-items'
|
||||
import { getPRConflictSummary } from './conflict-summary'
|
||||
import { execFileAsync, ghExecFileAsync, acquire, release, getOwnerRepo } from './gh-utils'
|
||||
export { _resetOwnerRepoCache } from './gh-utils'
|
||||
export { getIssue, listIssues, createIssue } from './issues'
|
||||
export {
|
||||
getIssue,
|
||||
listIssues,
|
||||
createIssue,
|
||||
updateIssue,
|
||||
addIssueComment,
|
||||
listLabels,
|
||||
listAssignableUsers
|
||||
} from './issues'
|
||||
import {
|
||||
mapCheckRunRESTStatus,
|
||||
mapCheckRunRESTConclusion,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { execFile } from 'child_process'
|
||||
import { promisify } from 'util'
|
||||
import { gitExecFileAsync, ghExecFileAsync } from '../git/runner'
|
||||
import type { ClassifiedError } from '../../shared/types'
|
||||
|
||||
// Why: legacy generic execFile wrapper — only used by callers that don't need
|
||||
// WSL-aware routing (e.g. non-repo-scoped gh commands). Repo-scoped callers
|
||||
@@ -34,6 +35,35 @@ export function release(): void {
|
||||
}
|
||||
}
|
||||
|
||||
// ── Error classification ─────────────────────────────────────────────
|
||||
// Why: gh CLI surfaces API errors as unstructured stderr. This helper maps
|
||||
// known patterns to typed errors so callers can show user-friendly messages.
|
||||
export function classifyGhError(stderr: string): ClassifiedError {
|
||||
const s = stderr.toLowerCase()
|
||||
if (s.includes('http 403') || s.includes('resource not accessible')) {
|
||||
return {
|
||||
type: 'permission_denied',
|
||||
message: "You don't have permission to edit this issue. Check your GitHub token scopes."
|
||||
}
|
||||
}
|
||||
if (s.includes('http 404') || s.includes('could not resolve')) {
|
||||
return { type: 'not_found', message: 'Issue not found — it may have been deleted.' }
|
||||
}
|
||||
if (s.includes('http 422') || s.includes('validation failed')) {
|
||||
return { type: 'validation_error', message: `Invalid update — ${stderr.trim()}` }
|
||||
}
|
||||
if (s.includes('rate limit')) {
|
||||
return {
|
||||
type: 'rate_limited',
|
||||
message: 'GitHub rate limit hit. Try again in a few minutes.'
|
||||
}
|
||||
}
|
||||
if (s.includes('timeout') || s.includes('no such host') || s.includes('network')) {
|
||||
return { type: 'network_error', message: 'Network error — check your connection.' }
|
||||
}
|
||||
return { type: 'unknown', message: `Failed to update issue: ${stderr.trim()}` }
|
||||
}
|
||||
|
||||
// ── Owner/repo resolution for gh api --cache ──────────────────────────
|
||||
const ownerRepoCache = new Map<string, { owner: string; repo: string } | null>()
|
||||
|
||||
|
||||
+171
-4
@@ -1,6 +1,6 @@
|
||||
import type { IssueInfo } from '../../shared/types'
|
||||
import type { IssueInfo, GitHubIssueUpdate } from '../../shared/types'
|
||||
import { mapIssueInfo } from './mappers'
|
||||
import { ghExecFileAsync, acquire, release, getOwnerRepo } from './gh-utils'
|
||||
import { ghExecFileAsync, acquire, release, getOwnerRepo, classifyGhError } from './gh-utils'
|
||||
|
||||
/**
|
||||
* Get a single issue by number.
|
||||
@@ -98,9 +98,9 @@ export async function createIssue(
|
||||
'-X',
|
||||
'POST',
|
||||
`repos/${ownerRepo.owner}/${ownerRepo.repo}/issues`,
|
||||
'-f',
|
||||
'--raw-field',
|
||||
`title=${trimmedTitle}`,
|
||||
'-f',
|
||||
'--raw-field',
|
||||
`body=${body}`
|
||||
],
|
||||
{ cwd: repoPath }
|
||||
@@ -121,3 +121,170 @@ export async function createIssue(
|
||||
release()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing GitHub issue. Fans out to separate gh commands for
|
||||
* state changes vs field edits since `gh issue edit` does not support state.
|
||||
*/
|
||||
export async function updateIssue(
|
||||
repoPath: string,
|
||||
issueNumber: number,
|
||||
updates: GitHubIssueUpdate
|
||||
): Promise<{ ok: true } | { ok: false; error: string }> {
|
||||
const ownerRepo = await getOwnerRepo(repoPath)
|
||||
if (!ownerRepo) {
|
||||
return { ok: false, error: 'Could not resolve GitHub owner/repo for this repository' }
|
||||
}
|
||||
|
||||
const repo = `${ownerRepo.owner}/${ownerRepo.repo}`
|
||||
const errors: string[] = []
|
||||
|
||||
// State change requires a separate command
|
||||
if (updates.state) {
|
||||
await acquire()
|
||||
try {
|
||||
const cmd = updates.state === 'closed' ? 'close' : 'reopen'
|
||||
await ghExecFileAsync(['issue', cmd, String(issueNumber), '--repo', repo], {
|
||||
cwd: repoPath
|
||||
})
|
||||
} catch (err) {
|
||||
const stderr = err instanceof Error ? err.message : String(err)
|
||||
// Treat "already closed/open" as a no-op
|
||||
if (!stderr.toLowerCase().includes('already')) {
|
||||
errors.push(classifyGhError(stderr).message)
|
||||
}
|
||||
} finally {
|
||||
release()
|
||||
}
|
||||
}
|
||||
|
||||
// Field edits (labels, assignees, title) via gh issue edit
|
||||
const editArgs: string[] = ['issue', 'edit', String(issueNumber), '--repo', repo]
|
||||
let hasEditArgs = false
|
||||
|
||||
if (updates.title) {
|
||||
editArgs.push('--title', updates.title)
|
||||
hasEditArgs = true
|
||||
}
|
||||
for (const label of updates.addLabels ?? []) {
|
||||
editArgs.push('--add-label', label)
|
||||
hasEditArgs = true
|
||||
}
|
||||
for (const label of updates.removeLabels ?? []) {
|
||||
editArgs.push('--remove-label', label)
|
||||
hasEditArgs = true
|
||||
}
|
||||
for (const assignee of updates.addAssignees ?? []) {
|
||||
editArgs.push('--add-assignee', assignee)
|
||||
hasEditArgs = true
|
||||
}
|
||||
for (const assignee of updates.removeAssignees ?? []) {
|
||||
editArgs.push('--remove-assignee', assignee)
|
||||
hasEditArgs = true
|
||||
}
|
||||
|
||||
if (hasEditArgs) {
|
||||
await acquire()
|
||||
try {
|
||||
await ghExecFileAsync(editArgs, { cwd: repoPath })
|
||||
} catch (err) {
|
||||
const stderr = err instanceof Error ? err.message : String(err)
|
||||
errors.push(classifyGhError(stderr).message)
|
||||
} finally {
|
||||
release()
|
||||
}
|
||||
}
|
||||
|
||||
if (errors.length > 0) {
|
||||
return { ok: false, error: errors.join('; ') }
|
||||
}
|
||||
return { ok: true }
|
||||
}
|
||||
|
||||
export async function addIssueComment(
|
||||
repoPath: string,
|
||||
issueNumber: number,
|
||||
body: string
|
||||
): Promise<{ ok: true; id: number } | { ok: false; error: string }> {
|
||||
const ownerRepo = await getOwnerRepo(repoPath)
|
||||
if (!ownerRepo) {
|
||||
return { ok: false, error: 'Could not resolve GitHub owner/repo for this repository' }
|
||||
}
|
||||
await acquire()
|
||||
try {
|
||||
const { stdout } = await ghExecFileAsync(
|
||||
[
|
||||
'api',
|
||||
'-X',
|
||||
'POST',
|
||||
`repos/${ownerRepo.owner}/${ownerRepo.repo}/issues/${issueNumber}/comments`,
|
||||
'--raw-field',
|
||||
`body=${body}`
|
||||
],
|
||||
{ cwd: repoPath }
|
||||
)
|
||||
const data = JSON.parse(stdout) as { id?: number }
|
||||
return { ok: true, id: data.id ?? 0 }
|
||||
} catch (err) {
|
||||
const stderr = err instanceof Error ? err.message : String(err)
|
||||
return { ok: false, error: classifyGhError(stderr).message }
|
||||
} finally {
|
||||
release()
|
||||
}
|
||||
}
|
||||
|
||||
export async function listLabels(repoPath: string): Promise<string[]> {
|
||||
const ownerRepo = await getOwnerRepo(repoPath)
|
||||
if (!ownerRepo) {
|
||||
return []
|
||||
}
|
||||
await acquire()
|
||||
try {
|
||||
const { stdout } = await ghExecFileAsync(
|
||||
[
|
||||
'api',
|
||||
'--paginate',
|
||||
`repos/${ownerRepo.owner}/${ownerRepo.repo}/labels`,
|
||||
'--jq',
|
||||
'.[].name'
|
||||
],
|
||||
{ cwd: repoPath }
|
||||
)
|
||||
return stdout
|
||||
.trim()
|
||||
.split('\n')
|
||||
.filter((l) => l.length > 0)
|
||||
} catch {
|
||||
return []
|
||||
} finally {
|
||||
release()
|
||||
}
|
||||
}
|
||||
|
||||
export async function listAssignableUsers(repoPath: string): Promise<string[]> {
|
||||
const ownerRepo = await getOwnerRepo(repoPath)
|
||||
if (!ownerRepo) {
|
||||
return []
|
||||
}
|
||||
await acquire()
|
||||
try {
|
||||
const { stdout } = await ghExecFileAsync(
|
||||
[
|
||||
'api',
|
||||
'--paginate',
|
||||
`repos/${ownerRepo.owner}/${ownerRepo.repo}/assignees`,
|
||||
'--jq',
|
||||
'.[].login'
|
||||
],
|
||||
{ cwd: repoPath }
|
||||
)
|
||||
return stdout
|
||||
.trim()
|
||||
.split('\n')
|
||||
.filter((l) => l.length > 0)
|
||||
} catch {
|
||||
return []
|
||||
} finally {
|
||||
release()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ async function getPRFiles(repoPath: string, prNumber: number): Promise<GitHubPRF
|
||||
async function getIssueBodyAndComments(
|
||||
repoPath: string,
|
||||
issueNumber: number
|
||||
): Promise<{ body: string; comments: PRComment[] }> {
|
||||
): Promise<{ body: string; comments: PRComment[]; assignees: string[] }> {
|
||||
const ownerRepo = await getOwnerRepo(repoPath)
|
||||
try {
|
||||
if (ownerRepo) {
|
||||
@@ -152,7 +152,10 @@ async function getIssueBodyAndComments(
|
||||
{ cwd: repoPath }
|
||||
)
|
||||
])
|
||||
const issue = JSON.parse(issueResult.stdout) as { body?: string | null }
|
||||
const issue = JSON.parse(issueResult.stdout) as {
|
||||
body?: string | null
|
||||
assignees?: { login: string }[]
|
||||
}
|
||||
type RESTComment = {
|
||||
id: number
|
||||
user: { login: string; avatar_url: string } | null
|
||||
@@ -170,11 +173,12 @@ async function getIssueBodyAndComments(
|
||||
url: c.html_url
|
||||
})
|
||||
)
|
||||
return { body: issue.body ?? '', comments }
|
||||
const assignees = (issue.assignees ?? []).map((a) => a.login)
|
||||
return { body: issue.body ?? '', comments, assignees }
|
||||
}
|
||||
// Fallback: non-GitHub remote
|
||||
const { stdout } = await ghExecFileAsync(
|
||||
['issue', 'view', String(issueNumber), '--json', 'body,comments'],
|
||||
['issue', 'view', String(issueNumber), '--json', 'body,comments,assignees'],
|
||||
{ cwd: repoPath }
|
||||
)
|
||||
const data = JSON.parse(stdout) as {
|
||||
@@ -185,6 +189,7 @@ async function getIssueBodyAndComments(
|
||||
createdAt: string
|
||||
url: string
|
||||
}[]
|
||||
assignees?: { login: string }[]
|
||||
}
|
||||
const comments = (data.comments ?? []).map(
|
||||
(c, i): PRComment => ({
|
||||
@@ -196,9 +201,10 @@ async function getIssueBodyAndComments(
|
||||
url: c.url ?? ''
|
||||
})
|
||||
)
|
||||
return { body: data.body ?? '', comments }
|
||||
const fallbackAssignees = (data.assignees ?? []).map((a) => a.login)
|
||||
return { body: data.body ?? '', comments, assignees: fallbackAssignees }
|
||||
} catch {
|
||||
return { body: '', comments: [] }
|
||||
return { body: '', comments: [], assignees: [] }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -238,8 +244,8 @@ export async function getWorkItemDetails(
|
||||
await acquire()
|
||||
try {
|
||||
if (item.type === 'issue') {
|
||||
const { body, comments } = await getIssueBodyAndComments(repoPath, item.number)
|
||||
return { item, body, comments }
|
||||
const { body, comments, assignees } = await getIssueBodyAndComments(repoPath, item.number)
|
||||
return { item, body, comments, assignees }
|
||||
}
|
||||
|
||||
// PR: fetch body + comments + checks + files + head/base SHAs in parallel.
|
||||
|
||||
+43
-1
@@ -1,6 +1,6 @@
|
||||
import { ipcMain } from 'electron'
|
||||
import { resolve } from 'path'
|
||||
import type { Repo } from '../../shared/types'
|
||||
import type { Repo, GitHubIssueUpdate } from '../../shared/types'
|
||||
import type { Store } from '../persistence'
|
||||
import type { StatsCollector } from '../stats/collector'
|
||||
import {
|
||||
@@ -11,6 +11,10 @@ import {
|
||||
listWorkItems,
|
||||
getWorkItem,
|
||||
createIssue,
|
||||
updateIssue,
|
||||
addIssueComment,
|
||||
listLabels,
|
||||
listAssignableUsers,
|
||||
getAuthenticatedViewer,
|
||||
getPRChecks,
|
||||
getPRComments,
|
||||
@@ -173,6 +177,44 @@ export function registerGitHubHandlers(store: Store, stats: StatsCollector): voi
|
||||
}
|
||||
)
|
||||
|
||||
ipcMain.handle(
|
||||
'gh:updateIssue',
|
||||
(_event, args: { repoPath: string; number: number; updates: GitHubIssueUpdate }) => {
|
||||
const repo = assertRegisteredRepo(args.repoPath, store)
|
||||
if (typeof args.number !== 'number' || !Number.isInteger(args.number) || args.number < 1) {
|
||||
return { ok: false, error: 'Invalid issue number' }
|
||||
}
|
||||
if (!args.updates || typeof args.updates !== 'object') {
|
||||
return { ok: false, error: 'Updates object is required' }
|
||||
}
|
||||
return updateIssue(repo.path, args.number, args.updates)
|
||||
}
|
||||
)
|
||||
|
||||
ipcMain.handle(
|
||||
'gh:addIssueComment',
|
||||
(_event, args: { repoPath: string; number: number; body: string }) => {
|
||||
const repo = assertRegisteredRepo(args.repoPath, store)
|
||||
if (typeof args.number !== 'number' || !Number.isInteger(args.number) || args.number < 1) {
|
||||
return { ok: false, error: 'Invalid issue number' }
|
||||
}
|
||||
if (!args.body?.trim()) {
|
||||
return { ok: false, error: 'Comment body required' }
|
||||
}
|
||||
return addIssueComment(repo.path, args.number, args.body.trim())
|
||||
}
|
||||
)
|
||||
|
||||
ipcMain.handle('gh:listLabels', (_event, args: { repoPath: string }) => {
|
||||
const repo = assertRegisteredRepo(args.repoPath, store)
|
||||
return listLabels(repo.path)
|
||||
})
|
||||
|
||||
ipcMain.handle('gh:listAssignableUsers', (_event, args: { repoPath: string }) => {
|
||||
const repo = assertRegisteredRepo(args.repoPath, store)
|
||||
return listAssignableUsers(repo.path)
|
||||
})
|
||||
|
||||
// Star operations target the Orca repo itself — no repoPath validation needed
|
||||
ipcMain.handle('gh:viewer', () => getAuthenticatedViewer())
|
||||
ipcMain.handle('gh:checkOrcaStarred', () => checkOrcaStarred())
|
||||
|
||||
+85
-1
@@ -1,8 +1,19 @@
|
||||
import { ipcMain } from 'electron'
|
||||
import { connect, disconnect, getStatus } from '../linear/client'
|
||||
import { _resetPreflightCache } from './preflight'
|
||||
import { getIssue, searchIssues, listIssues } from '../linear/issues'
|
||||
import {
|
||||
getIssue,
|
||||
searchIssues,
|
||||
listIssues,
|
||||
updateIssue,
|
||||
addIssueComment,
|
||||
getIssueComments,
|
||||
getTeamStates,
|
||||
getTeamLabels,
|
||||
getTeamMembers
|
||||
} from '../linear/issues'
|
||||
import type { LinearListFilter } from '../linear/issues'
|
||||
import type { LinearIssueUpdate } from '../../shared/types'
|
||||
|
||||
const VALID_FILTERS = new Set<LinearListFilter>(['assigned', 'created', 'all', 'completed'])
|
||||
|
||||
@@ -52,4 +63,77 @@ export function registerLinearHandlers(): void {
|
||||
}
|
||||
return getIssue(args.id.trim())
|
||||
})
|
||||
|
||||
ipcMain.handle(
|
||||
'linear:updateIssue',
|
||||
async (_event, args: { id: string; updates: LinearIssueUpdate }) => {
|
||||
if (typeof args?.id !== 'string' || !args.id.trim()) {
|
||||
return { ok: false, error: 'Issue ID is required' }
|
||||
}
|
||||
// Why: IPC args are untyped at runtime — validate the updates object and
|
||||
// individual fields to prevent the Linear SDK from receiving unexpected
|
||||
// primitives that would produce confusing API errors.
|
||||
if (!args.updates || typeof args.updates !== 'object') {
|
||||
return { ok: false, error: 'Updates object is required' }
|
||||
}
|
||||
const u = args.updates
|
||||
if (u.stateId !== undefined && (typeof u.stateId !== 'string' || !u.stateId.trim())) {
|
||||
return { ok: false, error: 'Invalid state ID' }
|
||||
}
|
||||
if (
|
||||
u.priority !== undefined &&
|
||||
(!Number.isInteger(u.priority) || u.priority < 0 || u.priority > 4)
|
||||
) {
|
||||
return { ok: false, error: 'Priority must be an integer 0-4' }
|
||||
}
|
||||
if (
|
||||
u.labelIds !== undefined &&
|
||||
(!Array.isArray(u.labelIds) || !u.labelIds.every((id: unknown) => typeof id === 'string'))
|
||||
) {
|
||||
return { ok: false, error: 'Label IDs must be an array of strings' }
|
||||
}
|
||||
return updateIssue(args.id.trim(), args.updates)
|
||||
}
|
||||
)
|
||||
|
||||
ipcMain.handle(
|
||||
'linear:addIssueComment',
|
||||
async (_event, args: { issueId: string; body: string }) => {
|
||||
if (typeof args?.issueId !== 'string' || !args.issueId.trim()) {
|
||||
return { ok: false, error: 'Issue ID is required' }
|
||||
}
|
||||
if (!args.body?.trim()) {
|
||||
return { ok: false, error: 'Comment body is required' }
|
||||
}
|
||||
return addIssueComment(args.issueId.trim(), args.body.trim())
|
||||
}
|
||||
)
|
||||
|
||||
ipcMain.handle('linear:issueComments', async (_event, args: { issueId: string }) => {
|
||||
if (typeof args?.issueId !== 'string' || !args.issueId.trim()) {
|
||||
return []
|
||||
}
|
||||
return getIssueComments(args.issueId.trim())
|
||||
})
|
||||
|
||||
ipcMain.handle('linear:teamStates', async (_event, args: { teamId: string }) => {
|
||||
if (typeof args?.teamId !== 'string' || !args.teamId.trim()) {
|
||||
return []
|
||||
}
|
||||
return getTeamStates(args.teamId.trim())
|
||||
})
|
||||
|
||||
ipcMain.handle('linear:teamLabels', async (_event, args: { teamId: string }) => {
|
||||
if (typeof args?.teamId !== 'string' || !args.teamId.trim()) {
|
||||
return []
|
||||
}
|
||||
return getTeamLabels(args.teamId.trim())
|
||||
})
|
||||
|
||||
ipcMain.handle('linear:teamMembers', async (_event, args: { teamId: string }) => {
|
||||
if (typeof args?.teamId !== 'string' || !args.teamId.trim()) {
|
||||
return []
|
||||
}
|
||||
return getTeamMembers(args.teamId.trim())
|
||||
})
|
||||
}
|
||||
|
||||
+204
-1
@@ -1,4 +1,11 @@
|
||||
import type { LinearIssue } from '../../shared/types'
|
||||
import type {
|
||||
LinearIssue,
|
||||
LinearIssueUpdate,
|
||||
LinearComment,
|
||||
LinearWorkflowState,
|
||||
LinearLabel,
|
||||
LinearMember
|
||||
} from '../../shared/types'
|
||||
import { acquire, release, getClient, isAuthError, clearToken } from './client'
|
||||
import { mapLinearIssue } from './mappers'
|
||||
|
||||
@@ -112,3 +119,199 @@ export async function listIssues(
|
||||
release()
|
||||
}
|
||||
}
|
||||
|
||||
export async function updateIssue(
|
||||
id: string,
|
||||
updates: LinearIssueUpdate
|
||||
): Promise<{ ok: true } | { ok: false; error: string }> {
|
||||
const client = getClient()
|
||||
if (!client) {
|
||||
return { ok: false, error: 'Not connected to Linear' }
|
||||
}
|
||||
|
||||
await acquire()
|
||||
try {
|
||||
// Why: labelIds is a full-replace field — a TOCTOU race exists if another
|
||||
// user changes labels between fetch and write. The caller passes the
|
||||
// complete set built from recently-fetched data. Acceptable for v1;
|
||||
// a future version could re-fetch right before writing or use webhooks.
|
||||
const resolvedLabelIds = updates.labelIds
|
||||
|
||||
const payload: Record<string, unknown> = {}
|
||||
if (updates.stateId !== undefined) {
|
||||
payload.stateId = updates.stateId
|
||||
}
|
||||
if (updates.title !== undefined) {
|
||||
payload.title = updates.title
|
||||
}
|
||||
if (updates.assigneeId !== undefined) {
|
||||
payload.assigneeId = updates.assigneeId
|
||||
}
|
||||
if (updates.priority !== undefined) {
|
||||
payload.priority = updates.priority
|
||||
}
|
||||
if (resolvedLabelIds !== undefined) {
|
||||
payload.labelIds = resolvedLabelIds
|
||||
}
|
||||
|
||||
const result = await client.updateIssue(id, payload)
|
||||
if (!result.success) {
|
||||
return { ok: false, error: 'Linear update failed' }
|
||||
}
|
||||
return { ok: true }
|
||||
} catch (error) {
|
||||
if (isAuthError(error)) {
|
||||
clearToken()
|
||||
throw error
|
||||
}
|
||||
const message = error instanceof Error ? error.message : String(error)
|
||||
return { ok: false, error: message }
|
||||
} finally {
|
||||
release()
|
||||
}
|
||||
}
|
||||
|
||||
export async function addIssueComment(
|
||||
issueId: string,
|
||||
body: string
|
||||
): Promise<{ ok: true; id: string } | { ok: false; error: string }> {
|
||||
const client = getClient()
|
||||
if (!client) {
|
||||
return { ok: false, error: 'Not connected to Linear' }
|
||||
}
|
||||
|
||||
await acquire()
|
||||
try {
|
||||
const result = await client.createComment({ issueId, body })
|
||||
if (!result.success) {
|
||||
return { ok: false, error: 'Failed to create comment' }
|
||||
}
|
||||
const comment = await result.comment
|
||||
return { ok: true, id: comment?.id ?? '' }
|
||||
} catch (error) {
|
||||
if (isAuthError(error)) {
|
||||
clearToken()
|
||||
throw error
|
||||
}
|
||||
const message = error instanceof Error ? error.message : String(error)
|
||||
return { ok: false, error: message }
|
||||
} finally {
|
||||
release()
|
||||
}
|
||||
}
|
||||
|
||||
export async function getIssueComments(issueId: string): Promise<LinearComment[]> {
|
||||
const client = getClient()
|
||||
if (!client) {
|
||||
return []
|
||||
}
|
||||
|
||||
await acquire()
|
||||
try {
|
||||
const issue = await client.issue(issueId)
|
||||
const comments = await issue.comments()
|
||||
const results: LinearComment[] = []
|
||||
for (const c of comments.nodes) {
|
||||
const user = await c.user
|
||||
results.push({
|
||||
id: c.id,
|
||||
body: c.body,
|
||||
createdAt: c.createdAt.toISOString(),
|
||||
user: user
|
||||
? { displayName: user.displayName, avatarUrl: user.avatarUrl ?? undefined }
|
||||
: undefined
|
||||
})
|
||||
}
|
||||
return results
|
||||
} catch (error) {
|
||||
if (isAuthError(error)) {
|
||||
clearToken()
|
||||
throw error
|
||||
}
|
||||
console.warn('[linear] getIssueComments failed:', error)
|
||||
return []
|
||||
} finally {
|
||||
release()
|
||||
}
|
||||
}
|
||||
|
||||
export async function getTeamStates(teamId: string): Promise<LinearWorkflowState[]> {
|
||||
const client = getClient()
|
||||
if (!client) {
|
||||
return []
|
||||
}
|
||||
|
||||
await acquire()
|
||||
try {
|
||||
const team = await client.team(teamId)
|
||||
const states = await team.states()
|
||||
return states.nodes
|
||||
.map((s) => ({
|
||||
id: s.id,
|
||||
name: s.name,
|
||||
type: s.type,
|
||||
color: s.color,
|
||||
position: s.position
|
||||
}))
|
||||
.sort((a, b) => a.position - b.position)
|
||||
} catch (error) {
|
||||
if (isAuthError(error)) {
|
||||
clearToken()
|
||||
throw error
|
||||
}
|
||||
console.warn('[linear] getTeamStates failed:', error)
|
||||
return []
|
||||
} finally {
|
||||
release()
|
||||
}
|
||||
}
|
||||
|
||||
export async function getTeamLabels(teamId: string): Promise<LinearLabel[]> {
|
||||
const client = getClient()
|
||||
if (!client) {
|
||||
return []
|
||||
}
|
||||
|
||||
await acquire()
|
||||
try {
|
||||
const team = await client.team(teamId)
|
||||
const labels = await team.labels()
|
||||
return labels.nodes.map((l) => ({ id: l.id, name: l.name, color: l.color }))
|
||||
} catch (error) {
|
||||
if (isAuthError(error)) {
|
||||
clearToken()
|
||||
throw error
|
||||
}
|
||||
console.warn('[linear] getTeamLabels failed:', error)
|
||||
return []
|
||||
} finally {
|
||||
release()
|
||||
}
|
||||
}
|
||||
|
||||
export async function getTeamMembers(teamId: string): Promise<LinearMember[]> {
|
||||
const client = getClient()
|
||||
if (!client) {
|
||||
return []
|
||||
}
|
||||
|
||||
await acquire()
|
||||
try {
|
||||
const team = await client.team(teamId)
|
||||
const members = await team.members()
|
||||
return members.nodes.map((m) => ({
|
||||
id: m.id,
|
||||
displayName: m.displayName,
|
||||
avatarUrl: m.avatarUrl ?? undefined
|
||||
}))
|
||||
} catch (error) {
|
||||
if (isAuthError(error)) {
|
||||
clearToken()
|
||||
throw error
|
||||
}
|
||||
console.warn('[linear] getTeamMembers failed:', error)
|
||||
return []
|
||||
} finally {
|
||||
release()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,13 +14,17 @@ export async function mapLinearIssue(issue: Issue | IssueSearchResult): Promise<
|
||||
// for search results we fall back to empty (label names are a nice-to-have
|
||||
// in the UI, not critical for identification).
|
||||
let labelNames: string[] = []
|
||||
let labelIds: string[] = []
|
||||
if ('labels' in issue && typeof issue.labels === 'function') {
|
||||
try {
|
||||
const labelsConnection = await (issue as Issue).labels()
|
||||
labelNames = labelsConnection.nodes.map((l) => l.name)
|
||||
labelIds = labelsConnection.nodes.map((l) => l.id)
|
||||
} catch {
|
||||
// Swallow — labels are non-critical display data.
|
||||
}
|
||||
} else if ('labelIds' in issue && Array.isArray(issue.labelIds)) {
|
||||
labelIds = issue.labelIds as string[]
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -35,12 +39,18 @@ export async function mapLinearIssue(issue: Issue | IssueSearchResult): Promise<
|
||||
color: state?.color ?? ''
|
||||
},
|
||||
team: {
|
||||
id: team?.id ?? '',
|
||||
name: team?.name ?? '',
|
||||
key: team?.key ?? ''
|
||||
},
|
||||
labels: labelNames,
|
||||
labelIds,
|
||||
assignee: assignee
|
||||
? { displayName: assignee.displayName, avatarUrl: assignee.avatarUrl ?? undefined }
|
||||
? {
|
||||
id: assignee.id,
|
||||
displayName: assignee.displayName,
|
||||
avatarUrl: assignee.avatarUrl ?? undefined
|
||||
}
|
||||
: undefined,
|
||||
priority: issue.priority,
|
||||
updatedAt: issue.updatedAt.toISOString()
|
||||
|
||||
Reference in New Issue
Block a user