mirror of
https://github.com/stablyai/orca.git
synced 2026-10-31 00:57:45 +00:00
* fix(github): resolve SSH host aliases for account binding An origin like git@github-personal:owner/repo kept the alias as the required gh host, so the Settings account list matched nothing. * fix(github): keep github.com filter for resolved aliases and resolve in the gh runtime Real canonical keys carry github.com, so an alias resolving to github.com must filter to github.com like a direct remote. Resolve via the runtime-scoped resolveSshConfigHostname (WSL distro aware) and keep Enterprise hosts exact. * fix(github): expand SSH aliases only for SSH-transport remotes * fix(github): resolve the SSH alias with its original case --------- Co-authored-by: orchardprior <342342873+orchardprior@users.noreply.github.com> Co-authored-by: Neil <neil@stably.ai>
178 lines
5.3 KiB
TypeScript
178 lines
5.3 KiB
TypeScript
import type { ListWorkItemsResult } from '../../shared/github/work-item-types'
|
|
import type { Repo } from '../../shared/repo-types'
|
|
import type { LocalProjectGhExecOptions } from '../project-runtime-git-options'
|
|
import {
|
|
countWorkItems,
|
|
getWorkItem,
|
|
getWorkItemByOwnerRepo,
|
|
listAssignableUsers,
|
|
listIssues,
|
|
listLabels,
|
|
listWorkItems,
|
|
type MainWorkItem
|
|
} from '../github/client'
|
|
import {
|
|
listGhAccountBindingInventory,
|
|
validateGhAccountBinding
|
|
} from '../github/gh-account-binding-inventory'
|
|
import { getRateLimit } from '../github/rate-limit'
|
|
import { resolveGhAccountRequiredHost } from '../github/account-binding-required-host'
|
|
import { getWorkItemDetails } from '../github/work-item-details'
|
|
|
|
type LocalGitArgs = [] | [LocalProjectGhExecOptions]
|
|
|
|
type RuntimeGitHubRepositoryQueryCommandsDeps = {
|
|
resolveRepo: (selector: string) => Promise<Repo>
|
|
getLocalGitArgs: (repo: Repo) => LocalGitArgs
|
|
}
|
|
|
|
export class RuntimeGitHubRepositoryQueryCommands {
|
|
constructor(private readonly deps: RuntimeGitHubRepositoryQueryCommandsDeps) {}
|
|
|
|
async listRepoWorkItems(
|
|
repoSelector: string,
|
|
limit?: number,
|
|
query?: string,
|
|
page?: number,
|
|
noCache?: boolean
|
|
): Promise<ListWorkItemsResult<MainWorkItem>> {
|
|
const repo = await this.deps.resolveRepo(repoSelector)
|
|
return listWorkItems(
|
|
repo.path,
|
|
limit,
|
|
query,
|
|
page,
|
|
repo.issueSourcePreference,
|
|
repo.connectionId ?? null,
|
|
noCache,
|
|
...this.deps.getLocalGitArgs(repo)
|
|
)
|
|
}
|
|
|
|
async listRepoIssues(
|
|
repoSelector: string,
|
|
limit?: number
|
|
): Promise<Awaited<ReturnType<typeof listIssues>>['items']> {
|
|
const repo = await this.deps.resolveRepo(repoSelector)
|
|
const result = await listIssues(
|
|
repo.path,
|
|
limit,
|
|
repo.issueSourcePreference,
|
|
repo.connectionId ?? null,
|
|
...this.deps.getLocalGitArgs(repo)
|
|
)
|
|
return result.items
|
|
}
|
|
|
|
async getRepoWorkItem(
|
|
repoSelector: string,
|
|
number: number,
|
|
type?: 'issue' | 'pr'
|
|
): Promise<Awaited<ReturnType<typeof getWorkItem>>> {
|
|
const repo = await this.deps.resolveRepo(repoSelector)
|
|
return getWorkItem(
|
|
repo.path,
|
|
number,
|
|
type,
|
|
repo.connectionId ?? null,
|
|
this.deps.getLocalGitArgs(repo)[0] ?? {},
|
|
repo.issueSourcePreference
|
|
)
|
|
}
|
|
|
|
async getRepoWorkItemByOwnerRepo(
|
|
repoSelector: string,
|
|
ownerRepo: { owner: string; repo: string; host?: string },
|
|
number: number,
|
|
type: 'issue' | 'pr'
|
|
): Promise<Awaited<ReturnType<typeof getWorkItemByOwnerRepo>>> {
|
|
const repo = await this.deps.resolveRepo(repoSelector)
|
|
return getWorkItemByOwnerRepo(
|
|
repo.path,
|
|
ownerRepo,
|
|
number,
|
|
type,
|
|
repo.connectionId ?? null,
|
|
...this.deps.getLocalGitArgs(repo)
|
|
)
|
|
}
|
|
|
|
async getRepoWorkItemDetails(
|
|
repoSelector: string,
|
|
number: number,
|
|
type?: 'issue' | 'pr'
|
|
): Promise<Awaited<ReturnType<typeof getWorkItemDetails>>> {
|
|
const repo = await this.deps.resolveRepo(repoSelector)
|
|
return getWorkItemDetails(
|
|
repo.path,
|
|
number,
|
|
type,
|
|
repo.connectionId ?? null,
|
|
this.deps.getLocalGitArgs(repo)[0] ?? {},
|
|
repo.issueSourcePreference
|
|
)
|
|
}
|
|
|
|
async countRepoWorkItems(repoSelector: string, query?: string): Promise<number> {
|
|
const repo = await this.deps.resolveRepo(repoSelector)
|
|
return countWorkItems(
|
|
repo.path,
|
|
query,
|
|
repo.issueSourcePreference,
|
|
repo.connectionId ?? null,
|
|
...this.deps.getLocalGitArgs(repo)
|
|
)
|
|
}
|
|
|
|
async listRepoLabels(repoSelector: string): Promise<Awaited<ReturnType<typeof listLabels>>> {
|
|
const repo = await this.deps.resolveRepo(repoSelector)
|
|
return listLabels(
|
|
repo.path,
|
|
repo.issueSourcePreference,
|
|
repo.connectionId ?? null,
|
|
...this.deps.getLocalGitArgs(repo)
|
|
)
|
|
}
|
|
|
|
async listRepoAssignableUsers(
|
|
repoSelector: string
|
|
): Promise<Awaited<ReturnType<typeof listAssignableUsers>>> {
|
|
const repo = await this.deps.resolveRepo(repoSelector)
|
|
return listAssignableUsers(
|
|
repo.path,
|
|
repo.issueSourcePreference,
|
|
repo.connectionId ?? null,
|
|
...this.deps.getLocalGitArgs(repo)
|
|
)
|
|
}
|
|
|
|
getGitHubRateLimit(options?: {
|
|
force?: boolean
|
|
}): Promise<Awaited<ReturnType<typeof getRateLimit>>> {
|
|
return getRateLimit(options)
|
|
}
|
|
|
|
async listGitHubBindableAccounts(
|
|
repoSelector: string,
|
|
options?: { refreshCapability?: boolean }
|
|
): Promise<Awaited<ReturnType<typeof listGhAccountBindingInventory>>> {
|
|
const repo = await this.deps.resolveRepo(repoSelector)
|
|
const localGitOptions = this.deps.getLocalGitArgs(repo)[0] ?? {}
|
|
const requiredHost = await resolveGhAccountRequiredHost(repo, localGitOptions)
|
|
return listGhAccountBindingInventory(localGitOptions, {
|
|
refreshCapability: options?.refreshCapability === true,
|
|
...(requiredHost ? { requiredHost } : {})
|
|
})
|
|
}
|
|
|
|
async validateGitHubAccountBinding(
|
|
repoSelector: string,
|
|
binding: { host: string; user: string }
|
|
): Promise<Awaited<ReturnType<typeof validateGhAccountBinding>>> {
|
|
const repo = await this.deps.resolveRepo(repoSelector)
|
|
const localGitOptions = this.deps.getLocalGitArgs(repo)[0] ?? {}
|
|
const requiredHost = await resolveGhAccountRequiredHost(repo, localGitOptions)
|
|
return validateGhAccountBinding(binding, localGitOptions, requiredHost ? { requiredHost } : {})
|
|
}
|
|
}
|