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
49594480
Commit
49594480
authored
Dec 23, 2019
by
智勇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复是否sonar的判断
parent
103d7c34
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
22 deletions
+17
-22
dbsync.js
app/controller/dbsync.js
+6
-5
pipeline.js
app/controller/pipeline.js
+11
-17
No files found.
app/controller/dbsync.js
View file @
49594480
const
Router
=
require
(
'
koa-router
'
)
const
Router
=
require
(
'
koa-router
'
)
const
bodyParser
=
require
(
'
koa-bodyparser
'
)
const
bodyParser
=
require
(
'
koa-bodyparser
'
)
const
_
=
require
(
'
lodash
'
)
const
_
=
require
(
'
lodash
'
)
const
mysql
=
require
(
'
mysql2/promise
'
);
const
mysql
=
require
(
'
mysql2/promise
'
)
const
logger
=
require
(
'
koa-log4
'
).
getLogger
(
'
dbsync
'
)
const
jenkinsService
=
require
(
'
../service/jenkinsService
'
)
const
jenkinsService
=
require
(
'
../service/jenkinsService
'
)
const
k8sService
=
require
(
'
../service/k8sService
'
)
const
k8sService
=
require
(
'
../service/k8sService
'
)
const
{
DBConfig
}
=
require
(
'
../service/mongoService
'
)
const
{
DBConfig
}
=
require
(
'
../service/mongoService
'
)
const
{
config
}
=
require
(
'
../../src
'
)
const
{
api
}
=
require
(
'
../../src
'
)
const
domain
=
'
liangkebang.com
'
const
domain
=
'
liangkebang.com
'
let
domainTKE
=
'
liangkebang.net
'
let
domainTKE
=
'
liangkebang.net
'
...
@@ -74,7 +74,7 @@ const dbSyncTke = async function (ctx) {
...
@@ -74,7 +74,7 @@ const dbSyncTke = async function (ctx) {
}
}
let
res
=
await
ctx
.
curl
({
let
res
=
await
ctx
.
curl
({
uri
:
`
${
api
.
tke_api
}
/service/details`
,
uri
:
`
${
config
.
tke_api
}
/service/details`
,
headers
:
{
headers
:
{
cluster
:
ctx
.
request
.
headers
.
cluster
,
cluster
:
ctx
.
request
.
headers
.
cluster
,
},
},
...
@@ -131,7 +131,7 @@ const dbSyncQuery = async function (ctx) {
...
@@ -131,7 +131,7 @@ const dbSyncQuery = async function (ctx) {
const
getDropSQL
=
async
(
ctx
)
=>
{
const
getDropSQL
=
async
(
ctx
)
=>
{
const
{
dbName
}
=
ctx
.
request
.
query
const
{
dbName
}
=
ctx
.
request
.
query
const
select
=
`select \`sql\`,base from core_sqlrecord where to_days(date) = to_days(now())
const
select
=
`select \`sql\`,base from core_sqlrecord where to_days(date) = to_days(now())
and state
='Execute Successfully
' and \`sql\` like '%drop %'`
and state
like '%Execute Successfully%
' and \`sql\` like '%drop %'`
const
connection
=
await
mysql
.
createConnection
({
const
connection
=
await
mysql
.
createConnection
({
host
:
'
172.30.4.8
'
,
host
:
'
172.30.4.8
'
,
user
:
'
sync_del
'
,
user
:
'
sync_del
'
,
...
@@ -145,6 +145,7 @@ const getDropSQL = async (ctx) => {
...
@@ -145,6 +145,7 @@ const getDropSQL = async (ctx) => {
}
}
return
a
return
a
},
''
)
},
''
)
logger
.
info
(
dbName
,
'
dropSQL:
'
,
res
)
ctx
.
body
=
res
ctx
.
body
=
res
}
}
...
...
app/controller/pipeline.js
View file @
49594480
const
Router
=
require
(
'
koa-router
'
)
const
Router
=
require
(
'
koa-router
'
)
const
moment
=
require
(
'
moment
'
)
const
moment
=
require
(
'
moment
'
)
const
bodyParser
=
require
(
'
koa-bodyparser
'
)
const
bodyParser
=
require
(
'
koa-bodyparser
'
)
const
logger
=
require
(
'
koa-log4
'
)
const
logger
=
require
(
'
koa-log4
'
).
getLogger
(
'
pipeline
'
)
.
getLogger
(
'
pipeline
'
)
const
{
PipeLine
,
PipeLinePush
,
SonarJob
}
=
require
(
'
../service/mongoService
'
)
const
{
PipeLine
,
PipeLinePush
,
SonarJob
}
=
require
(
'
../service/mongoService
'
)
const
jenkinsService
=
require
(
'
../service/jenkinsService
'
)
const
jenkinsService
=
require
(
'
../service/jenkinsService
'
)
const
dingTalk
=
require
(
'
../utils/dingTalk
'
)
const
dingTalk
=
require
(
'
../utils/dingTalk
'
)
...
@@ -95,26 +94,21 @@ const webhooks = async function (ctx) {
...
@@ -95,26 +94,21 @@ const webhooks = async function (ctx) {
return
return
}
}
const
gitUser
=
req
.
user_username
||
req
.
user_email
.
split
(
'
@
'
)[
0
]
const
commitMes
=
req
.
commits
[
req
.
commits
.
length
-
1
].
message
let
projects
=
await
ProConfig
.
findByQuery
({
is_active
:
true
,
deploy_to_testenv
:
true
,
type
:
'
java
'
},
{
project_name
:
1
})
let
projects
=
await
ProConfig
.
findByQuery
({
is_active
:
true
,
deploy_to_testenv
:
true
,
type
:
'
java
'
},
{
project_name
:
1
})
projects
=
projects
.
map
(
i
=>
i
.
project_name
)
projects
=
projects
.
map
(
i
=>
i
.
project_name
)
if
(
!
projects
.
includes
(
projectName
))
{
if
(
projects
.
includes
(
projectName
))
{
logger
.
info
(
`
${
projectName
}
不是激活且部署到容器的java服务,不执行jenkins`
)
logger
.
info
(
'
webhooks 触发 sonar jenkins build
'
,
projectName
,
branchName
,
req
.
checkout_sha
)
sonarJenkinsBuild
({
projectName
,
branchName
,
branchHash
:
req
.
checkout_sha
,
gitUser
,
commitMes
,
})
}
else
{
logger
.
info
(
`
${
projectName
}
不是激活且部署到容器的java服务,不执行sonar jenkins`
)
ctx
.
body
=
ctx
.
ok
(
`
${
projectName
}
不是激活且部署到容器的java服务`
)
ctx
.
body
=
ctx
.
ok
(
`
${
projectName
}
不是激活且部署到容器的java服务`
)
return
}
}
const
gitUser
=
req
.
user_username
||
req
.
user_email
.
split
(
'
@
'
)[
0
]
const
commitMes
=
req
.
commits
[
req
.
commits
.
length
-
1
].
message
// const project = await ProConfig.getOneProject({ project_name: projectName })
// if (project.sonar) {
// }
logger
.
info
(
'
webhooks 触发 sonar jenkins build
'
,
projectName
,
branchName
,
req
.
checkout_sha
)
sonarJenkinsBuild
({
projectName
,
branchName
,
branchHash
:
req
.
checkout_sha
,
gitUser
,
commitMes
,
})
const
data
=
await
PipeLine
.
getMatchPipe
(
projectName
)
const
data
=
await
PipeLine
.
getMatchPipe
(
projectName
)
// 获取项目的分类
// 获取项目的分类
let
gitObject
;
let
gitObject
;
...
...
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