From d7e9d8746a47c689fd8014f3913c47c4d6692709 Mon Sep 17 00:00:00 2001 From: Andrew Scott Date: Wed, 15 Apr 2020 16:49:48 -0700 Subject: [PATCH] build: list feat commits in patch branch in relase review script (#36651) PR Close #36651 --- scripts/compare-master-to-patch.js | 32 ++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/scripts/compare-master-to-patch.js b/scripts/compare-master-to-patch.js index f5849dff10..4ae5befeca 100755 --- a/scripts/compare-master-to-patch.js +++ b/scripts/compare-master-to-patch.js @@ -14,6 +14,9 @@ * This script compares commits in master and patch branches to find the delta between them. This is * useful for release reviews, to make sure all the necessary commits were included into the patch * branch and there is no discrepancy. + * + * Additionally, lists all 'feat' commits that were merged to the patch branch to aid in ensuring + * features are only released to master. */ const {exec} = require('shelljs'); @@ -57,6 +60,10 @@ function maybeExtractReleaseVersion(commit) { return matches ? matches[1] || matches[2] : null; } +/** + * @param rawGitCommits + * @returns {Map} - Map of commit message to [commit info, version] + */ function collectCommitsAsMap(rawGitCommits) { const commits = toArray(rawGitCommits); const commitsMap = new Map(); @@ -81,6 +88,10 @@ function collectCommitsAsMap(rawGitCommits) { return commitsMap; } +function getCommitInfoAsString(commitInfo, version) { + return `[${version}+] ${commitInfo}`; +} + /** * Returns a list of items present in `mapA`, but *not* present in `mapB`. * This function is needed to compare 2 sets of commits and return the list of unique commits in the @@ -90,12 +101,26 @@ function diff(mapA, mapB) { const result = []; mapA.forEach((value, key) => { if (!mapB.has(key)) { - result.push(`[${value[1]}+] ${value[0]}`); + result.push(getCommitInfoAsString(value[1], value[0])); } }); return result; } +/** + * @param {Map} commitsMap - commit map from collectCommitsAsMap + * @returns {string[]} List of commits with commit messages that start with 'feat' + */ +function listFeatures(commitsMap) { + return Array.from(commitsMap.keys()).reduce((result, key) => { + if (key.startsWith('feat')) { + const value = commitsMap.get(key); + result.push(getCommitInfoAsString(value[1], value[0])); + } + return result; + }, []); +} + function getBranchByTag(tag) { const version = semver(tag); return `${version.major}.${version.minor}.x`; // e.g. 9.0.x @@ -141,7 +166,10 @@ ${diff(masterCommitsMap, patchCommitsMap).join('\n') || 'No extra commits'} ***** Only in PATCH (${branch}) ***** ${diff(patchCommitsMap, masterCommitsMap).join('\n') || 'No extra commits'} + +***** Features in PATCH (${branch}) - should always be empty ***** +${listFeatures(patchCommitsMap).join('\n') || 'No extra commits'} `); } -main(); \ No newline at end of file +main();