verify-commit-msg.js 808 B

12345678910111213141516
  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 = /^(revert: )?(feat|fix|polish|docs|style|refactor|perf|test|workflow|ci|chore|types|build|merge)(\(.+\))?: .{1,50}/
  5. if (!commitRE.test(msg)) {
  6. console.error(
  7. ` ${chalk.bgRed.white(' ERROR ')} ${chalk.red(`invalid commit message format.`)}\n\n` +
  8. chalk.red(` Proper commit message format is required for automated changelog generation. Examples:\n\n`) +
  9. ` ${chalk.green(`feat(compiler): add 'comments' option`)}\n` +
  10. ` ${chalk.green(`fix(v-model): handle events on blur (close #28)`)}\n\n` +
  11. chalk.red(` You can also use ${chalk.cyan(`npm run commit`)} to interactively generate a commit message.\n`)
  12. )
  13. process.exit(1)
  14. }