From 4a181169d3abd97f06b0ae7856f56f1e39ea1b9a Mon Sep 17 00:00:00 2001 From: Blake Kostner Date: Mon, 14 Mar 2022 15:16:09 -0600 Subject: [PATCH 1/2] feat: allow catchall for types when analyzing commits --- lib/analyze-commit.js | 10 +++++++--- test/analyze-commit.test.js | 4 ++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/analyze-commit.js b/lib/analyze-commit.js index be1572eb..734f5985 100644 --- a/lib/analyze-commit.js +++ b/lib/analyze-commit.js @@ -22,9 +22,13 @@ module.exports = (releaseRules, commit) => { // If the rule is not `revert` or the commit is not a revert (!revert || commit.revert) && // Otherwise match the regular rules - isMatchWith(commit, rule, (object, src) => - isString(src) && isString(object) ? micromatch.isMatch(object, src) : undefined - ) + isMatchWith(commit, rule, (object, src) => { + if (object === null && src === '*') { + return true; + } + + return isString(src) && isString(object) ? micromatch.isMatch(object, src) : undefined; + }) ) .every((match) => { if (compareReleaseTypes(releaseType, match.release)) { diff --git a/test/analyze-commit.test.js b/test/analyze-commit.test.js index b0aa2c40..5f82bf2b 100644 --- a/test/analyze-commit.test.js +++ b/test/analyze-commit.test.js @@ -85,6 +85,10 @@ test('Match with glob', (t) => { t.is(analyzeCommit(rules, notMatch), undefined); }); +test('Match with catchall and undefined commit', (t) => { + t.is(analyzeCommit([{type: '*', release: 'patch'}], {type: null}), 'patch'); +}); + test('Return highest release type if multiple rules match', (t) => { const commit = { type: 'feat', From ee58f065d28ec5a63e8c268f0cdd2fd418240acf Mon Sep 17 00:00:00 2001 From: Blake Kostner Date: Wed, 16 Mar 2022 14:50:39 -0600 Subject: [PATCH 2/2] remove null check --- lib/analyze-commit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/analyze-commit.js b/lib/analyze-commit.js index 734f5985..c2d3d056 100644 --- a/lib/analyze-commit.js +++ b/lib/analyze-commit.js @@ -23,7 +23,7 @@ module.exports = (releaseRules, commit) => { (!revert || commit.revert) && // Otherwise match the regular rules isMatchWith(commit, rule, (object, src) => { - if (object === null && src === '*') { + if (src === '*') { return true; }