From 9593d85df73dd8499223df2dd4d855eb23c329ad Mon Sep 17 00:00:00 2001 From: Jeff Chew Date: Mon, 11 Jan 2021 13:40:45 -0500 Subject: [PATCH 1/2] chore(changelog): updating changelog script This adds two things to the changelog script: - Adds `Housekeeping` section that includes all chores - Grouping by commit names --- tasks/get-changelog.js | 93 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 76 insertions(+), 17 deletions(-) diff --git a/tasks/get-changelog.js b/tasks/get-changelog.js index 572f509a1bf..8e25a47e043 100644 --- a/tasks/get-changelog.js +++ b/tasks/get-changelog.js @@ -1,7 +1,7 @@ #!/usr/bin/env node /** - * Copyright IBM Corp. 2020 + * Copyright IBM Corp. 2020, 2021 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. @@ -64,6 +64,34 @@ function getCommits(folder) { return output.split(`${delimiter}\n`); } +/** + * Returns the name from the commit string + * + * @param {string} str Commit string + * @returns {string} commit name + * @private + */ +function _getCommitName(str) { + return str + .substring(str.indexOf('(') + 1, str.indexOf('):')) + .trim() + .toLowerCase(); +} + +/** + * Returns the subject from the commit string + * + * @param {string} str Commit string + * @returns {string} commit subject + * @private + */ +function _getCommitSubject(str) { + return str + .substring(str.indexOf('):') + 2, str.length) + .trim() + .toLowerCase(); +} + /** * Gets the changelog content * @@ -76,41 +104,72 @@ function getChangelog(pkgName, folder) { let changelog = `## ${pkgName}\n`; // Stores the list of features - const features = []; + const features = {}; // Stores the list of fixes - const fixes = []; + const fixes = {}; + + // Stores the list of chores + const chores = {}; const commitsArray = getCommits(folder); commitsArray.forEach(commit => { const commitParse = commit.replace(delimiter, ''); if (commit.startsWith('feat(')) { - const pushFeat = commitParse - .replace('feat(', '- **') - .replace('):', '**: '); - features.push(`${pushFeat}\n`); + const featName = _getCommitName(commitParse); + const featSubject = _getCommitSubject(commitParse); + + features[featName] = features[featName] || []; + features[featName].push(featSubject); } + if (commit.startsWith('fix(')) { - const pushFeat = commitParse - .replace('fix(', '- **') - .replace('):', '**: '); - fixes.push(`${pushFeat}\n`); + const fixName = _getCommitName(commitParse); + const fixSubject = _getCommitSubject(commitParse); + + fixes[fixName] = fixes[fixName] || []; + fixes[fixName].push(fixSubject); + } + + if (commit.startsWith('chore(')) { + const choreName = _getCommitName(commitParse); + const choreSubject = _getCommitSubject(commitParse); + + chores[choreName] = chores[choreName] || []; + chores[choreName].push(choreSubject); } }); - if (features.length) { + if (Object.keys(features).length) { changelog += `### Features\n`; - features.forEach(feature => { - changelog += feature; + Object.keys(features).forEach(featureName => { + changelog += `- **${featureName}**\n`; + features[featureName].forEach(feature => { + changelog += ` - ${feature}\n`; + }); }); changelog += '\n'; } - if (fixes.length) { + if (Object.keys(fixes).length) { changelog += `### Fixes\n`; - fixes.forEach(fix => { - changelog += fix; + Object.keys(fixes).forEach(fixName => { + changelog += `- **${fixName}**\n`; + fixes[fixName].forEach(fix => { + changelog += ` - ${fix}\n`; + }); + }); + changelog += '\n'; + } + + if (Object.keys(chores).length) { + changelog += `### Housekeeping\n`; + Object.keys(chores).forEach(choreName => { + changelog += `- **${choreName}**\n`; + chores[choreName].forEach(chore => { + changelog += ` - ${chore}\n`; + }); }); changelog += '\n'; } From 3b2520da2b5c487c11f1bcffaf30ce00a4f10e2f Mon Sep 17 00:00:00 2001 From: Jeff Chew Date: Mon, 11 Jan 2021 14:07:16 -0500 Subject: [PATCH 2/2] chore(changelog): adding `docs` and `test` to housekeeping --- tasks/get-changelog.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tasks/get-changelog.js b/tasks/get-changelog.js index 8e25a47e043..748d0a03bb5 100644 --- a/tasks/get-changelog.js +++ b/tasks/get-changelog.js @@ -132,7 +132,11 @@ function getChangelog(pkgName, folder) { fixes[fixName].push(fixSubject); } - if (commit.startsWith('chore(')) { + if ( + commit.startsWith('chore(') || + commit.startsWith('docs(') || + commit.startsWith('test(') + ) { const choreName = _getCommitName(commitParse); const choreSubject = _getCommitSubject(commitParse);