Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Adapt changelog script to WooCommerce Blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Aljullu committed Aug 16, 2019
1 parent 5460b9b commit fda59b1
Showing 1 changed file with 23 additions and 54 deletions.
77 changes: 23 additions & 54 deletions bin/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ const headers = {
const columnIds = [];

const getPullRequestType = labels => {
const typeLabel = labels.find( label => label.name.includes( '[Type]' ) );
const typeLabel = labels.find( label => label.name.includes( 'type:' ) );
if ( ! typeLabel ) {
return 'Dev';
return 'dev';
}
return typeLabel.name.replace( '[Type] ', '' );
return typeLabel.name.replace( 'type: ', '' );
};

const getLabels = labels => {
return labels
.filter( label => ! /\[.*\]/.test( label.name ) )
.filter( label => ! label.name.startsWith( 'status:' ) && ! label.name.startsWith( 'type:' ) )
.map( label => label.name )
.join( ', ' );
};
Expand Down Expand Up @@ -78,8 +78,8 @@ const writeEntry = async ( content_url ) => {
const labelTag = labels.length ? `(${ labels })` : '';
const authorTag = collaborator ? '' : `👏 @${ data.user.login }`;
let title;
if ( /### Changelog Note/.test( data.body ) ) {
const bodyParts = data.body.split( '### Changelog Note:' );
if ( /### Changelog/.test( data.body ) ) {
const bodyParts = data.body.split( '### Changelog\r\n\r\n> ' );
const note = bodyParts[ bodyParts.length - 1 ];
title = note
// Remove comment prompt
Expand All @@ -103,48 +103,20 @@ const writeEntry = async ( content_url ) => {
});
};

const makeChangelog = async column_id => {
octokit.paginate(
'GET /projects/columns/:column_id/cards',
{ headers, column_id },
response => response.data.forEach( async card => {
await writeEntry( card.content_url );
} )
).catch( err => {
console.log( '🤯' );
console.log( err.message );
})
};

const printProjectColumns = async () => {
const makeChangelog = async version => {
const options = {
url: 'https://api.github.com/projects/1492664/columns',
url: `https://api.github.com/search/issues?q=milestone:${ version }+type:pr+repo:woocommerce/woocommerce-gutenberg-products-block`,
headers,
json: true,
}

console.log( chalk.yellow( 'Gathering columns from the project board, https://github.com/orgs/woocommerce/projects/2' ) );

return requestPromise( options )
.then( data => {
console.log( ' ' );
console.log( chalk.yellow( 'The project board contains the following columns:' ) );
console.log( ' ' );
console.log( '+---------+-----------------------------' );
console.log( '| id | sprint name ' );
console.log( '+---------+-----------------------------' );
data.forEach( column => {
columnIds.push( column.id.toString() );
console.log( '| ' + chalk.green( column.id ) + ' | ' + column.name );
data.items.forEach( async ( pr ) => {
await writeEntry( pr.url );
} );
console.log( '+---------+-----------------------------' );
console.log( ' ' );
} ).catch( err => {
console.log( '🤯' );
console.log( err.message );
exit;
});
}
} );
};

( async () => {
console.log( chalk.yellow( 'This program requires an api token. You can create one here: ' ) + 'https://github.com/settings/tokens' );
Expand All @@ -157,20 +129,17 @@ const printProjectColumns = async () => {
const ready = await promptly.confirm( 'Are you ready to continue? ' );

if ( ready ) {
await printProjectColumns();
const id = await promptly.prompt( chalk.yellow( 'Enter a column id: ' ) );

if ( columnIds.includes( id ) ) {
console.log( '' );
console.log( chalk.green( 'Here is the generated changelog. Be sure to remove entries ' +
'not intended for a WooCommerce Admin release.' ) );
console.log( '' );
makeChangelog( id );
} else {
console.log( '' );
console.log( chalk.red( 'Invalid column id' ) );
console.log( '' );
}
console.log( '' );
console.log( chalk.yellow( 'In order to generate the changelog, you will have to provide a version number to retrieve the PRs from.' ) );
console.log( '' );
console.log( chalk.yellow( 'Write it as it appears in the milestones page: ' ) + 'https://github.com/woocommerce/woocommerce-gutenberg-products-block/milestones' );
console.log( '' );
const version = await promptly.prompt( 'Version number: ' );
console.log( '' );
console.log( chalk.green( 'Here is the generated changelog. Be sure to remove entries ' +
'not intended for a WooCommerce Admin release.' ) );
console.log( '' );
makeChangelog( version );
} else {
console.log( '' );
console.log( chalk.yellow( 'Ok, see you soon.' ) );
Expand Down

0 comments on commit fda59b1

Please sign in to comment.