Skip to content

Commit

Permalink
Merge pull request #29 from knowledge-work/feat/multi-command-inputs
Browse files Browse the repository at this point in the history
feat: allows passing multiple command names
  • Loading branch information
wadackel authored Nov 22, 2024
2 parents b82759f + a19e7c2 commit de3d299
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 12 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ Supports null in JSON format.

<!-- gha-inputs-start -->

| ID | Required | Default | Description |
| :----------------- | :----------------- | :------------------- | :------------------------------------------------------------------------------------------- |
| `command` | :white_check_mark: | n/a | The name of the command to be used in IssueOps. |
| `allowed_contexts` | | `issue,pull_request` | The comment contexts that trigger the IssueOps command, specified as a comma-separated list. |
| ID | Required | Default | Description |
| :----------------- | :----------------- | :------------------- | :------------------------------------------------------------------------------------------------ |
| `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. |
| `allowed_contexts` | | `issue,pull_request` | The comment contexts that trigger the IssueOps command, specified as a comma-separated list. |

<!-- gha-inputs-end -->

Expand Down
2 changes: 1 addition & 1 deletion action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ branding:

inputs:
command:
description: 'The name of the command to be used in IssueOps.'
description: 'The name of the command to be used in IssueOps, which can be specified as a comma-separated list.'
required: true
allowed_contexts:
description: 'The comment contexts that trigger the IssueOps command, specified as a comma-separated list.'
Expand Down
11 changes: 8 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34197,6 +34197,7 @@ const run = async () => {
_actions_core__WEBPACK_IMPORTED_MODULE_0__.setOutput('issue_number', _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.payload.issue.number);
_actions_core__WEBPACK_IMPORTED_MODULE_0__.setOutput('comment_id', _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.payload.comment.id);
_actions_core__WEBPACK_IMPORTED_MODULE_0__.setOutput('actor', _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.payload.comment.user.login);
const commands = (0,_utils_js__WEBPACK_IMPORTED_MODULE_4__/* .str2array */ .Z)(inputs.command);
const body = (_actions_github__WEBPACK_IMPORTED_MODULE_1__.context.payload.comment?.['body'] ?? '');
const result = (0,_parse_js__WEBPACK_IMPORTED_MODULE_3__/* .parse */ .Q)(body);
_actions_core__WEBPACK_IMPORTED_MODULE_0__.debug(`parse result: ${JSON.stringify(result)}`);
Expand All @@ -34210,12 +34211,13 @@ const run = async () => {
_actions_core__WEBPACK_IMPORTED_MODULE_0__.info('No command was detected in the comment.');
return 0;
}
if (result.command !== inputs.command) {
if (!commands.includes(result.command)) {
_actions_core__WEBPACK_IMPORTED_MODULE_0__.setOutput('continue', 'false');
_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.`);
_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.`);
return 0;
}
_actions_core__WEBPACK_IMPORTED_MODULE_0__.setOutput('continue', 'true');
_actions_core__WEBPACK_IMPORTED_MODULE_0__.setOutput('command', result.command);
_actions_core__WEBPACK_IMPORTED_MODULE_0__.setOutput('params', JSON.stringify(result.params));
_actions_core__WEBPACK_IMPORTED_MODULE_0__.info('params:');
_actions_core__WEBPACK_IMPORTED_MODULE_0__.info(JSON.stringify(result.params, null, 2));
Expand Down Expand Up @@ -34347,7 +34349,10 @@ const parse = (input) => {
/**
* Helpers
*/
const str2array = (input) => input.split(',').map((s) => s.trim());
const str2array = (input) => input
.split(',')
.map((s) => s.trim())
.filter((s) => s !== '');


/***/ }),
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const run = async () => {
core.setOutput('comment_id', context.payload.comment!.id);
core.setOutput('actor', context.payload.comment!['user'].login);

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

if (result.command !== inputs.command) {
if (!commands.includes(result.command)) {
core.setOutput('continue', 'false');
core.info(
`The "${result.command}" command was detected in the comment. However, since it is not the "${inputs.command}" command, the trigger has been canceled.`,
`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.`,
);
return 0;
}

core.setOutput('continue', 'true');
core.setOutput('command', result.command);
core.setOutput('params', JSON.stringify(result.params));

core.info('params:');
Expand Down
11 changes: 11 additions & 0 deletions src/utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { expect, test } from 'vitest';
import { str2array } from './utils.js';

test.each([
['empty', '', []],
['single item', 'foo', ['foo']],
['multiple items', 'foo,bar,baz', ['foo', 'bar', 'baz']],
['trailing comma', 'a,b,c,', ['a', 'b', 'c']],
])('str2array - %s', (_, input, expected) => {
expect(str2array(input)).toEqual(expected);
});
6 changes: 5 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/**
* Helpers
*/
export const str2array = (input: string): string[] => input.split(',').map((s) => s.trim());
export const str2array = (input: string): string[] =>
input
.split(',')
.map((s) => s.trim())
.filter((s) => s !== '');

0 comments on commit de3d299

Please sign in to comment.