Skip to content
Latchkey

How to Handle a Slash Command With repository_dispatch in GitHub Actions

A repository_dispatch workflow receives the command name as an event type and the parsed arguments in github.event.client_payload.

slash-command-dispatch fires a repository_dispatch with event_type of <command>-command. Match it with on.repository_dispatch.types and read the PR context from client_payload.

Steps

  • Trigger on repository_dispatch with types: [deploy-command].
  • Read the PR number from github.event.client_payload.
  • Run the command logic against that PR.

Handler workflow

.github/workflows/deploy-command.yml
on:
  repository_dispatch:
    types: [deploy-command]
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - env:
          PR: ${{ github.event.client_payload.pull_request.number }}
          REF: ${{ github.event.client_payload.pull_request.head.sha }}
        run: ./deploy.sh --pr "$PR" --sha "$REF"

Gotchas

  • The dispatcher already checked permissions, but a standalone repository_dispatch handler must not be triggerable by unauthorized API calls; require a scoped token.
  • client_payload carries the slash command args and the PR object populated by the dispatcher.
  • repository_dispatch workflows always run from the default branch.

Related guides

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