Skip to content

Commit fbb352c

Browse files
committed
feat: 规范chameleon仓库commit信息
1 parent 2f3930f commit fbb352c

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,53 @@ husky > commit-msg hook failed (add --no-verify to bypass)
6565

6666
[config-conventional-github](https://github.com/conventional-changelog/commitlint/tree/master/%40commitlint/config-conventional#type-enum)
6767

68+
### 5 自己配置校验规则
6869

70+
5.1 新增commit-ling.js 文件,内容如下; 注意这里获取 commit 信息的路径,对于 husky ,是 `HUSKY_GIT_PARAMS` 这个变量,指向 `.git/COMMIT_EDITMSG`
71+
72+
```
73+
cd .git
74+
ls
75+
76+
COMMIT_EDITMSG HEAD TAG_EDITMSG description index logs refs
77+
FETCH_HEAD ORIG_HEAD config hooks info objects
78+
79+
```
80+
```javascript
81+
const chalk = require('chalk')
82+
const msgPath = process.env.HUSKY_GIT_PARAMS
83+
console.log('process.env',process.env.HUSKY_GIT_PARAMS)
84+
debugger;
85+
const msg = require('fs').readFileSync(msgPath, 'utf-8').trim()
86+
87+
const commitRE = /^(revert: )?(feat|fix|polish|docs|style|refactor|perf|test|workflow|ci|chore|types|build)(\(.+\))?: .{1,50}/
88+
console.log(msg)
89+
console.log('process.env',process.env)
90+
if (!commitRE.test(msg)) {
91+
console.log()
92+
console.error(
93+
` ${chalk.bgRed.white(' ERROR ')} ${chalk.red(`invalid commit message format.`)}\n\n` +
94+
chalk.red(` Proper commit message format is required for automated changelog generation. Examples:\n\n`) +
95+
` ${chalk.green(`feat(compiler): add 'comments' option`)}\n` +
96+
` ${chalk.green(`fix(v-model): handle events on blur (close #28)`)}\n\n` +
97+
chalk.red(` See .github/COMMIT_CONVENTION.md for more details.\n`) +
98+
chalk.red(` You can also use ${chalk.cyan(`npm run commit`)} to interactively generate a commit message.\n`)
99+
)
100+
process.exit(1)
101+
}
102+
103+
104+
```
105+
106+
package.json 中 githooks 中修改为如下:
107+
```json
108+
109+
"husky": {
110+
"hooks": {
111+
"commit-msg": "node commit-lint.js"
112+
}
113+
},
114+
```
69115

70116
Commit Message格式
71117

0 commit comments

Comments
 (0)