Skip to content
Latchkey

How to Fail a PR That Exceeds a Diff Size

Read additions plus deletions from the PR payload and fail the check when the total exceeds your cap.

The pull_request payload exposes additions and deletions. Use actions/github-script to sum them and call core.setFailed when the total crosses your limit, with an override label as an escape hatch.

Steps

  • Trigger on pull_request opened and synchronize.
  • Sum additions and deletions from the payload.
  • Fail when the total exceeds the cap unless an override label is set.

Workflow

.github/workflows/ci.yml
on:
  pull_request:
    types: [opened, synchronize]
jobs:
  size-gate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/github-script@v7
        with:
          script: |
            const pr = context.payload.pull_request
            const total = pr.additions + pr.deletions
            const override = pr.labels.some((l) => l.name === 'large-pr-ok')
            const cap = 800
            if (total > cap && !override) {
              core.setFailed(`PR changes ${total} lines, over the ${cap} line cap.`)
            }

Gotchas

  • additions and deletions count all changed lines, including generated files; exclude those with a Danger rule if needed.
  • The synchronize event refreshes the numbers on each new push.

Related guides

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