fix(pr-template-policy): avoid false positive on valid enhancement template banner (#3423)
This commit is contained in:
@@ -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.';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user