Skip to content

Pre-push hook

A lightweight, opt-in hook that mirrors the Validate PR body sections CI gate locally so PR bodies can be validated before opening / updating the PR.

Source .husky/pre-push

What it does

If the hook finds a PR body file at one of these paths it validates that the file contains the three mandatory headers required by .github/workflows/pr-body-check.yml:

Source (in priority order) Why
PR_BODY_FILE=<path> environment variable Explicit pointer used by automation / agents
.git/PR_BODY.md Per-repo, gitignored by default (lives under .git/)
.github/PR_BODY.md Versioned alternative for teams that prefer it

If none of those are present the hook prints a hint and exits 0 (most pushes are work-in-progress + branch syncing — the body doesn't exist yet).

Required headers

Header pr-guidlines.md cite
## Guideline compliance §10 — compliance table
## Why §7 — motivation paragraph
## What §7 — bullet list of touched files

These are the same three headers the CI workflow enforces on every PR open / edit / synchronise.

Manual invocation

The validator runs as a standalone npm script too:

# Validate a file
npm run lint:pr-body -- --file .git/PR_BODY.md

# Validate via env var
PR_BODY_FILE=.git/PR_BODY.md npm run lint:pr-body

# Pipe from another tool
gh pr view 336 --json body -q .body | node scripts/validate-pr-body.mjs --stdin
Exit code Meaning
0 Body contains all mandatory sections
1 At least one mandatory section is missing
2 Usage error (no source provided / file unreadable)

Why this hook exists

CR cycle PR #336 #1 paired a CodeRabbit code finding with a CI failure on Validate PR body sections — the PR was opened without the mandatory headers because nothing validated the body locally. This hook closes the gap so contributors and agents (who write the body file before invoking gh pr create --body-file …) get the same enforcement the CI workflow applies after the PR is opened.

Bot-author exemption (Dependabot, release-please, github-actions) lives only on the CI side — local pushes from a human contributor always validate when a body file is discoverable.

# 1. Write the PR body to the standard local artifact path
$EDITOR .git/PR_BODY.md

# 2. Optional: validate without pushing
npm run lint:pr-body -- --file .git/PR_BODY.md

# 3. Push — the pre-push hook validates again
git push

# 4. Open the PR with the validated body
gh pr create --body-file .git/PR_BODY.md

Bypassing the hook (don't)

The hook can be bypassed with git push --no-verify. Don't. The CI gate still blocks the PR until the body is fixed, wasting your iteration time.