#!/usr/bin/env bun /** * Validates that a pull request body follows .github/pull_request_template.md: * required sections are filled in and the key checklist items are ticked. * * Usage: bun scripts/check-pr-template.mjs * Output: a JSON array of human-readable problems (empty array = all good). * Exit: 0 = ok, 1 = one or more problems, 2 = no body file given. * * Env: AUTHOR_ASSOCIATION — when OWNER/MEMBER/COLLABORATOR, the AI-disclosure * check is skipped (maintainers self-police). */ import { existsSync, readFileSync } from "node:fs"; const bodyFile = process.argv[2]; if (!bodyFile) { console.error("usage: bun scripts/check-pr-template.mjs "); process.exit(2); } const body = readFileSync(bodyFile, "utf8").replace(/\r\n/g, "\n"); const association = (process.env.AUTHOR_ASSOCIATION || "").toUpperCase(); const isMaintainer = ["OWNER", "MEMBER", "COLLABORATOR"].includes(association); // Strip HTML comments in a single linear pass: remove complete `` // blocks, then drop any leftover unterminated `/g, "") .replace(/