From ea25d3a6f5ba854148c71a4a94e0567eebefa026 Mon Sep 17 00:00:00 2001 From: Peter Evans Date: Sat, 4 Jan 2020 17:45:21 +0900 Subject: [PATCH] Update documentation --- .github/slash-command-dispatch.json | 3 ++- README.md | 38 +++++++++++++++++++++++++++-- action.yml | 2 ++ 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/.github/slash-command-dispatch.json b/.github/slash-command-dispatch.json index cc18ef6..a419b1c 100644 --- a/.github/slash-command-dispatch.json +++ b/.github/slash-command-dispatch.json @@ -3,7 +3,8 @@ "command": "create", "permission": "write", "issue_type": "issue", - "event_type_suffix": "-cmd" + "event_type_suffix": "-cmd", + "named_args": true }, { "command": "delete", diff --git a/README.md b/README.md index dcd1e09..cbfbea8 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,7 @@ Use the JSON properties for [Advanced configuration](#advanced-configuration). | `allow-edits` | `allow_edits` | Allow edited comments to trigger command dispatches. | `false` | | `repository` | `repository` | The full name of the repository to send the dispatch events. | Current repository | | `event-type-suffix` | `event_type_suffix` | The repository dispatch event type suffix for the commands. | `-command` | +| `named-args` | `named_args` | Parse named arguments and add them to the command payload. | `false` | | `config` | | JSON configuration for commands. See [Advanced configuration](#advanced-configuration) | | | `config-from-file` | | JSON configuration from a file for commands. See [Advanced configuration](#advanced-configuration) | | @@ -122,7 +123,8 @@ jobs: "command": "integration-test", "permission": "write", "issue_type": "both", - "repository": "peter-evans/slash-command-dispatch-processor" + "repository": "peter-evans/slash-command-dispatch-processor", + "named_args": true }, { "command": "create-ticket", @@ -168,10 +170,12 @@ on: types: [integration-test-command] ``` -### Accessing command contexts +### Accessing contexts Commands are dispatched with a payload containing a number of contexts. +#### `slash_command` context + The slash command context can be accessed as follows. `args` is a space separated string of all the supplied arguments. 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 # etc. ``` +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. + +For example, the slash command `/deploy branch=master env=prod some other args` will be set in the JSON payload as follows. + +```json +{ + "command": "deploy", + "args": "branch=master env=prod some other args", + "unnamed_args": "some other args", + "branch": "master", + "env": "prod", + "arg1": "some", + "arg2": "other", + "arg3": "args" +} +``` + +These named args can be accessed in a workflow as follows. + +```yml + - name: Output command and named arguments + run: | + echo ${{ github.event.client_payload.slash_command.command }} + echo ${{ github.event.client_payload.slash_command.branch }} + echo ${{ github.event.client_payload.slash_command.env }} + echo ${{ github.event.client_payload.slash_command.unnamed_args }} +``` + +#### `github` and `pull_request` contexts + The payload contains the complete `github` context of the `issue_comment` event at path `github.event.client_payload.github`. 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`. diff --git a/action.yml b/action.yml index 7cf1c9f..9c2036b 100644 --- a/action.yml +++ b/action.yml @@ -21,6 +21,8 @@ inputs: description: 'The full name of the repository to send the dispatch events.' event-type-suffix: description: 'The repository dispatch event type suffix for the commands.' + named-args: + description: 'Parse named arguments and add them to the command payload.' config: description: 'JSON configuration for commands.' config-from-file: