Skip to content

Commit 608bd1a

Browse files
committed
Accept changelog headings without colons in PR validation
1 parent e6ebdc3 commit 608bd1a

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)