feat(github): source-repo indicator + surface issue fetch errors (#1250)
Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
@@ -223,6 +223,59 @@ describe('GitHub issue source split', () => {
|
||||
expect(item?.type).toBe('pr')
|
||||
})
|
||||
|
||||
it('surfaces a 403 from upstream issues through the listWorkItems envelope', async () => {
|
||||
// Why: parent design doc §3 / acceptance criterion 2 — the IPC envelope
|
||||
// must carry a classified error for the failing side so the renderer can
|
||||
// swap the empty-state for a retryable banner. `sources` must stay
|
||||
// populated so the banner copy can name the repo that failed.
|
||||
getIssueOwnerRepoMock.mockResolvedValueOnce({ owner: 'stablyai', repo: 'orca' })
|
||||
getOwnerRepoMock.mockResolvedValueOnce({ owner: 'fork', repo: 'orca' })
|
||||
ghExecFileAsyncMock
|
||||
.mockRejectedValueOnce(new Error('HTTP 403: Resource not accessible by integration'))
|
||||
.mockResolvedValueOnce({ stdout: '[]' })
|
||||
|
||||
const result = await listWorkItems('/repo-root', 10)
|
||||
|
||||
expect(result.items).toEqual([])
|
||||
expect(result.sources).toEqual({
|
||||
issues: { owner: 'stablyai', repo: 'orca' },
|
||||
prs: { owner: 'fork', repo: 'orca' }
|
||||
})
|
||||
expect(result.errors?.issues?.type).toBe('permission_denied')
|
||||
})
|
||||
|
||||
it('returns partial results when upstream issues fail but origin PRs succeed', async () => {
|
||||
// Why: parent design doc §2 partial-failure rule — a failing source must
|
||||
// not zero out the succeeding source. The UI renders origin PRs with a
|
||||
// banner above the list, not an empty state. Ensures the IPC shape
|
||||
// carries both the successful items and the error for the failing side.
|
||||
getIssueOwnerRepoMock.mockResolvedValueOnce({ owner: 'stablyai', repo: 'orca' })
|
||||
getOwnerRepoMock.mockResolvedValueOnce({ owner: 'fork', repo: 'orca' })
|
||||
ghExecFileAsyncMock
|
||||
.mockRejectedValueOnce(new Error('HTTP 403: Resource not accessible by integration'))
|
||||
.mockResolvedValueOnce({
|
||||
stdout: JSON.stringify([
|
||||
{
|
||||
number: 42,
|
||||
title: 'Fork PR',
|
||||
state: 'open',
|
||||
html_url: 'https://github.com/fork/orca/pull/42',
|
||||
labels: [],
|
||||
updated_at: '2026-03-31T00:00:00Z',
|
||||
user: { login: 'octocat' },
|
||||
draft: false,
|
||||
head: { ref: 'feature' },
|
||||
base: { ref: 'main' }
|
||||
}
|
||||
])
|
||||
})
|
||||
|
||||
const result = await listWorkItems('/repo-root', 10)
|
||||
|
||||
expect(result.items.map((i) => i.id)).toEqual(['pr:42'])
|
||||
expect(result.errors?.issues?.type).toBe('permission_denied')
|
||||
})
|
||||
|
||||
it('raw number lookup does not fall through on transient upstream errors', async () => {
|
||||
// Why: with issue source split, a non-404 upstream failure must not silently
|
||||
// route to origin's PR #N — that would return an unrelated item.
|
||||
|
||||
@@ -80,7 +80,11 @@ describe('listWorkItems', () => {
|
||||
}
|
||||
])
|
||||
})
|
||||
const items = await listWorkItems('/repo-root', 10, 'assignee:@me')
|
||||
const { items, sources } = await listWorkItems('/repo-root', 10, 'assignee:@me')
|
||||
expect(sources).toEqual({
|
||||
issues: { owner: 'acme', repo: 'widgets' },
|
||||
prs: { owner: 'acme', repo: 'widgets' }
|
||||
})
|
||||
expect(ghExecFileAsyncMock).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
[
|
||||
@@ -160,7 +164,7 @@ describe('listWorkItems', () => {
|
||||
}
|
||||
])
|
||||
})
|
||||
const items = await listWorkItems('/repo-root', 10, 'is:pr is:draft')
|
||||
const { items } = await listWorkItems('/repo-root', 10, 'is:pr is:draft')
|
||||
expect(ghExecFileAsyncMock).toHaveBeenCalledTimes(1)
|
||||
expect(ghExecFileAsyncMock).toHaveBeenCalledWith(
|
||||
[
|
||||
@@ -246,7 +250,7 @@ describe('listWorkItems', () => {
|
||||
}
|
||||
])
|
||||
})
|
||||
const items = await listWorkItems('/repo-root', 10, 'is:open')
|
||||
const { items } = await listWorkItems('/repo-root', 10, 'is:open')
|
||||
expect(ghExecFileAsyncMock).toHaveBeenCalledWith(
|
||||
[
|
||||
'issue',
|
||||
|
||||
+140
-70
@@ -1,6 +1,8 @@
|
||||
/* eslint-disable max-lines -- Why: co-locating all GitHub client functions keeps the
|
||||
concurrency acquire/release pattern and error handling consistent across operations. */
|
||||
import type {
|
||||
ClassifiedError,
|
||||
ListWorkItemsResult,
|
||||
PRInfo,
|
||||
PRMergeableState,
|
||||
PRCheckDetail,
|
||||
@@ -21,6 +23,7 @@ import {
|
||||
getOwnerRepo,
|
||||
getIssueOwnerRepo,
|
||||
classifyGhError,
|
||||
classifyListIssuesError,
|
||||
type OwnerRepo
|
||||
} from './gh-utils'
|
||||
export { _resetOwnerRepoCache } from './gh-utils'
|
||||
@@ -341,14 +344,27 @@ function buildWorkItemListArgs(args: {
|
||||
return out
|
||||
}
|
||||
|
||||
// Why: internal shape shared by listRecentWorkItems / listQueriedWorkItems so
|
||||
// listWorkItems can lift per-side errors into the IPC envelope. The issue-side
|
||||
// error is the specific new class of silent wrongness introduced by #1076 —
|
||||
// PR-side errors existed before and are explicitly out of scope for this
|
||||
// feature per the parent design doc §6.
|
||||
type PartialWorkItemsResult = {
|
||||
items: MainWorkItem[]
|
||||
issuesError?: ClassifiedError
|
||||
}
|
||||
|
||||
async function listRecentWorkItems(
|
||||
repoPath: string,
|
||||
issueOwnerRepo: OwnerRepo | null,
|
||||
prOwnerRepo: OwnerRepo | null,
|
||||
limit: number
|
||||
): Promise<MainWorkItem[]> {
|
||||
): Promise<PartialWorkItemsResult> {
|
||||
if (issueOwnerRepo || prOwnerRepo) {
|
||||
const [issuesResult, prsResult] = await Promise.all([
|
||||
// Why: allSettled so a 403 on upstream issues doesn't zero out the origin
|
||||
// PR half — the UI renders partial results plus a banner for the failing
|
||||
// side, matching the parent design doc's partial-failure rule (§2).
|
||||
const [issuesSettled, prsSettled] = await Promise.allSettled([
|
||||
issueOwnerRepo
|
||||
? ghExecFileAsync(
|
||||
[
|
||||
@@ -397,20 +413,61 @@ async function listRecentWorkItems(
|
||||
)
|
||||
])
|
||||
|
||||
const issues = (JSON.parse(issuesResult.stdout) as Record<string, unknown>[])
|
||||
// Why: the GitHub issues REST endpoint also returns pull requests with a
|
||||
// `pull_request` marker. The new-workspace task picker needs distinct
|
||||
// issue vs PR buckets, so drop PR-shaped issue rows here before merging.
|
||||
.filter((item) => !('pull_request' in item))
|
||||
.map(mapIssueWorkItem)
|
||||
let issues: MainWorkItem[] = []
|
||||
let issuesError: ClassifiedError | undefined
|
||||
if (issuesSettled.status === 'fulfilled') {
|
||||
issues = (JSON.parse(issuesSettled.value.stdout) as Record<string, unknown>[])
|
||||
// Why: the GitHub issues REST endpoint also returns pull requests with a
|
||||
// `pull_request` marker. The new-workspace task picker needs distinct
|
||||
// issue vs PR buckets, so drop PR-shaped issue rows here before merging.
|
||||
.filter((item) => !('pull_request' in item))
|
||||
.map(mapIssueWorkItem)
|
||||
} else {
|
||||
const stderr =
|
||||
issuesSettled.reason instanceof Error
|
||||
? issuesSettled.reason.message
|
||||
: String(issuesSettled.reason)
|
||||
issuesError = classifyListIssuesError(stderr)
|
||||
}
|
||||
|
||||
const prs = (JSON.parse(prsResult.stdout) as Record<string, unknown>[]).map((item) =>
|
||||
mapPullRequestWorkItem(item, prOwnerRepo?.owner ?? null)
|
||||
)
|
||||
let prs: MainWorkItem[] = []
|
||||
if (prsSettled.status === 'fulfilled') {
|
||||
prs = (JSON.parse(prsSettled.value.stdout) as Record<string, unknown>[]).map((item) =>
|
||||
mapPullRequestWorkItem(item, prOwnerRepo?.owner ?? null)
|
||||
)
|
||||
} else {
|
||||
// Why: PR-side failures must preserve the pre-diff behavior of
|
||||
// Promise.all by re-throwing so the rejection propagates up through
|
||||
// listWorkItems to the renderer's cross-repo aggregator (which counts
|
||||
// the repo as failed). This feature is scoped to the issue-side silent
|
||||
// wrongness from #1076; PR errors must not be silently swallowed here.
|
||||
// Why: if the issue side ALSO failed, the classified issuesError would
|
||||
// otherwise be silently dropped when we throw the PR reason. Log it so
|
||||
// debugging both-sides-failed scenarios (e.g. 403 on both endpoints)
|
||||
// isn't blind to the issue-side classification.
|
||||
if (issuesError) {
|
||||
console.warn(
|
||||
'listRecentWorkItems: both issue and PR sides failed; issuesError was classified:',
|
||||
issuesError.type,
|
||||
issuesError.message
|
||||
)
|
||||
}
|
||||
throw prsSettled.reason
|
||||
}
|
||||
|
||||
return sortWorkItemsByUpdatedAt([...issues, ...prs]).slice(0, limit)
|
||||
return {
|
||||
items: sortWorkItemsByUpdatedAt([...issues, ...prs]).slice(0, limit),
|
||||
issuesError
|
||||
}
|
||||
}
|
||||
|
||||
// Why: the fallback path (non-GitHub remote — neither issueOwnerRepo nor
|
||||
// prOwnerRepo resolved) intentionally stays on Promise.all rather than the
|
||||
// Promise.allSettled + per-side classification used above. There are no
|
||||
// `sources` to surface on this branch and nothing for the partial-failure
|
||||
// banner to render, so a single-side failure here means the whole call is
|
||||
// effectively unusable for the feature — reject-all matches reality. If
|
||||
// non-GitHub remotes ever grow source metadata, revisit this symmetry.
|
||||
const [issuesResult, prsResult] = await Promise.all([
|
||||
ghExecFileAsync(
|
||||
[
|
||||
@@ -447,7 +504,9 @@ async function listRecentWorkItems(
|
||||
mapPullRequestWorkItem(item, null)
|
||||
)
|
||||
|
||||
return sortWorkItemsByUpdatedAt([...issues, ...prs]).slice(0, limit)
|
||||
return {
|
||||
items: sortWorkItemsByUpdatedAt([...issues, ...prs]).slice(0, limit)
|
||||
}
|
||||
}
|
||||
|
||||
async function listQueriedWorkItems(
|
||||
@@ -457,55 +516,62 @@ async function listQueriedWorkItems(
|
||||
query: ParsedTaskQuery,
|
||||
limit: number,
|
||||
before?: string
|
||||
): Promise<MainWorkItem[]> {
|
||||
const fetchers: Promise<MainWorkItem[]>[] = []
|
||||
): Promise<PartialWorkItemsResult> {
|
||||
const issueScope = query.scope !== 'pr'
|
||||
const prScope = query.scope !== 'issue'
|
||||
|
||||
if (issueScope) {
|
||||
fetchers.push(
|
||||
(async () => {
|
||||
const args = buildWorkItemListArgs({
|
||||
kind: 'issue',
|
||||
ownerRepo: issueOwnerRepo,
|
||||
limit,
|
||||
query,
|
||||
before
|
||||
})
|
||||
try {
|
||||
const { stdout } = await ghExecFileAsync(args, { cwd: repoPath })
|
||||
return (JSON.parse(stdout) as Record<string, unknown>[]).map(mapIssueWorkItem)
|
||||
} catch {
|
||||
return []
|
||||
}
|
||||
})()
|
||||
)
|
||||
}
|
||||
// Why: run the issue and PR fetches in parallel but surface the
|
||||
// issue-side error separately so the IPC envelope can carry it up. PR-side
|
||||
// failures retain the prior swallow-and-log behavior per parent doc §6.
|
||||
const issueFetch = (async (): Promise<PartialWorkItemsResult> => {
|
||||
if (!issueScope) {
|
||||
return { items: [] }
|
||||
}
|
||||
const args = buildWorkItemListArgs({
|
||||
kind: 'issue',
|
||||
ownerRepo: issueOwnerRepo,
|
||||
limit,
|
||||
query,
|
||||
before
|
||||
})
|
||||
try {
|
||||
const { stdout } = await ghExecFileAsync(args, { cwd: repoPath })
|
||||
return {
|
||||
items: (JSON.parse(stdout) as Record<string, unknown>[]).map(mapIssueWorkItem)
|
||||
}
|
||||
} catch (err) {
|
||||
const stderr = err instanceof Error ? err.message : String(err)
|
||||
return { items: [], issuesError: classifyListIssuesError(stderr) }
|
||||
}
|
||||
})()
|
||||
|
||||
if (prScope) {
|
||||
fetchers.push(
|
||||
(async () => {
|
||||
const args = buildWorkItemListArgs({
|
||||
kind: 'pr',
|
||||
ownerRepo: prOwnerRepo,
|
||||
limit,
|
||||
query,
|
||||
before
|
||||
})
|
||||
try {
|
||||
const { stdout } = await ghExecFileAsync(args, { cwd: repoPath })
|
||||
return (JSON.parse(stdout) as Record<string, unknown>[]).map((item) =>
|
||||
mapPullRequestWorkItem(item, prOwnerRepo?.owner ?? null)
|
||||
)
|
||||
} catch {
|
||||
return []
|
||||
}
|
||||
})()
|
||||
)
|
||||
}
|
||||
const prFetch = (async (): Promise<MainWorkItem[]> => {
|
||||
if (!prScope) {
|
||||
return []
|
||||
}
|
||||
const args = buildWorkItemListArgs({
|
||||
kind: 'pr',
|
||||
ownerRepo: prOwnerRepo,
|
||||
limit,
|
||||
query,
|
||||
before
|
||||
})
|
||||
try {
|
||||
const { stdout } = await ghExecFileAsync(args, { cwd: repoPath })
|
||||
return (JSON.parse(stdout) as Record<string, unknown>[]).map((item) =>
|
||||
mapPullRequestWorkItem(item, prOwnerRepo?.owner ?? null)
|
||||
)
|
||||
} catch (err) {
|
||||
console.warn('listQueriedWorkItems PRs partial failure:', err)
|
||||
return []
|
||||
}
|
||||
})()
|
||||
|
||||
const results = await Promise.all(fetchers)
|
||||
return sortWorkItemsByUpdatedAt(results.flat()).slice(0, limit)
|
||||
const [issueResult, prItems] = await Promise.all([issueFetch, prFetch])
|
||||
return {
|
||||
items: sortWorkItemsByUpdatedAt([...issueResult.items, ...prItems]).slice(0, limit),
|
||||
issuesError: issueResult.issuesError
|
||||
}
|
||||
}
|
||||
|
||||
export async function listWorkItems(
|
||||
@@ -513,7 +579,7 @@ export async function listWorkItems(
|
||||
limit = 24,
|
||||
query?: string,
|
||||
before?: string
|
||||
): Promise<MainWorkItem[]> {
|
||||
): Promise<ListWorkItemsResult<MainWorkItem>> {
|
||||
const [issueOwnerRepo, prOwnerRepo] = await Promise.all([
|
||||
getIssueOwnerRepo(repoPath),
|
||||
getOwnerRepo(repoPath)
|
||||
@@ -525,19 +591,23 @@ export async function listWorkItems(
|
||||
// count this repo as failed and surface the partial-failure banner. A
|
||||
// catch-all here would make an auth/network failure indistinguishable from
|
||||
// an empty result and silently under-report per-repo failures.
|
||||
if (!trimmedQuery) {
|
||||
return await listRecentWorkItems(repoPath, issueOwnerRepo, prOwnerRepo, limit)
|
||||
}
|
||||
const partial = !trimmedQuery
|
||||
? await listRecentWorkItems(repoPath, issueOwnerRepo, prOwnerRepo, limit)
|
||||
: await listQueriedWorkItems(
|
||||
repoPath,
|
||||
issueOwnerRepo,
|
||||
prOwnerRepo,
|
||||
parseTaskQuery(trimmedQuery),
|
||||
limit,
|
||||
before
|
||||
)
|
||||
|
||||
const parsedQuery = parseTaskQuery(trimmedQuery)
|
||||
return await listQueriedWorkItems(
|
||||
repoPath,
|
||||
issueOwnerRepo,
|
||||
prOwnerRepo,
|
||||
parsedQuery,
|
||||
limit,
|
||||
before
|
||||
)
|
||||
const errors = partial.issuesError ? { issues: partial.issuesError } : undefined
|
||||
return {
|
||||
items: partial.items,
|
||||
sources: { issues: issueOwnerRepo, prs: prOwnerRepo },
|
||||
...(errors ? { errors } : {})
|
||||
}
|
||||
} finally {
|
||||
release()
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { execFile } from 'child_process'
|
||||
import { promisify } from 'util'
|
||||
import { gitExecFileAsync, ghExecFileAsync } from '../git/runner'
|
||||
import type { ClassifiedError } from '../../shared/types'
|
||||
import type { ClassifiedError, GitHubOwnerRepo } 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
|
||||
@@ -46,7 +46,12 @@ export function classifyGhError(stderr: string): ClassifiedError {
|
||||
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')) {
|
||||
// Why: the full gh message is "Could not resolve to a Repository with the
|
||||
// name ...". Matching the substring 'could not resolve' alone would also
|
||||
// capture DNS failures like "could not resolve host: api.github.com" and
|
||||
// misclassify them as not_found. Anchor on the 'repository' qualifier so
|
||||
// DNS errors fall through to the network_error branch below.
|
||||
if (s.includes('http 404') || s.includes('could not resolve to a repository')) {
|
||||
return { type: 'not_found', message: 'Issue not found — it may have been deleted.' }
|
||||
}
|
||||
if (s.includes('http 422') || s.includes('validation failed')) {
|
||||
@@ -58,14 +63,45 @@ export function classifyGhError(stderr: string): ClassifiedError {
|
||||
message: 'GitHub rate limit hit. Try again in a few minutes.'
|
||||
}
|
||||
}
|
||||
if (s.includes('timeout') || s.includes('no such host') || s.includes('network')) {
|
||||
if (
|
||||
s.includes('timeout') ||
|
||||
s.includes('no such host') ||
|
||||
s.includes('network') ||
|
||||
s.includes('could not resolve host')
|
||||
) {
|
||||
return { type: 'network_error', message: 'Network error — check your connection.' }
|
||||
}
|
||||
return { type: 'unknown', message: `Failed to update issue: ${stderr.trim()}` }
|
||||
}
|
||||
|
||||
// Why: classifyGhError's copy is phrased for edit/update operations, but
|
||||
// `listIssues` is a read op and the renderer interpolates err.message verbatim
|
||||
// into a read-context banner. Rewrite the message for read contexts while
|
||||
// keeping the typed classification so callers/telemetry are unaffected.
|
||||
export function classifyListIssuesError(stderr: string): ClassifiedError {
|
||||
const c = classifyGhError(stderr)
|
||||
const trimmed = stderr.trim()
|
||||
// Why: provide an explicit entry for every `ClassifiedError['type']` value
|
||||
// (even when the copy matches the generic fallback) so the read-context
|
||||
// rewrite is complete and any newly added error type surfaces as a
|
||||
// TypeScript error rather than silently falling through to edit-phrased copy.
|
||||
const readMessages: Record<ClassifiedError['type'], string> = {
|
||||
permission_denied:
|
||||
"You don't have permission to read issues for this repository. Check your GitHub token scopes.",
|
||||
not_found: 'Repository not found.',
|
||||
validation_error: `Invalid request — ${trimmed}`,
|
||||
rate_limited: 'GitHub rate limit hit. Try again in a few minutes.',
|
||||
network_error: 'Network error — check your connection.',
|
||||
unknown: `Failed to load issues: ${trimmed}`
|
||||
}
|
||||
return { type: c.type, message: readMessages[c.type] }
|
||||
}
|
||||
|
||||
// ── Owner/repo resolution for gh api --cache ──────────────────────────
|
||||
export type OwnerRepo = { owner: string; repo: string }
|
||||
// Why: alias the shared shape so `src/shared/types.ts#GitHubOwnerRepo` remains
|
||||
// the single source of truth while main-side call sites can keep using the
|
||||
// short local name `OwnerRepo`.
|
||||
export type OwnerRepo = GitHubOwnerRepo
|
||||
|
||||
const ownerRepoCache = new Map<string, OwnerRepo | null>()
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import type * as GhUtils from './gh-utils'
|
||||
|
||||
const { ghExecFileAsyncMock, getIssueOwnerRepoMock, acquireMock, releaseMock } = vi.hoisted(() => ({
|
||||
ghExecFileAsyncMock: vi.fn(),
|
||||
@@ -7,12 +8,16 @@ const { ghExecFileAsyncMock, getIssueOwnerRepoMock, acquireMock, releaseMock } =
|
||||
releaseMock: vi.fn()
|
||||
}))
|
||||
|
||||
vi.mock('./gh-utils', () => ({
|
||||
ghExecFileAsync: ghExecFileAsyncMock,
|
||||
getIssueOwnerRepo: getIssueOwnerRepoMock,
|
||||
acquire: acquireMock,
|
||||
release: releaseMock
|
||||
}))
|
||||
vi.mock('./gh-utils', async () => {
|
||||
const actual = await vi.importActual<typeof GhUtils>('./gh-utils')
|
||||
return {
|
||||
...actual,
|
||||
ghExecFileAsync: ghExecFileAsyncMock,
|
||||
getIssueOwnerRepo: getIssueOwnerRepoMock,
|
||||
acquire: acquireMock,
|
||||
release: releaseMock
|
||||
}
|
||||
})
|
||||
|
||||
import { createIssue, getIssue, listIssues } from './issues'
|
||||
|
||||
@@ -48,7 +53,7 @@ describe('issue source operations', () => {
|
||||
getIssueOwnerRepoMock.mockResolvedValueOnce({ owner: 'stablyai', repo: 'orca' })
|
||||
ghExecFileAsyncMock.mockResolvedValueOnce({ stdout: '[]' })
|
||||
|
||||
await listIssues('/repo-root', 5)
|
||||
await expect(listIssues('/repo-root', 5)).resolves.toEqual({ items: [] })
|
||||
|
||||
expect(ghExecFileAsyncMock).toHaveBeenCalledWith(
|
||||
[
|
||||
@@ -61,6 +66,21 @@ describe('issue source operations', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('surfaces a classified permission_denied error instead of collapsing to empty', async () => {
|
||||
// Why: parent design doc §3 — a 403 on a private upstream must not
|
||||
// masquerade as "No issues". The envelope carries an error the UI can
|
||||
// render as a banner with retry, not a silent empty list.
|
||||
getIssueOwnerRepoMock.mockResolvedValueOnce({ owner: 'stablyai', repo: 'orca' })
|
||||
ghExecFileAsyncMock.mockRejectedValueOnce(
|
||||
new Error('HTTP 403: Resource not accessible by integration')
|
||||
)
|
||||
|
||||
const result = await listIssues('/repo-root', 5)
|
||||
|
||||
expect(result.items).toEqual([])
|
||||
expect(result.error?.type).toBe('permission_denied')
|
||||
})
|
||||
|
||||
it('creates issues in the issue owner/repo', async () => {
|
||||
getIssueOwnerRepoMock.mockResolvedValueOnce({ owner: 'stablyai', repo: 'orca' })
|
||||
ghExecFileAsyncMock.mockResolvedValueOnce({
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type {
|
||||
ClassifiedError,
|
||||
GitHubAssignableUser,
|
||||
GitHubCommentResult,
|
||||
GitHubIssueUpdate,
|
||||
@@ -6,7 +7,13 @@ import type {
|
||||
PRComment
|
||||
} from '../../shared/types'
|
||||
import { mapIssueInfo } from './mappers'
|
||||
import { ghExecFileAsync, acquire, release, getIssueOwnerRepo, classifyGhError } from './gh-utils'
|
||||
// prettier-ignore
|
||||
import { ghExecFileAsync, acquire, release, getIssueOwnerRepo, classifyGhError, classifyListIssuesError } from './gh-utils'
|
||||
|
||||
// Why: distinguishes a successful-empty listing from a failed fetch. The
|
||||
// previous `catch { return [] }` conflated a 403 on a private upstream with an
|
||||
// empty backlog. Callers decide how to surface `error`.
|
||||
export type IssueListResult = { items: IssueInfo[]; error?: ClassifiedError }
|
||||
|
||||
/**
|
||||
* Get a single issue by number.
|
||||
@@ -46,8 +53,15 @@ export async function getIssue(repoPath: string, issueNumber: number): Promise<I
|
||||
/**
|
||||
* List issues for a repo.
|
||||
* Uses gh api --cache so 304 Not Modified responses don't count against the rate limit.
|
||||
*
|
||||
* Why: returns a structured result so a 403 (e.g. fork contributor without
|
||||
* read access to a private upstream) surfaces as an error the UI can render
|
||||
* instead of collapsing to "No issues". The empty-list-on-error behavior this
|
||||
* replaces was explicitly flagged as a merge-blocker in the parent design doc
|
||||
* (§3) — silently hiding failures re-creates the same silent-source-switch
|
||||
* class of wrongness #1186 warned against, one level deeper.
|
||||
*/
|
||||
export async function listIssues(repoPath: string, limit = 20): Promise<IssueInfo[]> {
|
||||
export async function listIssues(repoPath: string, limit = 20): Promise<IssueListResult> {
|
||||
const ownerRepo = await getIssueOwnerRepo(repoPath)
|
||||
await acquire()
|
||||
try {
|
||||
@@ -61,8 +75,16 @@ export async function listIssues(repoPath: string, limit = 20): Promise<IssueInf
|
||||
],
|
||||
{ cwd: repoPath }
|
||||
)
|
||||
const data = JSON.parse(stdout) as unknown[]
|
||||
return data.map((d) => mapIssueInfo(d as Parameters<typeof mapIssueInfo>[0]))
|
||||
const data = JSON.parse(stdout) as Record<string, unknown>[]
|
||||
// Why: the GitHub REST `/repos/{owner}/{repo}/issues` endpoint returns
|
||||
// pull requests alongside issues (PRs carry a `pull_request` key).
|
||||
// Strip them here so `listIssues` only returns true issues, matching the
|
||||
// filter applied in `listRecentWorkItems` (src/main/github/client.ts).
|
||||
return {
|
||||
items: data
|
||||
.filter((d) => !('pull_request' in d))
|
||||
.map((d) => mapIssueInfo(d as Parameters<typeof mapIssueInfo>[0]))
|
||||
}
|
||||
}
|
||||
// Fallback for non-GitHub remotes
|
||||
const { stdout } = await ghExecFileAsync(
|
||||
@@ -70,9 +92,10 @@ export async function listIssues(repoPath: string, limit = 20): Promise<IssueInf
|
||||
{ cwd: repoPath }
|
||||
)
|
||||
const data = JSON.parse(stdout) as unknown[]
|
||||
return data.map((d) => mapIssueInfo(d as Parameters<typeof mapIssueInfo>[0]))
|
||||
} catch {
|
||||
return []
|
||||
return { items: data.map((d) => mapIssueInfo(d as Parameters<typeof mapIssueInfo>[0])) }
|
||||
} catch (err) {
|
||||
const stderr = err instanceof Error ? err.message : String(err)
|
||||
return { items: [], error: classifyListIssuesError(stderr) }
|
||||
} finally {
|
||||
release()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user