From 4d1add585d6fe85f3d98b41fc71ffe087ac393e5 Mon Sep 17 00:00:00 2001 From: Juha Ruotsalainen Date: Thu, 23 Feb 2023 15:16:19 +0200 Subject: [PATCH 1/2] Use RegExp instead of micromatch. Micromatch is more geared towards path matching and that doesn't really play well with e.g. Bitbucket style pull request messages like this example: Pull request #323: feature/SMKY-1231 Responsiveness fixes That forward slash breaks the old micromatch based implementation. The side effect here is that `releaseRules` patterns must now be compilable to regular expressions. --- lib/analyze-commit.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/analyze-commit.js b/lib/analyze-commit.js index c3e3ec45..67b58bc9 100644 --- a/lib/analyze-commit.js +++ b/lib/analyze-commit.js @@ -1,5 +1,4 @@ const {isMatchWith, isString} = require('lodash'); -const micromatch = require('micromatch'); const debug = require('debug')('semantic-release:commit-analyzer'); const RELEASE_TYPES = require('./default-release-types.js'); const compareReleaseTypes = require('./compare-release-types.js'); @@ -22,9 +21,7 @@ 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) => new RegExp(src).test(object)) ) .every((match) => { if (compareReleaseTypes(releaseType, match.release)) { From f9f541e14cecded43f1ddcad48fdcab1e13bc327 Mon Sep 17 00:00:00 2001 From: Juha Ruotsalainen Date: Fri, 4 Aug 2023 10:32:38 +0300 Subject: [PATCH 2/2] Merged with upstream + redid the micromatch removal --- lib/analyze-commit.js | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/lib/analyze-commit.js b/lib/analyze-commit.js index df352b0d..77464f8e 100644 --- a/lib/analyze-commit.js +++ b/lib/analyze-commit.js @@ -1,10 +1,9 @@ -import { isMatchWith, isString } from "lodash-es"; -import micromatch from "micromatch"; -import debugFactory from "debug"; -import RELEASE_TYPES from "./default-release-types.js"; -import compareReleaseTypes from "./compare-release-types.js"; +import { isMatchWith, isString } from 'lodash-es' +import debugFactory from 'debug' +import RELEASE_TYPES from './default-release-types.js' +import compareReleaseTypes from './compare-release-types.js' -const debug = debugFactory("semantic-release:commit-analyzer"); +const debug = debugFactory('semantic-release:commit-analyzer') /** * Find all the rules matching and return the highest release type of the matching rules. * @@ -13,7 +12,7 @@ const debug = debugFactory("semantic-release:commit-analyzer"); * @return {string} the highest release type of the matching rules or `undefined` if no rule match the commit. */ export default (releaseRules, commit) => { - let releaseType; + let releaseType releaseRules .filter( @@ -27,23 +26,23 @@ export default (releaseRules, commit) => { ) .every((match) => { if (compareReleaseTypes(releaseType, match.release)) { - releaseType = match.release; - debug("The rule %o match commit with release type %o", match, releaseType); + releaseType = match.release + debug('The rule %o match commit with release type %o', match, releaseType) if (releaseType === RELEASE_TYPES[0]) { - debug("Release type %o is the highest possible. Stop analysis.", releaseType); - return false; + debug('Release type %o is the highest possible. Stop analysis.', releaseType) + return false } } else { debug( - "The rule %o match commit with release type %o but the higher release type %o has already been found for this commit", + 'The rule %o match commit with release type %o but the higher release type %o has already been found for this commit', match, match.release, releaseType - ); + ) } - return true; - }); + return true + }) - return releaseType; -}; + return releaseType +}