Files
archived-orca/src/main/runtime/runtime-github-worktree-base.ts
T
Neil 18f674e69f refactor: group workspace catalog and execution-host owners (#37641)
* refactor: group workspace catalog and execution-host owners

* test: annotate catalog fixtures with portable public mock types

* test(workspaces): preserve filesystem worktree mocks at concrete owners
2026-11-02 20:22:21 -08:00

89 lines
3.4 KiB
TypeScript

import type { GitHubPrStartPoint } from '../../shared/worktree/types'
import type { Repo } from '../../shared/repo-types'
import {
fetchPrHeadTrackingRef,
fetchGitHubPullRequestHeadRef
} from '../github/pr-head-tracking-ref'
import { resolveGitHubPrStartPoint } from '../github/pr-start-point'
import { resolvePrStartPointUnlessWslStopped } from '../github/pr-start-point-wsl-gate'
import { resolveGitHubReviewHeadRemote } from '../github/review-head-remote'
import { gitExecFileAsync } from '../git/runner'
import {
getLocalProjectGitExecOptions,
getLocalProjectGhExecOptions
} from '../workspaces/execution-host/project-runtime-git-options'
import { isFolderRepo } from '../../shared/repo-kind'
import { requireRepoLocalGitRoute } from '../workspaces/execution-host/repo-execution-host'
import type { ProjectRuntimeResolutionStore } from '../workspaces/execution-host/local-project-runtime-resolution'
import { reviewStartPointFailure } from '../../shared/review-start-point-failure-copy'
export type RuntimeGitHubWorktreeBaseArgs = {
repoSelector: string
prNumber: number
headRefName?: string
baseRefName?: string
isCrossRepository?: boolean
/** The user creating or launching from the PR: it may start a stopped WSL distro. */
wakeWslDistro?: boolean
}
export async function resolveRuntimeGitHubWorktreeBase(
args: RuntimeGitHubWorktreeBaseArgs,
deps: {
store: ProjectRuntimeResolutionStore | null
resolveRepo: (selector: string) => Promise<Repo>
}
): Promise<GitHubPrStartPoint | { error: string }> {
if (!deps.store) {
throw new Error('runtime_unavailable')
}
let repo: Repo
try {
repo = await deps.resolveRepo(args.repoSelector)
} catch {
return reviewStartPointFailure('repoNotFound')
}
if (isFolderRepo(repo)) {
return reviewStartPointFailure('folderUnsupported')
}
// Use shared host gating: executionHostId may be a row's only SSH marker.
requireRepoLocalGitRoute(repo)
const localGitExecOptions = getLocalProjectGitExecOptions(deps.store, repo)
const localGhOptions = getLocalProjectGhExecOptions(deps.store, repo)
const gitExec = (gitArgs: string[]) => gitExecFileAsync(gitArgs, localGitExecOptions)
const resolveRemote = (): Promise<string> =>
resolveGitHubReviewHeadRemote({
repoPath: repo.path,
issueSourcePreference: repo.issueSourcePreference,
connectionId: null,
localGitOptions: localGhOptions,
gitExec
})
const fetchRemoteTrackingRef = (remote: string, branch: string): Promise<void> =>
fetchPrHeadTrackingRef(repo, remote, branch, { localGitExecOptions })
const fetchPullRequestHeadRef = (remote: string, prNumber: number): Promise<string> =>
fetchGitHubPullRequestHeadRef(repo, remote, prNumber, {
localGitExecOptions
})
// A paired client's push-target ensure asks unprompted; it must not start a stopped distro (E9).
return resolvePrStartPointUnlessWslStopped(
{ path: repo.path, wslDistro: localGitExecOptions.wslDistro },
{ wakeWslDistro: args.wakeWslDistro },
() =>
resolveGitHubPrStartPoint({
repoPath: repo.path,
prNumber: args.prNumber,
headRefName: args.headRefName,
baseRefName: args.baseRefName,
isCrossRepository: args.isCrossRepository,
issueSourcePreference: repo.issueSourcePreference,
connectionId: null,
localGitOptions: localGhOptions,
gitExec,
fetchRemoteTrackingRef,
fetchPullRequestHeadRef,
resolveRemote
})
)
}