Skip to content

Commit de3d299

Browse files
authored
Merge pull request #29 from knowledge-work/feat/multi-command-inputs
feat: allows passing multiple command names
2 parents b82759f + a19e7c2 commit de3d299

File tree

7 files changed

+34
-12
lines changed

7 files changed

+34
-12
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,10 @@ Supports null in JSON format.
165165

166166
<!-- gha-inputs-start -->
167167

168-
| ID | Required | Default | Description |
169-
| :----------------- | :----------------- | :------------------- | :------------------------------------------------------------------------------------------- |
170-
| `command` | :white_check_mark: | n/a | The name of the command to be used in IssueOps. |
171-
| `allowed_contexts` | | `issue,pull_request` | The comment contexts that trigger the IssueOps command, specified as a comma-separated list. |
168+
| ID | Required | Default | Description |
169+
| :----------------- | :----------------- | :------------------- | :------------------------------------------------------------------------------------------------ |
170+
| `command` | :white_check_mark: | n/a | The name of the command to be used in IssueOps, which can be specified as a comma-separated list. |
171+
| `allowed_contexts` | | `issue,pull_request` | The comment contexts that trigger the IssueOps command, specified as a comma-separated list. |
172172

173173
<!-- gha-inputs-end -->
174174

action.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ branding:
77

88
inputs:
99
command:
10-
description: 'The name of the command to be used in IssueOps.'
10+
description: 'The name of the command to be used in IssueOps, which can be specified as a comma-separated list.'
1111
required: true
1212
allowed_contexts:
1313
description: 'The comment contexts that trigger the IssueOps command, specified as a comma-separated list.'

dist/index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34197,6 +34197,7 @@ const run = async () => {
3419734197
_actions_core__WEBPACK_IMPORTED_MODULE_0__.setOutput('issue_number', _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.payload.issue.number);
3419834198
_actions_core__WEBPACK_IMPORTED_MODULE_0__.setOutput('comment_id', _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.payload.comment.id);
3419934199
_actions_core__WEBPACK_IMPORTED_MODULE_0__.setOutput('actor', _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.payload.comment.user.login);
34200+
const commands = (0,_utils_js__WEBPACK_IMPORTED_MODULE_4__/* .str2array */ .Z)(inputs.command);
3420034201
const body = (_actions_github__WEBPACK_IMPORTED_MODULE_1__.context.payload.comment?.['body'] ?? '');
3420134202
const result = (0,_parse_js__WEBPACK_IMPORTED_MODULE_3__/* .parse */ .Q)(body);
3420234203
_actions_core__WEBPACK_IMPORTED_MODULE_0__.debug(`parse result: ${JSON.stringify(result)}`);
@@ -34210,12 +34211,13 @@ const run = async () => {
3421034211
_actions_core__WEBPACK_IMPORTED_MODULE_0__.info('No command was detected in the comment.');
3421134212
return 0;
3421234213
}
34213-
if (result.command !== inputs.command) {
34214+
if (!commands.includes(result.command)) {
3421434215
_actions_core__WEBPACK_IMPORTED_MODULE_0__.setOutput('continue', 'false');
34215-
_actions_core__WEBPACK_IMPORTED_MODULE_0__.info(`The "${result.command}" command was detected in the comment. However, since it is not the "${inputs.command}" command, the trigger has been canceled.`);
34216+
_actions_core__WEBPACK_IMPORTED_MODULE_0__.info(`The "${result.command}" command was detected in the comment. However, since it is not included in the list of commands ("${commands.join(', ')}"), the trigger has been canceled.`);
3421634217
return 0;
3421734218
}
3421834219
_actions_core__WEBPACK_IMPORTED_MODULE_0__.setOutput('continue', 'true');
34220+
_actions_core__WEBPACK_IMPORTED_MODULE_0__.setOutput('command', result.command);
3421934221
_actions_core__WEBPACK_IMPORTED_MODULE_0__.setOutput('params', JSON.stringify(result.params));
3422034222
_actions_core__WEBPACK_IMPORTED_MODULE_0__.info('params:');
3422134223
_actions_core__WEBPACK_IMPORTED_MODULE_0__.info(JSON.stringify(result.params, null, 2));
@@ -34347,7 +34349,10 @@ const parse = (input) => {
3434734349
/**
3434834350
* Helpers
3434934351
*/
34350-
const str2array = (input) => input.split(',').map((s) => s.trim());
34352+
const str2array = (input) => input
34353+
.split(',')
34354+
.map((s) => s.trim())
34355+
.filter((s) => s !== '');
3435134356

3435234357

3435334358
/***/ }),

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ const run = async () => {
5959
core.setOutput('comment_id', context.payload.comment!.id);
6060
core.setOutput('actor', context.payload.comment!['user'].login);
6161

62+
const commands = str2array(inputs.command);
6263
const body = (context.payload.comment?.['body'] ?? '') as string;
6364
const result = parse(body);
6465
core.debug(`parse result: ${JSON.stringify(result)}`);
@@ -75,15 +76,16 @@ const run = async () => {
7576
return 0;
7677
}
7778

78-
if (result.command !== inputs.command) {
79+
if (!commands.includes(result.command)) {
7980
core.setOutput('continue', 'false');
8081
core.info(
81-
`The "${result.command}" command was detected in the comment. However, since it is not the "${inputs.command}" command, the trigger has been canceled.`,
82+
`The "${result.command}" command was detected in the comment. However, since it is not included in the list of commands ("${commands.join(', ')}"), the trigger has been canceled.`,
8283
);
8384
return 0;
8485
}
8586

8687
core.setOutput('continue', 'true');
88+
core.setOutput('command', result.command);
8789
core.setOutput('params', JSON.stringify(result.params));
8890

8991
core.info('params:');

src/utils.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { expect, test } from 'vitest';
2+
import { str2array } from './utils.js';
3+
4+
test.each([
5+
['empty', '', []],
6+
['single item', 'foo', ['foo']],
7+
['multiple items', 'foo,bar,baz', ['foo', 'bar', 'baz']],
8+
['trailing comma', 'a,b,c,', ['a', 'b', 'c']],
9+
])('str2array - %s', (_, input, expected) => {
10+
expect(str2array(input)).toEqual(expected);
11+
});

src/utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
/**
22
* Helpers
33
*/
4-
export const str2array = (input: string): string[] => input.split(',').map((s) => s.trim());
4+
export const str2array = (input: string): string[] =>
5+
input
6+
.split(',')
7+
.map((s) => s.trim())
8+
.filter((s) => s !== '');

0 commit comments

Comments
 (0)