mirror of
https://github.com/stablyai/orca.git
synced 2026-10-18 16:03:17 +00:00
Refactor GitHub repository execution setup
This commit is contained in:
@@ -3,13 +3,30 @@ import {
|
||||
githubRepoIdentityKey,
|
||||
isDefaultGitHubHost
|
||||
} from '../../shared/github-repository-identity-key'
|
||||
import { getOwnerRepo, getOwnerRepoForRemote, type LocalGitExecOptions } from './gh-utils'
|
||||
import {
|
||||
getOwnerRepo,
|
||||
getOwnerRepoForRemote,
|
||||
ghRepoExecOptions,
|
||||
githubRepoContext,
|
||||
type LocalGitExecOptions
|
||||
} from './gh-utils'
|
||||
import {
|
||||
getEnterpriseGitHubRepoSlug,
|
||||
getEnterpriseGitHubRepoSlugForRemote
|
||||
} from './github-enterprise-repository'
|
||||
|
||||
export type GitHubApiRepository = GitHubOwnerRepo
|
||||
export type GitHubRepoExecOptions = ReturnType<typeof ghRepoExecOptions> & { host?: string }
|
||||
export type GitHubRepoExecution = {
|
||||
ownerRepo: GitHubApiRepository | null
|
||||
ghOptions: GitHubRepoExecOptions
|
||||
}
|
||||
|
||||
type GitHubApiRepositoryResolution =
|
||||
| GitHubApiRepository
|
||||
| null
|
||||
| undefined
|
||||
| (() => Promise<GitHubApiRepository | null>)
|
||||
|
||||
// Why: the enterprise branch spawns an uncached `git remote get-url` (an SSH
|
||||
// round trip on connection-backed repos) — hot paths like per-file contents
|
||||
@@ -256,6 +273,27 @@ export function githubHostExecOptions(repository: GitHubApiRepository | null | u
|
||||
return repository?.host ? { host: repository.host } : {}
|
||||
}
|
||||
|
||||
export async function resolveGitHubRepoExecution(
|
||||
repoPath: string,
|
||||
repository?: GitHubApiRepositoryResolution,
|
||||
connectionId?: string | null,
|
||||
localGitOptions: LocalGitExecOptions = {}
|
||||
): Promise<GitHubRepoExecution> {
|
||||
// Why: issue-scoped paths retain their upstream-first resolver while sharing
|
||||
// the same repo-scoped and host-scoped gh execution option construction.
|
||||
const ownerRepo =
|
||||
typeof repository === 'function'
|
||||
? await repository()
|
||||
: await resolveGitHubApiRepository(repoPath, repository, connectionId, localGitOptions)
|
||||
return {
|
||||
ownerRepo,
|
||||
ghOptions: {
|
||||
...ghRepoExecOptions(githubRepoContext(repoPath, connectionId, localGitOptions)),
|
||||
...githubHostExecOptions(ownerRepo)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function githubRepositoryWebHost(repository: GitHubApiRepository): string {
|
||||
return repository.host ?? 'github.com'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user