forked from darwinia-network/subql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commitlint.config.js
60 lines (54 loc) · 1.15 KB
/
commitlint.config.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
53
54
55
56
57
58
59
60
const message = process.env['HUSKY_GIT_PARAMS'];
const fs = require('fs');
const types = [
'build',
'chore',
'ci',
'docs',
'feat',
'fix',
'perf',
'refactor',
'release',
'revert',
'style',
'test',
];
const scopes = ['showcase', 'packaging', 'changelog', 'schematics', 'module:*', '#*'];
function parseMessage(message) {
const PATTERN = /^(\w+)(?:\(([^)]+)\))?\: ([^\u4e00-\u9fa5]+)$/;
const match = PATTERN.exec(message);
if (!match) {
return null;
}
return {
type: match[1] || null,
scope: match[2] || null,
};
}
function getScopesRule() {
const messages = fs.readFileSync(message, { encoding: 'utf-8' });
const parsed = parseMessage(messages.split('\n')[0]);
if (!parsed) {
return [2, 'always', scopes];
}
const { scope, type } = parsed;
if (
scope &&
!scopes.includes(scope) &&
type !== 'release' &&
!/module:.+/.test(scope) &&
!/#\d+/.test(scope)
) {
return [2, 'always', scopes];
} else {
return [2, 'always', []];
}
}
module.exports = {
extends: ['@commitlint/config-angular'],
rules: {
'type-enum': [2, 'always', types],
'scope-enum': getScopesRule,
},
};