Skip to content
Latchkey

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_comment created.
  • List allowed commands and required permission level.
  • Handle each repository_dispatch command 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: write

Handler 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_dispatch event can trigger further workflows.
  • permission: write blocks contributors without write access from running commands.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →