Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/review-edit-action.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"gcb-core": patch
"gcb-client": patch
"gcb-host": patch
---

Add `pr:review-edit <number> <id> --body`: update the body of an existing pull request review
through the fixed `PUT /repos/{owner}/{repo}/pulls/{pull_number}/reviews/{review_id}` endpoint.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
Expand Down
22 changes: 21 additions & 1 deletion packages/core/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -950,6 +969,7 @@ export const GH_ACTIONS: Readonly<Record<string, GhAction>> = 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,
Expand Down
28 changes: 28 additions & 0 deletions test/unit/actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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'),
Expand Down
Loading