Commit 01b7ab93 authored by shangbj's avatar shangbj

sdf

parent 14e22cd7
const getRepoInfo = require('git-repo-info')
const info = getRepoInfo();
/*
* 功能: git commit时,自动验证提交信息是否符合规范
* 提交规范: 信息中应包含字符"HELLO-",同时提交 当前版本的信息。例如:"08-18 HELLO-某个功能开发"
* https://github.com/typicode/husky/issues/71
* https://github.com/typicode/husky/issues/
* 主要是读取 .git/COMMIT_EDITMSG 这个文件,文件记录了当前commit之后的信息
*/
var fs = require('fs');
var path = require('path');
const objkeys = Object.keys(info)
var gitPath = path.join('../', process.env.GIT_PARAMS);
var commitMsg = fs.readFileSync(gitPath, 'utf-8');
for (const key of objkeys) {
console.log(key, info[key])
}
\ No newline at end of file
var pattern = /HELLO-/g;
if (!pattern.test(commitMsg)) {
console.log(' 提交代码信息不符合规范,信息中应包含字符"HELLO-".\n');
console.log(' 例如:08-28版本HELLO- frist commit.\n');
process.exit(1);
}
process.exit(0);
\ No newline at end of file
......@@ -12,7 +12,7 @@
},
"husky": {
"hooks": {
"commit-msg": "node ./build/hooks.js"
"commit-msg": "node ./build/hooks.js ${GIT_PARAMS}"
}
},
"keywords": [],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment