fix(pr-template-policy): avoid false positive on valid enhancement template banner (#3423)

This commit is contained in:
Tom Boucher
2026-05-11 22:45:33 -04:00
committed by GitHub
parent 3eb46a083c
commit 39e0113bcb
2 changed files with 27 additions and 7 deletions

View File

@@ -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.';
}
}

View File

@@ -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');