-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverify-commit-msg.js
48 lines (45 loc) · 2 KB
/
verify-commit-msg.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
// Invoked on the commit-msg git hook
const { readFileSync } = require('fs')
// process.argv: [node, verify-commit-msg.js, .git/COMMIT_EDITMSG]
const msgPath = process.argv[2]
const msg = readFileSync(msgPath, 'utf-8').trim()
const mergeReg = /^Merge branch/i
const releaseRE = /^v\d/
const pre = [
'add', // add something
'remove', // remove something
'ci', // updates to the continous integration system
'fix', // a bug fix
'feat', // a new feature
'docs', // documentation only changes
'perf', // a code change that improves performance
'test', // adding missing or correcting existing tests
'build', // changes related to build processes
'chore', // changes to the build process or auxiliary tools and libraries such as documentation generation
'config', // changing configuration files
'chore-deps', // add or delete dependencies
'chore-release', // code deployment or publishing to external repositories
'i18n', // internationalization and localization
'style', // changes that do not affect the meaning of code (white-space, formatting, missing semi-colors, etc)
'release', // code deployment or publishing to external repositories
'breaking', // introducing breaking changes
'refactor', // a code change that neither fixes a bug nor adds a feature
'security' // fixing security issues
]
const commitRE = new RegExp(
`^(revert: )?(${pre.join('|')})(\\(.+\\))?: .{1,50}`
)
if (!mergeReg.test(msg) && !releaseRE.test(msg) && !commitRE.test(msg)) {
console.log()
console.log()
console.error(
` \x1b[41m\x1b[37m ERROR \x1b[0m
\x1b[31minvalid commit message format.\x1b[0m
\n\n` +
` \x1b[31mProper commit message format is required for automated changelog generation. Examples:\x1b[0m\n\n` +
` \x1b[32mfeat: add 'comments' option\x1b[0m\n` +
` \x1b[32mfix: handle events on blur (close #28)\x1b[0m\n\n` +
` \x1b[31mSee https://github.com/kunlunjs/kunlun-fabric/blob/main/verify-commit-msg.js for more details.\x1b[0m\n`
)
process.exit(1)
}