pr-template-check
v0.1.0
Published
Check a draft pull request body against a GitHub repo's own PR template before you open it
Maintainers
Readme
pr-template-check
Check a draft pull request body against a GitHub repo's own PR template — before you open the PR.
Why
Every repo enforces its .github/pull_request_template.md differently: some require every
checklist box, some require a ## Description heading, some require a Fixes #123 reference,
and reviewers (or bots) will bounce your PR back if you miss one. There's no way to know which
of those a given repo actually cares about except by opening the template file and reading it
yourself, every single time, for every repo you contribute to.
pr-template-check reads the target repo's own template, extracts what it actually asks for
(checklist items, required headings, an expected Fixes #N reference), and checks your draft
against it locally — before you submit anything.
Install
npm install -g pr-template-checkRequires the GitHub CLI (gh), authenticated, since that's what
pr-template-check uses to read repo contents and PR bodies.
Usage
Check a draft body file against a repo's template:
pr-template-check check --repo dotnet/aspnetcore --body-file draft.mdCheck the body of a PR you've already opened:
pr-template-check check --repo dotnet/aspnetcore --pr 69280Pipe a draft from stdin:
cat draft.md | pr-template-check check --repo dotnet/aspnetcoreOr just see what a repo's template actually requires:
pr-template-check template --repo dotnet/aspnetcoreIf --repo is omitted, it's inferred from the current directory's git remote get-url origin.
Example
$ pr-template-check check --repo dotnet/aspnetcore --pr 69280
Template: .github/pull_request_template.md
Checklist items:
[x] You've read the Contributor Guide and Code of Conduct.
[x] You've included unit or integration tests for your change, where applicable.
[x] You've included inline docs for your change, where applicable.
[x] There's an open issue for the PR that you are making.
Required sections:
✓ ## Description
Placeholders to fill in manually (not auto-verifiable):
✓ found an issue reference Fixes #{bug number} (in this specific format)
PASS: all required checklist items and sections are present.The exit code is 0 on pass and 1 on fail, so it's usable as a pre-submit script or a local
git hook.
How matching works
- Checklist items (
- [ ] ...lines in the template) are matched against checklist lines in your draft using word-overlap, so minor rewording doesn't cause a false negative — but a missing item is reported as[MISSING]. - Headings (
## ...) must appear with matching text somewhere in your draft. - A placeholder title like
# {PR title}is recognized as an instruction to the contributor, not a literal required heading, and is skipped. - A
Fixes #{...}/Closes #{...}/Resolves #{...}placeholder is checked against your body for an actualfixes/closes/resolves #<number>reference, but — unlike checklist items and headings — it's reported as a warning only and never fails the check, since not every repo strictly requires a linked issue. - Everything else in the template (free-form prose, other placeholders) is printed for manual review, since it can't be reliably auto-verified.
Development
npm install
npm test # vitest
npm run build # tsup -> dist/
npm run typecheckLicense
MIT
