Browse Source

feat: add pre-commit hook

yangkaixuan 5 years ago
parent
commit
3105e17958
2 changed files with 14 additions and 0 deletions
  1. 1 0
      package.json
  2. 13 0
      scripts/verifymail.js

+ 1 - 0
package.json

@@ -24,6 +24,7 @@
   },
   "husky": {
     "hooks": {
+      "pre-commit": "node ./scripts/verifymail.js",
       "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
     }
   },

+ 13 - 0
scripts/verifymail.js

@@ -0,0 +1,13 @@
+#!/usr/bin/env node
+const { execSync} = require('child_process');
+
+const stdout = execSync('git config user.email').toString();
+ 
+if(stdout && /@jd.com$/ig.test(stdout.replace(/^\s+|\s+$/g,""))){
+    console.log( '\x1B[31m%s\x1B[39m','ERROR:', '不能使用京东企业邮箱提交,请设置个人GitHub邮箱');
+    console.log('提示: git config user.email xxxxxxxx@xx.com')
+    process.exit(1);
+ }else{
+    process.exit(0);
+ }
+