Skip to content

Commit fa2baa2

Browse files
cortinicometa-codesync[bot]
authored andcommitted
Accept changelog headings with or without a colon (#59219)
Summary: Allow Analyze Pull Request to recognize both `## Changelog` and `## Changelog:` in PR descriptions. The PR template uses a colon, but a properly tagged changelog under a heading without one was incorrectly reported as missing. Preserve the existing colon format and requirement for a tagged entry. Remove the stateful global flag from the internal changelog pattern so repeated validations agree. ## Changelog: [INTERNAL] [FIXED] - Accept changelog headings with or without a colon in PR validation. Pull Request resolved: #59219 Test Plan: - `yarn test .github/workflow-scripts/__tests__/validatePRBody-test.js --runInBand --silent` — passed (6 tests). - `yarn prettier .github/workflow-scripts/validatePRBody.js .github/workflow-scripts/__tests__/validatePRBody-test.js --check` — passed. - `yarn lint` — passed. - `git diff --check` — passed. No UI changes; screenshots are not applicable. Reviewed By: cipolleschi Differential Revision: D126318404 Pulled By: cortinico fbshipit-source-id: aac410fba37299a3c2de5d238e21527968acd7fd
1 parent e6ebdc3 commit fa2baa2

2 files changed

Lines changed: 68 additions & 5 deletions

File tree

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @format
8+
*/
9+
10+
'use strict';
11+
12+
const validatePRBody = require('../validatePRBody');
13+
14+
function prBody(changelog) {
15+
return `## Summary
16+
17+
Explain why the change is needed.
18+
19+
${changelog}
20+
21+
## Test Plan
22+
23+
Run the unit tests.`;
24+
}
25+
26+
describe('validatePRBody changelog headings', () => {
27+
it.each(['## Changelog', '## Changelog:'])(
28+
'accepts %s with a tagged entry',
29+
heading => {
30+
expect(
31+
validatePRBody(prBody(`${heading}\n\n[GENERAL] [FIXED] - Fix a bug`)),
32+
).toEqual({message: '', status: 'PASS'});
33+
},
34+
);
35+
36+
it('accepts a heading without a colon with CRLF line endings', () => {
37+
const body = prBody('## Changelog\n\n[INTERNAL] [FIXED] - Fix CI');
38+
expect(validatePRBody(body.replace(/\n/g, '\r\n'))).toEqual({
39+
message: '',
40+
status: 'PASS',
41+
});
42+
});
43+
44+
it('accepts consecutive internal changelogs consistently', () => {
45+
const body = prBody('## Changelog\n\n[INTERNAL] [FIXED] - Fix CI');
46+
expect(validatePRBody(body).status).toBe('PASS');
47+
expect(validatePRBody(body).status).toBe('PASS');
48+
});
49+
50+
it('still requires a tagged entry', () => {
51+
expect(validatePRBody(prBody('## Changelog\n\nNo tags')).message).toContain(
52+
'Invalid Changelog Format',
53+
);
54+
});
55+
56+
it('does not treat an unmarked Changelog line as a heading', () => {
57+
expect(
58+
validatePRBody(prBody('Changelog\n\n[GENERAL] [FIXED] - Fix a bug'))
59+
.message,
60+
).toContain('Missing Changelog');
61+
});
62+
});

‎.github/workflow-scripts/validatePRBody.js‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
const changelogRegex =
1313
/\[\s?(ANDROID|GENERAL|IOS|INTERNAL)\s?\]\s?\[\s?(BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY)\s?\]\s*?-?\s*?(.*)/i;
1414

15-
const internalChangelogRegex = /\[\s?(INTERNAL)\s?\].*/gi;
15+
const internalChangelogRegex = /\[\s?(INTERNAL)\s?\].*/i;
1616

17-
function validateChangelog(commitMsg) {
18-
if (!commitMsg.toLowerCase().includes('changelog:')) {
17+
function validateChangelog(prBody) {
18+
const hasChangelogHeading = /^##[ \t]+changelog[ \t]*\r?$/im.test(prBody);
19+
if (!prBody.toLowerCase().includes('changelog:') && !hasChangelogHeading) {
1920
return 'missing';
2021
}
21-
const hasValidChangelog = changelogRegex.test(commitMsg);
22-
const hasValidInternalChangelog = internalChangelogRegex.test(commitMsg);
22+
const hasValidChangelog = changelogRegex.test(prBody);
23+
const hasValidInternalChangelog = internalChangelogRegex.test(prBody);
2324

2425
if (hasValidChangelog || hasValidInternalChangelog) {
2526
return 'valid';

0 commit comments

Comments
 (0)