Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve changelog generation #27744

Merged
merged 18 commits into from
Dec 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 68 additions & 24 deletions bin/plugin/commands/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,51 @@ const manifest = require( '../../../package.json' );
*/

/**
* Mapping of label names to grouping heading text to be used in release notes,
* intended to be more readable in the context of release notes. Also used in
* merging multiple related groupings to a single heading.
* Mapping of label names to sections in the release notes.
*
* Labels are sorted by the priority they have when there are
* multiple candidates. For example, if an issue has the labels
* "[Block] Navigation" and "[Type] Bug", it'll be assigned the
* section declared by "[Block] Navigation".
*
* @type {Record<string,string>}
*/
const LABEL_TYPE_MAPPING = {
Bug: 'Bug Fixes',
Regression: 'Bug Fixes',
Feature: 'Features',
Enhancement: 'Enhancements',
'New API': 'New APIs',
Experimental: 'Experiments',
Task: 'Various',
'[Block] Navigation': 'Experiments',
'[Block] Query': 'Experiments',
'[Block] Post Comments Count': 'Experiments',
'[Block] Post Comments Form': 'Experiments',
'[Block] Post Comments': 'Experiments',
'[Block] Post Featured Image': 'Experiments',
'[Block] Post Hierarchical Terms': 'Experiments',
'[Block] Post Title': 'Experiments',
'[Block] Site Logo': 'Experiments',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just tested the PR and it works great. as a follow-up we might want to group more things automatically for instance, create a sublist for all FSE related block PRs

``

Experiments:

  • Full Site Editing Blocks:
    • entry 1
    • entry 2

There are more things that could use this "sub grouping".

'[Feature] Full Site Editing': 'Experiments',
'Global Styles': 'Experiments',
'[Feature] Navigation Screen': 'Experiments',
'[Feature] Widgets Screen': 'Experiments',
'[Package] Dependency Extraction Webpack Plugin': 'Tools',
'[Package] Jest Puppeteer aXe': 'Tools',
'[Package] E2E Tests': 'Tools',
'[Package] E2E Test Utils': 'Tools',
'[Package] Env': 'Tools',
'[Package] ESLint plugin': 'Tools',
'[Package] stylelint config': 'Tools',
'[Package] Project management automation': 'Tools',
'[Type] Project Management': 'Tools',
'[Package] Scripts': 'Tools',
'[Type] Build Tooling': 'Tools',
'Automated Testing': 'Tools',
'[Type] Experimental': 'Experiments',
'[Type] Bug': 'Bug Fixes',
'[Type] Regression': 'Bug Fixes',
'[Type] Feature': 'Features',
'[Type] Enhancement': 'Enhancements',
'[Type] New API': 'New APIs',
'[Type] Performance': 'Performance',
'[Type] Documentation': 'Documentation',
'[Type] Code Quality': 'Code Quality',
'[Type] Security': 'Security',
};

/**
Expand All @@ -78,6 +109,7 @@ const GROUP_TITLE_ORDER = [
'Experiments',
'Documentation',
'Code Quality',
'Tools',
undefined,
'Various',
];
Expand Down Expand Up @@ -105,7 +137,8 @@ const REWORD_TERMS = {
};

/**
* Returns type candidates based on given issue label names.
* Returns candidates based on whether the given labels
* are part of the allowed list.
*
* @param {string[]} labels Label names.
*
Expand All @@ -114,13 +147,10 @@ const REWORD_TERMS = {
function getTypesByLabels( labels ) {
return uniq(
labels
.filter( ( label ) => label.startsWith( '[Type] ' ) )
.map( ( label ) => label.slice( '[Type] '.length ) )
.map( ( label ) =>
LABEL_TYPE_MAPPING.hasOwnProperty( label )
? LABEL_TYPE_MAPPING[ label ]
: label
.filter( ( label ) =>
Object.keys( LABEL_TYPE_MAPPING ).includes( label )
)
.map( ( label ) => LABEL_TYPE_MAPPING[ label ] )
);
}

Expand Down Expand Up @@ -151,12 +181,29 @@ function getTypesByTitle( title ) {
* @return {string} Type label.
*/
function getIssueType( issue ) {
const labels = issue.labels.map( ( { name } ) => name );
const candidates = [
...getTypesByLabels( issue.labels.map( ( { name } ) => name ) ),
...getTypesByLabels( labels ),
...getTypesByTitle( issue.title ),
];

return candidates.length ? candidates.sort( sortGroup )[ 0 ] : 'Various';
return candidates.length ? candidates.sort( sortType )[ 0 ] : 'Various';
}

/**
* Sort comparator, comparing two label candidates.
*
* @param {string} a First candidate.
* @param {string} b Second candidate.
*
* @return {number} Sort result.
*/
function sortType( a, b ) {
const [ aIndex, bIndex ] = [ a, b ].map( ( title ) => {
return Object.keys( LABEL_TYPE_MAPPING ).indexOf( title );
} );

return aIndex - bIndex;
}

/**
Expand Down Expand Up @@ -287,11 +334,8 @@ function removeRedundantTypePrefix( title, issue ) {
* @type {Array<WPChangelogNormalization>}
*/
const TITLE_NORMALIZATIONS = [
createOmitByTitlePrefix( [ '[rnmobile]' ] ),
createOmitByLabel( [
'Mobile App Compatibility',
'[Type] Project Management',
] ),
createOmitByLabel( [ 'Mobile App Android/iOS' ] ),
createOmitByTitlePrefix( [ '[rnmobile]', '[mobile]', 'Mobile Release' ] ),
removeRedundantTypePrefix,
reword,
capitalizeAfterColonSeparatedPrefix,
Expand Down
11 changes: 1 addition & 10 deletions bin/plugin/commands/test/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,7 @@ describe( 'getNormalizedTitle', () => {
undefined,
{
...DEFAULT_ISSUE,
labels: [ { name: 'Mobile App Compatibility' } ],
},
],
[
'omits project management',
'Add codeowner',
undefined,
{
...DEFAULT_ISSUE,
labels: [ { name: '[Type] Project Management' } ],
labels: [ { name: 'Mobile App Android/iOS' } ],
},
],
[
Expand Down