diff --git a/.husky/commit-msg b/.husky/commit-msg index 23c4c7ca..680fc2b2 100755 --- a/.husky/commit-msg +++ b/.husky/commit-msg @@ -1,4 +1,4 @@ #!/usr/bin/env sh . "$(dirname -- "$0")/_/husky.sh" -ts-node scripts/verifyCommit.ts \ No newline at end of file +node scripts/verifyCommit.cjs \ No newline at end of file diff --git a/scripts/verifyCommit.cjs b/scripts/verifyCommit.cjs new file mode 100644 index 00000000..a29c2b77 --- /dev/null +++ b/scripts/verifyCommit.cjs @@ -0,0 +1,17 @@ +const msg = require('fs') + .readFileSync('.git/COMMIT_EDITMSG', 'utf-8') + .trim() + +const commitRE = /^(revert: )?(feat|fix|docs|dx|style|refactor|perf|test|workflow|build|ci|chore|types|wip|release)(\(.+\))?: .{1,50}/ +const mergeRe = /^(Merge pull request|Merge branch)/ +if (!commitRE.test(msg)) { + if(!mergeRe.test(msg)){ + console.log('git commit message does not pass validation') + + console.error(`git commit message format error, use \" title(scope): desc\" as the format`) + process.exit(1) + } + +}else{ + console.log('git commit message validation test passes') +} \ No newline at end of file