mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-08-29 01:53:47 +08:00
chore: improve template validation
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user