@@ -4665,13 +4665,15 @@ var fs = __webpack_require__(747);
4665
4665
const core = __webpack_require__ ( 470 ) ;
4666
4666
4667
4667
const MAX_ARGS = 50 ;
4668
+ const namedArgPattern = / ^ (?< name > [ a - z A - Z 0 - 9 _ ] + ) = (?< value > [ ^ \s ] + ) $ / ;
4668
4669
4669
4670
const commandDefaults = Object . freeze ( {
4670
4671
permission : "write" ,
4671
4672
issue_type : "both" ,
4672
4673
allow_edits : false ,
4673
4674
repository : process . env . GITHUB_REPOSITORY ,
4674
- event_type_suffix : "-command"
4675
+ event_type_suffix : "-command" ,
4676
+ named_args : false
4675
4677
} ) ;
4676
4678
4677
4679
function toBool ( input , defaultVal ) {
@@ -4695,6 +4697,7 @@ function getInputs() {
4695
4697
allowEdits : core . getInput ( "allow-edits" ) ,
4696
4698
repository : core . getInput ( "repository" ) ,
4697
4699
eventTypeSuffix : core . getInput ( "event-type-suffix" ) ,
4700
+ namedArgs : core . getInput ( "named-args" ) ,
4698
4701
config : core . getInput ( "config" ) ,
4699
4702
configFromFile : core . getInput ( "config-from-file" )
4700
4703
} ;
@@ -4738,6 +4741,7 @@ function getCommandsConfigFromInputs(inputs) {
4738
4741
cmd . event_type_suffix = inputs . eventTypeSuffix
4739
4742
? inputs . eventTypeSuffix
4740
4743
: cmd . event_type_suffix ;
4744
+ cmd . named_args = toBool ( inputs . namedArgs , cmd . named_args ) ;
4741
4745
config . push ( cmd ) ;
4742
4746
}
4743
4747
return config ;
@@ -4759,6 +4763,7 @@ function getCommandsConfigFromJson(json) {
4759
4763
cmd . event_type_suffix = jc . event_type_suffix
4760
4764
? jc . event_type_suffix
4761
4765
: cmd . event_type_suffix ;
4766
+ cmd . named_args = toBool ( jc . named_args , cmd . named_args ) ;
4762
4767
config . push ( cmd ) ;
4763
4768
}
4764
4769
return config ;
@@ -4817,16 +4822,30 @@ async function addReaction(octokit, repo, commentId, reaction) {
4817
4822
}
4818
4823
}
4819
4824
4820
- function getSlashCommandPayload ( commentWords ) {
4825
+ function getSlashCommandPayload ( commentWords , namedArgs ) {
4821
4826
var payload = {
4822
4827
command : commentWords [ 0 ] ,
4823
4828
args : ""
4824
4829
} ;
4825
4830
if ( commentWords . length > 1 ) {
4826
4831
const argWords = commentWords . slice ( 1 , MAX_ARGS + 1 ) ;
4827
4832
payload . args = argWords . join ( " " ) ;
4828
- for ( var i = 0 ; i < argWords . length ; i ++ ) {
4829
- payload [ `arg${ i + 1 } ` ] = argWords [ i ] ;
4833
+ // Parse named and unnamed args
4834
+ var unnamedCount = 1 ;
4835
+ var unnamedArgs = [ ] ;
4836
+ for ( var argWord of argWords ) {
4837
+ if ( namedArgs && namedArgPattern . test ( argWord ) ) {
4838
+ const { groups : { name, value } } = namedArgPattern . exec ( argWord ) ;
4839
+ payload [ `${ name } ` ] = value ;
4840
+ } else {
4841
+ unnamedArgs . push ( argWord )
4842
+ payload [ `arg${ unnamedCount } ` ] = argWord ;
4843
+ unnamedCount += 1 ;
4844
+ }
4845
+ }
4846
+ // Add a string of only the unnamed args
4847
+ if ( namedArgs && unnamedArgs . length > 0 ) {
4848
+ payload [ "unnamed_args" ] = unnamedArgs . join ( " " ) ;
4830
4849
}
4831
4850
}
4832
4851
return payload ;
@@ -8049,10 +8068,8 @@ async function run() {
8049
8068
core . info ( `Command '${ commentWords [ 0 ] } ' to be dispatched.` ) ;
8050
8069
8051
8070
// Define payload
8052
- const slashCommandPayload = getSlashCommandPayload ( commentWords ) ;
8053
- core . debug ( `Slash command payload: ${ inspect ( slashCommandPayload ) } ` ) ;
8054
8071
var clientPayload = {
8055
- slash_command : slashCommandPayload ,
8072
+ slash_command : { } ,
8056
8073
github : github . context
8057
8074
} ;
8058
8075
@@ -8067,6 +8084,15 @@ async function run() {
8067
8084
8068
8085
// Dispatch for each matching configuration
8069
8086
for ( const cmd of configMatches ) {
8087
+ // Generate slash command payload
8088
+ clientPayload . slash_command = getSlashCommandPayload (
8089
+ commentWords ,
8090
+ cmd . named_args
8091
+ ) ;
8092
+ core . debug (
8093
+ `Slash command payload: ${ inspect ( clientPayload . slash_command ) } `
8094
+ ) ;
8095
+ // Dispatch the command
8070
8096
const dispatchRepo = cmd . repository . split ( "/" ) ;
8071
8097
const eventType = cmd . command + cmd . event_type_suffix ;
8072
8098
await octokit . repos . createDispatchEvent ( {
0 commit comments