Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions scripts/pr-policy.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,19 @@ function normalizePath(filePath) {
.replace(/^\.\/+/, "");
}

function normalizeSectionHeading(value) {
return String(value ?? "")
.trim()
.replace(/\s+#+\s*$/, "")
.trim()
.toLowerCase();
}

function section(body, heading) {
const source = String(body ?? "");
const headings = [...source.matchAll(/^##\s+(.+?)\s*$/gim)];
const matchIndex = headings.findIndex((match) => match[1]?.trim().toLowerCase() === heading.toLowerCase());
const headings = [...source.matchAll(/^#{2,6}[ \t]+(.+?)[ \t]*$/gim)];
const targetHeading = normalizeSectionHeading(heading);
const matchIndex = headings.findIndex((match) => normalizeSectionHeading(match[1]) === targetHeading);
if (matchIndex < 0) return "";
const start = (headings[matchIndex]?.index ?? 0) + (headings[matchIndex]?.[0].length ?? 0);
const end = headings[matchIndex + 1]?.index ?? source.length;
Expand Down Expand Up @@ -254,6 +263,10 @@ function selfTest() {
operationalRisk: false,
ui: false,
});
assert.equal(
section("### Summary ###\n\n- concise summary\n\n### Verification\n\n- [x] `npm run verify:pr-local`\n", "Summary"),
"- concise summary",
);
const template = readFileSync(new URL("../.github/pull_request_template.md", import.meta.url), "utf8");
for (const item of requiredClinicalGovernanceItems)
assert.match(template, new RegExp(`- \\[ \\] ${item.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`));
Expand Down
Loading