Run approved commands from comments (ChatOps)

DevOps, Hands On25 minutesFreeSteps checked 19 November 2026By Cloud Hands On

In this task you'll let trusted people run a deployment by commenting on a pull request.

ChatOps puts operations where the team already talks: a comment such as /deploy staging on a pull request starts the deployment, and the bot replies with the result. Everyone sees who asked, what ran and what happened.

The workflow runs on issue_comment. It must check who commented (author_association such as OWNER, MEMBER or COLLABORATOR) and what they asked for, and ignore everything else: a public repository gets comments from anyone.

Example. SS Kaiser's developers comment /deploy staging on their pull requests. The workflow checks they're a collaborator, deploys that branch to staging, and replies 'Deployed abc1234 to staging' with a link to the run.

Before you start

You need: A GitHub repository. Time: 25 minutes.

Where to look

  1. Repository
  2. Actions
  3. New workflow

Steps

  1. Add a workflow on issue_comment: types: created .
  2. In the job's if:, require the comment to be on a pull request, to start with /deploy, and to come from OWNER, MEMBER or COLLABORATOR.
  3. Do the work, then reply with gh pr comment and the result.
  4. Test with a comment from your account, and confirm a comment from someone else is ignored.

Commands

gh pr comment 12 --body "/deploy staging"

Watch out for

Cost
Free on public repositories.
Security
Never run code or commands taken from the comment text itself; match exact commands only.
Common mistakes
Forgetting the author check, so anyone can trigger a deployment.

Clean up

Delete the workflow file.

Words to know

ChatOps
Running operations from a chat or comment, with the result posted back for everyone to see.
issue_comment
The GitHub event for comments on issues and pull requests.
author_association
How a commenter relates to the repository, such as OWNER, MEMBER, COLLABORATOR or NONE.

Tick off each step and track your progress in the guide.

Open this task in DevOps, Hands On

Keep going