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
6 changes: 6 additions & 0 deletions .changeset/catalog-search.md
Original file line number Diff line number Diff line change
@@ -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`, and rejects `repo:` / `org:` / `user:` qualifiers in the query, so a search cannot escape the allowlist.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
<!-- action-permissions:end -->

`pr status` with `--repo` reports the app identity's relevant pull requests and review requests
Expand Down
62 changes: 62 additions & 0 deletions packages/core/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' }],
Comment thread
JounQin marked this conversation as resolved.
Resolved
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<Record<string, GhAction>> = Object.freeze({
'pr:view': PR_VIEW,
Expand Down Expand Up @@ -803,6 +854,8 @@ export const GH_ACTIONS: Readonly<Record<string, GhAction>> = 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. */
Expand Down Expand Up @@ -1000,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');
Expand Down
46 changes: 46 additions & 0 deletions test/unit/actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
});

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -254,6 +260,46 @@ 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',
],
);
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,
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'],
);

assert.deepEqual(
buildGhArgv('issue:comment-delete', { commentId: 123 }, 'acme/widget'),
['api', '--method', 'DELETE', 'repos/acme/widget/issues/comments/123'],
Expand Down
Loading