Skip to content

Commit 00faff1

Browse files
committed
Add named args command config
1 parent 899b263 commit 00faff1

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

src/func.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ const commandDefaults = Object.freeze({
1010
issue_type: "both",
1111
allow_edits: false,
1212
repository: process.env.GITHUB_REPOSITORY,
13-
event_type_suffix: "-command"
13+
event_type_suffix: "-command",
14+
named_args: false
1415
});
1516

1617
function toBool(input, defaultVal) {
@@ -34,6 +35,7 @@ function getInputs() {
3435
allowEdits: core.getInput("allow-edits"),
3536
repository: core.getInput("repository"),
3637
eventTypeSuffix: core.getInput("event-type-suffix"),
38+
namedArgs: core.getInput("named-args"),
3739
config: core.getInput("config"),
3840
configFromFile: core.getInput("config-from-file")
3941
};
@@ -77,6 +79,7 @@ function getCommandsConfigFromInputs(inputs) {
7779
cmd.event_type_suffix = inputs.eventTypeSuffix
7880
? inputs.eventTypeSuffix
7981
: cmd.event_type_suffix;
82+
cmd.named_args = toBool(inputs.namedArgs, cmd.named_args);
8083
config.push(cmd);
8184
}
8285
return config;
@@ -98,6 +101,7 @@ function getCommandsConfigFromJson(json) {
98101
cmd.event_type_suffix = jc.event_type_suffix
99102
? jc.event_type_suffix
100103
: cmd.event_type_suffix;
104+
cmd.named_args = toBool(jc.named_args, cmd.named_args);
101105
config.push(cmd);
102106
}
103107
return config;

src/func.test.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ test("building config with required inputs only", async () => {
2323
expect(config[i].event_type_suffix).toEqual(
2424
commandDefaults.event_type_suffix
2525
);
26+
expect(config[i].named_args).toEqual(commandDefaults.named_args);
2627
}
2728
});
2829

@@ -33,7 +34,8 @@ test("building config with optional inputs", async () => {
3334
issueType: "pull-request",
3435
allowEdits: true,
3536
repository: "owner/repo",
36-
eventTypeSuffix: "-cmd"
37+
eventTypeSuffix: "-cmd",
38+
namedArgs: true
3739
};
3840
const commands = inputs.commands.replace(/\s+/g, "").split(",");
3941
const config = getCommandsConfigFromInputs(inputs);
@@ -45,6 +47,7 @@ test("building config with optional inputs", async () => {
4547
expect(config[i].allow_edits).toEqual(inputs.allowEdits);
4648
expect(config[i].repository).toEqual(inputs.repository);
4749
expect(config[i].event_type_suffix).toEqual(inputs.eventTypeSuffix);
50+
expect(config[i].named_args).toEqual(inputs.namedArgs);
4851
}
4952
});
5053

@@ -69,6 +72,7 @@ test("building config with required JSON only", async () => {
6972
expect(config[i].event_type_suffix).toEqual(
7073
commandDefaults.event_type_suffix
7174
);
75+
expect(config[i].named_args).toEqual(commandDefaults.named_args);
7276
}
7377
});
7478

@@ -80,7 +84,8 @@ test("building config with optional JSON properties", async () => {
8084
"issue_type": "pull-request",
8185
"allow_edits": true,
8286
"repository": "owner/repo",
83-
"event_type_suffix": "-cmd"
87+
"event_type_suffix": "-cmd",
88+
"named_args": true
8489
},
8590
{
8691
"command": "test-all-the-things",
@@ -96,6 +101,7 @@ test("building config with optional JSON properties", async () => {
96101
expect(config[0].allow_edits).toBeTruthy();
97102
expect(config[0].repository).toEqual("owner/repo");
98103
expect(config[0].event_type_suffix).toEqual("-cmd");
104+
expect(config[0].named_args).toBeTruthy();
99105
expect(config[1].command).toEqual(commands[1]);
100106
expect(config[1].permission).toEqual("read");
101107
expect(config[1].issue_type).toEqual(commandDefaults.issue_type);

src/index.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,8 @@ async function run() {
136136
core.info(`Command '${commentWords[0]}' to be dispatched.`);
137137

138138
// Define payload
139-
const slashCommandPayload = getSlashCommandPayload(commentWords);
140-
core.debug(`Slash command payload: ${inspect(slashCommandPayload)}`);
141139
var clientPayload = {
142-
slash_command: slashCommandPayload,
140+
slash_command: {},
143141
github: github.context
144142
};
145143

@@ -154,6 +152,15 @@ async function run() {
154152

155153
// Dispatch for each matching configuration
156154
for (const cmd of configMatches) {
155+
// Generate slash command payload
156+
clientPayload.slash_command = getSlashCommandPayload(
157+
commentWords,
158+
cmd.named_args
159+
);
160+
core.debug(
161+
`Slash command payload: ${inspect(clientPayload.slash_command)}`
162+
);
163+
// Dispatch the command
157164
const dispatchRepo = cmd.repository.split("/");
158165
const eventType = cmd.command + cmd.event_type_suffix;
159166
await octokit.repos.createDispatchEvent({

0 commit comments

Comments
 (0)