Skip to content

Commit 1daeadb

Browse files
committed
workflow: enforce commit format
1 parent 3347015 commit 1daeadb

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"boot": "node scripts/bootstrap.js"
1818
},
1919
"gitHooks": {
20-
"pre-commit": "lint-staged"
20+
"pre-commit": "lint-staged",
21+
"commit-msg": "node scripts/verifyCommitMsg.js"
2122
},
2223
"jest": {
2324
"testEnvironment": "node",

scripts/verifyCommitMsg.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const chalk = require('chalk')
2+
const msgPath = process.env.GIT_PARAMS
3+
const msg = require('fs').readFileSync(msgPath, 'utf-8').trim()
4+
5+
const commitRE = /^(revert: )?(feat|fix|docs|style|refactor|perf|test|workflow|ci|chore|types)(\(.+\))?: .{1,50}/
6+
7+
if (!commitRE.test(msg)) {
8+
console.log()
9+
console.error(
10+
` ${chalk.bgRed.white(' ERROR ')} ${chalk.red(`invalid commit message format.`)}\n\n` +
11+
chalk.red(` Proper commit message format is required for automated changelog generation. Examples:\n\n`) +
12+
` ${chalk.green(`feat(compiler): add 'comments' option`)}\n` +
13+
` ${chalk.green(`fix(v-model): handle events on blur (close #28)`)}\n\n` +
14+
chalk.red(` See .github/COMMIT_CONVENTION.md for more details.\n`) +
15+
chalk.red(` You can also use ${chalk.cyan(`npm run commit`)} to interactively generate a commit message.\n`)
16+
)
17+
process.exit(1)
18+
}

0 commit comments

Comments
 (0)