Skip to content
This repository was archived by the owner on Jun 23, 2023. It is now read-only.

Commit 6e29068

Browse files
committed
chore: add verify commit script
1 parent 708a418 commit 6e29068

3 files changed

Lines changed: 30 additions & 19 deletions

File tree

.commitlintrc.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"@types/babel__core": "^7.1.9",
4343
"@typescript-eslint/eslint-plugin": "^4.20.0",
4444
"@typescript-eslint/parser": "^4.20.0",
45+
"chalk": "^4.1.1",
4546
"eslint": "^7.23.0",
4647
"eslint-config-prettier": "^8.3.0",
4748
"eslint-plugin-prettier": "^3.4.0",
@@ -57,8 +58,8 @@
5758
},
5859
"husky": {
5960
"hooks": {
60-
"commit-msg": "commitlint -E $HUSKY_GIT_PARAMS",
61-
"pre-commit": "lint-staged"
61+
"pre-commit": "lint-staged",
62+
"commit-msg": "node scripts/verifyCommit.js"
6263
}
6364
},
6465
"lint-staged": {

scripts/verifyCommit.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Invoked on the commit-msg git hook by yorkie.
2+
3+
const fs = require('fs')
4+
const chalk = require('chalk')
5+
const msgPath = process.env.HUSKY_GIT_PARAMS
6+
const msg = fs.readFileSync(msgPath, 'utf-8').trim()
7+
8+
const commitRE =
9+
/^(revert: )?(feat|fix|docs|dx|style|refactor|perf|test|workflow|build|ci|chore|types|wip|release)(\(.+\))?: .{1,50}/
10+
11+
if (!commitRE.test(msg)) {
12+
console.log()
13+
console.error(
14+
` ${chalk.bgRed.white(' ERROR ')} ${chalk.red(
15+
`invalid commit message format.`
16+
)}\n\n` +
17+
chalk.red(
18+
` Proper commit message format is required for automated changelog generation. Examples:\n\n`
19+
) +
20+
` ${chalk.green(`feat(compiler): add 'comments' option`)}\n` +
21+
` ${chalk.green(
22+
`fix(v-model): handle events on blur (close #28)`
23+
)}\n\n` +
24+
chalk.red(` See .github/commit-convention.md for more details.\n`)
25+
)
26+
process.exit(1)
27+
}

0 commit comments

Comments
 (0)