-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathverify-commit.js
More file actions
25 lines (22 loc) · 837 Bytes
/
verify-commit.js
File metadata and controls
25 lines (22 loc) · 837 Bytes
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
import { readFileSync } from 'fs'
import path from 'path'
import color from 'ansi-colors'
const msgPath = path.resolve('.git/COMMIT_EDITMSG')
const msg = readFileSync(msgPath, 'utf-8').trim()
const commitRE
= /^(revert: )?(update|optimizate|feat|fix|docs|dx|style|refactor|perf|test|workflow|build|ci|chore|types|wip|release)(\(.+\))?: .{1,50}/
if (!commitRE.test(msg)) {
console.error(
` ${color.bgRed.white(' ERROR ')} ${color.red(
'invalid commit message format.',
)}\n\n${
color.red(
' Proper commit message format is required for automated changelog generation. Examples:\n\n',
)
} ${color.green('feat: add \'comments\' option')}\n`
+ ` ${color.green(
'fix: handle events on blur',
)}`,
)
process.exit(1)
}