File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -65,7 +65,53 @@ husky > commit-msg hook failed (add --no-verify to bypass)
65
65
66
66
[ config-conventional-github] ( https://github.com/conventional-changelog/commitlint/tree/master/%40commitlint/config-conventional#type-enum )
67
67
68
+ ### 5 自己配置校验规则
68
69
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
+ ```
69
115
70
116
Commit Message格式
71
117
You can’t perform that action at this time.
0 commit comments