Skip to content

Commit ea25d3a

Browse files
committed
Update documentation
1 parent 00faff1 commit ea25d3a

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

.github/slash-command-dispatch.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"command": "create",
44
"permission": "write",
55
"issue_type": "issue",
6-
"event_type_suffix": "-cmd"
6+
"event_type_suffix": "-cmd",
7+
"named_args": true
78
},
89
{
910
"command": "delete",

README.md

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ Use the JSON properties for [Advanced configuration](#advanced-configuration).
7171
| `allow-edits` | `allow_edits` | Allow edited comments to trigger command dispatches. | `false` |
7272
| `repository` | `repository` | The full name of the repository to send the dispatch events. | Current repository |
7373
| `event-type-suffix` | `event_type_suffix` | The repository dispatch event type suffix for the commands. | `-command` |
74+
| `named-args` | `named_args` | Parse named arguments and add them to the command payload. | `false` |
7475
| `config` | | JSON configuration for commands. See [Advanced configuration](#advanced-configuration) | |
7576
| `config-from-file` | | JSON configuration from a file for commands. See [Advanced configuration](#advanced-configuration) | |
7677

@@ -122,7 +123,8 @@ jobs:
122123
"command": "integration-test",
123124
"permission": "write",
124125
"issue_type": "both",
125-
"repository": "peter-evans/slash-command-dispatch-processor"
126+
"repository": "peter-evans/slash-command-dispatch-processor",
127+
"named_args": true
126128
},
127129
{
128130
"command": "create-ticket",
@@ -168,10 +170,12 @@ on:
168170
types: [integration-test-command]
169171
```
170172

171-
### Accessing command contexts
173+
### Accessing contexts
172174

173175
Commands are dispatched with a payload containing a number of contexts.
174176

177+
#### `slash_command` context
178+
175179
The slash command context can be accessed as follows.
176180
`args` is a space separated string of all the supplied arguments.
177181
Each argument is also supplied in a numbered property, i.e. `arg1`, `arg2`, `arg3`, etc.
@@ -187,6 +191,36 @@ Each argument is also supplied in a numbered property, i.e. `arg1`, `arg2`, `arg
187191
# etc.
188192
```
189193

194+
If the `named-args` input (or `named_args` JSON property) is set to `true`, any arguments that are prefixed in the format `name=argument` will be parsed and added to the payload.
195+
196+
For example, the slash command `/deploy branch=master env=prod some other args` will be set in the JSON payload as follows.
197+
198+
```json
199+
{
200+
"command": "deploy",
201+
"args": "branch=master env=prod some other args",
202+
"unnamed_args": "some other args",
203+
"branch": "master",
204+
"env": "prod",
205+
"arg1": "some",
206+
"arg2": "other",
207+
"arg3": "args"
208+
}
209+
```
210+
211+
These named args can be accessed in a workflow as follows.
212+
213+
```yml
214+
- name: Output command and named arguments
215+
run: |
216+
echo ${{ github.event.client_payload.slash_command.command }}
217+
echo ${{ github.event.client_payload.slash_command.branch }}
218+
echo ${{ github.event.client_payload.slash_command.env }}
219+
echo ${{ github.event.client_payload.slash_command.unnamed_args }}
220+
```
221+
222+
#### `github` and `pull_request` contexts
223+
190224
The payload contains the complete `github` context of the `issue_comment` event at path `github.event.client_payload.github`.
191225
Additionally, if the comment was made in a pull request, the action calls the [GitHub API to fetch the pull request detail](https://developer.github.com/v3/pulls/#get-a-single-pull-request) and attach it to the payload at path `github.event.client_payload.pull_request`.
192226

action.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ inputs:
2121
description: 'The full name of the repository to send the dispatch events.'
2222
event-type-suffix:
2323
description: 'The repository dispatch event type suffix for the commands.'
24+
named-args:
25+
description: 'Parse named arguments and add them to the command payload.'
2426
config:
2527
description: 'JSON configuration for commands.'
2628
config-from-file:

0 commit comments

Comments
 (0)