From ab0a5967b58053829b24f033bafea83d24d1ab2b Mon Sep 17 00:00:00 2001 From: yogevbd Date: Wed, 4 Nov 2020 12:32:45 +0200 Subject: [PATCH 1/7] Add post group formatter --- lib/src/Gren.js | 5 ++++- test/Gren.spec.js | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/src/Gren.js b/lib/src/Gren.js index 67d3cafe..3f29afe5 100644 --- a/lib/src/Gren.js +++ b/lib/src/Gren.js @@ -606,13 +606,16 @@ class Gren { * @return {string} */ _templateGroups(groups) { + const { postGroupFormatter } = this.options; + return Object.entries(groups).map(([key, value]) => { const heading = generate({ heading: key }, this.options.template.group); const body = value.join('\n'); + const content = heading + '\n' + body; - return heading + '\n' + body; + return postGroupFormatter ? postGroupFormatter(content) : content; }); } diff --git a/test/Gren.spec.js b/test/Gren.spec.js index b268b412..48b3caa3 100644 --- a/test/Gren.spec.js +++ b/test/Gren.spec.js @@ -211,6 +211,23 @@ describe('Gren', () => { }; assert.deepEqual(gren._groupBy(normal), [`All\n${normal[0].title}`], 'The issue does not match any labels, and goes in the ... group'); }); + + it('Should format group using post formatter', () => { + const { normal, noLabel } = issues; + + gren.options.groupBy = { + 'Test': ['enhancement'], + 'Others': ['closed'] + }; + + gren.options.postGroupFormatter = (groupContent) => { + console.log(groupContent) + return groupContent.replace('Test', '### Test'); + } + + assert.deepEqual(gren._groupBy(normal), [`### Test\n${normal[0].title}`], 'Passing one heading for one issue'); + assert.deepEqual(gren._groupBy(noLabel), [`Others\n${noLabel[0].title}`], 'Group option is "label" with no labels'); + }); }); describe('_filterIssue', () => { From 02d5b21de8fc93952b6e1e594e7e8a2a6a4e39ee Mon Sep 17 00:00:00 2001 From: yogevbd Date: Wed, 4 Nov 2020 12:42:09 +0200 Subject: [PATCH 2/7] Push dist and bin --- .gitignore | 4 +- bin/_examples.js | 109 +++ bin/_options.js | 151 +++ bin/gren-changelog.js | 43 + bin/gren-examples.js | 45 + bin/gren-init.js | 68 ++ bin/gren-release.js | 33 + bin/gren.js | 22 + dist/GitHubInfo.js | 152 +++ dist/Gren.js | 2050 +++++++++++++++++++++++++++++++++++++++++ dist/Program.js | 367 ++++++++ dist/_init.js | 406 ++++++++ dist/_template.js | 46 + dist/_utils.js | 426 +++++++++ dist/templates.js | 19 + 15 files changed, 3939 insertions(+), 2 deletions(-) create mode 100755 bin/_examples.js create mode 100755 bin/_options.js create mode 100755 bin/gren-changelog.js create mode 100755 bin/gren-examples.js create mode 100755 bin/gren-init.js create mode 100755 bin/gren-release.js create mode 100755 bin/gren.js create mode 100644 dist/GitHubInfo.js create mode 100644 dist/Gren.js create mode 100644 dist/Program.js create mode 100644 dist/_init.js create mode 100644 dist/_template.js create mode 100644 dist/_utils.js create mode 100644 dist/templates.js diff --git a/.gitignore b/.gitignore index 341f9a07..f5fcb277 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ npm-debug.log docs/_site docs/.sass-cache coverage -dist -bin +# dist +# bin test/**.js.xml .vscode diff --git a/bin/_examples.js b/bin/_examples.js new file mode 100755 index 00000000..b77638a3 --- /dev/null +++ b/bin/_examples.js @@ -0,0 +1,109 @@ +'use strict'; + +var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray'); + +var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +var chalk = require('chalk'); + +/** + * Generate examples based on an Array + * + * @param {Array} examples + */ // istanbul ignore next +function generateExamples(title, examples) { + process.stdout.write('\n Examples for ' + title + ':'); + var spaceify = function spaceify(number) { + return new Array(!number || number < 0 ? 0 : number + 1).join(' '); + }; + var spaces = spaceify(6); + var descriptionPlaceholder = spaceify(Math.max.apply(Math, (0, _toConsumableArray3.default)(examples.map(function (_ref) { + var description = _ref.description; + return description ? description.length : 0; + })))); + + examples.forEach(function (_ref2) { + var name = _ref2.name, + description = _ref2.description, + code = _ref2.code; + + var tabs = spaceify(descriptionPlaceholder.length - (description ? description.length : 0)); + + if (name) { + process.stdout.write('\n\n ' + chalk.blue(name) + ':\n'); + } + + if (description) { + process.stdout.write('\n' + spaces + description); + } else { + process.stdout.write(spaces); + } + + if (code) { + process.stdout.write('' + tabs + spaces + chalk.green('$ ' + code) + '\n'); + } + }); +} + +module.exports = { + generateExamples: generateExamples, + gren: [{ + name: 'Help', + description: 'Show the general help of the gren tool', + code: 'gren' + }, { + code: 'gren --help' + }, { + code: 'gren -h' + }, { + name: 'Version', + description: 'Show the using version', + code: 'gren --version' + }, { + code: 'gren -v' + }, { + description: 'Get help for the release options', + code: 'gren help release' + }], + release: [{ + name: 'Manual repo infos', + description: 'Run gren outside of the project folder.', + code: 'gren release --username=REPO_USER --repo=REPO_NAME' + }, { + name: 'Override an existing release', + description: 'By default, `gren` won\'t override an existing release and it will flag `Skipping 4.0.0 (use --override to replace it)`. If you want to override, as it suggests, use:', + code: 'gren release --override' + }, { + name: 'Create release notes for a specific tag', + description: 'Create release notes from the commits or issues closed for the specified tag and the one before.', + code: 'gren release --tags=4.0.0' + }, { + description: 'Create release notes from the commits or the issues between two specified tags.', + code: 'gren release --tags=4.0.0..3.0.0' + }, { + name: 'Create release notes for all the tags', + description: 'Create release notes for all the tags in the repository.', + code: 'gren release --tags=all' + }, { + description: 'Ignore the tags including an Array of strings', + code: 'gren release --tags=all --ignore-tags-with="-rc","-alpha","-beta"' + }, { + name: 'Work with milestones', + description: 'Create release notes for a tag using the belonging to a milestone that matches the name of the tag. e.g. If the tag is 4.0.0, `gren` is going to match the milestone _"Release 4.0.0"_.', + code: 'gren release --data-source=milestones --milestone-match="Release {{tag_name}}"' + }, { + description: 'Otherwise, you can just filter the issues that belong to _a_ milestone', + code: 'gren release --only-milestones' + }, { + name: 'Use commit messages', + description: 'Generate release notes based on commit messages', + code: 'gren release --data-source=commits' + }], + changelog: [{ + name: 'Custom changelog', + description: 'Create a changelog with a custom filename', + code: 'gren changelog --generate --override --changelog-filename=RELEASE_NOTES.md' + }] +}; \ No newline at end of file diff --git a/bin/_options.js b/bin/_options.js new file mode 100755 index 00000000..52c47364 --- /dev/null +++ b/bin/_options.js @@ -0,0 +1,151 @@ +'use strict'; + +var chalk = require('chalk'); + +module.exports = { + changelogOptions: [{ + short: false, + name: false, + description: '\n' + chalk.yellow('Changelog options') + '\n\n' + }, { + short: '-G', + name: 'generate', + description: 'Generate the changelog with gren rather than using the repo releases' + }, { + short: '-f', + name: 'changelog-filename', + valueType: '', + description: 'The name of the changelog file. [CHANGELOG.md]', + defaultValue: 'CHANGELOG.md' + }, { + short: false, + name: false, + description: '\n\n' + chalk.yellow('Release options') + ' \n' + chalk.blue('(only applicable with the --generate option).') + '\n\n' + }], + globalOptions: [{ + short: '-u', + name: 'username', + valueType: '', + description: 'The username of the repo e.g. github-tools' + }, { + short: '-r', + name: 'repo', + valueType: '', + description: 'The repository name e.g. github-release-notes' + }, { + short: '-T', + name: 'token', + valueType: '', + description: 'The token generated with repo access' + }, { + short: '-a', + name: 'api-url', + valueType: '', + description: 'Override the GitHub API URL, allows gren to connect to a private GHE installation' + }, { + short: '-o', + name: 'override', + description: 'Override the release notes if exist' + }, { + short: '-B', + name: 'debug', + description: 'Run the command in debugging mode' + }, { + short: '-t', + name: 'tags', + valueType: '..', + description: 'Write release notes for using data collected until . If only one tag is specified, will use data until the previous tag. To run gren for all the tags, use --tags=all', + action: function action(value) { + return value.split('..'); + } + }, { + short: '-l', + name: 'limit', + valueType: '', + description: 'Just produce release notes for the last releases.' + }, { + short: '-D', + name: 'data-source', + valueType: '', + description: 'The informations you want to use to build release notes. [issues]', + action: /^(issues|commits|milestones|prs|prs-with-issues)$/i, + defaultValue: 'issues' + }, { + short: '-N', + name: 'include-messages', + valueType: '', + description: 'Filter the messages added to the release notes. Only used when --data-source used is commits [commits]', + action: /^(merge|commits|all)$/i, + defaultValue: 'commits' + }, { + short: '-i', + name: 'ignore-tags-with', + valueType: ',', + description: 'Ignore tags that contain one of the specified strings.', + action: function action(value) { + return value.split(','); + } + }, { + short: '-C', + name: 'ignore-commits-with', + valueType: ',', + description: 'Ignore commits that contain one of the specified strings.', + action: function action(value) { + return value.split(','); + } + }, { + short: '-p', + name: 'prefix', + valueType: '', + description: 'Add a prefix to the tag version. e.g. \'v\'' + }, { + short: '-g', + name: 'group-by', + valueType: '