name: Slash Command Dispatch
on:
issue_comment:
types: [created]
jobs:
slashCommandDispatch:
runs-on: ubuntu-latest
steps:
- name: Slash Command Dispatch
uses: peter-evans/slash-command-dispatch@v4
with:
token: ${{ secrets.PAT }}
commands: |
deploy
integration-test
build-docs
slash-command-dispatch-action
This action enables ChatOps by processing slash commands from GitHub issue comments and creating dispatch events.
What is slash-command-dispatch-action?β
The slash-command-dispatch-action
allows you to set up slash commands in GitHub comments and dispatch them to execute workflows, enabling efficient "ChatOps" integration. This allows for flexible command processing while keeping the workflow queue moving quickly.
How to Use the token
Inputβ
To dispatch commands, the action requires a repository scoped Personal Access Token (PAT). The default GITHUB_TOKEN
will not work for this.
with:
token: ${{ secrets.PAT }}
Make sure the PAT has sufficient permissions, such as public_repo
for public repositories.
How to Add Reactions to Commentsβ
You can configure reactions (e.g., π for seen, π for dispatched) by setting the reactions
input:
with:
reactions: true
You can also use a custom reaction-token
to have the reactions made by a specific user rather than the GitHub Actions bot:
with:
reaction-token: ${{ secrets.PAT }}
How to Specify Required Permissions for Command Dispatchβ
Use the permission
input to specify the repository permission level required to execute slash commands. The default is write
, meaning users with write, maintain, or admin permissions can execute commands:
with:
permission: write
You can set it to one of the following: none
, read
, triage
, write
, maintain
, admin
.
How to Define the Event Type Suffixβ
The event-type-suffix
option allows you to customize the suffix for the event type created by the slash command. The default suffix is -command
:
with:
event-type-suffix: "-action"
For example, the command /deploy
would create an event of type deploy-action
.
How to Dispatch Workflow Eventsβ
By default, the action creates repository_dispatch
events. If you need to create workflow_dispatch
events, set dispatch-type
to workflow
:
with:
dispatch-type: workflow
This allows workflows to run in specific branches by using the ref
argument in your slash command.
How to Add Static Arguments to Commandsβ
You can define static arguments that will be dispatched with every command using the static-args
input:
with:
static-args: |
production
region=us-east-1
These arguments will be included in the payload along with any dynamic arguments provided in the comment.
How to Handle Command Outputsβ
To respond to a command completion, you can add a reaction or a comment. Hereβs how to add a π reaction to the comment:
- name: Add reaction
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.PAT }}
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
reactions: hooray
You can also create a new comment with a link to the run output:
- name: Create URL to the run output
id: vars
run: echo "run-url=https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" >> $GITHUB_OUTPUT
- name: Create comment
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.PAT }}
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
issue-number: ${{ github.event.client_payload.github.payload.issue.number }}
body: |
[Command run output][1]
[1]: ${{ steps.vars.outputs.run-url }}
Monitoring GitHub Actions Workflows
CICube is a GitHub Actions monitoring tool that provides you with detailed insights into your workflows to further optimize your CI/CD pipeline. With CICube, you will be able to track your workflow runs, understand where the bottlenecks are, and tease out the best from your build times. Go to cicube.io now and create a free account to better optimize your GitHub Actions workflows!