Skip to content

Commit

Permalink
Merge changes published in the Gutenberg plugin "release/8.1" branch
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo committed May 14, 2020
1 parent 0bd9521 commit 74ba445
Show file tree
Hide file tree
Showing 486 changed files with 9,390 additions and 3,229 deletions.
6 changes: 6 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,5 +172,11 @@ module.exports = {
'jest/expect-expect': 'off',
},
},
{
files: [ 'bin/**/*.js' ],
rules: {
'no-console': 'off',
},
},
],
};
25 changes: 22 additions & 3 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
/packages/core-data @youknowriad @nerrad
/packages/data @youknowriad @nerrad @coderkevin
/packages/redux-routine @youknowriad @nerrad
/packages/data-controls @nerrad @aduth

# Blocks
/packages/block-library @Soean @ajitbohra @jorgefilipecosta @talldan
Expand All @@ -26,10 +27,20 @@
/packages/editor
/packages/list-reusable-blocks @youknowriad @noisysocks
/packages/shortcode
/packages/block-directory
/packages/interface
/packages/media-utils
/packages/server-side-render

# Widgets
/packages/edit-widgets @youknowriad

# Navigation
/packages/edit-navigation

# Full Site Editing
/packages/edit-site

# Tooling
/bin @ntwb @nerrad @ajitbohra
/bin/api-docs @ntwb @nerrad @ajitbohra @nosolosw
Expand All @@ -51,6 +62,8 @@
/packages/npm-package-json-lint-config @gziolo @ntwb @nerrad @ajitbohra
/packages/postcss-themes @youknowriad @ntwb @nerrad @ajitbohra
/packages/scripts @youknowriad @gziolo @ntwb @nerrad @ajitbohra
/packages/dependency-extraction-webpack-plugin @gziolo
/packages/prettier-config @ntwb @gziolo @aduth

# UI Components
/packages/components @youknowriad @ajitbohra @jaymanpandya @jorgefilipecosta @chrisvanpatten
Expand All @@ -59,6 +72,9 @@
/packages/notices @ajitbohra @jaymanpandya @jorgefilipecosta
/packages/nux @ajitbohra @jaymanpandya @jorgefilipecosta @noisysocks
/packages/viewport @youknowriad @ajitbohra @jaymanpandya @jorgefilipecosta
/packages/base-styles
/packages/icons
/packages/primitives

# Utilities
/packages/a11y @youknowriad @aduth
Expand All @@ -76,6 +92,8 @@
/packages/token-list @aduth
/packages/url @talldan @aduth
/packages/wordcount @aduth
/packages/warning
/packages/keyboard-shortcuts

# Extensibility
/packages/hooks @gziolo @adamsilverstein
Expand All @@ -86,6 +104,10 @@
/packages/rich-text @ellatrix @jorgefilipecosta @daniloercoli @sergioestevao @etoledom
/packages/block-editor/src/components/rich-text @ellatrix @jorgefilipecosta @daniloercoli @sergioestevao @etoledom

# Project Management
/.github @youknowriad @mapk @karmatosed
/packages/project-management-automation @aduth

# wp-env
/packages/env @epiqueras @noahtallen @noisysocks

Expand All @@ -99,6 +121,3 @@
*.native.scss @ghost
*.android.scss @ghost
*.ios.scss @ghost

# Project Management
/.github @youknowriad @mapk @karmatosed
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ jobs:
- name: Lint
install:
- npm ci
# eslint-plugin-import/no-extraneous-dependencies relies on modules to
# be "installed", which in practice requires that packages be built,
# presumably so that pkg.main can be resolved.
#
# See: https://github.com/benmosher/eslint-plugin-import/blob/92caa35/resolvers/node/index.js
- node ./bin/packages/build.js
script:
- npm run lint

Expand Down
3 changes: 0 additions & 3 deletions bin/api-docs/update-api-docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,6 @@ glob.stream( [
{ shell: true }
);
} catch ( error ) {
// Disable reason: Errors should log to console.

// eslint-disable-next-line no-console
console.error( error );
process.exit( 1 );
}
Expand Down
271 changes: 271 additions & 0 deletions bin/changelog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,271 @@
#!/usr/bin/env node
'use strict';

/*
* External dependencies
*/
const { groupBy } = require( 'lodash' );
const chalk = require( 'chalk' );
const Octokit = require( '@octokit/rest' );

/*
* Internal dependencies
*/
// @ts-ignore
const manifest = require( '../package.json' );

/** @typedef {import('@octokit/rest')} GitHub */
/** @typedef {import('@octokit/rest').IssuesListForRepoResponseItem} IssuesListForRepoResponseItem */
/** @typedef {import('@octokit/rest').IssuesListMilestonesForRepoResponseItem} OktokitIssuesListMilestonesForRepoResponseItem */

/**
* @typedef WPChangelogSettings
*
* @property {string} owner Repository owner.
* @property {string} repo Repository name.
* @property {string=} token Optional personal access token.
* @property {string} milestone Milestone title.
*/

/**
* Optional GitHub token used to authenticate requests.
*
* @type {string=}
*/
const GITHUB_TOKEN = process.env.GITHUB_TOKEN;

/**
* Optional explicit milestone title to use for generating changelog.
*
* @type {string=}
*/
const MILESTONE = process.env.MILESTONE;

/**
* Given a SemVer-formatted version string, returns an assumed milestone title
* associated with that version.
*
* @see https://semver.org/
*
* @param {string} version Version string.
*
* @return {string} Milestone title.
*/
function getMilestone( version ) {
const [ major, minor ] = version.split( '.' );
return `Gutenberg ${ major }.${ minor }`;
}

/**
* Returns a type label for a given issue object, or a default if type cannot
* be determined.
*
* @param {IssuesListForRepoResponseItem} issue Issue object.
*
* @return {string} Type label.
*/
function getIssueType( issue ) {
const typeLabel = issue.labels.find( ( label ) =>
label.name.startsWith( '[Type] ' )
);

return typeLabel ? typeLabel.name.replace( /^\[Type\] /, '' ) : 'Various';
}

/**
* Given an issue title, returns the title with normalization transforms
* applied.
*
* @param {string} title Original title.
*
* @return {string} Normalized title.
*/
function getNormalizedTitle( title ) {
if ( ! title.endsWith( '.' ) ) {
title = title + '.';
}

return title;
}

/**
* Returns a formatted changelog entry for a given issue object.
*
* @param {IssuesListForRepoResponseItem} issue Issue object.
*
* @return {string} Formatted changelog entry.
*/
function getEntry( issue ) {
const title = getNormalizedTitle( issue.title );

return `- ${ title } ([${ issue.number }](${ issue.html_url }))`;
}

/**
* Returns a promise resolving to a milestone by a given title, if exists.
*
* @param {GitHub} octokit Initialized Octokit REST client.
* @param {string} owner Repository owner.
* @param {string} repo Repository name.
* @param {string} title Milestone title.
*
* @return {Promise<OktokitIssuesListMilestonesForRepoResponseItem|void>} Promise resolving to milestone, if exists.
*/
async function getMilestoneByTitle( octokit, owner, repo, title ) {
const options = octokit.issues.listMilestonesForRepo.endpoint.merge( {
owner,
repo,
} );

/**
* @type {AsyncIterableIterator<import('@octokit/rest').Response<import('@octokit/rest').IssuesListMilestonesForRepoResponse>>}
*/
const responses = octokit.paginate.iterator( options );

for await ( const response of responses ) {
const milestones = response.data;
for ( const milestone of milestones ) {
if ( milestone.title === title ) {
return milestone;
}
}
}
}

/**
* Returns a promise resolving to pull requests by a given milestone ID.
*
* @param {GitHub} octokit Initialized Octokit REST client.
* @param {string} owner Repository owner.
* @param {string} repo Repository name.
* @param {number} milestone Milestone ID.
*
* @return {Promise<IssuesListForRepoResponseItem[]>} Promise resolving to pull
* requests for the given
* milestone.
*/
async function getPullRequestsByMilestone( octokit, owner, repo, milestone ) {
const options = octokit.issues.listForRepo.endpoint.merge( {
owner,
repo,
milestone,
state: 'closed',
} );

/**
* @type {AsyncIterableIterator<import('@octokit/rest').Response<import('@octokit/rest').IssuesListForRepoResponse>>}
*/
const responses = octokit.paginate.iterator( options );

const pulls = [];

for await ( const response of responses ) {
const issues = response.data;
pulls.push( ...issues.filter( ( issue ) => issue.pull_request ) );
}

return pulls;
}

/**
* Returns a promise resolving to an array of pull requests associated with the
* changelog settings object.
*
* @param {GitHub} octokit GitHub REST client.
* @param {WPChangelogSettings} settings Changelog settings.
*
* @return {Promise<IssuesListForRepoResponseItem[]>} Promise resolving to array of
* pull requests.
*/
async function fetchAllPullRequests( octokit, settings ) {
const { owner, repo, milestone: milestoneTitle } = settings;
const milestone = await getMilestoneByTitle(
octokit,
owner,
repo,
milestoneTitle
);

if ( ! milestone ) {
throw new Error(
`Cannot find milestone by title: ${ settings.milestone }`
);
}

const { number } = milestone;
return getPullRequestsByMilestone( octokit, owner, repo, number );
}

/**
* Returns a promise resolving to the changelog string for given settings.
*
* @param {WPChangelogSettings} settings Changelog settings.
*
* @return {Promise<string>} Promise resolving to changelog.
*/
async function getChangelog( settings ) {
const octokit = new Octokit( {
auth: settings.token,
} );

const pullRequests = await fetchAllPullRequests( octokit, settings );
if ( ! pullRequests.length ) {
throw new Error(
'There are no pull requests associated with the milestone.'
);
}

let changelog = '';

const groupedPullRequests = groupBy( pullRequests, getIssueType );
for ( const group of Object.keys( groupedPullRequests ) ) {
changelog += '### ' + group + '\n\n';

const groupPullRequests = groupedPullRequests[ group ];
for ( const pullRequest of groupPullRequests ) {
changelog += getEntry( pullRequest ) + '\n';
}

changelog += '\n';
}

return changelog;
}

/**
* Generates and logs changelog for a milestone.
*
* @param {WPChangelogSettings} settings Changelog settings.
*/
async function createChangelog( settings ) {
console.log(
chalk.bold(
`💃Preparing changelog for milestone: "${ settings.milestone }"\n\n`
)
);

let changelog;
try {
changelog = await getChangelog( settings );
} catch ( error ) {
changelog = chalk.yellow( error.stack );
}

console.log( changelog );
}

if ( ! module.parent ) {
createChangelog( {
owner: 'WordPress',
repo: 'gutenberg',
token: GITHUB_TOKEN,
milestone:
MILESTONE === undefined
? getMilestone( manifest.version )
: MILESTONE,
} );
}

/** @type {NodeJS.Module} */ ( module ).exports = {
getNormalizedTitle,
};
3 changes: 0 additions & 3 deletions bin/check-latest-npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,6 @@ Run ${ yellow(
}
} )
.catch( ( error ) => {
// Disable reason: A failure should log to the terminal.

// eslint-disable-next-line no-console
console.error(
'Latest NPM check failed!\n\n' + error.toString() + '\n'
);
Expand Down
Loading

0 comments on commit 74ba445

Please sign in to comment.