From 7568eee578f57b8bf041919872de302e18fd42f1 Mon Sep 17 00:00:00 2001 From: JounQin Date: Mon, 9 Nov 2026 16:18:07 +0000 Subject: [PATCH 1/3] feat: add repo-scoped issue and PR search --- .changeset/catalog-search.md | 6 ++++ README.md | 2 ++ packages/core/src/actions.ts | 53 ++++++++++++++++++++++++++++++++++++ test/unit/actions.test.ts | 28 +++++++++++++++++++ 4 files changed, 89 insertions(+) create mode 100644 .changeset/catalog-search.md diff --git a/.changeset/catalog-search.md b/.changeset/catalog-search.md new file mode 100644 index 00000000..dfbbb3a8 --- /dev/null +++ b/.changeset/catalog-search.md @@ -0,0 +1,6 @@ +--- +'gcb-core': minor +--- + +Add repo-scoped search actions: `search:issues` (`issues: read`) and `search:prs` +(`pull_requests: read`). The broker still injects `--repo`, so a search cannot escape the allowlist. diff --git a/README.md b/README.md index 62f2771a..e4412255 100644 --- a/README.md +++ b/README.md @@ -832,6 +832,8 @@ actions. Grant them on the App, then approve any changed permissions on each ins | `label create` | `issues: write` | | `label edit` | `issues: write` | | `label delete` | `issues: write` | +| `search issues` | `issues: read` | +| `search prs` | `pull_requests: 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 42a4417c..2ba43237 100644 --- a/packages/core/src/actions.ts +++ b/packages/core/src/actions.ts @@ -757,6 +757,57 @@ const LABEL_DELETE: GhAction = { appUser: true, }; +// GitHub: GET /search/issues (issues) +const SEARCH_ISSUES: GhAction = { + name: 'search:issues', + command: ['search', 'issues'], + positionals: [{ name: 'query', type: 'string' }], + flags: [ + { name: 'assignee', type: 'string' }, + { name: 'author', type: 'string' }, + { name: 'json', type: 'string' }, + { name: 'jq', type: 'string' }, + { name: 'label', type: 'string', repeatable: true }, + { name: 'limit', type: 'number' }, + { name: 'match', type: 'string', repeatable: true }, + { name: 'order', type: 'string' }, + { name: 'sort', type: 'string' }, + { name: 'state', type: 'string' }, + { name: 'template', type: 'string' }, + ], + permissions: { issues: 'read' }, + timeoutSeconds: 120, + readOnly: true, + appUser: true, +}; + +// GitHub: GET /search/issues (pull requests) +const SEARCH_PRS: GhAction = { + name: 'search:prs', + command: ['search', 'prs'], + positionals: [{ name: 'query', type: 'string' }], + flags: [ + { name: 'assignee', type: 'string' }, + { name: 'author', type: 'string' }, + { name: 'base', type: 'string' }, + { name: 'draft', type: 'boolean' }, + { name: 'head', type: 'string' }, + { name: 'json', type: 'string' }, + { name: 'jq', type: 'string' }, + { name: 'label', type: 'string', repeatable: true }, + { name: 'limit', type: 'number' }, + { name: 'match', type: 'string', repeatable: true }, + { name: 'order', type: 'string' }, + { name: 'sort', type: 'string' }, + { name: 'state', type: 'string' }, + { name: 'template', type: 'string' }, + ], + permissions: { pull_requests: '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, @@ -803,6 +854,8 @@ export const GH_ACTIONS: Readonly> = Object.freeze({ 'label:create': LABEL_CREATE, 'label:edit': LABEL_EDIT, 'label:delete': LABEL_DELETE, + 'search:issues': SEARCH_ISSUES, + 'search:prs': SEARCH_PRS, }); /** The built-in action names, in a stable order. */ diff --git a/test/unit/actions.test.ts b/test/unit/actions.test.ts index 40a58df4..bbe43560 100644 --- a/test/unit/actions.test.ts +++ b/test/unit/actions.test.ts @@ -57,6 +57,8 @@ describe('gh action catalog', () => { 'label:create', 'label:edit', 'label:delete', + 'search:issues', + 'search:prs', ]); assert.equal('pr:merge' in GH_ACTIONS, false); assert.equal(getGhAction('pr:create').command.join(' '), 'pr create'); @@ -117,6 +119,8 @@ describe('gh action catalog', () => { assert.deepEqual(getGhAction('label:create').permissions, { issues: 'write' }); assert.deepEqual(getGhAction('label:edit').permissions, { issues: 'write' }); assert.deepEqual(getGhAction('label:delete').permissions, { issues: 'write' }); + assert.deepEqual(getGhAction('search:issues').permissions, { issues: 'read' }); + assert.deepEqual(getGhAction('search:prs').permissions, { pull_requests: 'read' }); assert.equal(getGhAction('pr:checks').timeoutSeconds, 300); }); @@ -147,6 +151,8 @@ describe('gh action catalog', () => { 'workflow:list', 'workflow:view', 'label:list', + 'search:issues', + 'search:prs', ]) { assert.equal(getGhAction(name).readOnly, true, name); assert.equal(getGhAction(name).appUser, true, name); @@ -254,6 +260,28 @@ describe('buildGhArgv', () => { /needs --yes/u, ); + assert.deepEqual( + buildGhArgv('search:issues', { query: 'bug', label: ['one', 'two'], limit: 5 }, 'acme/widget'), + [ + 'search', + 'issues', + '--label', + 'one', + '--label', + 'two', + '--limit', + '5', + '--repo', + 'acme/widget', + '--', + 'bug', + ], + ); + assert.deepEqual( + buildGhArgv('search:prs', { query: 'fix', draft: true }, 'acme/widget'), + ['search', 'prs', '--draft', '--repo', 'acme/widget', '--', 'fix'], + ); + assert.deepEqual( buildGhArgv('issue:comment-delete', { commentId: 123 }, 'acme/widget'), ['api', '--method', 'DELETE', 'repos/acme/widget/issues/comments/123'], From b75dba3d07348d66017dd53bc744e2499c33aa3e Mon Sep 17 00:00:00 2001 From: JounQin Date: Mon, 9 Nov 2026 16:33:05 +0000 Subject: [PATCH 2/3] fix: reject repo qualifiers in search queries --- .changeset/catalog-search.md | 2 +- packages/core/src/actions.ts | 9 +++++++++ test/unit/actions.test.ts | 9 +++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/.changeset/catalog-search.md b/.changeset/catalog-search.md index dfbbb3a8..f05f1ac9 100644 --- a/.changeset/catalog-search.md +++ b/.changeset/catalog-search.md @@ -3,4 +3,4 @@ --- Add repo-scoped search actions: `search:issues` (`issues: read`) and `search:prs` -(`pull_requests: read`). The broker still injects `--repo`, so a search cannot escape the allowlist. +(`pull_requests: read`). The broker still injects `--repo`, and rejects `repo:` / `org:` / `user:` qualifiers in the query, so a search cannot escape the allowlist. diff --git a/packages/core/src/actions.ts b/packages/core/src/actions.ts index 2ba43237..e934e079 100644 --- a/packages/core/src/actions.ts +++ b/packages/core/src/actions.ts @@ -1053,6 +1053,15 @@ export function buildGhArgv( } } + if ( + action.command[0] === 'search' && + typeof values['query'] === 'string' && + /(?:^|\s)-?(?:repo|org|user):/iu.test(values['query']) + ) { + throw new ActionError( + 'search query cannot contain repo:, org: or user:; the broker scopes it to --repo', + ); + } if (typeof values['title'] === 'string') { if (values['title'].trim() === '') { throw new ActionError('the title must not be empty'); diff --git a/test/unit/actions.test.ts b/test/unit/actions.test.ts index bbe43560..1e19280a 100644 --- a/test/unit/actions.test.ts +++ b/test/unit/actions.test.ts @@ -277,6 +277,15 @@ describe('buildGhArgv', () => { 'bug', ], ); + for (const query of ['repo:other/repo bug', 'org:other bug', 'user:other bug', '-repo:other/repo']) { + assert.throws( + () => buildGhArgv('search:issues', { query }, 'acme/widget'), + /cannot contain repo:, org: or user:/u, + query, + ); + } + assert.doesNotThrow(() => buildGhArgv('search:issues', { query: 'is:issue label:bug' }, 'acme/widget')); + assert.deepEqual( buildGhArgv('search:prs', { query: 'fix', draft: true }, 'acme/widget'), ['search', 'prs', '--draft', '--repo', 'acme/widget', '--', 'fix'], From 3153d7fd77ab8731e2a9e6424dd1dd37ced072f7 Mon Sep 17 00:00:00 2001 From: JounQin Date: Mon, 9 Nov 2026 16:42:52 +0000 Subject: [PATCH 3/3] fix: catch grouped repository qualifiers in search --- packages/core/src/actions.ts | 2 +- test/unit/actions.test.ts | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/core/src/actions.ts b/packages/core/src/actions.ts index e934e079..f442c40d 100644 --- a/packages/core/src/actions.ts +++ b/packages/core/src/actions.ts @@ -1056,7 +1056,7 @@ export function buildGhArgv( if ( action.command[0] === 'search' && typeof values['query'] === 'string' && - /(?:^|\s)-?(?:repo|org|user):/iu.test(values['query']) + /(?:^|[\s(])-?(?:repo|org|user):/iu.test(values['query']) ) { throw new ActionError( 'search query cannot contain repo:, org: or user:; the broker scopes it to --repo', diff --git a/test/unit/actions.test.ts b/test/unit/actions.test.ts index 1e19280a..2ba9b119 100644 --- a/test/unit/actions.test.ts +++ b/test/unit/actions.test.ts @@ -277,7 +277,16 @@ describe('buildGhArgv', () => { 'bug', ], ); - for (const query of ['repo:other/repo bug', 'org:other bug', 'user:other bug', '-repo:other/repo']) { + for (const query of [ + 'repo:other/repo bug', + 'org:other bug', + 'user:other bug', + '-repo:other/repo', + 'bug org:other', + '(repo:other/repo)', + '(org:other)', + '(user:other)', + ]) { assert.throws( () => buildGhArgv('search:issues', { query }, 'acme/widget'), /cannot contain repo:, org: or user:/u,