verify-commit.js 767 B

12345678910111213141516171819202122
  1. const chalk = require("chalk")
  2. const msgPath = process.env.HUSKY_GIT_PARAMS
  3. const msg = require("fs").readFileSync(msgPath, "utf-8").trim()
  4. const commitRE = /^(revert: )?(feat|fix|polish|docs|style|refactor|perf|test|workflow|ci|chore|types)(\(.+\))?: .{1,50}/
  5. if (!commitRE.test(msg)) {
  6. console.error(
  7. ` ${chalk.bgRed.white(" ERROR ")} ${chalk.red(
  8. "不合法的 commit 消息格式"
  9. )}\n\n` +
  10. chalk.red(" 请使用正确的提交格式:\n\n") +
  11. ` ${chalk.green("feat: add 'comments' option")}\n` +
  12. ` ${chalk.green("fix: handle events on blur (close #28)")}\n\n` +
  13. chalk.red(
  14. " 请查看 git commit 提交规范:https://github.com/vuejs/vue/blob/dev/.github/COMMIT_CONVENTION.md \n"
  15. )
  16. )
  17. process.exit(1)
  18. }