From 759626cf0ea55a1ebe49e61dda0daa070278f170 Mon Sep 17 00:00:00 2001 From: William Harrison <87287585+wdhdev@users.noreply.github.com> Date: Wed, 19 Aug 2026 12:07:29 +0800 Subject: [PATCH] Refactor PR template validation and requirements --- util/check-pr-template.js | 68 ++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/util/check-pr-template.js b/util/check-pr-template.js index 1b20233213..fbc4b58425 100644 --- a/util/check-pr-template.js +++ b/util/check-pr-template.js @@ -1,22 +1,18 @@ const body = process.env.PR_BODY || ""; const REQUIRED_CHECKBOXES = [ - "I agree to the [Terms of Service]", - "My file is following the [domain structure]", - "My website is reachable and completed.", - "My website is software development related.", - "My website is not for commercial use.", - "I have provided sufficient contact information in the `owner` key.", - "I have provided a link to my website below.", + "TOS", + "DOMAIN_STRUCTURE", + "WEBSITE_REACHABLE", + "SOFTWARE_RELATED", + "NON_COMMERCIAL", + "CONTACT_INFO", + "WEBSITE_LINK", ]; -function escapeRegExp(value) { - return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); -} - -function isRequiredCheckboxChecked(text) { +function isCheckboxChecked(marker) { const regex = new RegExp( - `-\\s*\\[[xX]\\]\\s*(?:\\s*)?${escapeRegExp(text)}`, + `-\\s*\\[[xX]\\]\\s*`, "i", ); @@ -34,41 +30,47 @@ function getSection(startMarker, endMarker) { return match ? match[1].trim() : ""; } +function escapeRegExp(value) { + return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); +} + const errors = []; -const uncheckedRequirements = REQUIRED_CHECKBOXES.filter( - (requirement) => !isRequiredCheckboxChecked(requirement), +for (const checkbox of REQUIRED_CHECKBOXES) { + if (!isCheckboxChecked(checkbox)) { + errors.push( + `The \`${checkbox}\` requirement has not been checked.`, + ); + } +} + +const websitePreview = getSection( + "", + "", ); -if (uncheckedRequirements.length > 0) { +if (!websitePreview) { errors.push( - "The following required checkboxes have not been checked:", - ...uncheckedRequirements.map((requirement) => `- ${requirement}`), + "The **Website Preview** section has not been filled out.", ); } -if ( - !getSection( - "", - "", - ) -) { - errors.push("The **Website Preview** section has not been filled out."); -} +const websitePurpose = getSection( + "", + "", +); -if ( - !getSection( - "", - "", - ) -) { - errors.push("The **Website Purpose** section has not been filled out."); +if (!websitePurpose) { + errors.push( + "The **Website Purpose** section has not been filled out.", + ); } if (errors.length > 0) { console.error("PR template validation failed."); console.error(""); console.error(errors.join("\n")); + process.exit(1); }