git-verify-commit.js 1019 B

12345678910111213141516171819202122232425
  1. /*
  2. * @Author: Rindy
  3. * @Date: 2021-04-29 09:57:47
  4. * @LastEditors: Rindy
  5. * @LastEditTime: 2021-04-29 10:10:32
  6. * @Description: git 提交规程检测
  7. */
  8. const chalk = require('chalk')
  9. const msgPath = process.env.GIT_PARAMS
  10. const msg = require('fs').readFileSync(msgPath, 'utf-8').trim()
  11. const commitRE = /^(revert: |Merge )?(feat|fix|docs|dx|style|refactor|perf|test|workflow|build|ci|chore|types|wip|release)(\(.+\))?: .{1,50}/i
  12. if (!commitRE.test(msg)) {
  13. console.log()
  14. console.error(
  15. ` ${chalk.bgRed.white(' ERROR ')} ${chalk.red(`Git 提交信息格式错误(注意冒号后的空格)。`)}\n\n` +
  16. chalk.red(` Proper commit message format is required for automated changelog generation. Examples:\n\n`) +
  17. ` ${chalk.green(`feat(plugin): add 'test' function`)}\n` +
  18. ` ${chalk.green(`fix(event): handle events on blur`)}\n\n` +
  19. chalk.red(` See commit-convention.md for more details.\n`)
  20. )
  21. process.exit(1)
  22. }