DevOps / Scripts bash Intermediate

GitHub PR Auto-Labeler via CLI

Automatically label GitHub PRs based on changed file paths using the gh CLI.

bash
#!/bin/bash
PR=$1
FILES=$(gh pr diff $PR --name-only)
if echo "$FILES" | grep -q "^frontend/"; then gh pr edit $PR --add-label frontend; fi
if echo "$FILES" | grep -q "^api/";      then gh pr edit $PR --add-label backend;  fi
if echo "$FILES" | grep -q "\.tf$";      then gh pr edit $PR --add-label terraform; fi

Prerequisites

  • gh CLI
  • GitHub repository

Pro Tips

  • → Call from a GitHub Actions workflow on pull_request events.

Was this module useful?

Share your experience — it helps the team improve.

Leave Feedback

Commercial Licensing

Acquire a production access token or template license for enterprise deployment.

Module Info

Language
bash
Level
Intermediate
Read time
2 min
Published
Jul 2025
License
Commercial License

Newsletter

New modules every week, directly to your inbox.