diff --git a/.changeset/review-edit-action.md b/.changeset/review-edit-action.md new file mode 100644 index 00000000..730b8c3b --- /dev/null +++ b/.changeset/review-edit-action.md @@ -0,0 +1,8 @@ +--- +"gcb-core": patch +"gcb-client": patch +"gcb-host": patch +--- + +Add `pr:review-edit --body`: update the body of an existing pull request review +through the fixed `PUT /repos/{owner}/{repo}/pulls/{pull_number}/reviews/{review_id}` endpoint. diff --git a/README.md b/README.md index b5f05114..b11a19e0 100644 --- a/README.md +++ b/README.md @@ -895,6 +895,7 @@ actions. Grant them on the App, then approve any changed permissions on each ins | `pr comment-edit` | `pull_requests: write` | | `pr comment-delete` | `pull_requests: write` | | `pr review` | `pull_requests: write` | +| `pr review-edit` | `pull_requests: write` | | `pr review --id` (`pr:review-by-id`) | `pull_requests: read` | | `discussion create` | `discussions: write` | | `discussion edit` | `discussions: write` | diff --git a/packages/core/src/actions.ts b/packages/core/src/actions.ts index 2a84d5e0..2f84bc8b 100644 --- a/packages/core/src/actions.ts +++ b/packages/core/src/actions.ts @@ -48,7 +48,7 @@ export interface FlagSpec { /** A fixed `gh api` request, with only typed values substituted. */ export interface ApiSpec { - readonly method: 'GET' | 'PATCH' | 'DELETE' + readonly method: 'GET' | 'PATCH' | 'PUT' | 'DELETE' readonly endpoint: string /** When true, the action sends `{ body }` as JSON through gh api --input. */ readonly jsonBody?: true @@ -349,6 +349,25 @@ const PR_REVIEW_BY_ID: GhAction = { }, } +// GitHub: PUT /repos/{owner}/{repo}/pulls/{pull_number}/reviews/{review_id} +const PR_REVIEW_EDIT: GhAction = { + name: 'pr:review-edit', + command: ['pr', 'review-edit'], + positionals: [ + { name: 'number', type: 'number', required: true }, + { name: 'id', type: 'number', required: true }, + ], + flags: [{ name: 'body', type: 'string', required: true, nonEmpty: true }], + permissions: { pull_requests: 'write' }, + timeoutSeconds: 120, + appUser: true, + api: { + method: 'PUT', + endpoint: 'repos/{owner}/{repo}/pulls/{number}/reviews/{id}', + jsonBody: true, + }, +} + // GitHub: POST /repos/{owner}/{repo}/pulls/{pull_number}/reviews const PR_REVIEW: GhAction = { name: 'pr:review', @@ -950,6 +969,7 @@ export const GH_ACTIONS: Readonly> = Object.freeze({ 'pr:comment-edit': PR_COMMENT_EDIT, 'pr:comment-delete': PR_COMMENT_DELETE, 'pr:review': PR_REVIEW, + 'pr:review-edit': PR_REVIEW_EDIT, 'pr:review-by-id': PR_REVIEW_BY_ID, 'discussion:create': DISCUSSION_CREATE, 'discussion:edit': DISCUSSION_EDIT, diff --git a/test/unit/actions.test.ts b/test/unit/actions.test.ts index 59990017..1dbbbd6e 100644 --- a/test/unit/actions.test.ts +++ b/test/unit/actions.test.ts @@ -31,6 +31,7 @@ describe('gh action catalog', () => { 'pr:comment-edit', 'pr:comment-delete', 'pr:review', + 'pr:review-edit', 'pr:review-by-id', 'discussion:create', 'discussion:edit', @@ -655,6 +656,33 @@ describe('buildGhArgv', () => { ) }) + it('builds the review-body edit api request', () => { + assert.deepEqual( + buildGhArgv( + 'pr:review-edit', + { number: 42, id: 9, body: 'updated' }, + 'acme/widget', + '/tmp/body.json', + ), + [ + 'api', + '--method', + 'PUT', + 'repos/acme/widget/pulls/42/reviews/9', + '--input', + '/tmp/body.json', + ], + ) + assert.throws( + () => buildGhArgv('pr:review-edit', { number: 42, id: 9 }, 'acme/widget'), + /body/u, + ) + assert.throws( + () => buildGhArgv('pr:review-edit', { number: 42, id: 9, body: ' ' }, 'acme/widget'), + /non-empty/u, + ) + }) + it('builds the edit flags', () => { assert.deepEqual( buildGhArgv('pr:edit', { number: 7, title: 't', base: 'main' }, 'acme/widget'),