From 39e0113bcbcfb5562d1d03a78c3fafdc0cda1425 Mon Sep 17 00:00:00 2001 From: Tom Boucher Date: Mon, 11 May 2026 22:45:33 -0400 Subject: [PATCH] fix(pr-template-policy): avoid false positive on valid enhancement template banner (#3423) --- scripts/pr-template-policy.cjs | 16 +++++++++------- tests/pr-template-policy.test.cjs | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/scripts/pr-template-policy.cjs b/scripts/pr-template-policy.cjs index f8dcc5455..2100ba622 100644 --- a/scripts/pr-template-policy.cjs +++ b/scripts/pr-template-policy.cjs @@ -112,19 +112,21 @@ function evaluatePrTemplate(body, authorAssociation) { if (!normalizedBody) { valid = false; reason = 'PR body is empty; a typed pull request template is required.'; - } else if (includesDefaultTemplate(normalizedBody)) { - valid = false; - reason = 'PR body still contains the default wrong-template guidance.'; } else { const match = matchingTemplate(normalizedBody); template = match.template; missingHeadings = match.missingHeadings; - if (!template) { - valid = false; - reason = 'PR body does not match the fix, enhancement, or feature template.'; - } else if (missingHeadings.length > 0) { + if (template && missingHeadings.length === 0) { + valid = true; + } else if (template && missingHeadings.length > 0) { valid = false; reason = `PR body appears to use the ${template} template but is missing required headings.`; + } else if (includesDefaultTemplate(normalizedBody)) { + valid = false; + reason = 'PR body still contains the default wrong-template guidance.'; + } else { + valid = false; + reason = 'PR body does not match the fix, enhancement, or feature template.'; } } diff --git a/tests/pr-template-policy.test.cjs b/tests/pr-template-policy.test.cjs index e5c818c3d..f274ba545 100644 --- a/tests/pr-template-policy.test.cjs +++ b/tests/pr-template-policy.test.cjs @@ -99,6 +99,24 @@ describe('pr-template-policy', () => { assert.equal(result.template, 'enhancement'); }); + test('does not flag default-template marker phrase inside a valid enhancement template', () => { + const body = enhancementBody.replace( + '## Linked Issue', + [ + '> **Using the wrong template?**', + '> - Bug fix: use [fix.md](?template=fix.md)', + '> - New feature: use [feature.md](?template=feature.md)', + '', + '## Linked Issue', + ].join('\n'), + ); + const result = evaluatePrTemplate(body, 'COLLABORATOR'); + + assert.equal(result.valid, true); + assert.equal(result.action, 'pass'); + assert.equal(result.template, 'enhancement'); + }); + test('passes PR bodies that use the feature template', () => { const result = evaluatePrTemplate(featureBody, 'FIRST_TIME_CONTRIBUTOR');