-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathanalyze-commit.js
50 lines (46 loc) · 1.85 KB
/
analyze-commit.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const {isMatchWith, isString} = require('lodash');
const micromatch = require('micromatch');
const debug = require('debug')('semantic-release:commit-analyzer');
const RELEASE_TYPES = require('./default-release-types');
const compareReleaseTypes = require('./compare-release-types');
/**
* Find all the rules matching and return the highest release type of the matching rules.
*
* @param {Array} releaseRules the rules to match the commit against.
* @param {Commit} commit a parsed commit.
* @return {string} the highest release type of the matching rules or `undefined` if no rule match the commit.
*/
module.exports = (releaseRules, commit) => {
let releaseType;
releaseRules
.filter(
({breaking, revert, release, ...rule}) =>
// If the rule is not `breaking` or the commit doesn't have a breaking change note
(!breaking || (commit.notes && commit.notes.length > 0)) &&
// 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
)
)
.every((match) => {
if (compareReleaseTypes(releaseType, match.release)) {
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;
}
} else {
debug(
'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 releaseType;
};