Commit 7c4d86da by zhangleyuan

测试

parent aed506de
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* @Author: 吴文洁 * @Author: 吴文洁
* @Date: 2020-06-05 14:59:14 * @Date: 2020-06-05 14:59:14
* @LastEditors: 吴文洁 * @LastEditors: 吴文洁
* @LastEditTime: 2020-08-04 19:28:08 * @LastEditTime: 2020-10-09 15:30:45
* @Description: * @Description:
* @Copyrigh: © 2020 杭州杰竞科技有限公司 版权所有 * @Copyrigh: © 2020 杭州杰竞科技有限公司 版权所有
*/ */
......
...@@ -2,11 +2,11 @@ ...@@ -2,11 +2,11 @@
/* /*
* @Author: 吴文洁 * @Author: 吴文洁
* @Date: 2020-06-05 09:38:03 * @Date: 2020-06-05 09:38:03
* @LastEditors: 吴文洁 * @LastEditors: louzhedong
* @LastEditTime: 2020-08-12 10:00:56 * @LastEditTime: 2020-12-26 16:08:19
* @Description: * @Description:
* @Copyrigh: © 2020 杭州杰竞科技有限公司 版权所有 * @Copyrigh: © 2020 杭州杰竞科技有限公司 版权所有
*/ */
const execSync = require('child_process').execSync; const execSync = require('child_process').execSync;
...@@ -14,7 +14,7 @@ const execSync = require('child_process').execSync; ...@@ -14,7 +14,7 @@ const execSync = require('child_process').execSync;
const branchName = execSync('git rev-parse --abbrev-ref HEAD').toString().trim(); const branchName = execSync('git rev-parse --abbrev-ref HEAD').toString().trim();
// 校验分支名是否合法 // 校验分支名是否合法
const firstPattern = new RegExp('dev|rc|gray|master'); const firstPattern = new RegExp('dev|rc|gray|master');
const secondPattern = new RegExp('(feature|hotfix)/[a-z]{4,}/[0-9]{8,}/[a-zA-Z-]{4,}'); const secondPattern = new RegExp('(feature|hotfix)/[a-z]{4,}/[0-9]{8,}/[0-9a-zA-Z-]{3,}');
const firstMatch = firstPattern.test(branchName); const firstMatch = firstPattern.test(branchName);
const secondMatch = secondPattern.test(branchName); const secondMatch = secondPattern.test(branchName);
...@@ -26,11 +26,12 @@ if (!firstMatch && !secondMatch) { ...@@ -26,11 +26,12 @@ if (!firstMatch && !secondMatch) {
// 获取缓存区内容 // 获取缓存区内容
// 通过diff指令获得所有改动过(不包括删除)的js文件路径 // 通过diff指令获得所有改动过(不包括删除)的js文件路径
const fileNameStr = execSync('git diff-index --cached HEAD --name-only').toString(); const fileNameStr = execSync('git diff --diff-filter=AM --cached HEAD --name-only').toString();
const fileNameList = fileNameStr.split('\n'); // 过滤掉空格
const fileNameList = fileNameStr.split('\n').filter((item) => !!item);
// 获取需要检测的文件 // 获取需要检测的文件
const detectedFileList = fileNameList.filter(file => { const detectedFileList = fileNameList.filter((file) => {
// 过滤掉空的和hooks文件夹下所有的文件 // 过滤掉空的和hooks文件夹下所有的文件
return file && file.indexOf('hooks') < 0; return file && file.indexOf('hooks') < 0;
}); });
...@@ -39,7 +40,8 @@ const detectedFileList = fileNameList.filter(file => { ...@@ -39,7 +40,8 @@ const detectedFileList = fileNameList.filter(file => {
let errorFileList = []; let errorFileList = [];
detectedFileList.forEach((file) => { detectedFileList.forEach((file) => {
const results = execSync(`git diff --cached ${file}`); const results = execSync(`git diff --cached ${file}`);
if (results.toString().indexOf('http://') > 0) { const pattern = /^http\:\/\/.{1,}/;
if (pattern.test(results.toString())) {
errorFileList.push(file); errorFileList.push(file);
} }
}); });
...@@ -59,7 +61,7 @@ fileNameList.forEach((file) => { ...@@ -59,7 +61,7 @@ fileNameList.forEach((file) => {
if (conflictPattern.test(results)) { if (conflictPattern.test(results)) {
conflictFileList.push(file); conflictFileList.push(file);
} }
}) });
if (conflictFileList.length > 0) { if (conflictFileList.length > 0) {
const conflictFileStr = JSON.stringify(conflictFileList); const conflictFileStr = JSON.stringify(conflictFileList);
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
...@@ -67,4 +69,4 @@ if (conflictFileList.length > 0) { ...@@ -67,4 +69,4 @@ if (conflictFileList.length > 0) {
process.exit(1); process.exit(1);
} }
process.exit(0); process.exit(0);
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment