refactor(github): organize concrete feature owners (#41601)

This commit is contained in:
Neil
2026-11-12 09:17:26 -08:00
committed by GitHub
parent ff9fd6634b
commit fb8d6f950b
1003 changed files with 4460 additions and 8422 deletions
+138
View File
@@ -0,0 +1,138 @@
import type { ClassifiedError } from '../../../shared/classified-error'
import type { IssueInfo } from '../../../shared/github/pull-requests/pull-request-types'
import type { IssueSourcePreference } from '../../../shared/repo-types'
import { mapIssueInfo } from '../api/github-read-response'
import type { LocalGitExecOptions } from '../repositories/github-repository-identity'
import {
getIssueGitHubApiRepository,
resolveGitHubRepoExecution,
resolveIssueGitHubApiRepositorySource
} from '../repositories/github-api-repository'
// prettier-ignore
import { ghExecFileAsync } from '../../git/command-runner/hosted-cli/gh-exec-file'
import { acquire, release } from '../execution/github-operation-slots'
import { classifyListIssuesError } from '../api/gh-error-classification'
// Keep successful-empty and failed listings distinguishable; fallback toasts belong to the Tasks envelope.
export type IssueListResult = {
items: IssueInfo[]
error?: ClassifiedError
}
/** Linked issue numbers keep heuristic source resolution; changing list preference must not retarget existing links. */
export async function getIssue(
repoPath: string,
issueNumber: number,
connectionId?: string | null,
localGitOptions: LocalGitExecOptions = {}
): Promise<IssueInfo | null> {
const { ownerRepo, ghOptions } = await resolveGitHubRepoExecution(
repoPath,
() => getIssueGitHubApiRepository(repoPath, connectionId, localGitOptions),
connectionId,
localGitOptions
)
// Without local cwd, unresolved connection-backed requests could target gh's default repository.
if (connectionId && !ownerRepo) {
return null
}
await acquire()
try {
if (ownerRepo) {
const { stdout } = await ghExecFileAsync(
[
'api',
'--cache',
'300s',
`repos/${ownerRepo.owner}/${ownerRepo.repo}/issues/${issueNumber}`
],
ghOptions
)
const data = JSON.parse(stdout)
return mapIssueInfo(data)
}
// Local compatibility path relies on gh repository discovery.
const { stdout } = await ghExecFileAsync(
['issue', 'view', String(issueNumber), '--json', 'number,title,state,url,labels,body'],
ghOptions
)
const data = JSON.parse(stdout)
return mapIssueInfo(data)
} catch {
return null
} finally {
release()
}
}
/** Return classified failures separately so unavailable repositories cannot look like empty backlogs. */
export async function listIssues(
repoPath: string,
limit = 20,
preference?: IssueSourcePreference,
connectionId?: string | null,
localGitOptions: LocalGitExecOptions = {}
): Promise<IssueListResult> {
const { ownerRepo, ghOptions } = await resolveGitHubRepoExecution(
repoPath,
async () =>
(
await resolveIssueGitHubApiRepositorySource(
repoPath,
preference,
connectionId,
localGitOptions
)
).source,
connectionId,
localGitOptions
)
// Refuse unresolved remote identities rather than listing gh's default repository.
if (connectionId && !ownerRepo) {
return {
items: [],
error: {
type: 'not_found',
message: 'Could not resolve GitHub owner/repo for this repository'
}
}
}
await acquire()
try {
if (ownerRepo) {
const { stdout } = await ghExecFileAsync(
[
'api',
'--cache',
'120s',
`repos/${ownerRepo.owner}/${ownerRepo.repo}/issues?per_page=${limit}&state=open&sort=updated&direction=desc`
],
ghOptions
)
const data = JSON.parse(stdout) as Record<string, unknown>[]
// GitHub REST issues includes PRs; exclude them from this issue-only result.
return {
items: data
.filter((d) => !('pull_request' in d))
.map((d) => mapIssueInfo(d as Parameters<typeof mapIssueInfo>[0]))
}
}
// Local compatibility path relies on gh repository discovery.
const { stdout } = await ghExecFileAsync(
['issue', 'list', '--json', 'number,title,state,url,labels', '--limit', String(limit)],
ghOptions
)
const data = JSON.parse(stdout) as unknown[]
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()
}
}