From 98244fd354fadb66f63e5cfdaceeb2992675abf8 Mon Sep 17 00:00:00 2001 From: JounQin Date: Sun, 8 Nov 2026 15:53:31 +0000 Subject: [PATCH 1/3] feat: add release and workflow read actions --- .changeset/catalog-release-workflow.md | 6 +++ README.md | 4 ++ packages/core/src/actions.ts | 75 ++++++++++++++++++++++++++ test/unit/actions.test.ts | 33 ++++++++++++ 4 files changed, 118 insertions(+) create mode 100644 .changeset/catalog-release-workflow.md diff --git a/.changeset/catalog-release-workflow.md b/.changeset/catalog-release-workflow.md new file mode 100644 index 00000000..8a89bc26 --- /dev/null +++ b/.changeset/catalog-release-workflow.md @@ -0,0 +1,6 @@ +--- +'gcb-core': minor +--- + +Add read-only release and workflow actions to the catalog: `release:list`, `release:view`, +`workflow:list`, and `workflow:view`, with their GitHub permissions, flags and tests. diff --git a/README.md b/README.md index 993df0a7..ca3f999a 100644 --- a/README.md +++ b/README.md @@ -819,6 +819,10 @@ actions. Grant them on the App, then approve any changed permissions on each ins | `run watch` | `actions: read`, `checks: read` | | `run cancel` | `actions: write` | | `run rerun` | `actions: write` | +| `release list` | `contents: read` | +| `release view` | `contents: read` | +| `workflow list` | `actions: read` | +| `workflow view` | `actions: read` | `pr status` with `--repo` reports the app identity's relevant pull requests and review requests diff --git a/packages/core/src/actions.ts b/packages/core/src/actions.ts index 120b5afd..3444e2f8 100644 --- a/packages/core/src/actions.ts +++ b/packages/core/src/actions.ts @@ -564,6 +564,77 @@ const RUN_LIST: GhAction = { appUser: true, }; +/** GitHub: GET /repos/{owner}/{repo}/releases */ +const RELEASE_LIST: GhAction = { + name: 'release:list', + command: ['release', 'list'], + positionals: [], + flags: [ + { name: 'exclude-drafts', type: 'boolean' }, + { name: 'exclude-pre-releases', type: 'boolean' }, + { name: 'json', type: 'string' }, + { name: 'jq', type: 'string' }, + { name: 'limit', type: 'number' }, + { name: 'order', type: 'string' }, + { name: 'template', type: 'string' }, + ], + permissions: { contents: 'read' }, + timeoutSeconds: 120, + readOnly: true, + appUser: true, +}; + +/** GitHub: GET /repos/{owner}/{repo}/releases/tags/{tag} */ +const RELEASE_VIEW: GhAction = { + name: 'release:view', + command: ['release', 'view'], + positionals: [{ name: 'tag', type: 'string' }], + flags: [ + { name: 'json', type: 'string' }, + { name: 'jq', type: 'string' }, + { name: 'template', type: 'string' }, + { name: 'web', type: 'boolean' }, + ], + permissions: { contents: 'read' }, + timeoutSeconds: 120, + readOnly: true, + appUser: true, +}; + +/** GitHub: GET /repos/{owner}/{repo}/actions/workflows */ +const WORKFLOW_LIST: GhAction = { + name: 'workflow:list', + command: ['workflow', 'list'], + positionals: [], + flags: [ + { name: 'all', type: 'boolean' }, + { name: 'json', type: 'string' }, + { name: 'jq', type: 'string' }, + { name: 'limit', type: 'number' }, + { name: 'template', type: 'string' }, + ], + permissions: { actions: 'read' }, + timeoutSeconds: 120, + readOnly: true, + appUser: true, +}; + +/** GitHub: GET /repos/{owner}/{repo}/actions/workflows/{workflow_id} */ +const WORKFLOW_VIEW: GhAction = { + name: 'workflow:view', + command: ['workflow', 'view'], + positionals: [{ name: 'workflow', type: 'string' }], + flags: [ + { name: 'ref', type: 'string' }, + { name: 'web', type: 'boolean' }, + { name: 'yaml', type: 'boolean' }, + ], + permissions: { actions: 'read' }, + timeoutSeconds: 120, + readOnly: true, + appUser: true, +}; + /** Every built-in action, keyed by its action name. */ export const GH_ACTIONS: Readonly> = Object.freeze({ 'pr:view': PR_VIEW, @@ -598,6 +669,10 @@ export const GH_ACTIONS: Readonly> = Object.freeze({ 'run:watch': RUN_WATCH, 'run:cancel': RUN_CANCEL, 'run:rerun': RUN_RERUN, + 'release:list': RELEASE_LIST, + 'release:view': RELEASE_VIEW, + 'workflow:list': WORKFLOW_LIST, + 'workflow:view': WORKFLOW_VIEW, }); /** The built-in action names, in a stable order. */ diff --git a/test/unit/actions.test.ts b/test/unit/actions.test.ts index f691df3e..37d6f6ff 100644 --- a/test/unit/actions.test.ts +++ b/test/unit/actions.test.ts @@ -45,6 +45,10 @@ describe('gh action catalog', () => { 'run:watch', 'run:cancel', 'run:rerun', + 'release:list', + 'release:view', + 'workflow:list', + 'workflow:view', ]); assert.equal('pr:merge' in GH_ACTIONS, false); assert.equal(getGhAction('pr:create').command.join(' '), 'pr create'); @@ -86,6 +90,10 @@ describe('gh action catalog', () => { }); assert.deepEqual(getGhAction('issue:view').permissions, { issues: 'read' }); assert.deepEqual(getGhAction('issue:list').permissions, { issues: 'read' }); + assert.deepEqual(getGhAction('release:list').permissions, { contents: 'read' }); + assert.deepEqual(getGhAction('release:view').permissions, { contents: 'read' }); + assert.deepEqual(getGhAction('workflow:list').permissions, { actions: 'read' }); + assert.deepEqual(getGhAction('workflow:view').permissions, { actions: 'read' }); assert.equal(getGhAction('pr:checks').timeoutSeconds, 300); }); @@ -111,6 +119,10 @@ describe('gh action catalog', () => { 'run:view', 'run:list', 'run:watch', + 'release:list', + 'release:view', + 'workflow:list', + 'workflow:view', ]) { assert.equal(getGhAction(name).readOnly, true, name); assert.equal(getGhAction(name).appUser, true, name); @@ -170,6 +182,27 @@ describe('gh action catalog', () => { }); describe('buildGhArgv', () => { + it('builds release and workflow read argv', () => { + assert.deepEqual(buildGhArgv('release:list', { limit: 5, json: 'tagName' }, 'acme/widget'), [ + 'release', + 'list', + '--json', + 'tagName', + '--limit', + '5', + '--repo', + 'acme/widget', + ]); + assert.deepEqual(buildGhArgv('workflow:view', { workflow: 'ci.yml', yaml: true }, 'acme/widget'), [ + 'workflow', + 'view', + 'ci.yml', + '--yaml', + '--repo', + 'acme/widget', + ]); + }); + it('rebuilds the canonical argv and injects the repository', () => { assert.deepEqual( buildGhArgv( From dd673bf57eb5541eace132c08c0a69f52985a373 Mon Sep 17 00:00:00 2001 From: JounQin Date: Sun, 8 Nov 2026 16:18:28 +0000 Subject: [PATCH 2/3] fix: narrow workflow view and drop web flags --- README.md | 2 +- packages/core/src/actions.ts | 22 ++++++++++++++-------- test/unit/actions.test.ts | 25 ++++++++++++++++++++++++- 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index ca3f999a..a96e4528 100644 --- a/README.md +++ b/README.md @@ -822,7 +822,7 @@ actions. Grant them on the App, then approve any changed permissions on each ins | `release list` | `contents: read` | | `release view` | `contents: read` | | `workflow list` | `actions: read` | -| `workflow view` | `actions: read` | +| `workflow view` | `actions: read`, `contents: read` | `pr status` with `--repo` reports the app identity's relevant pull requests and review requests diff --git a/packages/core/src/actions.ts b/packages/core/src/actions.ts index 3444e2f8..23c89689 100644 --- a/packages/core/src/actions.ts +++ b/packages/core/src/actions.ts @@ -63,6 +63,8 @@ export interface GhAction { readonly bodyRequiredWith?: readonly string[]; /** Flag pairs that may not be present together. */ readonly conflicts?: readonly (readonly [string, string])[]; + /** When the first flag is present, the second must be present too. */ + readonly requires?: readonly (readonly [string, string])[]; /** This action only reads; publicRead may run it on a verified public repository with the route's public-read token. */ readonly readOnly?: boolean; readonly permissions: Readonly>>; @@ -564,7 +566,7 @@ const RUN_LIST: GhAction = { appUser: true, }; -/** GitHub: GET /repos/{owner}/{repo}/releases */ +// GitHub: GET /repos/{owner}/{repo}/releases const RELEASE_LIST: GhAction = { name: 'release:list', command: ['release', 'list'], @@ -584,7 +586,7 @@ const RELEASE_LIST: GhAction = { appUser: true, }; -/** GitHub: GET /repos/{owner}/{repo}/releases/tags/{tag} */ +// GitHub: GET /repos/{owner}/{repo}/releases/tags/{tag} const RELEASE_VIEW: GhAction = { name: 'release:view', command: ['release', 'view'], @@ -593,7 +595,6 @@ const RELEASE_VIEW: GhAction = { { name: 'json', type: 'string' }, { name: 'jq', type: 'string' }, { name: 'template', type: 'string' }, - { name: 'web', type: 'boolean' }, ], permissions: { contents: 'read' }, timeoutSeconds: 120, @@ -601,7 +602,7 @@ const RELEASE_VIEW: GhAction = { appUser: true, }; -/** GitHub: GET /repos/{owner}/{repo}/actions/workflows */ +// GitHub: GET /repos/{owner}/{repo}/actions/workflows const WORKFLOW_LIST: GhAction = { name: 'workflow:list', command: ['workflow', 'list'], @@ -619,17 +620,17 @@ const WORKFLOW_LIST: GhAction = { appUser: true, }; -/** GitHub: GET /repos/{owner}/{repo}/actions/workflows/{workflow_id} */ +// GitHub: GET /repos/{owner}/{repo}/actions/workflows/{workflow_id} (and contents for --yaml/--ref) const WORKFLOW_VIEW: GhAction = { name: 'workflow:view', command: ['workflow', 'view'], - positionals: [{ name: 'workflow', type: 'string' }], + positionals: [{ name: 'workflow', type: 'string', required: true }], flags: [ { name: 'ref', type: 'string' }, - { name: 'web', type: 'boolean' }, { name: 'yaml', type: 'boolean' }, ], - permissions: { actions: 'read' }, + requires: [['ref', 'yaml']], + permissions: { actions: 'read', contents: 'read' }, timeoutSeconds: 120, readOnly: true, appUser: true, @@ -852,6 +853,11 @@ export function buildGhArgv( throw new ActionError(`${name} does not allow --${left} with --${right}`); } } + for (const [left, right] of action.requires ?? []) { + if (present.has(left) && !present.has(right)) { + throw new ActionError(`${name} needs --${right} with --${left}`); + } + } if (typeof values['title'] === 'string') { if (values['title'].trim() === '') { diff --git a/test/unit/actions.test.ts b/test/unit/actions.test.ts index 37d6f6ff..dc4b07f3 100644 --- a/test/unit/actions.test.ts +++ b/test/unit/actions.test.ts @@ -93,7 +93,7 @@ describe('gh action catalog', () => { assert.deepEqual(getGhAction('release:list').permissions, { contents: 'read' }); assert.deepEqual(getGhAction('release:view').permissions, { contents: 'read' }); assert.deepEqual(getGhAction('workflow:list').permissions, { actions: 'read' }); - assert.deepEqual(getGhAction('workflow:view').permissions, { actions: 'read' }); + assert.deepEqual(getGhAction('workflow:view').permissions, { actions: 'read', contents: 'read' }); assert.equal(getGhAction('pr:checks').timeoutSeconds, 300); }); @@ -201,6 +201,29 @@ describe('buildGhArgv', () => { '--repo', 'acme/widget', ]); + assert.deepEqual(buildGhArgv('workflow:list', { all: true, limit: 10 }, 'acme/widget'), [ + 'workflow', + 'list', + '--all', + '--limit', + '10', + '--repo', + 'acme/widget', + ]); + assert.deepEqual(buildGhArgv('release:view', { tag: 'v1.0.0', json: 'tagName' }, 'acme/widget'), [ + 'release', + 'view', + 'v1.0.0', + '--json', + 'tagName', + '--repo', + 'acme/widget', + ]); + assert.throws(() => buildGhArgv('workflow:view', {}, 'acme/widget'), /needs workflow/u); + assert.throws( + () => buildGhArgv('workflow:view', { workflow: 'ci.yml', ref: 'main' }, 'acme/widget'), + /needs --yaml with --ref/u, + ); }); it('rebuilds the canonical argv and injects the repository', () => { From 2822667df6d97b47657faf0ebf4d1b198d1edc20 Mon Sep 17 00:00:00 2001 From: JounQin Date: Sun, 8 Nov 2026 16:34:18 +0000 Subject: [PATCH 3/3] fix: keep string positionals behind an argument separator --- packages/core/src/actions.ts | 11 +++++++++-- test/unit/actions.test.ts | 12 ++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/packages/core/src/actions.ts b/packages/core/src/actions.ts index 23c89689..d9b2d6c8 100644 --- a/packages/core/src/actions.ts +++ b/packages/core/src/actions.ts @@ -743,6 +743,7 @@ export function buildGhArgv( } let argv: string[]; + const trailingPositionals: string[] = []; if (action.api !== undefined) { const substitutions: Record = { owner, @@ -776,7 +777,7 @@ export function buildGhArgv( if (positional.type === 'number') { argv.push(String(asNumber(value, positional.name))); } else { - argv.push(asString(value, positional.name)); + trailingPositionals.push(asString(value, positional.name)); } } } @@ -871,7 +872,13 @@ export function buildGhArgv( throw new ActionError(`the body must be at most ${MAX_BODY_CHARS} characters`); } - if (action.api === undefined) argv.push('--repo', repo); + if (action.api === undefined) { + argv.push('--repo', repo); + if (trailingPositionals.length > 0) { + // Keep caller-controlled strings after -- so a tag or workflow name cannot become a flag. + argv.push('--', ...trailingPositionals); + } + } return argv; } diff --git a/test/unit/actions.test.ts b/test/unit/actions.test.ts index dc4b07f3..96da7c01 100644 --- a/test/unit/actions.test.ts +++ b/test/unit/actions.test.ts @@ -196,11 +196,16 @@ describe('buildGhArgv', () => { assert.deepEqual(buildGhArgv('workflow:view', { workflow: 'ci.yml', yaml: true }, 'acme/widget'), [ 'workflow', 'view', - 'ci.yml', '--yaml', '--repo', 'acme/widget', + '--', + 'ci.yml', ]); + assert.deepEqual( + 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('workflow:list', { all: true, limit: 10 }, 'acme/widget'), [ 'workflow', 'list', @@ -213,12 +218,15 @@ describe('buildGhArgv', () => { assert.deepEqual(buildGhArgv('release:view', { tag: 'v1.0.0', json: 'tagName' }, 'acme/widget'), [ 'release', 'view', - 'v1.0.0', '--json', 'tagName', '--repo', 'acme/widget', + '--', + 'v1.0.0', ]); + const injected = buildGhArgv('release:view', { tag: '--web' }, 'acme/widget'); + assert.deepEqual(injected.slice(-2), ['--', '--web']); assert.throws(() => buildGhArgv('workflow:view', {}, 'acme/widget'), /needs workflow/u); assert.throws( () => buildGhArgv('workflow:view', { workflow: 'ci.yml', ref: 'main' }, 'acme/widget'),