mirror of
https://github.com/stablyai/orca.git
synced 2026-11-18 20:06:10 +00:00
feat(github): let mobile turn a pull request back into a draft (#37000)
Adds github.markPRDraft (gh pr ready --undo) on the host, allowlisted for paired phones and advertised with mobile.github.markPRDraft.v1 so older hosts simply hide the action.
This commit is contained in:
@@ -37,7 +37,7 @@ export { setPRAutoMerge } from './client/merge/pr-auto-merge'
|
||||
export { setPRCommentReaction } from './client/update/pr-comment-reaction'
|
||||
export { setPRFileViewed } from './client/update/pr-file-viewed'
|
||||
export { updatePRDetails, updatePRTitle } from './client/update/pr-details'
|
||||
export { markPRReadyForReview } from './client/update/pr-ready'
|
||||
export { markPRDraft, markPRReadyForReview } from './client/update/pr-ready'
|
||||
export { updatePRState } from './client/update/pr-state'
|
||||
export type { GitHubPRBranchLookupOptions } from './client/lookup/pull-request-lookup-data'
|
||||
export type { MainWorkItem } from './client/map/work-item-field-coercion'
|
||||
|
||||
@@ -9,12 +9,34 @@ import {
|
||||
import { resolveGitHubRepoExecution, type GitHubApiRepository } from '../../github-api-repository'
|
||||
import { codeHostFailure, classifiedFailure } from '../../../../shared/code-host-failure-copy'
|
||||
|
||||
export async function markPRReadyForReview(
|
||||
export function markPRReadyForReview(
|
||||
repoPath: string,
|
||||
prNumber: number,
|
||||
connectionId?: string | null,
|
||||
prRepo?: GitHubApiRepository | null,
|
||||
localGitOptions: LocalGitExecOptions = {}
|
||||
): Promise<{ ok: true } | { ok: false; error: string }> {
|
||||
return setPRReadyState(repoPath, prNumber, true, connectionId, prRepo, localGitOptions)
|
||||
}
|
||||
|
||||
// `gh pr ready --undo` turns an open pull request back into a draft.
|
||||
export function markPRDraft(
|
||||
repoPath: string,
|
||||
prNumber: number,
|
||||
connectionId?: string | null,
|
||||
prRepo?: GitHubApiRepository | null,
|
||||
localGitOptions: LocalGitExecOptions = {}
|
||||
): Promise<{ ok: true } | { ok: false; error: string }> {
|
||||
return setPRReadyState(repoPath, prNumber, false, connectionId, prRepo, localGitOptions)
|
||||
}
|
||||
|
||||
async function setPRReadyState(
|
||||
repoPath: string,
|
||||
prNumber: number,
|
||||
ready: boolean,
|
||||
connectionId?: string | null,
|
||||
prRepo?: GitHubApiRepository | null,
|
||||
localGitOptions: LocalGitExecOptions = {}
|
||||
): Promise<{ ok: true } | { ok: false; error: string }> {
|
||||
const { ownerRepo, ghOptions } = await resolveGitHubRepoExecution(
|
||||
repoPath,
|
||||
@@ -29,7 +51,14 @@ export async function markPRReadyForReview(
|
||||
await acquire()
|
||||
try {
|
||||
await ghExecFileAsync(
|
||||
['pr', 'ready', String(prNumber), '--repo', `${ownerRepo.owner}/${ownerRepo.repo}`],
|
||||
[
|
||||
'pr',
|
||||
'ready',
|
||||
String(prNumber),
|
||||
'--repo',
|
||||
`${ownerRepo.owner}/${ownerRepo.repo}`,
|
||||
...(ready ? [] : ['--undo'])
|
||||
],
|
||||
ghOptions
|
||||
)
|
||||
invalidateReviewLookupsAfterPRMutation(repoPath, connectionId)
|
||||
|
||||
@@ -91,6 +91,7 @@ const mutations: { label: string; run: (repo: Repo) => Promise<unknown> }[] = [
|
||||
run: (repo) => runtime.updateRepoPRState(repo.id, 7, { state: 'open' })
|
||||
},
|
||||
{ label: 'RPC ready', run: (repo) => runtime.markRepoPRReadyForReview(repo.id, 7) },
|
||||
{ label: 'RPC draft', run: (repo) => runtime.markRepoPRDraft(repo.id, 7) },
|
||||
{ label: 'RPC details', run: (repo) => runtime.updateRepoPRDetails(repo.id, 7, { body: 'B' }) },
|
||||
{ label: 'RPC reviewers', run: (repo) => runtime.removeRepoPRReviewers(repo.id, 7, ['octo']) }
|
||||
]
|
||||
@@ -141,6 +142,15 @@ describe('PR mutation review-lookup fencing', () => {
|
||||
expect(mocks.resolve).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('turns a PR back into a draft with gh pr ready --undo', async () => {
|
||||
await runtime.markRepoPRDraft(local.id, 7)
|
||||
expect(mocks.exec.mock.calls[0]?.[0]).toEqual(
|
||||
expect.arrayContaining(['pr', 'ready', '7', '--undo'])
|
||||
)
|
||||
await runtime.markRepoPRReadyForReview(local.id, 7)
|
||||
expect(mocks.exec.mock.calls[1]?.[0]).not.toContain('--undo')
|
||||
})
|
||||
|
||||
it('fences only the host that ran the mutation', async () => {
|
||||
const heldLocal = holdLookup(local)
|
||||
await vi.waitFor(() => expect(mocks.resolve).toHaveBeenCalledTimes(1))
|
||||
|
||||
Reference in New Issue
Block a user