jackywongmm / noteBook

noteBook
0 stars 0 forks source link

使用GIT HOOK来规范commit #7

Open jackywongmm opened 5 years ago

jackywongmm commented 5 years ago

js脚本 image

` // Invoked on the commit-msg git hook by yorkie. const chalk = require('chalk') // 终端输出 const msgPath = process.env.GIT_PARAMS //获取git命令行 输入 const msg = require('fs') //读取git命令 .readFileSync(msgPath, 'utf-8') .trim()

const commitRE = /^(revert: )?(feat|fix|docs|dx|style|refactor|perf|test|workflow|build|ci|chore|types|wip)((.+))?: .{1,50}/

if (!commitRE.test(msg)) { // 对git命令校验 console.log() console.error( \ ${chalk.bgRed.white(' ERROR ')} ${chalk.red( invalid commit message format.` )}\n\n+ chalk.red( \ Proper commit message format is required for automated changelog generation. Examples:\n\n` ) + ` ${chalk.green(`feat(compiler): add 'comments' option`)}\n` + ` ${chalk.green( `fix(v-model): handle events on blur (close #28)` )}\n\n` + chalk.red(` See .github/commit-convention.md for more details.\n`) ) process.exit(1) } ` 需要安装的npm 模块 yorkie 和 lint-staged,分别对应gitHooks和lint-staged的package.json package.json 配置 image