Update PR template and auto change log with better no-entry support (#44023)
* Update PR template and auto change log * Ignore .github md files in linting * Rebuilt monorepo-utils to solve conflict * Updated regex pattern to include uppercase X * Move the changelog entry not required checkbox on top of the description. * Return the comment even if shouldAutomateNoChangelog is false * Updated tests * Rebuilt monorepo-utils --------- Co-authored-by: Adrian Moldovan <3854374+adimoldovan@users.noreply.github.com>
This commit is contained in:
parent
2f4c9ecf57
commit
f56d3e3ee0
|
@ -35,6 +35,10 @@ Using the [WooCommerce Testing Instructions Guide](https://github.com/woocommerc
|
|||
|
||||
- [ ] Automatically create a changelog entry from the details below.
|
||||
|
||||
<!-- If no changelog entry is required for this PR, you can specify that below and provide a comment explaining why. This cannot be used if you selected the option to automatically create a changelog entry above. -->
|
||||
|
||||
- [ ] This Pull Request does not require a changelog entry. (Comment required below)
|
||||
|
||||
<details>
|
||||
|
||||
#### Significance
|
||||
|
@ -59,6 +63,12 @@ Using the [WooCommerce Testing Instructions Guide](https://github.com/woocommerc
|
|||
|
||||
#### Message <!-- Add a changelog message here -->
|
||||
|
||||
#### 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" -->
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
|
||||
#### Comment <!-- If your Pull Request doesn't require a changelog entry, a comment explaining why is required instead -->
|
||||
|
||||
|
||||
</details>
|
||||
|
|
|
@ -29,5 +29,5 @@ jobs:
|
|||
|
||||
- name: Generate Changelog File
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
GITHUB_TOKEN: ${{ secrets.PR_CREATE_TOKEN || secrets.GITHUB_TOKEN }}
|
||||
run: pnpm utils changefile ${{github.event.number || inputs.prNumber}} -o ${{ github.repository_owner }}
|
||||
|
|
|
@ -21,6 +21,7 @@ jobs:
|
|||
**/*.md
|
||||
files_ignore: |
|
||||
docs/**/*.md
|
||||
.github/**/*.md
|
||||
|
||||
- name: Get docs changed files
|
||||
id: docs-changed-files
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -15,6 +15,7 @@ import { cloneAuthenticatedRepo, checkoutRemoteBranch } from '../core/git';
|
|||
import {
|
||||
getPullRequestData,
|
||||
shouldAutomateChangelog,
|
||||
shouldAutomateNoChangelog,
|
||||
getChangelogDetails,
|
||||
getChangelogDetailsError,
|
||||
} from './lib/github';
|
||||
|
@ -58,14 +59,23 @@ const program = new Command( 'changefile' )
|
|||
|
||||
Logger.endTask();
|
||||
|
||||
if ( ! shouldAutomateChangelog( prBody ) ) {
|
||||
const autoChangelog = shouldAutomateChangelog( prBody );
|
||||
const autoNoChangelog = shouldAutomateNoChangelog( prBody );
|
||||
|
||||
if ( ! autoChangelog && ! autoNoChangelog ) {
|
||||
Logger.notice(
|
||||
`PR #${ prNumber } does not have the "Automatically create a changelog entry from the details" checkbox checked. No changelog will be created.`
|
||||
`PR #${ prNumber } does not have the "Automatically create a changelog entry from the details" or the "This Pull Request does not require a changelog entry" checkbox checked. No changelog will be created.`
|
||||
);
|
||||
|
||||
process.exit( 0 );
|
||||
}
|
||||
|
||||
if ( autoChangelog && autoNoChangelog ) {
|
||||
Logger.error(
|
||||
`PR #${ prNumber } has both the "Automatically create a changelog entry from the details" and the "This Pull Request does not require a changelog entry" checkboxes checked. These options are mutually exclusive and only one may be selected.`
|
||||
);
|
||||
}
|
||||
|
||||
const details = getChangelogDetails( prBody );
|
||||
const { significance, type, message, comment } = details;
|
||||
const changelogDetailsError = getChangelogDetailsError( details );
|
||||
|
|
|
@ -7,6 +7,7 @@ import {
|
|||
getChangelogType,
|
||||
getChangelogDetails,
|
||||
getChangelogDetailsError,
|
||||
shouldAutomateNoChangelog,
|
||||
} from '../github';
|
||||
import { Logger } from '../../../core/logger';
|
||||
|
||||
|
@ -62,6 +63,44 @@ describe( 'shouldAutomateChangelog', () => {
|
|||
} );
|
||||
} );
|
||||
|
||||
describe( 'shouldAutomateNoChangelog', () => {
|
||||
it( 'should return true when checked', () => {
|
||||
const body =
|
||||
'<!-- If no changelog entry is required for this PR, you can specify that below and provide a comment explaining why. This cannot be used if you selected the option to automatically create a changelog entry above. -->\r\n' +
|
||||
'\r\n' +
|
||||
'- [x] This Pull Request does not require a changelog entry. (Comment required below)' +
|
||||
'\r\n';
|
||||
const shouldAutomate = shouldAutomateNoChangelog( body );
|
||||
expect( shouldAutomate ).toBe( true );
|
||||
} );
|
||||
|
||||
it( 'should return true when checked with upper-case', () => {
|
||||
const body =
|
||||
'<!-- If no changelog entry is required for this PR, you can specify that below and provide a comment explaining why. This cannot be used if you selected the option to automatically create a changelog entry above. -->\r\n' +
|
||||
'\r\n' +
|
||||
'- [X] This Pull Request does not require a changelog entry. (Comment required below)' +
|
||||
'\r\n';
|
||||
const shouldAutomate = shouldAutomateNoChangelog( body );
|
||||
expect( shouldAutomate ).toBe( true );
|
||||
} );
|
||||
|
||||
it( 'should return false when unchecked', () => {
|
||||
const body =
|
||||
'<!-- If no changelog entry is required for this PR, you can specify that below and provide a comment explaining why. This cannot be used if you selected the option to automatically create a changelog entry above. -->\r\n' +
|
||||
'\r\n' +
|
||||
'- [ ] This Pull Request does not require a changelog entry. (Comment required below)' +
|
||||
'\r\n';
|
||||
const shouldAutomate = shouldAutomateNoChangelog( body );
|
||||
expect( shouldAutomate ).toBe( false );
|
||||
} );
|
||||
|
||||
it( 'should return false when missing from body', () => {
|
||||
const body = '';
|
||||
const shouldAutomate = shouldAutomateNoChangelog( body );
|
||||
expect( shouldAutomate ).toBe( false );
|
||||
} );
|
||||
} );
|
||||
|
||||
describe( 'getChangelogSignificance', () => {
|
||||
it( 'should return the selected significance', () => {
|
||||
const body =
|
||||
|
@ -398,6 +437,7 @@ describe( 'getChangelogDetails', () => {
|
|||
'<!-- 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' +
|
||||
'- [ ] This Pull Request does not require a changelog entry. (Comment required below)\r\n' +
|
||||
'\r\n' +
|
||||
'<details>\r\n' +
|
||||
'\r\n' +
|
||||
|
@ -421,8 +461,7 @@ describe( 'getChangelogDetails', () => {
|
|||
'<!-- 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` +
|
||||
'#### Comment <!-- a comment explaining why there is no changlog --> ' +
|
||||
'\r\n' +
|
||||
'</details>';
|
||||
|
||||
|
@ -440,6 +479,7 @@ describe( 'getChangelogDetails', () => {
|
|||
'<!-- 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' +
|
||||
'- [ ] This Pull Request does not require a changelog entry. (Comment required below)\r\n' +
|
||||
'\r\n' +
|
||||
'<details>\r\n' +
|
||||
'\r\n' +
|
||||
|
@ -463,7 +503,7 @@ describe( 'getChangelogDetails', () => {
|
|||
'<!-- Add a changelog message here -->\r\n' +
|
||||
'This is a very useful fix.\r\n' +
|
||||
'\r\n' +
|
||||
'#### Comment ' +
|
||||
'#### Comment <!-- a comment explaining why there is no changlog --> ' +
|
||||
`<!-- 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` +
|
||||
'This is a very useful comment.\r\n' +
|
||||
'\r\n' +
|
||||
|
@ -474,7 +514,7 @@ describe( 'getChangelogDetails', () => {
|
|||
expect( details.comment ).toEqual( 'This is a very useful comment.' );
|
||||
} );
|
||||
|
||||
it( 'should remove newlines from message and comment', () => {
|
||||
it( 'should remove newlines from message', () => {
|
||||
const body =
|
||||
'### Changelog entry\r\n' +
|
||||
'\r\n' +
|
||||
|
@ -505,7 +545,7 @@ describe( 'getChangelogDetails', () => {
|
|||
'This is a very useful fix.\r\n' +
|
||||
'I promise!\r\n' +
|
||||
'\r\n' +
|
||||
'#### Comment ' +
|
||||
'#### Comment <!-- a comment explaining why there is no changlog --> ' +
|
||||
`<!-- 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` +
|
||||
'This is a very useful comment.\r\n' +
|
||||
"I don't promise!\r\n" +
|
||||
|
@ -528,6 +568,8 @@ describe( 'getChangelogDetails', () => {
|
|||
'<!-- 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' +
|
||||
`<!-- 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` +
|
||||
'- [ ] This Pull Request does not require a changelog entry. (Comment required below)\r\n' +
|
||||
'\r\n' +
|
||||
'<details>\r\n' +
|
||||
'\r\n' +
|
||||
|
@ -550,7 +592,7 @@ describe( 'getChangelogDetails', () => {
|
|||
'#### Message ' +
|
||||
'<!-- Add a changelog message here -->\r\n' +
|
||||
'\r\n' +
|
||||
'#### Comment ' +
|
||||
'#### Comment <!-- a comment explaining why there is no changlog --> ' +
|
||||
`<!-- 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` +
|
||||
'This is a very useful comment.\r\n' +
|
||||
'\r\n' +
|
||||
|
@ -560,6 +602,50 @@ describe( 'getChangelogDetails', () => {
|
|||
expect( details.comment ).toEqual( 'This is a very useful comment.' );
|
||||
expect( details.significance ).toEqual( 'minor' );
|
||||
} );
|
||||
|
||||
it( 'should return details when no changelog required is 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' +
|
||||
'- [ ] Automatically create a changelog entry from the details below.\r\n' +
|
||||
'- [x] This Pull Request does not require a changelog entry. (Comment required below)\r\n' +
|
||||
'\r\n' +
|
||||
'<details>\r\n' +
|
||||
'\r\n' +
|
||||
'#### Significance\r\n' +
|
||||
'<!-- Choose only one -->\r\n' +
|
||||
'- [ ] 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' +
|
||||
'- [ ] 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 <!-- a comment explaining why there is no changlog --> ' +
|
||||
`<!-- 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` +
|
||||
'This is a very useful comment.\r\n' +
|
||||
'\r\n' +
|
||||
'</details>';
|
||||
|
||||
const details = getChangelogDetails( body );
|
||||
expect( details.significance ).toEqual( 'patch' );
|
||||
expect( details.type ).toEqual( 'tweak' );
|
||||
expect( details.message ).toEqual( '' );
|
||||
expect( details.comment ).toEqual( 'This is a very useful comment.' );
|
||||
} );
|
||||
} );
|
||||
|
||||
describe( 'getChangelogDetailsError', () => {
|
||||
|
|
|
@ -38,7 +38,7 @@ export const getPullRequestData = async (
|
|||
};
|
||||
|
||||
/**
|
||||
* Determine if a pull request description activates the changelog automation.
|
||||
* Determine if a pull request description activates the changelog automation with a changelog entry.
|
||||
*
|
||||
* @param {string} body pull request description.
|
||||
* @return {boolean} if the pull request description activates the changelog automation.
|
||||
|
@ -49,6 +49,18 @@ export const shouldAutomateChangelog = ( body: string ) => {
|
|||
return regex.test( body );
|
||||
};
|
||||
|
||||
/**
|
||||
* Determine if a pull request description activates the changelog automation without a changelog entry.
|
||||
*
|
||||
* @param {string} body pull request description.
|
||||
* @return {boolean} if the pull request description activates the changelog automation.
|
||||
*/
|
||||
export const shouldAutomateNoChangelog = ( body: string ) => {
|
||||
const regex =
|
||||
/\[(?:x|X)\] This Pull Request does not require a changelog entry/gm;
|
||||
return regex.test( body );
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the changelog significance from a pull request description.
|
||||
*
|
||||
|
@ -153,6 +165,14 @@ export const getChangelogComment = ( body: string ) => {
|
|||
* @return {Object} Changelog details
|
||||
*/
|
||||
export const getChangelogDetails = ( body: string ) => {
|
||||
if ( shouldAutomateNoChangelog( body ) ) {
|
||||
return {
|
||||
significance: 'patch',
|
||||
type: 'tweak',
|
||||
message: '',
|
||||
comment: getChangelogComment( body ),
|
||||
};
|
||||
}
|
||||
return {
|
||||
significance: getChangelogSignificance( body ),
|
||||
type: getChangelogType( body ),
|
||||
|
|
Loading…
Reference in New Issue