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: https://github.com/react/react-native/pull/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
This commit is contained in:
Nicola Corti authored and meta-codesync[bot] committed 2026-10-20 04:01:26 -07:00
1 parent e6ebdc3794
commit fa2baa2849
2 files changed
+68 -5

No files matched your search

@@ -0,0 +1,62 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
'use strict';
const validatePRBody = require('../validatePRBody');
function prBody(changelog) {
return `## Summary
Explain why the change is needed.
${changelog}
## Test Plan
Run the unit tests.`;
}
describe('validatePRBody changelog headings', () => {
it.each(['## Changelog', '## Changelog:'])(
'accepts %s with a tagged entry',
heading => {
expect(
validatePRBody(prBody(`${heading}\n\n[GENERAL] [FIXED] - Fix a bug`)),
).toEqual({message: '', status: 'PASS'});
},
);
it('accepts a heading without a colon with CRLF line endings', () => {
const body = prBody('## Changelog\n\n[INTERNAL] [FIXED] - Fix CI');
expect(validatePRBody(body.replace(/\n/g, '\r\n'))).toEqual({
message: '',
status: 'PASS',
});
});
it('accepts consecutive internal changelogs consistently', () => {
const body = prBody('## Changelog\n\n[INTERNAL] [FIXED] - Fix CI');
expect(validatePRBody(body).status).toBe('PASS');
expect(validatePRBody(body).status).toBe('PASS');
});
it('still requires a tagged entry', () => {
expect(validatePRBody(prBody('## Changelog\n\nNo tags')).message).toContain(
'Invalid Changelog Format',
);
});
it('does not treat an unmarked Changelog line as a heading', () => {
expect(
validatePRBody(prBody('Changelog\n\n[GENERAL] [FIXED] - Fix a bug'))
.message,
).toContain('Missing Changelog');
});
});
+6 -5
View File
@@ -12,14 +12,15 @@
const changelogRegex =
/\[\s?(ANDROID|GENERAL|IOS|INTERNAL)\s?\]\s?\[\s?(BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY)\s?\]\s*?-?\s*?(.*)/i;
const internalChangelogRegex = /\[\s?(INTERNAL)\s?\].*/gi;
const internalChangelogRegex = /\[\s?(INTERNAL)\s?\].*/i;
function validateChangelog(commitMsg) {
if (!commitMsg.toLowerCase().includes('changelog:')) {
function validateChangelog(prBody) {
const hasChangelogHeading = /^##[ \t]+changelog[ \t]*\r?$/im.test(prBody);
if (!prBody.toLowerCase().includes('changelog:') && !hasChangelogHeading) {
return 'missing';
}
const hasValidChangelog = changelogRegex.test(commitMsg);
const hasValidInternalChangelog = internalChangelogRegex.test(commitMsg);
const hasValidChangelog = changelogRegex.test(prBody);
const hasValidInternalChangelog = internalChangelogRegex.test(prBody);
if (hasValidChangelog || hasValidInternalChangelog) {
return 'valid';