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
7 changes: 7 additions & 0 deletions .changeset/comment-delete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'gcb-core': minor
---

Add `issue:comment-delete` (`issues: write`) and `pr:comment-delete`
(`pull_requests: write`), which DELETE one issue/PR conversation comment through the same fixed
gh api endpoint as the edit actions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -802,12 +802,14 @@ actions. Grant them on the App, then approve any changed permissions on each ins
| `pr status` | `pull_requests: read`, `checks: read`, `statuses: read` |
| `pr comment` | `pull_requests: write` |
| `pr comment-edit` | `pull_requests: write` |
| `pr comment-delete` | `pull_requests: write` |
| `pr review` | `pull_requests: write` |
| `pr review --id` (`pr:review-by-id`) | `pull_requests: read` |
| `issue create` | `issues: write` |
| `issue edit` | `issues: write` |
| `issue comment` | `issues: write` |
| `issue comment-edit` | `issues: write` |
| `issue comment-delete` | `issues: write` |
| `issue close` | `issues: write` |
| `issue reopen` | `issues: write` |
| `issue lock` | `issues: write` |
Expand Down
27 changes: 26 additions & 1 deletion packages/core/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export interface FlagSpec {

/** A fixed `gh api` request, with only typed values substituted. */
export interface ApiSpec {
readonly method: 'GET' | 'PATCH';
readonly method: 'GET' | 'PATCH' | 'DELETE';
readonly endpoint: string;
/** When true, the action sends `{ body }` as JSON through gh api --input. */
readonly jsonBody?: true;
Expand Down Expand Up @@ -430,6 +430,29 @@ const PR_COMMENT_EDIT: GhAction = {
permissions: { pull_requests: 'write' },
};

// GitHub: DELETE /repos/{owner}/{repo}/issues/comments/{comment_id}
const ISSUE_COMMENT_DELETE: GhAction = {
name: 'issue:comment-delete',
command: ['issue', 'comment-delete'],
positionals: [{ name: 'commentId', type: 'number', required: true }],
flags: [],
permissions: { issues: 'write' },
timeoutSeconds: 120,
appUser: true,
api: {
method: 'DELETE',
endpoint: 'repos/{owner}/{repo}/issues/comments/{commentId}',
},
};

// GitHub: DELETE /repos/{owner}/{repo}/issues/comments/{comment_id}; a PR conversation comment is an issue comment
const PR_COMMENT_DELETE: GhAction = {
...ISSUE_COMMENT_DELETE,
name: 'pr:comment-delete',
command: ['pr', 'comment-delete'],
permissions: { pull_requests: 'write' },
};

// GitHub: GET /repos/{owner}/{repo}/issues/{issue_number}
const ISSUE_VIEW: GhAction = {
name: 'issue:view',
Expand Down Expand Up @@ -690,12 +713,14 @@ export const GH_ACTIONS: Readonly<Record<string, GhAction>> = Object.freeze({
'pr:status': PR_STATUS,
'pr:comment': PR_COMMENT,
'pr:comment-edit': PR_COMMENT_EDIT,
'pr:comment-delete': PR_COMMENT_DELETE,
'pr:review': PR_REVIEW,
'pr:review-by-id': PR_REVIEW_BY_ID,
'issue:create': ISSUE_CREATE,
'issue:edit': ISSUE_EDIT,
'issue:comment': ISSUE_COMMENT,
'issue:comment-edit': ISSUE_COMMENT_EDIT,
'issue:comment-delete': ISSUE_COMMENT_DELETE,
'issue:close': ISSUE_CLOSE,
'issue:reopen': ISSUE_REOPEN,
'issue:lock': ISSUE_LOCK,
Expand Down
10 changes: 10 additions & 0 deletions test/unit/actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ describe('gh action catalog', () => {
'pr:status',
'pr:comment',
'pr:comment-edit',
'pr:comment-delete',
'pr:review',
'pr:review-by-id',
'issue:create',
'issue:edit',
'issue:comment',
'issue:comment-edit',
'issue:comment-delete',
'issue:close',
'issue:reopen',
'issue:lock',
Expand Down Expand Up @@ -98,6 +100,10 @@ describe('gh action catalog', () => {
assert.equal(getGhAction('pr:comment').appUser, true);
assert.equal(getGhAction('pr:comment-edit').appUser, true);
assert.equal(getGhAction('pr:comment-edit').command.join(' '), 'pr comment-edit');
assert.deepEqual(getGhAction('issue:comment-delete').permissions, { issues: 'write' });
assert.deepEqual(getGhAction('pr:comment-delete').permissions, { pull_requests: 'write' });
assert.equal(getGhAction('issue:comment-delete').appUser, true);
assert.equal(getGhAction('pr:comment-delete').appUser, true);
assert.equal(getGhAction('issue:comment-edit').appUser, true);
assert.deepEqual(getGhAction('release:list').permissions, { contents: 'read' });
assert.deepEqual(getGhAction('release:view').permissions, { contents: 'read' });
Expand Down Expand Up @@ -215,6 +221,10 @@ describe('buildGhArgv', () => {
buildGhArgv('workflow:view', { workflow: 'ci.yml', ref: 'main', yaml: true }, 'acme/widget'),
['workflow', 'view', '--ref', 'main', '--yaml', '--repo', 'acme/widget', '--', 'ci.yml'],
);
assert.deepEqual(
buildGhArgv('issue:comment-delete', { commentId: 123 }, 'acme/widget'),
['api', '--method', 'DELETE', 'repos/acme/widget/issues/comments/123'],
);
assert.deepEqual(
buildGhArgv('issue:comment-edit', { commentId: 123, body: 'secret' }, 'acme/widget', '/tmp/body.json'),
['api', '--method', 'PATCH', 'repos/acme/widget/issues/comments/123', '--input', '/tmp/body.json'],
Expand Down
Loading