From 0293d20e6377852d612115f8593e1a86c4e27cd7 Mon Sep 17 00:00:00 2001 From: alexcanessa Date: Fri, 10 Mar 2017 23:25:02 +0000 Subject: [PATCH] Add all tags option --- README.md | 10 +++++++++- src/gren.js | 26 +++++++++++++++++--------- test/utils.js | 2 +- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 27ae7b28..716460ae 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ The module will look for the last tag, get all the issues closed in the time bet Following the options for the module: - `--action=release|changelog` The **gren** action to run. Default: `release` _(see details below for changelog generator)_ -- `--tags=0.1.0|0.2.0,0.1.0` A specific tag or the range of tags to build the release notes from. +- `--tags=0.1.0|0.2.0,0.1.0|all` A specific tag or the range of tags to build the release notes from. You can also specify `all` to write all releases. _(To override existing releases use the --override flag)_ - `--ignore-labels=wont_fix|wont_fix,duplicate` One or more labels to ignore in the output. Default: `false` _(it will still output the issue, just without the specified labels)_ - `--ignore-issues-with=wont_fix|wont_fix,duplicate` Ignore issues that contains one of the specified labels. Default: `false` - `--time-wrap=latest|history` The release notes you want to include in the changelog. Default: `latest` _Only applicable to the `changelog` action_ @@ -152,6 +152,14 @@ If you want then to override, simple use: gren --override --tags=0.3.0 ``` +### Write all existing tags + +You can run the task to generate release notes for all existing tags. +Releases that already exist will be skipped. To override them, use the flag `--override` + +``` +gren --override --tags=all +``` ## Changelog Generator diff --git a/src/gren.js b/src/gren.js index 0cd7eef6..6e2b0b53 100644 --- a/src/gren.js +++ b/src/gren.js @@ -59,7 +59,7 @@ function editRelease(gren, releaseId, releaseOptions) { var release = response.data; - console.log(chalk.green('\n\n' + release.name + ' has been successfully updated!')); + console.log(chalk.green(release.name + ' has been successfully updated!')); return release; }); @@ -92,7 +92,7 @@ function createRelease(gren, releaseOptions) { loaded(); var release = response.data; - console.log(chalk.green('\n\n' + release.name + ' has been successfully created!')); + console.log(chalk.green(release.name + ' has been successfully created!')); return release; }); @@ -119,6 +119,12 @@ function prepareRelease(gren, block) { }; if (block.id) { + if (!gren.options.override) { + console.warn(chalk.yellow('Skipping ' + block.release + ' (use --override to replace it)')); + + return Promise.resolve(); + } + return editRelease(gren, block.id, releaseOptions); } @@ -132,12 +138,16 @@ function prepareRelease(gren, block) { * @since 0.5.0 * @private * - * @param {Boolean|Array} selectedTags + * @param {Array|string} selectedTags * @param {Object[]} tags * * @return {Boolean|Array} */ function getSelectedTags(optionTags, tags) { + if (optionTags.indexOf('all') >= 0) { + return tags; + } + if (!optionTags.length) { return false; } @@ -185,10 +195,6 @@ function getLastTags(gren, releases) { }; }); - if (filteredTags[0].releaseId && !gren.options.override) { - throw chalk.red(filteredTags[0].tag.name + ' is a release, use --override flag to override an existing release!'); - } - console.log('Tags found: ' + filteredTags.map(function(tag) { return tag.tag.name; }).join(', ')); @@ -575,7 +581,7 @@ function getClosedIssues(gren, releaseRanges) { * @return {Promise[]} */ function getIssueBlocks(gren, releaseRanges) { - console.log('\nCreating the body blocks from releases:'); + console.log('Creating the body blocks from releases:'); return getClosedIssues(gren, releaseRanges) .then(function(issues) { @@ -862,7 +868,9 @@ GithubReleaseNotes.prototype.release = function() { ); }) .then(function(blocks) { - return prepareRelease(gren, blocks[0]); + return blocks.reduce(function(carry, block) { + return carry.then(prepareRelease.bind(null, gren, block)); + }, Promise.resolve()); }); }; diff --git a/test/utils.js b/test/utils.js index 154d11a6..184b6966 100644 --- a/test/utils.js +++ b/test/utils.js @@ -40,4 +40,4 @@ exports['utils'] = { test.done(); } -}; \ No newline at end of file +};