From 54f5c579c1e152c9bb82f09a2dae87b9297f8663 Mon Sep 17 00:00:00 2001 From: TonyRL Date: Wed, 12 Aug 2026 01:48:50 +0800 Subject: [PATCH] chore: improve template validation --- scripts/workflow/test-route/identify.mjs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/scripts/workflow/test-route/identify.mjs b/scripts/workflow/test-route/identify.mjs index 947793fe08..5e8e127521 100644 --- a/scripts/workflow/test-route/identify.mjs +++ b/scripts/workflow/test-route/identify.mjs @@ -9,7 +9,6 @@ const allowedUser = new Set(['dependabot[bot]', 'pull[bot]']); // dependabot and const requiredHeadings = ['Involved Issue / 该 PR 相关 Issue', 'Example for the Proposed Route(s) / 路由地址示例', 'New RSS Route Checklist / 新 RSS 路由检查表', 'Note / 说明']; const routeHeading = requiredHeadings[1]; const checklistHeading = requiredHeadings[2]; -const requiredHeadingDepth = 2; /** @type {boolean} */ const isPR = Boolean(process.env.PULL_REQUEST); @@ -150,13 +149,18 @@ export default async function identify({ github, context, core }, body, number, if (isPR) { /** @param {string} text */ - const findHeading = (text) => ast.children.findIndex((node) => node.type === 'heading' && node.depth === requiredHeadingDepth && node.children?.some((child) => child.type === 'text' && child.value.trim() === text)); + const findHeading = (text) => ast.children.findIndex((node) => node.type === 'heading' && node.depth === 2 && node.children?.some((child) => child.type === 'text' && child.value.trim() === text)); /** @param {string} text */ const missingChecklist = (text) => { const headingIndex = findHeading(text); const nextHeading = ast.children.findIndex((node, i) => i > headingIndex && node.type === 'heading'); - return ast.children.slice(headingIndex + 1, nextHeading === -1 ? undefined : nextHeading).every((node) => node.type !== 'list' || !node.children?.some((item) => typeof item.checked === 'boolean')); + const checkboxCount = ast.children + .slice(headingIndex + 1, nextHeading === -1 ? undefined : nextHeading) + .filter((node) => node.type === 'list') + .flatMap((node) => node.children ?? []) + .filter((item) => typeof item.checked === 'boolean').length; + return checkboxCount < 5; }; const missingHeadings = requiredHeadings.filter((text) => findHeading(text) === -1);