How to Label Pull Requests by Size in GitHub Actions
A wall of unsized PRs is hard to triage; a size label lets reviewers grab the quick ones first.
Compute additions plus deletions from the PR payload, bucket it into a size label, and apply that label with the GitHub CLI.
Steps
- Trigger on
pull_requestsynchronize/opened. - Read
additionsanddeletionsfrom the event. - Bucket the total into a size label.
- Apply the label with
gh pr edit --add-label.
Workflow
.github/workflows/pr-size.yml
name: PR Size
on:
pull_request:
types: [opened, synchronize]
permissions:
pull-requests: write
jobs:
size:
runs-on: ubuntu-latest
steps:
- run: |
total=$(( ${{ github.event.pull_request.additions }} + ${{ github.event.pull_request.deletions }} ))
if [ "$total" -lt 30 ]; then label="size/S";
elif [ "$total" -lt 200 ]; then label="size/M";
else label="size/L"; fi
gh pr edit "${{ github.event.pull_request.number }}" --add-label "$label"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}Notes
- Create the
size/*labels beforehand orghwill fail on a missing label. - Exclude generated files (lockfiles, snapshots) for a fairer size if needed.
Related guides
How to Auto-Label Pull Requests in GitHub ActionsAutomatically label pull requests by changed paths in GitHub Actions with actions/labeler and a labeler confi…
How to Auto-Assign Reviewers in GitHub ActionsAutomatically request reviewers on a pull request from GitHub Actions using the GitHub CLI, so new PRs always…