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
e9815c4c
Commit
e9815c4c
authored
Nov 04, 2019
by
智勇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
保存触发
parent
9295f7a9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
35 deletions
+55
-35
pipeline.js
app/controller/pipeline.js
+54
-34
StatisticsLog.js
app/model/mongo/qa_api/StatisticsLog.js
+1
-1
No files found.
app/controller/pipeline.js
View file @
e9815c4c
...
@@ -21,21 +21,57 @@ const awaitRequest = function (options) {
...
@@ -21,21 +21,57 @@ const awaitRequest = function (options) {
})
})
})
})
}
}
const
jenkinsBuild
=
async
function
(
gitObject
,
gitUser
,
commitMes
,
timestamp
)
{
logger
.
info
(
'
执行jenkins
'
,
gitObject
,
gitUser
)
const
res
=
await
jenkinsService
.
build_with_params
(
`tke-
${
gitObject
.
type
}
`
,
{
depth
:
1
,
GIT_REPO
:
`
${
gitObject
.
groupName
}
/
${
gitObject
.
repository
}
`
,
BRANCH_NAME
:
gitObject
.
ref
.
name
,
IS_DEPLOY
:
'
false
'
,
IMAGE_REPOSITORY
:
`ccr.ccs.tencentyun.com/qa-
${
gitObject
.
type
}
`
,
})
let
flag
=
true
while
(
flag
)
{
const
apiJson
=
await
jenkinsService
.
queue_item
(
res
.
queueId
);
if
(
apiJson
.
executable
)
{
flag
=
false
const
store
=
{
buildId
:
apiJson
.
executable
.
number
,
branchName
:
gitObject
.
ref
.
name
,
commitMes
,
projectName
:
gitObject
.
repository
,
gitUser
,
gitEventTime
:
timestamp
,
}
await
PipeLinePush
.
savePipesPush
(
store
)
}
}
}
const
webhooks
=
async
function
(
ctx
)
{
const
webhooks
=
async
function
(
ctx
)
{
logger
.
info
(
'
webhooks
'
,
ctx
.
request
.
body
)
const
req
=
ctx
.
request
.
body
logger
.
info
(
'
webhooks
'
,
req
)
// user_add_to_team之类的操作
if
(
req
.
enent_name
!==
'
push
'
)
{
logger
.
info
(
`enent_name 是
${
req
.
enent_name
}
`
)
ctx
.
body
=
ctx
.
ok
(
`enent_name 是
${
req
.
enent_name
}
`
)
return
}
// 增删分支之类的push
// 增删分支之类的push
if
(
ctx
.
request
.
body
.
commits
.
length
===
0
)
{
if
(
req
.
commits
.
length
===
0
)
{
logger
.
info
(
`
${
ctx
.
request
.
body
.
repository
.
name
}
${
ctx
.
request
.
body
.
ref
}
没有commits`
)
logger
.
info
(
`
${
req
.
repository
.
name
}
${
req
.
ref
}
没有commits`
)
ctx
.
body
=
ctx
.
ok
(
`
${
ctx
.
request
.
body
.
repository
.
name
}
${
ctx
.
request
.
body
.
ref
}
没有commits`
)
ctx
.
body
=
ctx
.
ok
(
`
${
req
.
repository
.
name
}
${
req
.
ref
}
没有commits`
)
return
return
}
}
const
projectName
=
ctx
.
request
.
body
.
repository
.
name
const
projectName
=
req
.
repository
.
name
const
arr
=
ctx
.
request
.
body
.
ref
.
split
(
'
/
'
)
const
arr
=
req
.
ref
.
split
(
'
/
'
)
const
gitUser
=
ctx
.
request
.
body
.
user_name
const
gitUser
=
req
.
user_name
const
commitMes
=
ctx
.
request
.
body
.
commits
[
0
].
message
const
commitMes
=
req
.
commits
[
0
].
message
const
timestamp
=
ctx
.
request
.
body
.
commits
[
0
].
timestamp
const
timestamp
=
req
.
commits
[
0
].
timestamp
const
branchName
=
arr
[
arr
.
length
-
1
]
const
branchName
=
arr
[
arr
.
length
-
1
]
logger
.
info
(
`收到webhooks->>>项目名:
${
projectName
}
分支名:
${
branchName
}
`
)
logger
.
info
(
`收到webhooks->>>项目名:
${
projectName
}
分支名:
${
branchName
}
`
)
...
@@ -52,33 +88,11 @@ const webhooks = async function (ctx) {
...
@@ -52,33 +88,11 @@ const webhooks = async function (ctx) {
}
}
}
}
if
(
gitObject
==
null
||
gitObject
===
undefined
)
{
if
(
gitObject
==
null
||
gitObject
===
undefined
)
{
logger
.
info
(
`未获取到订阅信息->>>项目名:
${
projectName
}
分支名:
${
branchName
}
`
)
logger
.
info
(
`未查询到订阅信息->>>项目名:
${
projectName
}
分支名:
${
branchName
}
`
)
ctx
.
body
=
ctx
.
ok
(
`未获取到订阅信息->>>项目名:
${
projectName
}
分支名:
${
branchName
}
`
)
}
else
{
}
else
{
const
res
=
await
jenkinsService
.
build_with_params
(
`tke-
${
gitObject
.
type
}
`
,
{
await
jenkinsBuild
(
gitObject
,
gitUser
,
commitMes
,
timestamp
)
depth
:
1
,
GIT_REPO
:
`
${
gitObject
.
groupName
}
/
${
projectName
}
`
,
BRANCH_NAME
:
gitObject
.
ref
.
name
,
IS_DEPLOY
:
'
false
'
,
IMAGE_REPOSITORY
:
`ccr.ccs.tencentyun.com/qa-
${
gitObject
.
type
}
`
,
})
let
flag
=
true
while
(
flag
)
{
const
apiJson
=
await
jenkinsService
.
queue_item
(
res
.
queueId
);
if
(
apiJson
.
executable
)
{
flag
=
false
const
store
=
{
buildId
:
apiJson
.
executable
.
number
,
branchName
,
commitMes
,
projectName
,
gitUser
,
gitEventTime
:
timestamp
,
}
await
PipeLinePush
.
savePipesPush
(
store
)
}
}
}
}
ctx
.
body
=
ctx
.
ok
(
'
success
'
)
ctx
.
body
=
ctx
.
ok
(
'
success
'
)
}
}
...
@@ -110,11 +124,17 @@ const findPipes = async function (ctx) {
...
@@ -110,11 +124,17 @@ const findPipes = async function (ctx) {
const
data
=
await
PipeLine
.
getPipes
(
ctx
.
request
.
body
)
const
data
=
await
PipeLine
.
getPipes
(
ctx
.
request
.
body
)
ctx
.
body
=
ctx
.
ok
(
data
)
ctx
.
body
=
ctx
.
ok
(
data
)
}
}
const
save
=
async
function
(
ctx
)
{
const
save
=
async
function
(
ctx
)
{
const
data
=
ctx
.
request
.
body
const
data
=
ctx
.
request
.
body
await
PipeLine
.
savePipes
(
data
)
await
PipeLine
.
savePipes
(
data
)
for
(
const
item
of
data
.
repos
)
{
logger
.
info
(
'
save pipeline application
'
,
item
)
jenkinsBuild
(
item
,
'
qahome
'
,
'
save pipeline application
'
,
moment
().
format
(
'
YYYY-MM-DD HH:mm:ss
'
))
}
ctx
.
body
=
ctx
.
ok
(
'
ok
'
)
ctx
.
body
=
ctx
.
ok
(
'
ok
'
)
}
}
const
deletePipes
=
async
function
(
ctx
)
{
const
deletePipes
=
async
function
(
ctx
)
{
const
id
=
ctx
.
request
.
body
.
id
const
id
=
ctx
.
request
.
body
.
id
const
res
=
await
PipeLine
.
delete
(
id
)
const
res
=
await
PipeLine
.
delete
(
id
)
...
...
app/model/mongo/qa_api/StatisticsLog.js
View file @
e9815c4c
...
@@ -48,7 +48,7 @@ schema.statics.getLog = function (query, sort, num, count) {
...
@@ -48,7 +48,7 @@ schema.statics.getLog = function (query, sort, num, count) {
schema
.
statics
.
getLogCount
=
function
(
query
)
{
schema
.
statics
.
getLogCount
=
function
(
query
)
{
query
=
queryHandle
(
query
)
query
=
queryHandle
(
query
)
return
this
.
find
(
query
).
count
()
return
this
.
find
(
query
).
count
Documents
()
}
}
module
.
exports
=
schema
module
.
exports
=
schema
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