From bc17404f7ca085aed78f7c4cc8f05cd6e15ca8c8 Mon Sep 17 00:00:00 2001 From: William Harrison <87287585+wdhdev@users.noreply.github.com> Date: Wed, 19 Aug 2026 11:48:15 +0800 Subject: [PATCH] Create check-pr-template.js --- util/check-pr-template.js | 76 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 util/check-pr-template.js diff --git a/util/check-pr-template.js b/util/check-pr-template.js new file mode 100644 index 0000000000..c05db0f978 --- /dev/null +++ b/util/check-pr-template.js @@ -0,0 +1,76 @@ +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.", +]; + +function escapeRegExp(value) { + return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); +} + +function isRequiredCheckboxChecked(text) { + const regex = new RegExp( + `-\\s*\\[[xX]\\]\\s*(?:\\s*)?${escapeRegExp(text)}`, + "i", + ); + + return regex.test(body); +} + +function getSection(startMarker, endMarker) { + const regex = new RegExp( + `${escapeRegExp(startMarker)}([\\s\\S]*?)${escapeRegExp(endMarker)}`, + "i", + ); + + const match = body.match(regex); + + return match ? match[1].trim() : ""; +} + +const errors = []; + +const uncheckedRequirements = REQUIRED_CHECKBOXES.filter( + (requirement) => !isRequiredCheckboxChecked(requirement), +); + +if (uncheckedRequirements.length > 0) { + errors.push( + "The following required checkboxes have not been checked:", + ...uncheckedRequirements.map((requirement) => `- ${requirement}`), + ); +} + +const websitePreview = getSection( + "", + "", +); + +if (!websitePreview) { + errors.push("The **Website Preview** section has not been filled out."); +} + +const websitePurpose = getSection( + "", + "", +); + +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); +} + +console.log("PR template validation passed.");