Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use RegExp instead of micromatch. #419

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 17 additions & 20 deletions 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.
*
Expand All @@ -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(
Expand All @@ -23,29 +22,27 @@ export default (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)) {
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
}