verifyCommit.js 542 B

123456789101112131415161718
  1. import fs from 'node:fs'
  2. import process from 'node:process'
  3. const msg = fs.readFileSync('.git/COMMIT_EDITMSG', 'utf-8').trim()
  4. const commitRE = /^(revert: )?(feat|fix|docs|dx|style|refactor|perf|test|workflow|build|ci|chore|types|wip|release)(\(.+\))?: .{1,50}/
  5. const mergeRe = /^(Merge pull request|Merge branch)/
  6. if (!commitRE.test(msg)) {
  7. if (!mergeRe.test(msg)) {
  8. console.log('git commit unpass')
  9. console.error('git commit error, needs title(scope): desc')
  10. process.exit(1)
  11. }
  12. }
  13. else {
  14. console.log('git commit pass')
  15. }