Require the command to be in the first line

This commit is contained in:
Peter Evans
2020-03-03 19:22:35 +09:00
parent 351fb8d890
commit 7a310a37e7
3 changed files with 297 additions and 298 deletions
+279 -281
View File
File diff suppressed because one or more lines are too long
+4 -4
View File
@@ -160,13 +160,13 @@ async function addReaction(octokit, repo, commentId, reaction) {
}
}
function getSlashCommandPayload(commentWords, namedArgs) {
function getSlashCommandPayload(commandWords, namedArgs) {
var payload = {
command: commentWords[0],
command: commandWords[0],
args: ""
};
if (commentWords.length > 1) {
const argWords = commentWords.slice(1, MAX_ARGS + 1);
if (commandWords.length > 1) {
const argWords = commandWords.slice(1, MAX_ARGS + 1);
payload.args = argWords.join(" ");
// Parse named and unnamed args
var unnamedCount = 1;
+14 -13
View File
@@ -44,23 +44,24 @@ async function run() {
core.debug(`Comment body: ${commentBody}`);
core.debug(`Comment id: ${commentId}`);
// Check if the comment is a slash command
if (commentBody.charAt(0) != "/" || commentBody.length < 2) {
core.info("Comment is not a valid slash command.");
// Check if the first line of the comment is a slash command
const firstLine = commentBody.split(/\r?\n/)[0];
if (firstLine.length < 2 || firstLine.charAt(0) != "/") {
console.debug("The first line of the comment is not a valid slash command.");
return;
}
// Split the comment into "words"
const commentWords = commentBody.slice(1).split(" ");
core.debug(`Comment words: ${inspect(commentWords)}`);
// Split the first line into "words"
const commandWords = firstLine.slice(1).split(" ");
core.debug(`Command words: ${inspect(commandWords)}`);
// Check if the command is registered for dispatch
var configMatches = config.filter(function(cmd) {
return cmd.command == commentWords[0];
return cmd.command == commandWords[0];
});
core.debug(`Config matches on 'command': ${inspect(configMatches)}`);
if (configMatches.length == 0) {
core.info(`Command '${commentWords[0]}' is not registered for dispatch.`);
core.info(`Command '${commandWords[0]}' is not registered for dispatch.`);
return;
}
@@ -77,7 +78,7 @@ async function run() {
if (configMatches.length == 0) {
const issueType = isPullRequest ? "pull request" : "issue";
core.info(
`Command '${commentWords[0]}' is not configured for the issue type '${issueType}'.`
`Command '${commandWords[0]}' is not configured for the issue type '${issueType}'.`
);
return;
}
@@ -90,7 +91,7 @@ async function run() {
core.debug(`Config matches on 'allow_edits': ${inspect(configMatches)}`);
if (configMatches.length == 0) {
core.info(
`Command '${commentWords[0]}' is not configured to allow edits.`
`Command '${commandWords[0]}' is not configured to allow edits.`
);
return;
}
@@ -127,13 +128,13 @@ async function run() {
core.debug(`Config matches on 'permission': ${inspect(configMatches)}`);
if (configMatches.length == 0) {
core.info(
`Command '${commentWords[0]}' is not configured for the user's permission level '${actorPermission}'.`
`Command '${commandWords[0]}' is not configured for the user's permission level '${actorPermission}'.`
);
return;
}
// Determined that the command should be dispatched
core.info(`Command '${commentWords[0]}' to be dispatched.`);
core.info(`Command '${commandWords[0]}' to be dispatched.`);
// Define payload
var clientPayload = {
@@ -154,7 +155,7 @@ async function run() {
for (const cmd of configMatches) {
// Generate slash command payload
clientPayload.slash_command = getSlashCommandPayload(
commentWords,
commandWords,
cmd.named_args
);
core.debug(