Skip to content

Instantly share code, notes, and snippets.

@jrobinsonc
Created May 12, 2026 07:13
Show Gist options
  • Select an option

  • Save jrobinsonc/b55d4657fb7cd5af32f6924b2aae30f8 to your computer and use it in GitHub Desktop.

Select an option

Save jrobinsonc/b55d4657fb7cd5af32f6924b2aae30f8 to your computer and use it in GitHub Desktop.
Pre-Push Hook: Run checks for PRs

Pre-Push Hook — Draft PR Guard

This Husky pre-push hook skips CI checks when the current branch is linked to a GitHub draft pull request, allowing work-in-progress branches to be pushed freely. For all other branches (no PR or an open/ready PR), it enforces a full quality gate.

Flow:

  1. Resolves the current branch name via git rev-parse.
  2. Queries the GitHub API (via gh) for the branch's associated PR draft status.
  3. If draft → prints an informational message with the PR number and exits cleanly (exit 0), bypassing all checks.
  4. Otherwise → runs the full check suite via Turbo: check-types, lint, and test.

Dependencies: GitHub CLI (gh), Husky v9+, pnpm, Turborepo.

Check article about hook: https://www.joserobinson.com/en/blog/optimizing-pre-push-hook-skip-checks-draft-prs

# Skip pre-push checks only if the branch is linked to a draft pull request.
# This script requires the GitHub CLI (gh), and the package Husky v9+.
# Get the current branch name
BRANCH=$(git rev-parse --abbrev-ref HEAD)
# Check if there's a PR for this branch and get its draft status
PR_IS_DRAFT=$(gh pr view "$BRANCH" --json isDraft -q '.isDraft' 2>/dev/null || echo "false")
# Check if PR is in draft status
if [ "$PR_IS_DRAFT" = "true" ]; then
PR_NUMBER=$(gh pr view "$BRANCH" --json number -q '.number' 2>/dev/null)
echo "ℹ️ PR #$PR_NUMBER is in draft. Skipping pre-push checks."
echo
exit 0
fi
echo "✓ Running pre-push checks..."
echo
pnpm turbo run check-types lint test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment