Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into update/wp-requireme…
Browse files Browse the repository at this point in the history
…nts-wp57
  • Loading branch information
jeherve committed Feb 22, 2021
2 parents 343d2fe + f7954a1 commit 374f74a
Show file tree
Hide file tree
Showing 179 changed files with 3,727 additions and 7,687 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ projects/plugins/jetpack/vendor/
projects/plugins/jetpack/extensions/**/test/

### Packages
projects/packages/jitm/src/js/jetpack-jitm.js
projects/packages/lazy-images/src/js/IntersectionObserver-polyfill.js
projects/packages/*/vendor
projects/packages/*/wordpress
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/plugin_jetpack-beta.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name: Plugin - Jetpack Beta Tester
about: Create an issue report focused on the Jetpack Beta Tester plugin
title: 'Beta Plugin: ADD_YOUR_TITLE_HERE'
labels: '[Plugin] Beta Plugin, [Type] Bug'
labels: '[Plugin] Beta, [Type] Bug'
assignees: ''

---
Expand Down
1 change: 1 addition & 0 deletions .github/actions/repo-gardening/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Here is the current list of tasks handled by this action:

- Assign Issues: Adds assignee for issues which are being worked on, and adds the "In Progress" label.
- Add Milestone: Adds a valid milestone to all PRs that get merged and don't already include a milestone.
- Check Description: Checks the contents of a PR description, and ensure it matches our recommendations.

## Build your own

Expand Down
29 changes: 29 additions & 0 deletions .github/actions/repo-gardening/src/get-labels.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* global GitHub */

/**
* Get labels on a PR.
*
* @param {GitHub} octokit - Initialized Octokit REST client.
* @param {string} owner - Repository owner.
* @param {string} repo - Repository name.
* @param {string} number - PR number.
*
* @returns {Promise<Array>} Promise resolving to an array of all labels for that PR.
*/
async function getLabels( octokit, owner, repo, number ) {
const labelList = [];

for await ( const response of octokit.paginate.iterator( octokit.issues.listLabelsOnIssue, {
owner: owner.login,
repo,
issue_number: +number,
} ) ) {
response.data.map( label => {
labelList.push( label.name );
} );
}

return labelList;
}

module.exports = getLabels;
42 changes: 42 additions & 0 deletions .github/actions/repo-gardening/src/get-next-valid-milestone.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* External dependencies
*/
const moment = require( 'moment' );

/* global GitHub, OktokitIssuesListMilestonesForRepoResponseItem */

/**
* Returns a promise resolving to the next valid milestone, if exists.
*
* @param {GitHub} octokit - Initialized Octokit REST client.
* @param {string} owner - Repository owner.
* @param {string} repo - Repository name.
* @param {string} plugin - Plugin slug.
*
* @returns {Promise<OktokitIssuesListMilestonesForRepoResponseItem|void>} Promise resolving to milestone, if exists.
*/
async function getNextValidMilestone( octokit, owner, repo, plugin = 'jetpack' ) {
const options = octokit.issues.listMilestones.endpoint.merge( {
owner,
repo,
state: 'open',
sort: 'due_on',
direction: 'asc',
} );

const responses = octokit.paginate.iterator( options );

for await ( const response of responses ) {
// Find a milestone which name is a version number
// and it's due dates is earliest in a future
const reg = new RegExp( plugin + '/d.d' );
const nextMilestone = response.data
.filter( m => m.title.match( reg ) )
.sort( ( m1, m2 ) => parseFloat( m1.title ) - parseFloat( m2.title ) )
.find( milestone => milestone.due_on && moment( milestone.due_on ) > moment() );

return nextMilestone;
}
}

module.exports = getNextValidMilestone;
31 changes: 31 additions & 0 deletions .github/actions/repo-gardening/src/get-plugin-names.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* global GitHub */

/**
* Internal dependencies
*/
const getLabels = require( './get-labels' );

/**
* Get the name of the plugin concerned by this PR.
*
* @param {GitHub} octokit - Initialized Octokit REST client.
* @param {string} owner - Repository owner.
* @param {string} repo - Repository name.
* @param {string} number - PR / Issue number.
*
* @returns {Promise<Array>} Promise resolving to an array of all the plugins touched by that PR.
*/
async function getPluginNames( octokit, owner, repo, number ) {
const plugins = [];
const labels = await getLabels( octokit, owner, repo, number );
labels.map( label => {
const plugin = label.match( /^\[Plugin\]\s(?<pluginName>[^/]*)$/ );
if ( plugin && plugin.groups.pluginName ) {
plugins.push( plugin.groups.pluginName.toLowerCase() );
}
} );

return plugins;
}

module.exports = getPluginNames;
27 changes: 27 additions & 0 deletions .github/actions/repo-gardening/src/if-not-closed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Internal dependencies
*/
const debug = require( './debug' );

/* global WPAutomationTask */

/**
* Higher-order function which executes and returns the result of the given
* handler only if the PR is not currently closed.
*
* @param {WPAutomationTask} handler - Original task.
*
* @returns {WPAutomationTask} Enhanced task.
*/
function ifNotClosed( handler ) {
const newHandler = ( payload, octokit ) => {
if ( payload.pull_request.state !== 'closed' ) {
return handler( payload, octokit );
}
debug( `main: Skipping ${ handler.name } because the PR is closed.` );
};
Object.defineProperty( newHandler, 'name', { value: handler.name } );
return newHandler;
}

module.exports = ifNotClosed;
9 changes: 8 additions & 1 deletion .github/actions/repo-gardening/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ const { context, getOctokit } = require( '@actions/github' );
const assignIssues = require( './tasks/assign-issues' );
const addMilestone = require( './tasks/add-milestone' );
const addLabels = require( './tasks/add-labels' );
const checkDescription = require( './tasks/check-description' );
const debug = require( './debug' );
const ifNotFork = require( './if-not-fork' );
const ifNotClosed = require( './if-not-closed' );

const automations = [
{
Expand All @@ -26,7 +28,12 @@ const automations = [
{
event: 'pull_request',
action: [ 'opened', 'reopened', 'synchronize', 'edited', 'labeled' ],
task: addLabels,
task: ifNotClosed( addLabels ),
},
{
event: 'pull_request',
action: [ 'opened', 'reopened', 'synchronize', 'edited', 'labeled' ],
task: ifNotClosed( checkDescription ),
},
];

Expand Down
51 changes: 7 additions & 44 deletions .github/actions/repo-gardening/src/tasks/add-milestone/index.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,12 @@
/**
* External dependencies
*/
const moment = require( 'moment' );

/**
* Internal dependencies
*/
const debug = require( '../../debug' );
const getAssociatedPullRequest = require( '../../get-associated-pull-request' );
const getNextValidMilestone = require( '../../get-next-valid-milestone' );
const getPluginNames = require( '../../get-plugin-names' );

/* global GitHub, OktokitIssuesListMilestonesForRepoResponseItem, WebhookPayloadPullRequest */

/**
* Returns a promise resolving to the next valid milestone, if exists.
*
* @param {GitHub} octokit - Initialized Octokit REST client.
* @param {string} owner - Repository owner.
* @param {string} repo - Repository name.
*
* @returns {Promise<OktokitIssuesListMilestonesForRepoResponseItem|void>} Promise resolving to milestone, if exists.
*/
async function getNextValidMilestone( octokit, owner, repo ) {
const params = {
state: 'open',
sort: 'due_on',
direction: 'asc',
};

const options = octokit.issues.listMilestones.endpoint.merge( {
owner,
repo,
...params,
} );

const responses = octokit.paginate.iterator( options );

for await ( const response of responses ) {
// Find a milestone which name is a version number
// and it's due dates is earliest in a future
const nextMilestone = response.data
.filter( m => m.title.match( /\d\.\d/ ) )
.sort( ( m1, m2 ) => parseFloat( m1.title ) - parseFloat( m2.title ) )
.find( milestone => milestone.due_on && moment( milestone.due_on ) > moment() );

return nextMilestone;
}
}
/* global GitHub, WebhookPayloadPullRequest */

/**
* Assigns any issues that are being worked to the author of the matching PR.
Expand Down Expand Up @@ -78,8 +39,10 @@ async function addMilestone( payload, octokit ) {
return;
}

// Get next valid milestone.
const nextMilestone = await getNextValidMilestone( octokit, owner, repo );
const plugins = await getPluginNames( octokit, owner, repo, prNumber );

// Get next valid milestone (we can only add one).
const nextMilestone = await getNextValidMilestone( octokit, owner, repo, plugins[ 0 ] );

if ( ! nextMilestone ) {
throw new Error( 'Could not find a valid milestone' );
Expand Down
Loading

0 comments on commit 374f74a

Please sign in to comment.