浏览代码

feat: add pre-commit hook

yangkaixuan 5 年之前
父节点
当前提交
242b4b829d
共有 2 个文件被更改,包括 13 次插入1 次删除
  1. 1 1
      package.json
  2. 12 0
      scripts/verifymail.js

+ 1 - 1
package.json

@@ -35,7 +35,7 @@
   },
   "husky": {
     "hooks": {
-      "pre-commit": "lint-staged",
+      "pre-commit": "node ./scripts/verifymail.js && lint-staged",
       "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
     }
   },

+ 12 - 0
scripts/verifymail.js

@@ -0,0 +1,12 @@
+#!/usr/bin/env node
+const { execSync } = require('child_process');
+
+const stdout = execSync('git config user.email').toString();
+
+if (stdout && /@jd.com$/gi.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);
+}