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
4b2e174c
Commit
4b2e174c
authored
Nov 23, 2019
by
智勇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sonar
parent
d20f1886
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
206 additions
and
107 deletions
+206
-107
pipeline.js
app/controller/pipeline.js
+176
-83
sonar.js
app/controller/sonar.js
+19
-16
sonarCheck.js
app/jobs/sonarCheck.js
+6
-4
PipeLine.js
app/model/mongo/qa_api/PipeLine.js
+1
-1
PipeLinePush.js
app/model/mongo/qa_api/PipeLinePush.js
+3
-2
app.config.js
src/app.config.js
+1
-1
No files found.
app/controller/pipeline.js
View file @
4b2e174c
This diff is collapsed.
Click to expand it.
app/controller/sonar.js
View file @
4b2e174c
...
...
@@ -8,19 +8,21 @@ const { SonarJob } = require('../service/mongoService')
const
config
=
require
(
global
.
configPath
)
const
sendDing
=
async
(
data
,
item
,
executionTimeMs
)
=>
{
const
title
=
'
扫描结果如下
'
const
sendFailDing
=
async
(
data
,
item
,
executionTimeMs
)
=>
{
const
duration
=
data
.
duration
/
1000
const
executionTime
=
executionTimeMs
/
1000
const
text
=
`> <font color=#FF7F50> 扫描结果 :
${
item
.
status
.
qualityGateStatus
}
\n\n`
+
`> <font color=#000000> 项目名称 :
${
data
.
content
.
projectKey
}
\n\n`
+
`> <font color=#000000> 项目名称 :
${
data
.
project
}
\n\n`
+
`> 分支名称 :
${
data
.
branch
}
\n\n`
+
`> 扫描日期 :
${
item
.
analysisDate
}
\n\n`
+
`> 扫描时间 :
${
duration
}
s\n\n`
+
`> 分析时间 :
${
executionTime
}
s\n\n`
// + `[查看详情](${config.sonarHost}/dashboard?id=${data.content.projectKey})`
+
`[查看详情](
${
config
.
sonarHost
}
/project/activity?id=
${
data
.
content
.
projectKey
}
&&selected_date=
${
item
.
analysisDate
}
)`
+
`> 扫描日期 :
${
item
.
analysisDate
}
\n\n`
// + `[查看详情](${config.sonarHost}/dashboard?id=${data.project})`
+
`[查看详情](
${
config
.
sonarHost
}
/project/activity?id=
${
data
.
project
}
&&selected_date=
${
item
.
analysisDate
}
)`
const
address
=
data
.
dingRobotAddr
await
dingTalk
(
'
扫描结果如下
'
,
text
,
address
)
await
dingTalk
(
title
,
text
,
address
)
}
const
sendExceptionDing
=
async
(
data
)
=>
{
...
...
@@ -30,18 +32,19 @@ const sendExceptionDing = async (data) => {
+
`> 分支名称 :
${
data
.
branch
}
\n\n`
+
`[查看详情](
${
data
.
absoluteUrl
}
console)`
const
address
=
data
.
dingRobotAddr
||
config
.
snorDingRobotAddr
await
dingTalk
(
'
扫描结果如下
'
,
text
,
address
)
await
dingTalk
(
title
,
text
,
address
)
}
const
sendExistDing
=
async
(
data
,
dingRobotAddr
)
=>
{
const
text
=
`> <font color=#FF7F50> 本次执行的GITHASH曾经扫描过,扫描结果 :
${
data
.
sonarResult
}
\n\n`
const
text
=
'
> <font color=#FF7F50> 本次执行的GITHASH曾经扫描过
'
+
`> 扫描结果 :
${
data
.
sonarResult
}
\n\n`
+
`> <font color=#000000> 项目名称 :
${
data
.
projectName
}
\n\n`
+
`> 分支名称 :
${
data
.
branchName
}
\n\n`
+
`> GITHASH
:
${
data
.
branchHash
}
\n\n`
+
`> GITHASH
:
${
data
.
branchHash
}
\n\n`
+
`> 扫描分析日期 :
${
data
.
analysisDate
}
\n\n`
+
`[查看详情](
${
config
.
sonarHost
}
/project/activity?id=
${
data
.
projectName
}
&&selected_date=
${
data
.
analysisDate
}
)`
const
address
=
dingRobotAddr
||
config
.
snorDingRobotAddr
await
dingTalk
(
'
扫描结果如下
'
,
text
,
address
)
await
dingTalk
(
title
,
text
,
address
)
}
const
callback
=
async
(
ctx
)
=>
{
...
...
@@ -49,7 +52,7 @@ const callback = async (ctx) => {
logger
.
info
(
'
sonar callback info
'
,
data
)
if
(
data
.
sonarJob
)
{
logger
.
info
(
data
.
sonarJob
.
projectName
,
data
.
sonarJob
.
branchName
,
data
.
sonarJob
.
branchHash
,
'
git hash
曾经 扫描过
'
)
logger
.
info
(
data
.
sonarJob
.
projectName
,
data
.
sonarJob
.
branchName
,
data
.
sonarJob
.
branchHash
,
'
GITHASH
曾经 扫描过
'
)
if
(
data
.
sonarJob
.
sonarResult
!==
'
OK
'
&&
data
.
dingRobotAddr
)
{
sendExistDing
(
data
.
sonarJob
,
data
.
dingRobotAddr
)
}
...
...
@@ -86,16 +89,16 @@ const callback = async (ctx) => {
await
sleep
(
1
*
1000
)
}
const
res
=
await
awaitRequest
({
url
:
`
${
config
.
sonarHost
}
/api/project_branches/list?project=
${
data
.
content
.
projectKey
}
`
,
url
:
`
${
config
.
sonarHost
}
/api/project_branches/list?project=
${
data
.
project
}
`
,
method
:
'
GET
'
,
})
logger
.
info
(
'
analysisResult
'
,
data
.
content
.
projectKey
,
JSON
.
stringify
(
res
))
logger
.
info
(
'
analysisResult
'
,
data
.
project
,
JSON
.
stringify
(
res
))
for
(
const
i
of
res
.
branches
)
{
if
(
i
.
name
===
'
master
'
&&
i
.
status
.
qualityGateStatus
!==
'
OK
'
&&
data
.
dingRobotAddr
)
{
logger
.
info
(
data
.
content
.
projectKey
,
'
触发质量阀,发送ding消息
'
)
sendDing
(
data
,
i
,
executionTimeMs
)
logger
.
info
(
data
.
project
,
'
触发质量阀,发送ding消息
'
)
send
Fail
Ding
(
data
,
i
,
executionTimeMs
)
}
saveData
.
projectName
=
data
.
content
.
projectKey
saveData
.
projectName
=
data
.
project
saveData
.
buildResult
=
'
success
'
saveData
.
sonarResult
=
i
.
status
.
qualityGateStatus
saveData
.
analysisDate
=
i
.
analysisDate
...
...
app/jobs/sonarCheck.js
View file @
4b2e174c
...
...
@@ -7,7 +7,8 @@ const sleep = require('../utils/sleep')
const
sonarCheck
=
async
()
=>
{
logger
.
info
(
'
daily sonarCheck start
'
)
let
projects
=
await
ProConfig
.
findByQuery
({
is_active
:
true
,
type
:
'
java
'
,
deploy_to_testenv
:
true
},
{
project_name
:
1
})
let
projects
=
await
ProConfig
.
findByQuery
({
is_active
:
true
,
type
:
'
java
'
,
deploy_to_testenv
:
true
},
{
project_name
:
1
},
{
project_name
:
1
})
projects
=
projects
.
map
(
i
=>
i
.
project_name
)
logger
.
info
(
'
要扫描的项目
'
,
projects
)
...
...
@@ -16,10 +17,11 @@ const sonarCheck = async () => {
// projects = projects.filter(item => testProject.includes(item))
for
(
const
project
of
projects
)
{
const
data
=
{
GIT_REPO_NAME
:
project
,
GIT_BRANCH
:
'
master
'
,
GIT_REPO
:
project
,
BRANCH_NAME
:
'
master
'
,
FORCE_SCAN
:
'
false
'
,
}
await
jenkinsService
.
build_with_params
(
'
tke-sonar
'
,
data
)
jenkinsService
.
build_with_params
(
'
tke-sonar
'
,
data
)
logger
.
info
(
'
daily sonarCheck
'
,
data
)
await
sleep
(
30
*
1000
)
}
...
...
app/model/mongo/qa_api/PipeLine.js
View file @
4b2e174c
...
...
@@ -34,7 +34,7 @@ schema.statics.getPipes = function (data) {
data
.
new_user
=
new
RegExp
(
data
.
new_user
)
return
this
.
find
(
data
).
sort
({
createdAt
:
-
1
})
}
schema
.
statics
.
get
One
Pipe
=
function
(
name
)
{
schema
.
statics
.
get
Match
Pipe
=
function
(
name
)
{
return
this
.
find
({
repos
:
{
$elemMatch
:
{
repository
:
name
}
}
}).
sort
({
createdAt
:
1
})
}
schema
.
statics
.
delete
=
function
(
id
)
{
...
...
app/model/mongo/qa_api/PipeLinePush.js
View file @
4b2e174c
...
...
@@ -6,6 +6,7 @@ const { Schema } = require('mongoose')
// 表结构
const
schema
=
new
Schema
({
buildId
:
{
type
:
Number
},
buildJob
:
{
type
:
String
},
branchName
:
{
type
:
String
},
commitMes
:
{
type
:
String
},
gitUser
:
{
type
:
String
},
...
...
@@ -24,7 +25,7 @@ schema.statics.savePipesPush = function (doc) {
schema
.
statics
.
getPipesPush
=
function
(
data
)
{
return
this
.
find
(
data
).
sort
({
createdAt
:
1
})
}
schema
.
statics
.
getOnePipePush
=
function
(
id
)
{
return
this
.
find
({
buildId
:
id
}
)
schema
.
statics
.
getOnePipePush
=
function
(
data
)
{
return
this
.
find
One
(
data
)
}
module
.
exports
=
schema
src/app.config.js
View file @
4b2e174c
...
...
@@ -50,5 +50,5 @@ module.exports = {
dingdingMemory
:
'
https://oapi.dingtalk.com/robot/send?access_token
'
+
'
=7cab1f948d67c3565a30323c58773c0ba77c7bd1a3eb1c11f8b2d1b6b4a395df
'
,
sonarHost
:
'
http://sonar.quantgroups.com
'
,
snorDingRobotAddr
:
'
https://oapi.dingtalk.com/robot/send?access_token=
5c4c7fb82ed9c5fd2d9a959037eb79d21d5c76ceeffd00b2d1ace86409deae2c
'
,
snorDingRobotAddr
:
'
https://oapi.dingtalk.com/robot/send?access_token=
0da7a1066b42bb23f079dacec3b7975e8cc12cee7efc5316a9b5b1900779a407
'
,
}
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