verify-commit-msg.js 842 B

123456789101112131415161718192021222324
  1. const chalk = require('chalk')
  2. const msgPath = process.env.GIT_PARAMS
  3. const msg = require('fs').readFileSync(msgPath, 'utf-8').trim()
  4. const commitRE =
  5. /^(revert: )?(wip|release|feat|fix|polish|docs|style|refactor|perf|test|workflow|ci|chore|types|build)(\(.+\))?: .{1,50}/
  6. if (!commitRE.test(msg)) {
  7. console.log()
  8. console.error(
  9. ` ${chalk.bgRed.white(' ERROR ')} ${chalk.red(
  10. `invalid commit message format.`
  11. )}\n\n` +
  12. chalk.red(
  13. ` Proper commit message format is required for automated changelog generation. Examples:\n\n`
  14. ) +
  15. ` ${chalk.green(`feat(compiler): add 'comments' option`)}\n` +
  16. ` ${chalk.green(
  17. `fix(v-model): handle events on blur (close #28)`
  18. )}\n\n` +
  19. chalk.red(` See .github/COMMIT_CONVENTION.md for more details.\n`)
  20. )
  21. process.exit(1)
  22. }