Fix issue with changelog generation selection case-sensitivity (#46936)
* Fix issue with changelog generation selection case-sensitivity * Appease linter * Update case insensitivity to every field
This commit is contained in:
parent
dd8aa94db9
commit
b68ba7629f
File diff suppressed because one or more lines are too long
|
@ -2,6 +2,7 @@
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
*/
|
*/
|
||||||
import {
|
import {
|
||||||
|
shouldAutomateChangelog,
|
||||||
getChangelogSignificance,
|
getChangelogSignificance,
|
||||||
getChangelogType,
|
getChangelogType,
|
||||||
getChangelogDetails,
|
getChangelogDetails,
|
||||||
|
@ -17,6 +18,50 @@ jest.mock( '../../../core/logger', () => {
|
||||||
};
|
};
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
describe( 'shouldAutomateChangelog', () => {
|
||||||
|
it( 'should return true when checked', () => {
|
||||||
|
const body =
|
||||||
|
'### Changelog entry\r\n' +
|
||||||
|
'\r\n' +
|
||||||
|
'<!-- You can optionally choose to enter a changelog entry by checking the box and supplying data. -->\r\n' +
|
||||||
|
'\r\n' +
|
||||||
|
'- [x] Automatically create a changelog entry from the details below.\r\n' +
|
||||||
|
'\r\n';
|
||||||
|
const shouldAutomate = shouldAutomateChangelog( body );
|
||||||
|
expect( shouldAutomate ).toBe( true );
|
||||||
|
} );
|
||||||
|
|
||||||
|
it( 'should return true when checked with upper-case', () => {
|
||||||
|
const body =
|
||||||
|
'### Changelog entry\r\n' +
|
||||||
|
'\r\n' +
|
||||||
|
'<!-- You can optionally choose to enter a changelog entry by checking the box and supplying data. -->\r\n' +
|
||||||
|
'\r\n' +
|
||||||
|
'- [X] Automatically create a changelog entry from the details below.\r\n' +
|
||||||
|
'\r\n';
|
||||||
|
const shouldAutomate = shouldAutomateChangelog( body );
|
||||||
|
expect( shouldAutomate ).toBe( true );
|
||||||
|
} );
|
||||||
|
|
||||||
|
it( 'should return false when unchecked', () => {
|
||||||
|
const body =
|
||||||
|
'### Changelog entry\r\n' +
|
||||||
|
'\r\n' +
|
||||||
|
'<!-- You can optionally choose to enter a changelog entry by checking the box and supplying data. -->\r\n' +
|
||||||
|
'\r\n' +
|
||||||
|
'- [ ] Automatically create a changelog entry from the details below.\r\n' +
|
||||||
|
'\r\n';
|
||||||
|
const shouldAutomate = shouldAutomateChangelog( body );
|
||||||
|
expect( shouldAutomate ).toBe( false );
|
||||||
|
} );
|
||||||
|
|
||||||
|
it( 'should return false when missing from body', () => {
|
||||||
|
const body = '';
|
||||||
|
const shouldAutomate = shouldAutomateChangelog( body );
|
||||||
|
expect( shouldAutomate ).toBe( false );
|
||||||
|
} );
|
||||||
|
} );
|
||||||
|
|
||||||
describe( 'getChangelogSignificance', () => {
|
describe( 'getChangelogSignificance', () => {
|
||||||
it( 'should return the selected significance', () => {
|
it( 'should return the selected significance', () => {
|
||||||
const body =
|
const body =
|
||||||
|
@ -57,7 +102,7 @@ describe( 'getChangelogSignificance', () => {
|
||||||
expect( significance ).toBe( 'patch' );
|
expect( significance ).toBe( 'patch' );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
it( 'should error when no significance selected', () => {
|
it( 'should return the selected significance when upper-case', () => {
|
||||||
const body =
|
const body =
|
||||||
'### Changelog entry\r\n' +
|
'### Changelog entry\r\n' +
|
||||||
'\r\n' +
|
'\r\n' +
|
||||||
|
@ -70,6 +115,45 @@ describe( 'getChangelogSignificance', () => {
|
||||||
'#### Significance\r\n' +
|
'#### Significance\r\n' +
|
||||||
'<!-- Choose only one -->\r\n' +
|
'<!-- Choose only one -->\r\n' +
|
||||||
'- [ ] Patch\r\n' +
|
'- [ ] Patch\r\n' +
|
||||||
|
'- [X] Minor\r\n' +
|
||||||
|
'- [ ] Major\r\n' +
|
||||||
|
'\r\n' +
|
||||||
|
'#### Type\r\n' +
|
||||||
|
'<!-- Choose only one -->\r\n' +
|
||||||
|
'- [x] Fix - Fixes an existing bug\r\n' +
|
||||||
|
'- [ ] Add - Adds functionality\r\n' +
|
||||||
|
'- [ ] Update - Update existing functionality\r\n' +
|
||||||
|
'- [ ] Dev - Development related task\r\n' +
|
||||||
|
'- [ ] Tweak - A minor adjustment to the codebase\r\n' +
|
||||||
|
'- [ ] Performance - Address performance issues\r\n' +
|
||||||
|
'- [ ] Enhancement\r\n' +
|
||||||
|
'\r\n' +
|
||||||
|
'#### Message ' +
|
||||||
|
'<!-- Add a changelog message here -->\r\n' +
|
||||||
|
'This is a very useful fix.\r\n' +
|
||||||
|
'\r\n' +
|
||||||
|
'#### Comment ' +
|
||||||
|
`<!-- If the changes in this pull request don't warrant a changelog entry, you can alternatively supply a comment here. Note that comments are only accepted with a significance of "Patch" -->\r\n` +
|
||||||
|
'\r\n' +
|
||||||
|
'</details>';
|
||||||
|
|
||||||
|
const significance = getChangelogSignificance( body );
|
||||||
|
expect( significance ).toBe( 'minor' );
|
||||||
|
} );
|
||||||
|
|
||||||
|
it( 'should error when no significance selected', () => {
|
||||||
|
const body =
|
||||||
|
'### Changelog entry\r\n' +
|
||||||
|
'\r\n' +
|
||||||
|
'<!-- You can optionally choose to enter a changelog entry by checking the box and supplying data. -->\r\n' +
|
||||||
|
'\r\n' +
|
||||||
|
'- [X] Automatically create a changelog entry from the details below.\r\n' +
|
||||||
|
'\r\n' +
|
||||||
|
'<details>\r\n' +
|
||||||
|
'\r\n' +
|
||||||
|
'#### Significance\r\n' +
|
||||||
|
'<!-- Choose only one -->\r\n' +
|
||||||
|
'- [ ] Patch\r\n' +
|
||||||
'- [ ] Minor\r\n' +
|
'- [ ] Minor\r\n' +
|
||||||
'- [ ] Major\r\n' +
|
'- [ ] Major\r\n' +
|
||||||
'\r\n' +
|
'\r\n' +
|
||||||
|
@ -182,6 +266,45 @@ describe( 'getChangelogType', () => {
|
||||||
expect( type ).toBe( 'fix' );
|
expect( type ).toBe( 'fix' );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
it( 'should return the selected changelog type when upper-case', () => {
|
||||||
|
const body =
|
||||||
|
'### Changelog entry\r\n' +
|
||||||
|
'\r\n' +
|
||||||
|
'<!-- You can optionally choose to enter a changelog entry by checking the box and supplying data. -->\r\n' +
|
||||||
|
'\r\n' +
|
||||||
|
'- [x] Automatically create a changelog entry from the details below.\r\n' +
|
||||||
|
'\r\n' +
|
||||||
|
'<details>\r\n' +
|
||||||
|
'\r\n' +
|
||||||
|
'#### Significance\r\n' +
|
||||||
|
'<!-- Choose only one -->\r\n' +
|
||||||
|
'- [x] Patch\r\n' +
|
||||||
|
'- [ ] Minor\r\n' +
|
||||||
|
'- [ ] Major\r\n' +
|
||||||
|
'\r\n' +
|
||||||
|
'#### Type\r\n' +
|
||||||
|
'<!-- Choose only one -->\r\n' +
|
||||||
|
'- [ ] Fix - Fixes an existing bug\r\n' +
|
||||||
|
'- [ ] Add - Adds functionality\r\n' +
|
||||||
|
'- [ ] Update - Update existing functionality\r\n' +
|
||||||
|
'- [X] Dev - Development related task\r\n' +
|
||||||
|
'- [ ] Tweak - A minor adjustment to the codebase\r\n' +
|
||||||
|
'- [ ] Performance - Address performance issues\r\n' +
|
||||||
|
'- [ ] Enhancement\r\n' +
|
||||||
|
'\r\n' +
|
||||||
|
'#### Message ' +
|
||||||
|
'<!-- Add a changelog message here -->\r\n' +
|
||||||
|
'This is a very useful fix.\r\n' +
|
||||||
|
'\r\n' +
|
||||||
|
'#### Comment ' +
|
||||||
|
`<!-- If the changes in this pull request don't warrant a changelog entry, you can alternatively supply a comment here. Note that comments are only accepted with a significance of "Patch" -->\r\n` +
|
||||||
|
'\r\n' +
|
||||||
|
'</details>';
|
||||||
|
|
||||||
|
const type = getChangelogType( body );
|
||||||
|
expect( type ).toBe( 'dev' );
|
||||||
|
} );
|
||||||
|
|
||||||
it( 'should error when no type selected', () => {
|
it( 'should error when no type selected', () => {
|
||||||
const body =
|
const body =
|
||||||
'### Changelog entry\r\n' +
|
'### Changelog entry\r\n' +
|
||||||
|
|
|
@ -45,7 +45,7 @@ export const getPullRequestData = async (
|
||||||
*/
|
*/
|
||||||
export const shouldAutomateChangelog = ( body: string ) => {
|
export const shouldAutomateChangelog = ( body: string ) => {
|
||||||
const regex =
|
const regex =
|
||||||
/\[x\] Automatically create a changelog entry from the details/gm;
|
/\[(?:x|X)\] Automatically create a changelog entry from the details/gm;
|
||||||
return regex.test( body );
|
return regex.test( body );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ export const shouldAutomateChangelog = ( body: string ) => {
|
||||||
* @return {void|string} changelog significance.
|
* @return {void|string} changelog significance.
|
||||||
*/
|
*/
|
||||||
export const getChangelogSignificance = ( body: string ) => {
|
export const getChangelogSignificance = ( body: string ) => {
|
||||||
const regex = /\[x\] (Patch|Minor|Major)\r\n/gm;
|
const regex = /\[(?:x|X)\] (Patch|Minor|Major)\r\n/gm;
|
||||||
const matches = body.match( regex );
|
const matches = body.match( regex );
|
||||||
|
|
||||||
if ( matches === null ) {
|
if ( matches === null ) {
|
||||||
|
@ -85,7 +85,7 @@ export const getChangelogSignificance = ( body: string ) => {
|
||||||
*/
|
*/
|
||||||
export const getChangelogType = ( body: string ) => {
|
export const getChangelogType = ( body: string ) => {
|
||||||
const regex =
|
const regex =
|
||||||
/\[x\] (Fix|Add|Update|Dev|Tweak|Performance|Enhancement) -/gm;
|
/\[(?:x|X)\] (Fix|Add|Update|Dev|Tweak|Performance|Enhancement) -/gm;
|
||||||
const matches = body.match( regex );
|
const matches = body.match( regex );
|
||||||
|
|
||||||
if ( matches === null ) {
|
if ( matches === null ) {
|
||||||
|
|
Loading…
Reference in New Issue