How to Add Slash Commands to Pull Requests
A slash-command dispatcher parses issue comments and fires a repository_dispatch event per command.
Run peter-evans/slash-command-dispatch on issue_comment created events. It matches configured commands (like deploy, rebase) and dispatches a repository_dispatch event that a handler workflow listens for.
Steps
- Trigger a dispatcher workflow on
issue_commentcreated. - List allowed commands and required permission level.
- Handle each
repository_dispatchcommand in a separate workflow.
Dispatcher workflow
.github/workflows/ci.yml
on:
issue_comment:
types: [created]
jobs:
dispatch:
if: github.event.issue.pull_request
runs-on: ubuntu-latest
steps:
- uses: peter-evans/slash-command-dispatch@v4
with:
token: ${{ secrets.PAT }}
commands: |
deploy
rebase
permission: writeHandler workflow
.github/workflows/deploy-command.yml
on:
repository_dispatch:
types: [deploy-command]
jobs:
run-deploy:
runs-on: ubuntu-latest
steps:
- run: ./scripts/deploy.sh "${{ github.event.client_payload.pull_request.number }}"Gotchas
- A PAT is needed so the
repository_dispatchevent can trigger further workflows. permission: writeblocks contributors without write access from running commands.