From 9ecf57545e5edbd03ae1484bce5806d0cf7601eb Mon Sep 17 00:00:00 2001 From: Kelvin Amoaba <97001695+AmoabaKelvin@users.noreply.github.com> Date: Sun, 1 Nov 2026 17:51:43 +0000 Subject: [PATCH] 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. --- src/main/github/client.ts | 2 +- src/main/github/client/update/pr-ready.ts | 33 +++++++++++++++++-- .../pr-mutation-review-invalidation.test.ts | 10 ++++++ src/main/ipc/github-ipc-module-mocks.ts | 1 + .../github-pull-request-update-methods.ts | 8 +++++ ...runtime-github-review-mutation-commands.ts | 16 +++++++++ .../runtime/runtime-review-command-surface.ts | 2 ++ .../runtime-rpc-mobile-method-routing.ts | 1 + .../github-pull-request-update-params.ts | 5 +++ .../rpc-params-catalog.generated.ts | 2 ++ .../source-control-runtime-capabilities.ts | 4 +++ 11 files changed, 81 insertions(+), 3 deletions(-) diff --git a/src/main/github/client.ts b/src/main/github/client.ts index ed72bc12232..b7a1d5bc1da 100644 --- a/src/main/github/client.ts +++ b/src/main/github/client.ts @@ -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' diff --git a/src/main/github/client/update/pr-ready.ts b/src/main/github/client/update/pr-ready.ts index f4e745c80f8..30d44eb403d 100644 --- a/src/main/github/client/update/pr-ready.ts +++ b/src/main/github/client/update/pr-ready.ts @@ -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) diff --git a/src/main/github/pr-mutation-review-invalidation.test.ts b/src/main/github/pr-mutation-review-invalidation.test.ts index b00394e5448..bbe00d60b62 100644 --- a/src/main/github/pr-mutation-review-invalidation.test.ts +++ b/src/main/github/pr-mutation-review-invalidation.test.ts @@ -91,6 +91,7 @@ const mutations: { label: string; run: (repo: Repo) => Promise }[] = [ 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)) diff --git a/src/main/ipc/github-ipc-module-mocks.ts b/src/main/ipc/github-ipc-module-mocks.ts index 96905ab9c4d..1a8fcaff65b 100644 --- a/src/main/ipc/github-ipc-module-mocks.ts +++ b/src/main/ipc/github-ipc-module-mocks.ts @@ -29,6 +29,7 @@ const CLIENT_EXPORTS = [ 'setPRAutoMerge', 'updatePRState', 'markPRReadyForReview', + 'markPRDraft', 'rerunPRChecks', 'requestPRReviewers', 'removePRReviewers', diff --git a/src/main/runtime/rpc/methods/github-pull-request-update-methods.ts b/src/main/runtime/rpc/methods/github-pull-request-update-methods.ts index e2fbfa5937e..1643c74bc49 100644 --- a/src/main/runtime/rpc/methods/github-pull-request-update-methods.ts +++ b/src/main/runtime/rpc/methods/github-pull-request-update-methods.ts @@ -1,5 +1,6 @@ import { defineMethod } from '../core' import { + MarkPrDraft, MarkPrReadyForReview, MergePr, PRReviewComment, @@ -66,6 +67,13 @@ export const GITHUB_PULL_REQUEST_UPDATE_METHODS = [ handler: async (params, { runtime }) => runtime.markRepoPRReadyForReview(params.repo, params.prNumber, params.prRepo ?? null) }), + defineMethod({ + name: 'github.markPRDraft', + permission: 'workspace', + params: MarkPrDraft, + handler: async (params, { runtime }) => + runtime.markRepoPRDraft(params.repo, params.prNumber, params.prRepo ?? null) + }), defineMethod({ name: 'github.requestPRReviewers', permission: 'workspace', diff --git a/src/main/runtime/runtime-github-review-mutation-commands.ts b/src/main/runtime/runtime-github-review-mutation-commands.ts index 61390fd39d1..bcbe2c2105f 100644 --- a/src/main/runtime/runtime-github-review-mutation-commands.ts +++ b/src/main/runtime/runtime-github-review-mutation-commands.ts @@ -5,6 +5,7 @@ import type { Repo } from '../../shared/repo-types' import type { LocalProjectGhExecOptions } from '../project-runtime-git-options' import { mergePR, + markPRDraft, markPRReadyForReview, removePRReviewers, requestPRReviewers, @@ -183,6 +184,21 @@ export class RuntimeGitHubReviewMutationCommands { ) } + async markRepoPRDraft( + repoSelector: string, + prNumber: number, + prRepo?: GitHubOwnerRepo | null + ): Promise>> { + 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, diff --git a/src/main/runtime/runtime-review-command-surface.ts b/src/main/runtime/runtime-review-command-surface.ts index bfacc0b4415..42c3f2cba42 100644 --- a/src/main/runtime/runtime-review-command-surface.ts +++ b/src/main/runtime/runtime-review-command-surface.ts @@ -24,6 +24,7 @@ type GitHubReviewMutationName = | 'mergeRepoPR' | 'setRepoPRAutoMerge' | 'markRepoPRReadyForReview' + | 'markRepoPRDraft' | 'updateRepoPRState' | 'requestRepoPRReviewers' | 'removeRepoPRReviewers' @@ -97,6 +98,7 @@ export function installRuntimeReviewCommandSurface( mergeRepoPR: ghm.mergeRepoPR.bind(ghm), setRepoPRAutoMerge: ghm.setRepoPRAutoMerge.bind(ghm), markRepoPRReadyForReview: ghm.markRepoPRReadyForReview.bind(ghm), + markRepoPRDraft: ghm.markRepoPRDraft.bind(ghm), updateRepoPRState: ghm.updateRepoPRState.bind(ghm), requestRepoPRReviewers: ghm.requestRepoPRReviewers.bind(ghm), removeRepoPRReviewers: ghm.removeRepoPRReviewers.bind(ghm), diff --git a/src/main/runtime/runtime-rpc/runtime-rpc-mobile-method-routing.ts b/src/main/runtime/runtime-rpc/runtime-rpc-mobile-method-routing.ts index ea49a2356e0..1db6fd9302d 100644 --- a/src/main/runtime/runtime-rpc/runtime-rpc-mobile-method-routing.ts +++ b/src/main/runtime/runtime-rpc/runtime-rpc-mobile-method-routing.ts @@ -102,6 +102,7 @@ export const EXECUTION_HOST_METHODS = [ 'github.listAssignableUsers', 'github.listLabels', 'github.listWorkItems', + 'github.markPRDraft', 'github.markPRReadyForReview', 'github.mergePR', 'github.prCheckDetails', diff --git a/src/shared/rpc-contract/github-pull-request-update-params.ts b/src/shared/rpc-contract/github-pull-request-update-params.ts index f5fcc38ef73..642b0ce1856 100644 --- a/src/shared/rpc-contract/github-pull-request-update-params.ts +++ b/src/shared/rpc-contract/github-pull-request-update-params.ts @@ -43,6 +43,11 @@ export const MarkPrReadyForReview = RepoSelector.extend({ prRepo: SlugRepo.nullable().optional() }) +export const MarkPrDraft = RepoSelector.extend({ + prNumber: z.number().int().positive(), + prRepo: SlugRepo.nullable().optional() +}) + export const RequestPrReviewers = RepoSelector.extend({ prNumber: z.number().int().positive(), prRepo: SlugRepo.nullable().optional(), diff --git a/src/shared/rpc-contract/rpc-params-catalog.generated.ts b/src/shared/rpc-contract/rpc-params-catalog.generated.ts index bc7cd31e2a6..f15561eae84 100644 --- a/src/shared/rpc-contract/rpc-params-catalog.generated.ts +++ b/src/shared/rpc-contract/rpc-params-catalog.generated.ts @@ -313,6 +313,7 @@ import { ReviewThread } from './github-pull-request-params' import { + MarkPrDraft, MarkPrReadyForReview, MergePr, PRReviewComment, @@ -1073,6 +1074,7 @@ export const RPC_PARAMS_BY_METHOD = { 'github.listIssues': IssuesList, 'github.listLabels': RepoSelector, 'github.listWorkItems': WorkItemsList, + 'github.markPRDraft': MarkPrDraft, 'github.markPRReadyForReview': MarkPrReadyForReview, 'github.mergePR': MergePr, 'github.prCheckDetails': PullRequestCheckDetails, diff --git a/src/shared/source-control-runtime-capabilities.ts b/src/shared/source-control-runtime-capabilities.ts index bbccf6fa9b3..0ad4fad1e7b 100644 --- a/src/shared/source-control-runtime-capabilities.ts +++ b/src/shared/source-control-runtime-capabilities.ts @@ -2,6 +2,9 @@ export const GITHUB_MARK_PR_READY_RUNTIME_CAPABILITY = 'github.markPRReadyForRev // Hosts with this capability let mobile call github.markPRReadyForReview. export const MOBILE_GITHUB_MARK_PR_READY_RUNTIME_CAPABILITY = 'mobile.github.markPRReadyForReview.v1' as const +// Hosts with this capability let mobile call github.markPRDraft; older hosts hide Mark as draft. +export const MOBILE_GITHUB_MARK_PR_DRAFT_RUNTIME_CAPABILITY = + 'mobile.github.markPRDraft.v1' as const export const GITHUB_MARK_PR_READY_UPDATE_REQUIRED_MESSAGE = 'Marking a pull request ready requires a newer Orca server. Update the server and try again.' export const GITLAB_READY_FOR_REVIEW_RUNTIME_CAPABILITY = @@ -16,5 +19,6 @@ export const SOURCE_CONTROL_RUNTIME_CAPABILITIES = [ ANTIGRAVITY_CONFIGURED_MODEL_RUNTIME_CAPABILITY, GITHUB_MARK_PR_READY_RUNTIME_CAPABILITY, MOBILE_GITHUB_MARK_PR_READY_RUNTIME_CAPABILITY, + MOBILE_GITHUB_MARK_PR_DRAFT_RUNTIME_CAPABILITY, GITLAB_READY_FOR_REVIEW_RUNTIME_CAPABILITY ] as const