From 4bf6a9ea1961b73d0e8e3f7f33a7ee896c3e3ef8 Mon Sep 17 00:00:00 2001 From: JounQin Date: Sun, 8 Nov 2026 17:19:04 +0000 Subject: [PATCH 1/6] feat: add issue comment edit action --- .changeset/issue-comment-edit.md | 6 ++++++ README.md | 1 + packages/core/src/actions.ts | 31 +++++++++++++++++++++++++++++- packages/host/src/commands/host.ts | 13 ++++++++++++- packages/host/src/gh.ts | 6 ++++-- test/unit/actions.test.ts | 12 ++++++++++++ test/unit/gh.test.ts | 16 +++++++++++++++ 7 files changed, 81 insertions(+), 4 deletions(-) create mode 100644 .changeset/issue-comment-edit.md diff --git a/.changeset/issue-comment-edit.md b/.changeset/issue-comment-edit.md new file mode 100644 index 00000000..192903c0 --- /dev/null +++ b/.changeset/issue-comment-edit.md @@ -0,0 +1,6 @@ +--- +'gcb-core': minor +--- + +Add `issue:comment-edit`, which PATCHes one issue comment through a fixed gh api endpoint. The body +travels in an `--input` JSON file, never in argv; the action requires `issues: write`. diff --git a/README.md b/README.md index a96e4528..da75a8ba 100644 --- a/README.md +++ b/README.md @@ -806,6 +806,7 @@ actions. Grant them on the App, then approve any changed permissions on each ins | `issue create` | `issues: write` | | `issue edit` | `issues: write` | | `issue comment` | `issues: write` | +| `api` | `issues: write` | | `issue close` | `issues: write` | | `issue reopen` | `issues: write` | | `issue lock` | `issues: write` | diff --git a/packages/core/src/actions.ts b/packages/core/src/actions.ts index d9b2d6c8..40ca0d95 100644 --- a/packages/core/src/actions.ts +++ b/packages/core/src/actions.ts @@ -44,8 +44,10 @@ export interface FlagSpec { /** A fixed `gh api` request, with only typed values substituted. */ export interface ApiSpec { - readonly method: 'GET'; + readonly method: 'GET' | 'PATCH'; readonly endpoint: string; + /** When set, the action sends `{ body }` as JSON through gh api --input. */ + readonly body?: 'issue-comment'; } /** One allowed `gh` action. */ @@ -393,6 +395,22 @@ const ISSUE_REOPEN: GhAction = { target: 'issue', }; +// GitHub: PATCH /repos/{owner}/{repo}/issues/comments/{comment_id} +const ISSUE_COMMENT_EDIT: GhAction = { + name: 'issue:comment-edit', + command: ['api'], + positionals: [{ name: 'commentId', type: 'number', required: true }], + flags: [{ name: 'body', type: 'string', required: true, nonEmpty: true }], + permissions: { issues: 'write' }, + timeoutSeconds: 120, + appUser: true, + api: { + method: 'PATCH', + endpoint: 'repos/{owner}/{repo}/issues/comments/{commentId}', + body: 'issue-comment', + }, +}; + // GitHub: GET /repos/{owner}/{repo}/issues/{issue_number} const ISSUE_VIEW: GhAction = { name: 'issue:view', @@ -657,6 +675,7 @@ export const GH_ACTIONS: Readonly> = Object.freeze({ 'issue:create': ISSUE_CREATE, 'issue:edit': ISSUE_EDIT, 'issue:comment': ISSUE_COMMENT, + 'issue:comment-edit': ISSUE_COMMENT_EDIT, 'issue:close': ISSUE_CLOSE, 'issue:reopen': ISSUE_REOPEN, 'issue:lock': ISSUE_LOCK, @@ -803,6 +822,16 @@ export function buildGhArgv( continue; } + if (flag.name === 'body' && action.api?.body !== undefined) { + const text = asString(value, flag.name); + if (flag.nonEmpty === true && text.trim() === '') { + throw new ActionError(`${name} needs a non-empty --${flag.name}`); + } + if (bodyFile !== undefined) argv.push('--input', bodyFile); + present.add(flag.name); + provided.add(flag.name); + continue; + } if (flag.name === 'body' && bodyFile !== undefined) { const text = asString(value, flag.name); if (flag.nonEmpty === true && text.trim() === '') { diff --git a/packages/host/src/commands/host.ts b/packages/host/src/commands/host.ts index 87c3c33b..0bd5fd1b 100644 --- a/packages/host/src/commands/host.ts +++ b/packages/host/src/commands/host.ts @@ -643,7 +643,18 @@ async function openOne( }); return result; }; - return body === undefined ? invoke() : withBodyFile(body, invoke); + if (body === undefined) return invoke(); + if (action.api?.body !== undefined) { + const scratch = mkdtempSync(join(tmpdir(), 'gcb-api-body-')); + try { + const bodyFile = join(scratch, 'body.json'); + writeFileSync(bodyFile, JSON.stringify({ body }), { mode: 0o600 }); + return await invoke(bodyFile); + } finally { + rmSync(scratch, { recursive: true, force: true }); + } + } + return withBodyFile(body, invoke); }; let hostBlock: ReturnType; diff --git a/packages/host/src/gh.ts b/packages/host/src/gh.ts index 7bad2e01..1a1b87a8 100644 --- a/packages/host/src/gh.ts +++ b/packages/host/src/gh.ts @@ -231,8 +231,10 @@ export async function runGhAction(options: GhRunOptions): Promise { // argv, so this is about the free-form body rather than everything the person wrote. let bodyFile: string | undefined; if (typeof options.values['body'] === 'string') { - bodyFile = path.join(home, 'body.md'); - writeFileSync(bodyFile, options.values['body'], { mode: 0o600 }); + const apiBody = action.api?.body !== undefined; + bodyFile = path.join(home, apiBody ? 'body.json' : 'body.md'); + const content = apiBody ? JSON.stringify({ body: options.values['body'] }) : options.values['body']; + writeFileSync(bodyFile, content, { mode: 0o600 }); } const argv = buildGhArgv(action.name, options.values, options.repo, bodyFile); return await new Promise((resolve) => { diff --git a/test/unit/actions.test.ts b/test/unit/actions.test.ts index 96da7c01..6eabc856 100644 --- a/test/unit/actions.test.ts +++ b/test/unit/actions.test.ts @@ -32,6 +32,7 @@ describe('gh action catalog', () => { 'issue:create', 'issue:edit', 'issue:comment', + 'issue:comment-edit', 'issue:close', 'issue:reopen', 'issue:lock', @@ -90,6 +91,8 @@ describe('gh action catalog', () => { }); assert.deepEqual(getGhAction('issue:view').permissions, { issues: 'read' }); assert.deepEqual(getGhAction('issue:list').permissions, { issues: 'read' }); + assert.deepEqual(getGhAction('issue:comment-edit').permissions, { issues: 'write' }); + assert.equal(getGhAction('issue:comment-edit').appUser, true); assert.deepEqual(getGhAction('release:list').permissions, { contents: 'read' }); assert.deepEqual(getGhAction('release:view').permissions, { contents: 'read' }); assert.deepEqual(getGhAction('workflow:list').permissions, { actions: 'read' }); @@ -206,6 +209,15 @@ 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-edit', { commentId: 123, body: 'secret' }, 'acme/widget', '/tmp/body.json'), + ['api', '--method', 'PATCH', 'repos/acme/widget/issues/comments/123', '--input', '/tmp/body.json'], + ); + assert.deepEqual( + buildGhArgv('issue:comment-edit', { commentId: 123, body: 'secret' }, 'acme/widget'), + ['api', '--method', 'PATCH', 'repos/acme/widget/issues/comments/123'], + ); + assert.deepEqual(buildGhArgv('workflow:list', { all: true, limit: 10 }, 'acme/widget'), [ 'workflow', 'list', diff --git a/test/unit/gh.test.ts b/test/unit/gh.test.ts index c285f299..2f4620e8 100644 --- a/test/unit/gh.test.ts +++ b/test/unit/gh.test.ts @@ -186,6 +186,22 @@ describe('runGhAction', { skip: onWindows }, () => { assert.equal(result.stdout, 'ok\n'); }); + it('passes an issue-comment edit body through an input file', async () => { + const gh = shim('printf "ARGS=%s\n" "$*"; while [ "$#" -gt 0 ]; do if [ "$1" = "--input" ]; then cat "$2"; fi; shift; done'); + const result = await runGhAction({ + action: 'issue:comment-edit', + values: { commentId: 123, body: 'secret edit' }, + repo: 'acme/widget', + token: 'app-token', + ghPath: gh, + env: { PATH: process.env.PATH }, + }); + assert.equal(result.code, 0); + assert.match(result.stdout, /api --method PATCH repos\/acme\/widget\/issues\/comments\/123 --input/u); + assert.match(result.stdout, /"body":"secret edit"/u); + assert.doesNotMatch(result.stdout, /ARGS=.*secret edit/u); + }); + it('SIGKILLs after the grace period when the process ignores SIGTERM', async () => { const timeoutMs = 2_000; const gh = shim('trap "" TERM; while :; do sleep 1; done'); From 550a0a7f873b98b2d840ba011572071b822d65c6 Mon Sep 17 00:00:00 2001 From: JounQin Date: Sun, 8 Nov 2026 17:46:07 +0000 Subject: [PATCH 2/6] feat: add pr comment edit alias --- README.md | 1 + packages/core/src/actions.ts | 4 ++++ test/unit/actions.test.ts | 3 +++ 3 files changed, 8 insertions(+) diff --git a/README.md b/README.md index da75a8ba..33d23010 100644 --- a/README.md +++ b/README.md @@ -801,6 +801,7 @@ actions. Grant them on the App, then approve any changed permissions on each ins | `pr checks` | `pull_requests: read`, `checks: read`, `statuses: read` | | `pr status` | `pull_requests: read`, `checks: read`, `statuses: read` | | `pr comment` | `pull_requests: write` | +| `api` | `issues: write` | | `pr review` | `pull_requests: write` | | `pr review --id` (`pr:review-by-id`) | `pull_requests: read` | | `issue create` | `issues: write` | diff --git a/packages/core/src/actions.ts b/packages/core/src/actions.ts index 40ca0d95..04c45661 100644 --- a/packages/core/src/actions.ts +++ b/packages/core/src/actions.ts @@ -411,6 +411,9 @@ const ISSUE_COMMENT_EDIT: GhAction = { }, }; +// GitHub: PATCH /repos/{owner}/{repo}/issues/comments/{comment_id}; a PR conversation comment is an issue comment +const PR_COMMENT_EDIT: GhAction = { ...ISSUE_COMMENT_EDIT, name: 'pr:comment-edit' }; + // GitHub: GET /repos/{owner}/{repo}/issues/{issue_number} const ISSUE_VIEW: GhAction = { name: 'issue:view', @@ -670,6 +673,7 @@ export const GH_ACTIONS: Readonly> = Object.freeze({ 'pr:checks': PR_CHECKS, 'pr:status': PR_STATUS, 'pr:comment': PR_COMMENT, + 'pr:comment-edit': PR_COMMENT_EDIT, 'pr:review': PR_REVIEW, 'pr:review-by-id': PR_REVIEW_BY_ID, 'issue:create': ISSUE_CREATE, diff --git a/test/unit/actions.test.ts b/test/unit/actions.test.ts index 6eabc856..edfd1568 100644 --- a/test/unit/actions.test.ts +++ b/test/unit/actions.test.ts @@ -27,6 +27,7 @@ describe('gh action catalog', () => { 'pr:checks', 'pr:status', 'pr:comment', + 'pr:comment-edit', 'pr:review', 'pr:review-by-id', 'issue:create', @@ -92,6 +93,8 @@ describe('gh action catalog', () => { assert.deepEqual(getGhAction('issue:view').permissions, { issues: 'read' }); assert.deepEqual(getGhAction('issue:list').permissions, { issues: 'read' }); assert.deepEqual(getGhAction('issue:comment-edit').permissions, { issues: 'write' }); + assert.deepEqual(getGhAction('pr:comment-edit').permissions, { issues: 'write' }); + assert.equal(getGhAction('pr:comment-edit').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' }); From 85a68b2e39de72f11a4cadad95620d4dc67d8e5e Mon Sep 17 00:00:00 2001 From: JounQin Date: Mon, 9 Nov 2026 03:16:01 +0000 Subject: [PATCH 3/6] fix: label comment edit actions by their command --- README.md | 4 ++-- packages/core/src/actions.ts | 8 ++++++-- test/unit/actions.test.ts | 2 ++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 33d23010..7b75c35a 100644 --- a/README.md +++ b/README.md @@ -801,13 +801,13 @@ actions. Grant them on the App, then approve any changed permissions on each ins | `pr checks` | `pull_requests: read`, `checks: read`, `statuses: read` | | `pr status` | `pull_requests: read`, `checks: read`, `statuses: read` | | `pr comment` | `pull_requests: write` | -| `api` | `issues: write` | +| `pr comment-edit` | `issues: 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` | -| `api` | `issues: write` | +| `issue comment-edit` | `issues: write` | | `issue close` | `issues: write` | | `issue reopen` | `issues: write` | | `issue lock` | `issues: write` | diff --git a/packages/core/src/actions.ts b/packages/core/src/actions.ts index 04c45661..84d9079c 100644 --- a/packages/core/src/actions.ts +++ b/packages/core/src/actions.ts @@ -398,7 +398,7 @@ const ISSUE_REOPEN: GhAction = { // GitHub: PATCH /repos/{owner}/{repo}/issues/comments/{comment_id} const ISSUE_COMMENT_EDIT: GhAction = { name: 'issue:comment-edit', - command: ['api'], + command: ['issue', 'comment-edit'], positionals: [{ name: 'commentId', type: 'number', required: true }], flags: [{ name: 'body', type: 'string', required: true, nonEmpty: true }], permissions: { issues: 'write' }, @@ -412,7 +412,11 @@ const ISSUE_COMMENT_EDIT: GhAction = { }; // GitHub: PATCH /repos/{owner}/{repo}/issues/comments/{comment_id}; a PR conversation comment is an issue comment -const PR_COMMENT_EDIT: GhAction = { ...ISSUE_COMMENT_EDIT, name: 'pr:comment-edit' }; +const PR_COMMENT_EDIT: GhAction = { + ...ISSUE_COMMENT_EDIT, + name: 'pr:comment-edit', + command: ['pr', 'comment-edit'], +}; // GitHub: GET /repos/{owner}/{repo}/issues/{issue_number} const ISSUE_VIEW: GhAction = { diff --git a/test/unit/actions.test.ts b/test/unit/actions.test.ts index edfd1568..03921b25 100644 --- a/test/unit/actions.test.ts +++ b/test/unit/actions.test.ts @@ -93,8 +93,10 @@ describe('gh action catalog', () => { assert.deepEqual(getGhAction('issue:view').permissions, { issues: 'read' }); assert.deepEqual(getGhAction('issue:list').permissions, { issues: 'read' }); assert.deepEqual(getGhAction('issue:comment-edit').permissions, { issues: 'write' }); + assert.equal(getGhAction('issue:comment-edit').command.join(' '), 'issue comment-edit'); assert.deepEqual(getGhAction('pr:comment-edit').permissions, { issues: 'write' }); assert.equal(getGhAction('pr:comment-edit').appUser, true); + assert.equal(getGhAction('pr:comment-edit').command.join(' '), 'pr comment-edit'); assert.equal(getGhAction('issue:comment-edit').appUser, true); assert.deepEqual(getGhAction('release:list').permissions, { contents: 'read' }); assert.deepEqual(getGhAction('release:view').permissions, { contents: 'read' }); From 78f000e7993d59cf15f7c12b96544c63f50e4f20 Mon Sep 17 00:00:00 2001 From: JounQin Date: Mon, 9 Nov 2026 03:19:13 +0000 Subject: [PATCH 4/6] fix: grant the PR comment alias pull-request write --- README.md | 2 +- packages/core/src/actions.ts | 1 + test/unit/actions.test.ts | 5 ++++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7b75c35a..b0125c6b 100644 --- a/README.md +++ b/README.md @@ -801,7 +801,7 @@ actions. Grant them on the App, then approve any changed permissions on each ins | `pr checks` | `pull_requests: read`, `checks: read`, `statuses: read` | | `pr status` | `pull_requests: read`, `checks: read`, `statuses: read` | | `pr comment` | `pull_requests: write` | -| `pr comment-edit` | `issues: write` | +| `pr comment-edit` | `issues: write`, `pull_requests: write` | | `pr review` | `pull_requests: write` | | `pr review --id` (`pr:review-by-id`) | `pull_requests: read` | | `issue create` | `issues: write` | diff --git a/packages/core/src/actions.ts b/packages/core/src/actions.ts index 84d9079c..c6addf84 100644 --- a/packages/core/src/actions.ts +++ b/packages/core/src/actions.ts @@ -416,6 +416,7 @@ const PR_COMMENT_EDIT: GhAction = { ...ISSUE_COMMENT_EDIT, name: 'pr:comment-edit', command: ['pr', 'comment-edit'], + permissions: { issues: 'write', pull_requests: 'write' }, }; // GitHub: GET /repos/{owner}/{repo}/issues/{issue_number} diff --git a/test/unit/actions.test.ts b/test/unit/actions.test.ts index 03921b25..7e22ec9c 100644 --- a/test/unit/actions.test.ts +++ b/test/unit/actions.test.ts @@ -94,7 +94,10 @@ describe('gh action catalog', () => { assert.deepEqual(getGhAction('issue:list').permissions, { issues: 'read' }); assert.deepEqual(getGhAction('issue:comment-edit').permissions, { issues: 'write' }); assert.equal(getGhAction('issue:comment-edit').command.join(' '), 'issue comment-edit'); - assert.deepEqual(getGhAction('pr:comment-edit').permissions, { issues: 'write' }); + assert.deepEqual(getGhAction('pr:comment-edit').permissions, { + issues: 'write', + pull_requests: 'write', + }); assert.equal(getGhAction('pr:comment-edit').appUser, true); assert.equal(getGhAction('pr:comment-edit').command.join(' '), 'pr comment-edit'); assert.equal(getGhAction('issue:comment-edit').appUser, true); From 278ffc3e759df0d7d4465b27c8f4e408ada80468 Mon Sep 17 00:00:00 2001 From: JounQin Date: Mon, 9 Nov 2026 03:41:28 +0000 Subject: [PATCH 5/6] fix: align comment edit permissions and body encoding --- .changeset/issue-comment-edit.md | 5 +++-- README.md | 2 +- packages/core/src/actions.ts | 20 +++++++++++++++----- packages/host/src/commands/host.ts | 15 +++++---------- packages/host/src/gh.ts | 6 +++--- test/unit/actions.test.ts | 9 +-------- test/unit/host.test.ts | 30 ++++++++++++++++++++++++++++++ 7 files changed, 58 insertions(+), 29 deletions(-) diff --git a/.changeset/issue-comment-edit.md b/.changeset/issue-comment-edit.md index 192903c0..d01f9fc3 100644 --- a/.changeset/issue-comment-edit.md +++ b/.changeset/issue-comment-edit.md @@ -2,5 +2,6 @@ 'gcb-core': minor --- -Add `issue:comment-edit`, which PATCHes one issue comment through a fixed gh api endpoint. The body -travels in an `--input` JSON file, never in argv; the action requires `issues: write`. +Add `issue:comment-edit` (`issues: write`) and `pr:comment-edit` (`pull_requests: write`), which +PATCH one issue/PR conversation comment through a fixed gh api endpoint. The body travels in an +`--input` JSON file, never in argv. diff --git a/README.md b/README.md index b0125c6b..27043779 100644 --- a/README.md +++ b/README.md @@ -801,7 +801,7 @@ actions. Grant them on the App, then approve any changed permissions on each ins | `pr checks` | `pull_requests: read`, `checks: read`, `statuses: read` | | `pr status` | `pull_requests: read`, `checks: read`, `statuses: read` | | `pr comment` | `pull_requests: write` | -| `pr comment-edit` | `issues: write`, `pull_requests: write` | +| `pr comment-edit` | `pull_requests: write` | | `pr review` | `pull_requests: write` | | `pr review --id` (`pr:review-by-id`) | `pull_requests: read` | | `issue create` | `issues: write` | diff --git a/packages/core/src/actions.ts b/packages/core/src/actions.ts index c6addf84..fd3ce0dc 100644 --- a/packages/core/src/actions.ts +++ b/packages/core/src/actions.ts @@ -46,8 +46,8 @@ export interface FlagSpec { export interface ApiSpec { readonly method: 'GET' | 'PATCH'; readonly endpoint: string; - /** When set, the action sends `{ body }` as JSON through gh api --input. */ - readonly body?: 'issue-comment'; + /** When true, the action sends `{ body }` as JSON through gh api --input. */ + readonly jsonBody?: true; } /** One allowed `gh` action. */ @@ -83,6 +83,16 @@ export interface GhAction { /** Values supplied by the caller, keyed by positional or flag name. */ export type ActionValues = Readonly>; +/** + * Encode the body payload for a gh api action that posts `{ body }` as JSON. + * + * @param body - the comment text. + * @returns the JSON payload for gh api --input. + */ +export function apiBodyJson(body: string): string { + return JSON.stringify({ body }); +} + /** A failure the caller can act on, and that contains no provider output. */ export class ActionError extends Error { constructor(message: string) { @@ -407,7 +417,7 @@ const ISSUE_COMMENT_EDIT: GhAction = { api: { method: 'PATCH', endpoint: 'repos/{owner}/{repo}/issues/comments/{commentId}', - body: 'issue-comment', + jsonBody: true, }, }; @@ -416,7 +426,7 @@ const PR_COMMENT_EDIT: GhAction = { ...ISSUE_COMMENT_EDIT, name: 'pr:comment-edit', command: ['pr', 'comment-edit'], - permissions: { issues: 'write', pull_requests: 'write' }, + permissions: { pull_requests: 'write' }, }; // GitHub: GET /repos/{owner}/{repo}/issues/{issue_number} @@ -831,7 +841,7 @@ export function buildGhArgv( continue; } - if (flag.name === 'body' && action.api?.body !== undefined) { + if (flag.name === 'body' && action.api?.jsonBody === true) { const text = asString(value, flag.name); if (flag.nonEmpty === true && text.trim() === '') { throw new ActionError(`${name} needs a non-empty --${flag.name}`); diff --git a/packages/host/src/commands/host.ts b/packages/host/src/commands/host.ts index 0bd5fd1b..19d0bde7 100644 --- a/packages/host/src/commands/host.ts +++ b/packages/host/src/commands/host.ts @@ -30,6 +30,7 @@ import { requestProblems, writeHostBroker, writeResult, + apiBodyJson, HOST, REPOSITORY, ANSWER_TIMEOUT_MS, @@ -524,10 +525,11 @@ async function personRun( async function withBodyFile( body: string, work: (bodyFile: string) => Promise, + name = 'body.md', ): Promise { const scratch = mkdtempSync(join(tmpdir(), 'gcb-body-')); try { - const bodyFile = join(scratch, 'body.md'); + const bodyFile = join(scratch, name); writeFileSync(bodyFile, body, 'utf8'); return await work(bodyFile); } finally { @@ -644,15 +646,8 @@ async function openOne( return result; }; if (body === undefined) return invoke(); - if (action.api?.body !== undefined) { - const scratch = mkdtempSync(join(tmpdir(), 'gcb-api-body-')); - try { - const bodyFile = join(scratch, 'body.json'); - writeFileSync(bodyFile, JSON.stringify({ body }), { mode: 0o600 }); - return await invoke(bodyFile); - } finally { - rmSync(scratch, { recursive: true, force: true }); - } + if (action.api?.jsonBody === true) { + return withBodyFile(apiBodyJson(body), invoke, 'body.json'); } return withBodyFile(body, invoke); }; diff --git a/packages/host/src/gh.ts b/packages/host/src/gh.ts index 1a1b87a8..9d3c392e 100644 --- a/packages/host/src/gh.ts +++ b/packages/host/src/gh.ts @@ -11,7 +11,7 @@ import { tmpdir } from 'node:os'; import { StringDecoder } from 'node:string_decoder'; import path from 'node:path'; -import { buildGhArgv, getGhAction, type ActionValues } from 'gcb-core'; +import { apiBodyJson, buildGhArgv, getGhAction, type ActionValues } from 'gcb-core'; import { applyProxyChoice, PROXY_ENV_KEYS } from './http.ts'; /** The default stdout/stderr ceiling, in bytes per stream. */ @@ -231,9 +231,9 @@ export async function runGhAction(options: GhRunOptions): Promise { // argv, so this is about the free-form body rather than everything the person wrote. let bodyFile: string | undefined; if (typeof options.values['body'] === 'string') { - const apiBody = action.api?.body !== undefined; + const apiBody = action.api?.jsonBody === true; bodyFile = path.join(home, apiBody ? 'body.json' : 'body.md'); - const content = apiBody ? JSON.stringify({ body: options.values['body'] }) : options.values['body']; + const content = apiBody ? apiBodyJson(options.values['body']) : options.values['body']; writeFileSync(bodyFile, content, { mode: 0o600 }); } const argv = buildGhArgv(action.name, options.values, options.repo, bodyFile); diff --git a/test/unit/actions.test.ts b/test/unit/actions.test.ts index 7e22ec9c..6f801df6 100644 --- a/test/unit/actions.test.ts +++ b/test/unit/actions.test.ts @@ -94,10 +94,7 @@ describe('gh action catalog', () => { assert.deepEqual(getGhAction('issue:list').permissions, { issues: 'read' }); assert.deepEqual(getGhAction('issue:comment-edit').permissions, { issues: 'write' }); assert.equal(getGhAction('issue:comment-edit').command.join(' '), 'issue comment-edit'); - assert.deepEqual(getGhAction('pr:comment-edit').permissions, { - issues: 'write', - pull_requests: 'write', - }); + assert.deepEqual(getGhAction('pr:comment-edit').permissions, { pull_requests: 'write' }); assert.equal(getGhAction('pr:comment-edit').appUser, true); assert.equal(getGhAction('pr:comment-edit').command.join(' '), 'pr comment-edit'); assert.equal(getGhAction('issue:comment-edit').appUser, true); @@ -221,10 +218,6 @@ describe('buildGhArgv', () => { 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'], ); - assert.deepEqual( - buildGhArgv('issue:comment-edit', { commentId: 123, body: 'secret' }, 'acme/widget'), - ['api', '--method', 'PATCH', 'repos/acme/widget/issues/comments/123'], - ); assert.deepEqual(buildGhArgv('workflow:list', { all: true, limit: 10 }, 'acme/widget'), [ 'workflow', diff --git a/test/unit/host.test.ts b/test/unit/host.test.ts index f76e29ae..aac31cf6 100644 --- a/test/unit/host.test.ts +++ b/test/unit/host.test.ts @@ -434,6 +434,36 @@ describe('the host action route', () => { } }); + it('passes a comment edit body as JSON through --input', async () => { + const root = mkdtempSync(join(tmpdir(), 'host-broker-comment-edit-')); + const repo = join(root, 'checkout'); + mkdirSync(join(repo, '.git'), { recursive: true }); + writeFileSync(join(repo, '.git', 'HEAD'), 'ref: refs/heads/main\n', 'utf8'); + const config = forkConfig(root, 'acme/widget'); + const dir = channelDir(join(repo, '.git')); + const captured = join(root, 'captured.json'); + const command = join(root, 'not-gh'); + writeFileSync( + command, + '#!/bin/sh\nwhile [ "$#" -gt 0 ]; do if [ "$1" = "--input" ]; then cat "$2" > ' + captured + '; fi; shift; done\necho ok\n', + 'utf8', + ); + chmodSync(command, 0o755); + try { + const id = writeRequest(dir, { + kind: 'action', + action: 'pr:comment-edit', + repo: 'acme/widget', + values: { commentId: 123, body: 'secret edit' }, + }); + assert.equal(await runHostBroker(['--repo', repo, '--command', command, '--config', config, '--once']), 0); + assert.equal(readResult(dir, id)?.stdout, 'ok\n'); + assert.equal(readFileSync(captured, 'utf8'), '{"body":"secret edit"}'); + } finally { + rmSync(root, { recursive: true, force: true }); + } + }); + it('runs a catalogued action and returns its output', async () => { const root = mkdtempSync(join(tmpdir(), 'host-broker-action-')); const repo = join(root, 'checkout'); From 3c87de7ac358f791a6f4fa56c91dcc49ac80c946 Mon Sep 17 00:00:00 2001 From: JounQin Date: Mon, 9 Nov 2026 03:59:14 +0000 Subject: [PATCH 6/6] feat: allow pr comment creation as a person --- .changeset/issue-comment-edit.md | 3 ++- packages/core/src/actions.ts | 1 + test/unit/actions.test.ts | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.changeset/issue-comment-edit.md b/.changeset/issue-comment-edit.md index d01f9fc3..e1035381 100644 --- a/.changeset/issue-comment-edit.md +++ b/.changeset/issue-comment-edit.md @@ -4,4 +4,5 @@ Add `issue:comment-edit` (`issues: write`) and `pr:comment-edit` (`pull_requests: write`), which PATCH one issue/PR conversation comment through a fixed gh api endpoint. The body travels in an -`--input` JSON file, never in argv. +`--input` JSON file, never in argv. `pr:comment` also gains the person route, matching +`issue:comment`. diff --git a/packages/core/src/actions.ts b/packages/core/src/actions.ts index fd3ce0dc..ef234d55 100644 --- a/packages/core/src/actions.ts +++ b/packages/core/src/actions.ts @@ -199,6 +199,7 @@ const PR_COMMENT: GhAction = { flags: [{ name: 'body', type: 'string', required: true, nonEmpty: true }], permissions: { pull_requests: 'write' }, timeoutSeconds: 120, + appUser: true, }; // GitHub GraphQL: closePullRequest diff --git a/test/unit/actions.test.ts b/test/unit/actions.test.ts index 6f801df6..9c631c1a 100644 --- a/test/unit/actions.test.ts +++ b/test/unit/actions.test.ts @@ -95,6 +95,7 @@ describe('gh action catalog', () => { assert.deepEqual(getGhAction('issue:comment-edit').permissions, { issues: 'write' }); assert.equal(getGhAction('issue:comment-edit').command.join(' '), 'issue comment-edit'); assert.deepEqual(getGhAction('pr:comment-edit').permissions, { pull_requests: 'write' }); + 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.equal(getGhAction('issue:comment-edit').appUser, true);