Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qa-api
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
QA
qa-api
Commits
62ccd676
Commit
62ccd676
authored
Dec 06, 2019
by
智勇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
统一变量名
parent
93611fc2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
29 deletions
+56
-29
sonar.js
app/controller/sonar.js
+50
-22
SonarJob.js
app/model/mongo/qa_api/SonarJob.js
+6
-7
No files found.
app/controller/sonar.js
View file @
62ccd676
...
...
@@ -15,24 +15,24 @@ const sendFailMail = async (data, item, executionTimeMs) => {
const
duration
=
data
.
duration
/
1000
const
executionTime
=
executionTimeMs
/
1000
const
text
=
`<font color=#FF7F50> 扫描结果 :
${
item
.
status
.
qualityGateStatus
}
<br/>`
+
`<font color=#000000> 项目名称 :
${
data
.
project
}
<br/>`
+
`分支名称 :
${
data
.
branch
}
<br/>`
+
`<font color=#000000> 项目名称 :
${
data
.
project
Name
}
<br/>`
+
`分支名称 :
${
data
.
branch
Name
}
<br/>`
+
`扫描时间 :
${
duration
}
s<br/>`
+
`分析时间 :
${
executionTime
}
s<br/>`
+
`扫描日期 :
${
item
.
analysisDate
}
<br/>`
+
`查看详情 :
${
config
.
sonarHost
}
/project/activity?id=
${
data
.
project
}
&&selected_date=
${
item
.
analysisDate
}
`
sendMail
(
address
,
`
${
data
.
project
}
${
title
}
`
,
text
)
+
`查看详情 :
${
config
.
sonarHost
}
/project/activity?id=
${
data
.
project
Name
}
&&selected_date=
${
item
.
analysisDate
}
`
sendMail
(
address
,
`
${
data
.
project
Name
}
${
title
}
`
,
text
)
}
const
sendExceptionMail
=
async
(
data
)
=>
{
const
address
=
data
.
gitUser
?
`
${
data
.
gitUser
}
@quantgroup.cn`
:
data
.
gitUserMail
const
text
=
'
<font color=#FF0000> 扫描结果 : 扫描任务执行失败 <br/>
'
+
`<font color=#000000> 结果信息 :
${
data
.
error
}
<br/>`
+
`项目名称 :
${
data
.
project
}
<br/>`
+
`分支名称 :
${
data
.
branch
}
<br/>`
+
`Sonar详情 :
${
config
.
sonarHost
}
/dashboard?id=
${
data
.
project
}
<br/>`
+
`项目名称 :
${
data
.
project
Name
}
<br/>`
+
`分支名称 :
${
data
.
branch
Name
}
<br/>`
+
`Sonar详情 :
${
config
.
sonarHost
}
/dashboard?id=
${
data
.
project
Name
}
<br/>`
+
`Jenskins详情 :
${
data
.
absoluteUrl
}
console <br/>`
sendMail
(
address
,
`
${
data
.
project
}
${
title
}
`
,
text
)
sendMail
(
address
,
`
${
data
.
project
Name
}
${
title
}
`
,
text
)
}
const
sendExistMail
=
async
(
data
,
gitUser
)
=>
{
...
...
@@ -70,13 +70,6 @@ const callback = async (ctx) => {
return
}
// const saveData = {
// buildId: data.buildId,
// buildJob: data.buildJob,
// branchName: data.branch,
// projectName: data.project,
// }
if
(
data
.
error
)
{
data
.
buildResult
=
'
error
'
if
(
data
.
mail
!==
'
noMail
'
)
{
...
...
@@ -101,13 +94,13 @@ const callback = async (ctx) => {
await
sleep
(
1
*
1000
)
}
const
res
=
await
awaitRequest
({
url
:
`
${
config
.
sonarHost
}
/api/project_branches/list?project=
${
data
.
project
}
`
,
url
:
`
${
config
.
sonarHost
}
/api/project_branches/list?project=
${
data
.
project
Name
}
`
,
method
:
'
GET
'
,
})
logger
.
info
(
'
analysisResult
'
,
data
.
project
,
JSON
.
stringify
(
res
))
logger
.
info
(
'
analysisResult
'
,
data
.
project
Name
,
JSON
.
stringify
(
res
))
for
(
const
i
of
res
.
branches
)
{
if
(
i
.
name
===
'
master
'
&&
i
.
status
.
qualityGateStatus
!==
'
OK
'
&&
data
.
mail
!==
'
noMail
'
)
{
logger
.
info
(
data
.
project
,
'
触发质量阀,发送邮件通知
'
)
logger
.
info
(
data
.
project
Name
,
'
触发质量阀,发送邮件通知
'
)
sendFailMail
(
data
,
i
,
executionTimeMs
)
}
data
.
buildResult
=
'
success
'
...
...
@@ -157,7 +150,6 @@ const getSonarJob = async (ctx) => {
const
curDate
=
new
Date
()
const
date
=
new
Date
(
curDate
.
getTime
()
-
3
*
24
*
60
*
60
*
1000
)
Object
.
assign
(
query
,
{
updatedAt
:
{
$gte
:
date
}
})
console
.
log
(
1
,
query
)
const
data
=
await
SonarJob
.
getSonarJob
(
query
,
{
_id
:
0
},
{
updatedAt
:
-
1
},
page
)
const
count
=
await
SonarJob
.
getSonarJobCount
(
query
)
ctx
.
body
=
ctx
.
ok
({
data
,
count
})
...
...
@@ -173,13 +165,49 @@ const fetchQuality = async (ctx) => {
}
// const data = await SonarJob.getSonarJobGroup(query);
cons
t
data
=
await
SonarJob
.
getSonarJob
(
query
,
{
le
t
data
=
await
SonarJob
.
getSonarJob
(
query
,
{
_id
:
0
,
projectName
:
1
,
buildResult
:
1
,
sonarResult
:
1
,
},
{},
{});
// console.log(1, data)
data
=
data
.
reduce
((
prev
,
next
)
=>
{
if
(
!
prev
[
next
.
projectName
])
{
prev
[
next
.
projectName
]
=
{
exception
:
0
,
fail
:
0
,
success
:
0
,
sum
:
0
,
}
}
if
(
next
.
buildResult
===
'
error
'
)
{
prev
[
next
.
projectName
].
exception
+=
1
prev
[
next
.
projectName
].
sum
+=
1
}
if
(
next
.
buildResult
===
'
success
'
)
{
if
(
next
.
sonarResult
===
'
OK
'
)
{
prev
[
next
.
projectName
].
success
+=
1
}
else
{
prev
[
next
.
projectName
].
fail
+=
1
}
prev
[
next
.
projectName
].
sum
+=
1
}
return
prev
},
{})
const
res
=
[]
for
(
const
i
in
data
)
{
if
(
Object
.
prototype
.
hasOwnProperty
.
call
(
data
,
i
))
{
res
.
push
({
repository
:
i
,
success
:
data
[
i
].
success
,
fail
:
data
[
i
].
fail
,
exception
:
data
[
i
].
exception
,
run
:
data
[
i
].
sum
,
})
}
}
ctx
.
body
=
ctx
.
ok
(
data
)
ctx
.
body
=
ctx
.
ok
(
res
)
}
const
router
=
new
Router
()
...
...
app/model/mongo/qa_api/SonarJob.js
View file @
62ccd676
...
...
@@ -44,18 +44,17 @@ schema.statics.getSonarJobCount = function (query) {
}
schema
.
statics
.
getSonarJobGroup
=
function
(
query
)
{
console
.
log
(
2
,
{
$match
:
query
})
return
this
.
aggregate
([
{
$match
:
query
},
// { $match: { sonarResult: 'WARN' } },
{
$match
:
{
updatedAt
:
{
$gte
:
'
2019-12-03T16:00:00.000Z
'
,
$lte
:
'
2019-12-04T16:00:00.000Z
'
,
$group
:
{
_id
:
'
$projectName
'
,
result
:
{
$push
:
{
sonarResult
:
'
$sonarResult
'
,
buildResult
:
'
$buildResult
'
,
updatedAt
:
'
$updatedAt
'
},
},
},
},
{
$group
:
{
_id
:
'
$projectName
'
,
result
:
{
$push
:
{
sonarResult
:
'
$sonarResult
'
,
buildResult
:
'
$buildResult
'
}
}
}
},
])
}
...
...
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