refactor(runtime): group integration commands by concrete owner (#38504)

This commit is contained in:
Neil
2026-11-05 02:43:31 -08:00
committed by GitHub
parent 63f997c332
commit 99b1b81feb
93 changed files with 820 additions and 733 deletions
@@ -0,0 +1,124 @@
import '../../../github/rate-limit'
import type {
GitHubCreateIssueFields,
GitHubIssueUpdate
} from '../../../../shared/issue-mutation-types'
import type { GitHubOwnerRepo } from '../../../../shared/github/pull-request-types'
import type { GitHubPRReviewCommentInput } from '../../../../shared/github/comment-types'
import type { Repo } from '../../../../shared/repo-types'
import type { LocalProjectGhExecOptions } from '../../../workspaces/execution-host/project-runtime-git-options'
import { addIssueComment } from '../../../github/issue-comment'
import {
addPRReviewComment,
addPRReviewCommentReply
} from '../../../github/client/create/add-pr-review-comment'
import { createIssue } from '../../../github/issue-create'
import { updateIssue } from '../../../github/issue-update'
import { getRepoRoutingConnectionId } from '../../../../shared/execution-host'
type LocalGitArgs = [] | [LocalProjectGhExecOptions]
type RuntimeGitHubIssueCommentCommandsDeps = {
resolveRepo: (selector: string) => Promise<Repo>
getLocalGitArgs: (repo: Repo) => LocalGitArgs
}
export class RuntimeGitHubIssueCommentCommands {
constructor(private readonly deps: RuntimeGitHubIssueCommentCommandsDeps) {}
async createRepoIssue(
repoSelector: string,
title: string,
body: string,
fields?: GitHubCreateIssueFields
): Promise<Awaited<ReturnType<typeof createIssue>>> {
const repo = await this.deps.resolveRepo(repoSelector)
return createIssue(
repo.path,
title,
body,
repo.issueSourcePreference,
getRepoRoutingConnectionId(repo),
fields,
...this.deps.getLocalGitArgs(repo)
)
}
async updateRepoIssue(
repoSelector: string,
number: number,
updates: GitHubIssueUpdate,
ownerRepo?: GitHubOwnerRepo
): Promise<Awaited<ReturnType<typeof updateIssue>>> {
const repo = await this.deps.resolveRepo(repoSelector)
return updateIssue(
repo.path,
number,
updates,
getRepoRoutingConnectionId(repo),
this.deps.getLocalGitArgs(repo)[0],
repo.issueSourcePreference,
...(ownerRepo ? ([ownerRepo] as const) : ([] as const))
)
}
async addRepoIssueComment(
repoSelector: string,
number: number,
body: string,
prRepo?: GitHubOwnerRepo | null,
type?: 'issue' | 'pr'
): Promise<Awaited<ReturnType<typeof addIssueComment>>> {
const repo = await this.deps.resolveRepo(repoSelector)
return addIssueComment(
repo.path,
number,
body,
getRepoRoutingConnectionId(repo),
prRepo ?? null,
this.deps.getLocalGitArgs(repo)[0],
// Why: the issue source selector only scopes issues; PR comments keep their resolution.
type === 'pr' ? undefined : repo.issueSourcePreference
)
}
async addRepoPRReviewComment(
repoSelector: string,
args: Omit<GitHubPRReviewCommentInput, 'repoPath'>
): Promise<Awaited<ReturnType<typeof addPRReviewComment>>> {
const repo = await this.deps.resolveRepo(repoSelector)
return addPRReviewComment({
repoPath: repo.path,
connectionId: getRepoRoutingConnectionId(repo),
localGitOptions: this.deps.getLocalGitArgs(repo)[0],
...args
})
}
async addRepoPRReviewCommentReply(
repoSelector: string,
args: {
prNumber: number
commentId: number
body: string
threadId?: string
path?: string
line?: number
prRepo?: GitHubOwnerRepo | null
}
): Promise<Awaited<ReturnType<typeof addPRReviewCommentReply>>> {
const repo = await this.deps.resolveRepo(repoSelector)
return addPRReviewCommentReply(
repo.path,
args.prNumber,
args.commentId,
args.body,
args.threadId,
args.path,
args.line,
getRepoRoutingConnectionId(repo),
args.prRepo ?? null,
...this.deps.getLocalGitArgs(repo)
)
}
}
@@ -0,0 +1,91 @@
import {
addIssueCommentBySlug,
deleteIssueCommentBySlug,
updateIssueCommentBySlug
} from '../../../github/project-view/issue-comment-mutations'
import {
clearProjectItemFieldValue,
updateProjectItemFieldValue
} from '../../../github/project-view/project-field-mutations'
import { getProjectViewTable } from '../../../github/project-view/project-view-table'
import { getWorkItemDetailsBySlug } from '../../../github/project-view/work-item-details'
import { listAccessibleProjects } from '../../../github/project-view/project-view-discovery'
import {
listAssignableUsersBySlug,
listIssueTypesBySlug,
listLabelsBySlug
} from '../../../github/project-view/repository-field-options'
import { listProjectViews } from '../../../github/project-view/project-view-listing'
import { resolveProjectRef } from '../../../github/project-view/project-view-reference'
import { updateIssueBySlug } from '../../../github/project-view/mutations'
import { updateIssueTypeBySlug } from '../../../github/project-view/issue-type-mutation'
import { updatePullRequestBySlug } from '../../../github/project-view/pull-request-mutation'
import type {
AddIssueCommentBySlugArgs,
ClearProjectItemFieldArgs,
DeleteIssueCommentBySlugArgs,
GetProjectViewTableArgs,
ListAccessibleProjectsArgs,
ListAssignableUsersBySlugArgs,
ListIssueTypesBySlugArgs,
ListLabelsBySlugArgs,
ListProjectViewsArgs,
ProjectWorkItemDetailsBySlugArgs,
ResolveProjectRefArgs,
UpdateIssueBySlugArgs,
UpdateIssueCommentBySlugArgs,
UpdateIssueTypeBySlugArgs,
UpdateProjectItemFieldArgs,
UpdatePullRequestBySlugArgs
} from '../../../../shared/github/project-request-types'
export class RuntimeGitHubProjectCommands {
listGitHubProjects(args?: ListAccessibleProjectsArgs) {
return listAccessibleProjects(args)
}
listGitHubLabelsBySlug(args: ListLabelsBySlugArgs) {
return listLabelsBySlug(args)
}
listGitHubAssignableUsersBySlug(args: ListAssignableUsersBySlugArgs) {
return listAssignableUsersBySlug(args)
}
listGitHubIssueTypesBySlug(args: ListIssueTypesBySlugArgs) {
return listIssueTypesBySlug(args)
}
resolveGitHubProjectRef(args: ResolveProjectRefArgs) {
return resolveProjectRef(args)
}
listGitHubProjectViews(args: ListProjectViewsArgs) {
return listProjectViews(args)
}
getGitHubProjectViewTable(args: GetProjectViewTableArgs) {
return getProjectViewTable(args)
}
getGitHubProjectWorkItemDetailsBySlug(args: ProjectWorkItemDetailsBySlugArgs) {
return getWorkItemDetailsBySlug(args)
}
updateGitHubProjectItemField(args: UpdateProjectItemFieldArgs) {
return updateProjectItemFieldValue(args)
}
clearGitHubProjectItemField(args: ClearProjectItemFieldArgs) {
return clearProjectItemFieldValue(args)
}
updateGitHubIssueBySlug(args: UpdateIssueBySlugArgs) {
return updateIssueBySlug(args)
}
updateGitHubPullRequestBySlug(args: UpdatePullRequestBySlugArgs) {
return updatePullRequestBySlug(args)
}
updateGitHubIssueTypeBySlug(args: UpdateIssueTypeBySlugArgs) {
return updateIssueTypeBySlug(args)
}
addGitHubIssueCommentBySlug(args: AddIssueCommentBySlugArgs) {
return addIssueCommentBySlug(args)
}
updateGitHubIssueCommentBySlug(args: UpdateIssueCommentBySlugArgs) {
return updateIssueCommentBySlug(args)
}
deleteGitHubIssueCommentBySlug(args: DeleteIssueCommentBySlugArgs) {
return deleteIssueCommentBySlug(args)
}
}
@@ -0,0 +1,109 @@
import '../../rpc/unused-default-rpc-methods.test-fixture'
import type * as GitHubClient from '../../../github/client'
import { describe, expect, it, vi } from 'vitest'
import { RpcDispatcher } from '../../rpc/dispatcher'
import { GITHUB_REPO_WORK_ITEM_METHODS } from '../../rpc/methods/github-repo-work-item-methods'
import { RuntimeGitHubRepositoryQueryCommands } from './runtime-github-repository-query-commands'
import { OrcaRuntimeService } from '../../orca-runtime'
import type { Repo } from '../../../../shared/repo-types'
import {
WorkItemDetails,
WorkItem
} from '../../../../shared/rpc-contract/github-repo-work-item-params'
import { RPC_PARAMS_BY_METHOD } from '../../../../shared/rpc-contract/rpc-params-catalog.generated'
const { read } = vi.hoisted(() => ({ read: vi.fn().mockResolvedValue(null) }))
vi.mock('../../../github/work-item-details', () => ({ getWorkItemDetails: read }))
vi.mock('../../../github/client', async (original) => ({
...(await original<typeof GitHubClient>()),
countWorkItems: vi.fn(),
getWorkItem: vi.fn(),
getWorkItemByOwnerRepo: vi.fn(),
listAssignableUsers: vi.fn(),
listIssues: vi.fn(),
listLabels: vi.fn(),
listWorkItems: vi.fn()
}))
vi.mock('../../../github/gh-account-binding-inventory', () => ({
listGhAccountBindingInventory: vi.fn(),
validateGhAccountBinding: vi.fn()
}))
vi.mock('../../../github/rate-limit', () => ({ getRateLimit: vi.fn() }))
vi.mock('../../../github/account-binding-required-host', () => ({
resolveGhAccountRequiredHost: vi.fn()
}))
describe('registered direct details transport', () => {
it.each([
{ ownerRepo: undefined, canonical: undefined },
{
ownerRepo: { owner: 'fork', repo: 'widgets', host: 'github.enterprise.test' },
canonical: undefined
},
{
ownerRepo: { owner: 'fork', repo: 'widgets', host: 'github.enterprise.test' },
canonical: false
},
{
ownerRepo: { owner: 'fork', repo: 'widgets', host: 'github.enterprise.test' },
canonical: true
}
])(
'passes old and canonical payloads through the real schema, catalog, dispatcher and registered execution: %j',
async ({ ownerRepo, canonical }) => {
read.mockClear()
const repo: Repo = {
id: 'registered',
path: '/registered/folder',
kind: 'folder',
displayName: 'folder',
badgeColor: '',
addedAt: 0,
connectionId: 'ssh-target',
issueSourcePreference: 'upstream',
ghAccount: { host: 'github.enterprise.test', user: 'Alice' }
}
const options = { ghAccount: repo.ghAccount, wslDistro: 'Ubuntu-fixture' }
const commands = new RuntimeGitHubRepositoryQueryCommands({
resolveRepo: async (selector) => {
expect(selector).toBe('id:registered')
return repo
},
getLocalGitArgs: () => [options]
})
const runtime = new OrcaRuntimeService()
vi.spyOn(runtime, 'getRuntimeId').mockReturnValue('runtime')
vi.spyOn(runtime, 'getRepoWorkItemDetails').mockImplementation(
commands.getRepoWorkItemDetails.bind(commands)
)
const dispatcher = new RpcDispatcher({ runtime, methods: GITHUB_REPO_WORK_ITEM_METHODS })
const payload = {
repo: 'id:registered',
number: 5,
type: 'issue',
...(ownerRepo ? { ownerRepo } : {}),
...(canonical !== undefined ? { canonical } : {})
}
expect(WorkItemDetails.parse(payload)).toEqual(payload)
expect(RPC_PARAMS_BY_METHOD['github.workItemDetails'].parse(payload)).toEqual(payload)
expect(WorkItem.parse(payload)).toEqual({ repo: 'id:registered', number: 5, type: 'issue' })
expect(
await dispatcher.dispatch({
id: 'read',
authToken: 'fixture',
method: 'github.workItemDetails',
params: payload
})
).toMatchObject({ ok: true, result: null })
expect(read).toHaveBeenCalledExactlyOnceWith(
repo.path,
5,
'issue',
'ssh-target',
options,
'upstream',
ownerRepo,
canonical === true
)
}
)
})
@@ -0,0 +1,228 @@
import type { GhAccountBinding } from '../../../../shared/github/account-binding'
import type { GitHubOwnerRepo } from '../../../../shared/github/pull-request-types'
import type { ListWorkItemsResult } from '../../../../shared/github/work-item-types'
import type { Repo } from '../../../../shared/repo-types'
import type { LocalProjectGhExecOptions } from '../../../workspaces/execution-host/project-runtime-git-options'
import { countWorkItems } from '../../../github/client/list/count-work-items'
import { getWorkItem, getWorkItemByOwnerRepo } from '../../../github/client/fetch/get-work-item'
import { listAssignableUsers, listLabels } from '../../../github/issue-field-options'
import { listIssues } from '../../../github/issues'
import { listWorkItems } from '../../../github/client/list/list-work-items'
import type { MainWorkItem } from '../../../github/client/map/work-item-field-coercion'
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'
import { getRepoRoutingConnectionId } from '../../../../shared/execution-host'
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,
getRepoRoutingConnectionId(repo),
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,
getRepoRoutingConnectionId(repo),
...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,
getRepoRoutingConnectionId(repo),
this.deps.getLocalGitArgs(repo)[0] ?? {},
repo.issueSourcePreference
)
}
async getRepoWorkItemByOwnerRepo(
repoSelector: string,
ownerRepo: { owner: string; repo: string; host?: string },
number: number,
type: 'issue' | 'pr',
options: { preview?: boolean } = {}
): Promise<Awaited<ReturnType<typeof getWorkItemByOwnerRepo>>> {
const repo = await this.deps.resolveRepo(repoSelector)
return getWorkItemByOwnerRepo(
repo.path,
ownerRepo,
number,
type,
getRepoRoutingConnectionId(repo),
this.deps.getLocalGitArgs(repo)[0],
options
)
}
async getRepoWorkItemDetails(
repoSelector: string,
number: number,
type?: 'issue' | 'pr',
ownerRepo?: GitHubOwnerRepo,
canonical?: boolean,
expectedGhAccount?: GhAccountBinding | null
): Promise<Awaited<ReturnType<typeof getWorkItemDetails>>> {
const repo = await this.deps.resolveRepo(repoSelector)
const args = [
repo.path,
number,
type,
getRepoRoutingConnectionId(repo),
this.deps.getLocalGitArgs(repo)[0] ?? {},
repo.issueSourcePreference,
ownerRepo,
canonical === true
] as const
return expectedGhAccount === undefined
? getWorkItemDetails(...args)
: getWorkItemDetails(...args, expectedGhAccount)
}
async countRepoWorkItems(repoSelector: string, query?: string): Promise<number> {
const repo = await this.deps.resolveRepo(repoSelector)
return countWorkItems(
repo.path,
query,
repo.issueSourcePreference,
getRepoRoutingConnectionId(repo),
...this.deps.getLocalGitArgs(repo)
)
}
async listRepoLabels(
repoSelector: string,
ownerRepo?: GitHubOwnerRepo,
expectedGhAccount?: GhAccountBinding | null
): Promise<Awaited<ReturnType<typeof listLabels>>> {
const repo = await this.deps.resolveRepo(repoSelector)
if (expectedGhAccount !== undefined) {
return listLabels(
repo.path,
repo.issueSourcePreference,
getRepoRoutingConnectionId(repo),
this.deps.getLocalGitArgs(repo)[0] ?? {},
ownerRepo,
expectedGhAccount
)
}
return ownerRepo
? listLabels(
repo.path,
repo.issueSourcePreference,
getRepoRoutingConnectionId(repo),
this.deps.getLocalGitArgs(repo)[0] ?? {},
ownerRepo
)
: listLabels(
repo.path,
repo.issueSourcePreference,
getRepoRoutingConnectionId(repo),
...this.deps.getLocalGitArgs(repo)
)
}
async listRepoAssignableUsers(
repoSelector: string,
ownerRepo?: GitHubOwnerRepo,
expectedGhAccount?: GhAccountBinding | null
): Promise<Awaited<ReturnType<typeof listAssignableUsers>>> {
const repo = await this.deps.resolveRepo(repoSelector)
if (expectedGhAccount !== undefined) {
return listAssignableUsers(
repo.path,
repo.issueSourcePreference,
getRepoRoutingConnectionId(repo),
this.deps.getLocalGitArgs(repo)[0] ?? {},
ownerRepo,
expectedGhAccount
)
}
return ownerRepo
? listAssignableUsers(
repo.path,
repo.issueSourcePreference,
getRepoRoutingConnectionId(repo),
this.deps.getLocalGitArgs(repo)[0] ?? {},
ownerRepo
)
: listAssignableUsers(
repo.path,
repo.issueSourcePreference,
getRepoRoutingConnectionId(repo),
...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 } : {})
}
}
@@ -0,0 +1,249 @@
import type { GhAccountBinding } from '../../../../shared/github/account-binding'
import type { GitHubOwnerRepo } from '../../../../shared/github/pull-request-types'
import type { GitHubPullRequestStateUpdate } from '../../../../shared/issue-mutation-types'
import type { GitHubReactionContent } from '../../../../shared/github/comment-types'
import type { Repo } from '../../../../shared/repo-types'
import type { LocalProjectGhExecOptions } from '../../../workspaces/execution-host/project-runtime-git-options'
import { mergePR } from '../../../github/client/merge/merge-pr'
import { markPRDraft, markPRReadyForReview } from '../../../github/client/update/pr-ready'
import { removePRReviewers, requestPRReviewers } from '../../../github/client/update/pr-reviewers'
import { rerunPRChecks } from '../../../github/client/check/rerun-pr-checks'
import { resolveReviewThread } from '../../../github/client/update/resolve-review-thread'
import { setPRAutoMerge } from '../../../github/client/merge/pr-auto-merge'
import { setPRCommentReaction } from '../../../github/client/update/pr-comment-reaction'
import { setPRFileViewed } from '../../../github/client/update/pr-file-viewed'
import { updatePRDetails, updatePRTitle } from '../../../github/client/update/pr-details'
import { updatePRState } from '../../../github/client/update/pr-state'
import { getRepoRoutingConnectionId } from '../../../../shared/execution-host'
type LocalGitArgs = [] | [LocalProjectGhExecOptions]
type RuntimeGitHubReviewMutationCommandsDeps = {
resolveRepo: (selector: string) => Promise<Repo>
getLocalGitArgs: (repo: Repo) => LocalGitArgs
}
export class RuntimeGitHubReviewMutationCommands {
constructor(private readonly deps: RuntimeGitHubReviewMutationCommandsDeps) {}
async rerunRepoPRChecks(
repoSelector: string,
prNumber: number,
options?: { headSha?: string; failedOnly?: boolean; prRepo?: GitHubOwnerRepo | null }
): Promise<Awaited<ReturnType<typeof rerunPRChecks>>> {
const repo = await this.deps.resolveRepo(repoSelector)
return rerunPRChecks(
repo.path,
prNumber,
options,
getRepoRoutingConnectionId(repo),
...this.deps.getLocalGitArgs(repo)
)
}
async setRepoPRCommentReaction(
repoSelector: string,
reactionSubjectId: string,
content: GitHubReactionContent,
reacted: boolean,
prRepo?: GitHubOwnerRepo | null
): Promise<Awaited<ReturnType<typeof setPRCommentReaction>>> {
const repo = await this.deps.resolveRepo(repoSelector)
return setPRCommentReaction(
repo.path,
reactionSubjectId,
content,
reacted,
getRepoRoutingConnectionId(repo),
prRepo ?? null,
...this.deps.getLocalGitArgs(repo)
)
}
async resolveRepoReviewThread(
repoSelector: string,
threadId: string,
resolve: boolean,
prRepo?: GitHubOwnerRepo | null
): Promise<Awaited<ReturnType<typeof resolveReviewThread>>> {
const repo = await this.deps.resolveRepo(repoSelector)
return resolveReviewThread(
repo.path,
threadId,
resolve,
getRepoRoutingConnectionId(repo),
prRepo ?? null,
...this.deps.getLocalGitArgs(repo)
)
}
async setRepoPRFileViewed(
repoSelector: string,
args: {
prRepo?: GitHubOwnerRepo | null
pullRequestId: string
path: string
viewed: boolean
expectedGhAccount?: GhAccountBinding | null
}
): Promise<Awaited<ReturnType<typeof setPRFileViewed>>> {
const repo = await this.deps.resolveRepo(repoSelector)
return setPRFileViewed({
repoPath: repo.path,
connectionId: getRepoRoutingConnectionId(repo),
localGitOptions: this.deps.getLocalGitArgs(repo)[0],
...args
})
}
async updateRepoPRTitle(
repoSelector: string,
prNumber: number,
title: string,
prRepo?: GitHubOwnerRepo | null
): Promise<Awaited<ReturnType<typeof updatePRTitle>>> {
const repo = await this.deps.resolveRepo(repoSelector)
return updatePRTitle(
repo.path,
prNumber,
title,
getRepoRoutingConnectionId(repo),
prRepo ?? null,
...this.deps.getLocalGitArgs(repo)
)
}
async updateRepoPRDetails(
repoSelector: string,
prNumber: number,
updates: { title?: string; body?: string },
prRepo?: GitHubOwnerRepo | null
): Promise<Awaited<ReturnType<typeof updatePRDetails>>> {
const repo = await this.deps.resolveRepo(repoSelector)
return updatePRDetails(
repo.path,
prNumber,
updates,
getRepoRoutingConnectionId(repo),
prRepo ?? null,
...this.deps.getLocalGitArgs(repo)
)
}
async mergeRepoPR(
repoSelector: string,
prNumber: number,
method?: 'merge' | 'squash' | 'rebase',
prRepo?: GitHubOwnerRepo | null
): Promise<Awaited<ReturnType<typeof mergePR>>> {
const repo = await this.deps.resolveRepo(repoSelector)
return mergePR(
repo.path,
prNumber,
method,
getRepoRoutingConnectionId(repo),
prRepo ?? null,
...this.deps.getLocalGitArgs(repo)
)
}
async setRepoPRAutoMerge(
repoSelector: string,
prNumber: number,
enabled: boolean,
method?: 'merge' | 'squash' | 'rebase',
prRepo?: GitHubOwnerRepo | null
): Promise<Awaited<ReturnType<typeof setPRAutoMerge>>> {
const repo = await this.deps.resolveRepo(repoSelector)
return setPRAutoMerge(
repo.path,
prNumber,
enabled,
method,
getRepoRoutingConnectionId(repo),
prRepo ?? null,
...this.deps.getLocalGitArgs(repo)
)
}
async markRepoPRReadyForReview(
repoSelector: string,
prNumber: number,
prRepo?: GitHubOwnerRepo | null
): Promise<Awaited<ReturnType<typeof markPRReadyForReview>>> {
const repo = await this.deps.resolveRepo(repoSelector)
return markPRReadyForReview(
repo.path,
prNumber,
getRepoRoutingConnectionId(repo),
prRepo ?? null,
...this.deps.getLocalGitArgs(repo)
)
}
async markRepoPRDraft(
repoSelector: string,
prNumber: number,
prRepo?: GitHubOwnerRepo | null
): Promise<Awaited<ReturnType<typeof markPRDraft>>> {
const repo = await this.deps.resolveRepo(repoSelector)
return markPRDraft(
repo.path,
prNumber,
getRepoRoutingConnectionId(repo),
prRepo ?? null,
...this.deps.getLocalGitArgs(repo)
)
}
async updateRepoPRState(
repoSelector: string,
prNumber: number,
updates: GitHubPullRequestStateUpdate,
prRepo?: GitHubOwnerRepo | null
): Promise<Awaited<ReturnType<typeof updatePRState>>> {
const repo = await this.deps.resolveRepo(repoSelector)
return updatePRState(
repo.path,
prNumber,
updates,
getRepoRoutingConnectionId(repo),
prRepo ?? null,
...this.deps.getLocalGitArgs(repo)
)
}
async requestRepoPRReviewers(
repoSelector: string,
prNumber: number,
reviewers: string[],
prRepo?: GitHubOwnerRepo | null
): Promise<Awaited<ReturnType<typeof requestPRReviewers>>> {
const repo = await this.deps.resolveRepo(repoSelector)
return requestPRReviewers(
repo.path,
prNumber,
reviewers,
getRepoRoutingConnectionId(repo),
prRepo ?? null,
...this.deps.getLocalGitArgs(repo)
)
}
async removeRepoPRReviewers(
repoSelector: string,
prNumber: number,
reviewers: string[],
prRepo?: GitHubOwnerRepo | null
): Promise<Awaited<ReturnType<typeof removePRReviewers>>> {
const repo = await this.deps.resolveRepo(repoSelector)
return removePRReviewers(
repo.path,
prNumber,
reviewers,
getRepoRoutingConnectionId(repo),
prRepo ?? null,
...this.deps.getLocalGitArgs(repo)
)
}
}
@@ -0,0 +1,111 @@
import type { GitHubOwnerRepo, GitHubPRFile } from '../../../../shared/github/pull-request-types'
import type { Repo } from '../../../../shared/repo-types'
import type { LocalProjectGhExecOptions } from '../../../workspaces/execution-host/project-runtime-git-options'
import { getIssue } from '../../../github/issues'
import { getPRCheckDetails } from '../../../github/client/check/get-pr-check-details'
import { getPRChecks } from '../../../github/client/check/get-pr-checks'
import { getPRComments } from '../../../github/client/fetch/get-pr-comments'
import { getPRFileContents } from '../../../github/work-item-details'
import { getRepoRoutingConnectionId } from '../../../../shared/execution-host'
type LocalGitArgs = [] | [LocalProjectGhExecOptions]
type RuntimeGitHubReviewQueryCommandsDeps = {
resolveRepo: (selector: string) => Promise<Repo>
getLocalGitArgs: (repo: Repo) => LocalGitArgs
}
export class RuntimeGitHubReviewQueryCommands {
constructor(private readonly deps: RuntimeGitHubReviewQueryCommandsDeps) {}
async getRepoIssue(
repoSelector: string,
number: number
): Promise<Awaited<ReturnType<typeof getIssue>>> {
const repo = await this.deps.resolveRepo(repoSelector)
return getIssue(
repo.path,
number,
getRepoRoutingConnectionId(repo),
...this.deps.getLocalGitArgs(repo)
)
}
async getRepoPRChecks(
repoSelector: string,
prNumber: number,
headSha?: string,
prRepo?: GitHubOwnerRepo | null,
options?: { noCache?: boolean; userRefresh?: boolean }
): Promise<Awaited<ReturnType<typeof getPRChecks>>> {
const repo = await this.deps.resolveRepo(repoSelector)
return getPRChecks(
repo.path,
prNumber,
headSha,
prRepo ?? null,
options,
getRepoRoutingConnectionId(repo),
...this.deps.getLocalGitArgs(repo)
)
}
async getRepoPRCheckDetails(
repoSelector: string,
args: {
checkRunId?: number
workflowRunId?: number
checkName?: string
url?: string | null
prRepo?: GitHubOwnerRepo | null
},
signal?: AbortSignal
): Promise<Awaited<ReturnType<typeof getPRCheckDetails>>> {
const repo = await this.deps.resolveRepo(repoSelector)
const localGitOptions = this.deps.getLocalGitArgs(repo)[0] ?? {}
return getPRCheckDetails(
repo.path,
{ ...args, prRepo: args.prRepo ?? null },
getRepoRoutingConnectionId(repo),
localGitOptions,
signal
)
}
async getRepoPRComments(
repoSelector: string,
prNumber: number,
prRepo?: GitHubOwnerRepo | null,
options?: { noCache?: boolean }
): Promise<Awaited<ReturnType<typeof getPRComments>>> {
const repo = await this.deps.resolveRepo(repoSelector)
return getPRComments(
repo.path,
prNumber,
{ ...options, prRepo: prRepo ?? null },
getRepoRoutingConnectionId(repo),
...this.deps.getLocalGitArgs(repo)
)
}
async getRepoPRFileContents(
repoSelector: string,
args: {
prNumber: number
prRepo?: GitHubOwnerRepo | null
path: string
oldPath?: string
status: GitHubPRFile['status']
headSha: string
baseSha: string
}
): Promise<Awaited<ReturnType<typeof getPRFileContents>>> {
const repo = await this.deps.resolveRepo(repoSelector)
return getPRFileContents({
repoPath: repo.path,
connectionId: getRepoRoutingConnectionId(repo),
localGitOptions: this.deps.getLocalGitArgs(repo)[0],
...args
})
}
}
@@ -0,0 +1,88 @@
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/command-runner/git-exec-file'
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
})
)
}