Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
X
xiaomai-cloud-class-web
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
xiaomai-cloud-class
xiaomai-cloud-class-web
Commits
7c4d86da
Commit
7c4d86da
authored
Jun 04, 2021
by
zhangleyuan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
测试
parent
aed506de
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
13 deletions
+14
-13
hooks/commit-msg.js
+1
-1
hooks/pre-commit.js
+13
-12
No files found.
hooks/commit-msg.js
View file @
7c4d86da
...
@@ -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 杭州杰竞科技有限公司 版权所有
*/
*/
...
...
hooks/pre-commit.js
View file @
7c4d86da
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment