forked from conventional-changelog/commitlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
52 lines (50 loc) · 1.41 KB
/
index.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
51
52
import semver from 'semver';
export const WILDCARDS = [
c =>
c.match(
/^((Merge pull request)|(Merge (.*?) into (.*?)|(Merge branch (.*?)))(?:\r?\n)*$)/m
),
c => c.match(/^(R|r)evert (.*)/),
c => c.match(/^(fixup|squash)!/),
c =>
semver.valid(
c
.split('\n')
.shift()
.replace(/^chore(\([^)]+\))?:/, '')
.trim()
),
c => c.match(/^Merged (.*?)(in|into) (.*)/),
c => c.match(/^Merge remote-tracking branch (.*)/),
c => c.match(/^Automatic merge(.*)/),
c => c.match(/^Auto-merged (.*?) into (.*)/)
];
export default function isIgnored(commit = '', opts = {}) {
let wildcards = [];
if (opts.ignoredMessages) {
if (opts.disableDefaultIgnoredMessages) {
wildcards = wildcards.concat(WILDCARDS);
}
if (!Array.isArray(opts.ignoredMessages)) {
throw new Error('ignoredMessages must be an Array');
}
opts.ignoredMessages.forEach(ignoreConfig => {
if (typeof ignoreConfig === 'function') {
wildcards.push(ignoreConfig);
} else if (ignoreConfig instanceof RegExp) {
wildcards.push(c => c.match(ignoreConfig));
} else if (typeof ignoreConfig === 'string') {
wildcards.push(c => c.match(new RegExp(ignoreConfig)));
} else {
throw new Error(
'ignoredMessage element must be a function, string or RegExp'
);
}
});
} else if (opts.disableDefaultIgnoredMessages) {
return false;
} else {
wildcards = WILDCARDS;
}
return wildcards.some(w => w(commit));
}