Skip to content
Latchkey

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_request synchronize/opened.
  • Read additions and deletions from 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 or gh will fail on a missing label.
  • Exclude generated files (lockfiles, snapshots) for a fairer size if needed.

Related guides

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