Skip to content

Commit

Permalink
Merge branch 'trunk' into enhancement/move-admin-to-includes
Browse files Browse the repository at this point in the history
  • Loading branch information
thelovekesh authored Mar 21, 2024
2 parents 949c6c5 + b687c60 commit 1059283
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 96 deletions.
4 changes: 1 addition & 3 deletions .github/ISSUE_TEMPLATE/trac_ticket.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ labels: [ "Trac Ticket", "WP Core" ]
---

<!--
Trac ticket issues are for team organization purposes only. Please update the title of the issue and link to the Trac ticket below.
If a focus area is known, please add the appropriate label, e.g., "[Focus] Images".
Trac ticket issues are for team organization purposes only. Please update the title of the issue and link to the Trac ticket below.
-->

Trac ticket: <!-- insert a link to the WordPress Trac ticket here -->
Expand Down
4 changes: 2 additions & 2 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Fixes #
<!--
For maintainers only, please make sure:
- PR has either `[Focus]` or `Infrastructure` label.
- PR has a `[Type]` label.
- PR has a milestone or the `no milestone` label.
- PR has a plugin-specific milestone, or the `no milestone` label if it does not apply to any specific plugin.
- PR has a changelog-friendly title, or the `skip changelog` label if it should not be mentioned in the plugin's changelog.
-->
6 changes: 0 additions & 6 deletions .github/workflows/pr-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ jobs:
steps:
- if: contains( env.LABELS, '[Type]' ) == false
run: exit 1
check-focus-label:
name: Check [Focus] Label
runs-on: ubuntu-latest
steps:
- if: contains( env.LABELS, '[Focus]' ) == false && contains( env.LABELS, 'Infrastructure' ) == false
run: exit 1
check-milestone:
name: Check Milestone
runs-on: ubuntu-latest
Expand Down
121 changes: 36 additions & 85 deletions bin/plugin/commands/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@ const {
const config = require( '../config' );

const MISSING_TYPE = 'MISSING_TYPE';
const MISSING_FOCUS = 'MISSING_FOCUS';
const TYPE_PREFIX = '[Type] ';
const FOCUS_PREFIX = '[Focus] ';
const INFRASTRUCTURE_LABEL = 'Infrastructure';
const PRIMARY_TYPE_LABELS = {
'[Type] Feature': 'Features',
'[Type] Enhancement': 'Enhancements',
'[Type] Bug': 'Bug Fixes',
};
const PRIMARY_TYPE_ORDER = Object.values( PRIMARY_TYPE_LABELS );
const SKIP_CHANGELOG_LABEL = 'skip changelog';

/** @typedef {import('@octokit/rest')} GitHub */
/** @typedef {import('@octokit/rest').IssuesListForRepoResponseItem} IssuesListForRepoResponseItem */
Expand Down Expand Up @@ -102,7 +100,13 @@ async function fetchAllPullRequests( octokit, settings ) {
milestone.number,
'closed'
);
return issues.filter( ( issue ) => issue.pull_request );

// Return all pull requests except those with the SKIP_CHANGELOG_LABEL.
return issues.filter(
( issue ) =>
issue.pull_request &&
! issue.labels.find( ( { name } ) => name === SKIP_CHANGELOG_LABEL )
);
}

/**
Expand All @@ -129,30 +133,6 @@ function getIssueType( issue ) {
return typeLabels[ 0 ].replace( TYPE_PREFIX, '' );
}

/**
* Returns a focus label for a given issue object, or MISSING_FOCUS if focus
* cannot be determined.
*
* @param {IssuesListForRepoResponseItem} issue Issue object.
*
* @return {string} Focus label, or MISSING_FOCUS.
*/
function getIssueFocus( issue ) {
const labelNames = issue.labels.map( ( { name } ) => name );
const focusLabels = labelNames.filter( ( label ) =>
label.startsWith( FOCUS_PREFIX )
);

if ( ! focusLabels.length ) {
if ( labelNames.includes( INFRASTRUCTURE_LABEL ) ) {
return INFRASTRUCTURE_LABEL;
}
return MISSING_FOCUS;
}

return focusLabels[ 0 ].replace( FOCUS_PREFIX, '' );
}

/**
* Formats the changelog string for a given list of pull requests.
*
Expand All @@ -162,7 +142,14 @@ function getIssueFocus( issue ) {
* @return {string} The formatted changelog string.
*/
function formatChangelog( milestone, pullRequests ) {
let changelog = '= ' + milestone.replace( 'PL Plugin ', '' ) + ' =\n\n';
const version = milestone.match( /\d+\.\d+(\.\d+)?(-[A-Za-z0-9.]+)?$/ );
if ( ! version ) {
throw new Error(
`The ${ milestone } milestone does not end with a version number.`
);
}

let changelog = '= ' + version[ 0 ] + ' =\n\n';

// Group PRs by type.
const typeGroups = groupBy( pullRequests, getIssueType );
Expand Down Expand Up @@ -194,62 +181,26 @@ function formatChangelog( milestone, pullRequests ) {
// Start a new section within the changelog.
changelog += '**' + group + '**\n\n';

// Group PRs within this section per focus.
const focusGroups = groupBy( typeGroups[ group ], getIssueFocus );
if ( focusGroups[ MISSING_FOCUS ] ) {
const prURLs = focusGroups[ MISSING_FOCUS ].map(
( { html_url } ) => html_url // eslint-disable-line camelcase
);
throw new Error(
`The following pull-requests are missing a "${ FOCUS_PREFIX }xyz" or "${ INFRASTRUCTURE_LABEL }" label: ${ prURLs.join(
', '
) }`
);
}

// Sort focuses alphabetically, except infrastructure which comes last.
const focusGroupNames = Object.keys( focusGroups ).sort( ( a, b ) => {
if (
( a !== INFRASTRUCTURE_LABEL && b !== INFRASTRUCTURE_LABEL ) ||
a === b
) {
return a - b;
}
return a !== INFRASTRUCTURE_LABEL ? -1 : 1;
} );

// Output all PRs within this section.
focusGroupNames.forEach( ( featureName ) => {
const focusGroupPRs = focusGroups[ featureName ];

focusGroupPRs
.map( ( issue ) => {
const title = issue.title
// Strip feature name from title if used as prefix.
.replace(
new RegExp(
`^${ featureName.toLowerCase() }: `,
'i'
),
''
)
// Strip trailing whitespace.
.trim()
// Ensure first letter is uppercase.
.replace( /^([a-z])/, ( _match, firstLetter ) =>
firstLetter.toUpperCase()
)
// Add trailing period.
.replace( /\s*\.?$/, '' )
.concat( '.' );
return `* ${ featureName }: ${ title } ([${ issue.number }](${ issue.html_url }))`; // eslint-disable-line camelcase
} )
.filter( Boolean )
.sort()
.forEach( ( entry ) => {
changelog += `${ entry }\n`;
} );
} );
const typeGroupPRs = typeGroups[ group ];
typeGroupPRs
.map( ( issue ) => {
const title = issue.title
// Strip trailing whitespace.
.trim()
// Ensure first letter is uppercase.
.replace( /^([a-z])/, ( _match, firstLetter ) =>
firstLetter.toUpperCase()
)
// Add trailing period.
.replace( /\s*\.?$/, '' )
.concat( '.' );
return `* ${ title } ([${ issue.number }](${ issue.html_url }))`; // eslint-disable-line camelcase
} )
.filter( Boolean )
.sort()
.forEach( ( entry ) => {
changelog += `${ entry }\n`;
} );

changelog += '\n';
}
Expand Down

0 comments on commit 1059283

Please sign in to comment.