Skip to content

Commit

Permalink
Add missing labels to changelog script, and enhance mapping function. (
Browse files Browse the repository at this point in the history
…#55066)

* Add Commands package label as a changelog feature

* Compare labels using lowercase values

Avoids missing mappings due to capitalization mismatch. eg. at the time
of this change, the code looked for [Package] Block Editor, but on
GitHub the label is actually typed [Package] Block editor — PRs labeled
as such, were being sorted under Various.

* Add site editor label

* Add tests for case insensitivity

* Update fixtures and snapshots
  • Loading branch information
vcanales authored Dec 2, 2023
1 parent 6833642 commit ded792b
Show file tree
Hide file tree
Showing 4 changed files with 18,580 additions and 9,431 deletions.
41 changes: 33 additions & 8 deletions bin/plugin/commands/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,17 @@ const LABEL_FEATURE_MAPPING = {
'[Feature] Raw Handling': 'Block Editor',
'[Package] Edit Post': 'Post Editor',
'[Package] Icons': 'Icons',
'[Package] Block Editor': 'Block Editor',
'[Package] Block editor': 'Block Editor',
'[Package] Block library': 'Block Library',
'[Package] Editor': 'Post Editor',
'[Package] Edit Site': 'Site Editor',
'[Package] Edit Widgets': 'Widgets Editor',
'[Package] Widgets Customizer': 'Widgets Editor',
'[Package] Components': 'Components',
'[Package] Block Library': 'Block Library',
'[Package] Rich text': 'Block Editor',
'[Package] Data': 'Data Layer',
'[Package] Commands': 'Commands',
'[Block] Legacy Widget': 'Widgets Editor',
'REST API Interaction': 'REST API',
'New Block': 'Block Library',
Expand Down Expand Up @@ -220,9 +222,18 @@ function getTypesByLabels( labels ) {
...new Set(
labels
.filter( ( label ) =>
Object.keys( LABEL_TYPE_MAPPING ).includes( label )
Object.keys( LABEL_TYPE_MAPPING )
.map( ( currentLabel ) => currentLabel.toLowerCase() )
.includes( label.toLowerCase() )
)
.map( ( label ) => LABEL_TYPE_MAPPING[ label ] )
.map( ( label ) => {
const lowerCaseLabel =
Object.keys( LABEL_TYPE_MAPPING ).find(
( key ) => key.toLowerCase() === label.toLowerCase()
) || label;

return LABEL_TYPE_MAPPING[ lowerCaseLabel ];
} )
),
];
}
Expand All @@ -236,11 +247,24 @@ function getTypesByLabels( labels ) {
* @return {string[]} Feature candidates.
*/
function mapLabelsToFeatures( labels ) {
return labels
.filter( ( label ) =>
Object.keys( LABEL_FEATURE_MAPPING ).includes( label )
)
.map( ( label ) => LABEL_FEATURE_MAPPING[ label ] );
return [
...new Set(
labels
.filter( ( label ) =>
Object.keys( LABEL_FEATURE_MAPPING )
.map( ( currentLabel ) => currentLabel.toLowerCase() )
.includes( label.toLowerCase() )
)
.map( ( label ) => {
const lowerCaseLabel =
Object.keys( LABEL_FEATURE_MAPPING ).find(
( key ) => key.toLowerCase() === label.toLowerCase()
) || label;

return LABEL_FEATURE_MAPPING[ lowerCaseLabel ];
} )
),
];
}

/**
Expand Down Expand Up @@ -1070,4 +1094,5 @@ async function getReleaseChangelog( options ) {
getChangelog,
getUniqueByUsername,
skipCreatedByBots,
mapLabelsToFeatures,
};
Loading

0 comments on commit ded792b

Please sign in to comment.