Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
holmes
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
0
Merge Requests
0
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
holmes
Commits
a59f7a76
Commit
a59f7a76
authored
Jun 08, 2021
by
黎博
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增ding robot和pipeline各种接口
parent
ca1b56c3
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
428 additions
and
203 deletions
+428
-203
pom.xml
pom.xml
+6
-0
GitlabController.java
...java/cn/qg/holmes/controller/gitlab/GitlabController.java
+68
-0
PipelineController.java
...va/cn/qg/holmes/controller/gitlab/PipelineController.java
+95
-13
JiraController.java
...ain/java/cn/qg/holmes/controller/jira/JiraController.java
+127
-50
JiraWebhookController.java
...a/cn/qg/holmes/controller/jira/JiraWebhookController.java
+0
-138
DingRobotPipelineVo.java
.../java/cn/qg/holmes/entity/gitlab/DingRobotPipelineVo.java
+15
-0
SendSmokingResultVo.java
...in/java/cn/qg/holmes/entity/jira/SendSmokingResultVo.java
+13
-0
DingdingUtils.java
src/main/java/cn/qg/holmes/utils/DingdingUtils.java
+36
-1
GitlabService.java
src/main/java/cn/qg/holmes/utils/GitlabService.java
+68
-0
JenkinsService.java
src/main/java/cn/qg/holmes/utils/JenkinsService.java
+0
-1
No files found.
pom.xml
View file @
a59f7a76
...
@@ -142,6 +142,12 @@
...
@@ -142,6 +142,12 @@
<version>
0.3.8
</version>
<version>
0.3.8
</version>
</dependency>
</dependency>
<dependency>
<groupId>
org.gitlab
</groupId>
<artifactId>
java-gitlab-api
</artifactId>
<version>
4.1.1
</version>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
...
...
src/main/java/cn/qg/holmes/controller/gitlab/GitlabController.java
0 → 100644
View file @
a59f7a76
package
cn
.
qg
.
holmes
.
controller
.
gitlab
;
import
cn.qg.holmes.common.JsonResult
;
import
cn.qg.holmes.utils.GitlabService
;
import
cn.qg.holmes.utils.HttpClientUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.bind.annotation.CrossOrigin
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.*
;
@CrossOrigin
@RestController
@RequestMapping
(
"/gitlab"
)
public
class
GitlabController
{
@Autowired
GitlabService
gitlabService
;
/**
* 获取项目名列表
* @return
*/
@GetMapping
(
"/projects"
)
public
JsonResult
getProjectsList
()
{
String
baseUrl
=
"http://qaapi.liangkebang.com/proconfig/get_project_for_jenkins?type="
;
String
javaResult
=
HttpClientUtils
.
doGet
(
baseUrl
+
"java"
);
String
uiResult
=
HttpClientUtils
.
doGet
(
baseUrl
+
"ui"
);
String
nodeResult
=
HttpClientUtils
.
doGet
(
baseUrl
+
"node"
);
List
<
String
>
javaList
=
Arrays
.
asList
(
javaResult
.
split
(
"\n"
));
List
<
String
>
uiList
=
Arrays
.
asList
(
uiResult
.
split
(
"\n"
));
List
<
String
>
nodeList
=
Arrays
.
asList
(
nodeResult
.
split
(
"\n"
));
List
<
Map
<
String
,
String
>>
serviceList
=
new
ArrayList
<>();
for
(
String
service:
javaList
)
{
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"name"
,
service
);
map
.
put
(
"type"
,
"java"
);
serviceList
.
add
(
map
);
}
for
(
String
service:
uiList
)
{
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"name"
,
service
);
map
.
put
(
"type"
,
"ui"
);
serviceList
.
add
(
map
);
}
for
(
String
service:
nodeList
)
{
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"name"
,
service
);
map
.
put
(
"type"
,
"node"
);
serviceList
.
add
(
map
);
}
return
JsonResult
.
buildSuccessResult
(
serviceList
);
}
/**
* 根据项目名获取分支列表
* @param projectName 项目名
* @return
*/
@GetMapping
(
"/branches"
)
public
JsonResult
getBranchesByProject
(
String
projectName
)
{
List
<
String
>
branches
=
gitlabService
.
getBranchesByProjectName
(
projectName
);
return
JsonResult
.
buildSuccessResult
(
branches
);
}
}
src/main/java/cn/qg/holmes/controller/gitlab/PipelineController.java
View file @
a59f7a76
package
cn
.
qg
.
holmes
.
controller
.
gitlab
;
package
cn
.
qg
.
holmes
.
controller
.
gitlab
;
import
cn.qg.holmes.common.JsonResult
;
import
cn.qg.holmes.common.JsonResult
;
import
cn.qg.holmes.entity.gitlab.DingRobotPipelineVo
;
import
cn.qg.holmes.entity.gitlab.Pipeline
;
import
cn.qg.holmes.entity.gitlab.Pipeline
;
import
cn.qg.holmes.entity.jira.DingRobot
;
import
cn.qg.holmes.service.gitlab.PipelineService
;
import
cn.qg.holmes.service.gitlab.PipelineService
;
import
cn.qg.holmes.service.jira.DingRobotService
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
javax.management.Query
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
java.io.BufferedReader
;
import
java.io.BufferedReader
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
@Slf4j
@Slf4j
@RestController
@RestController
@CrossOrigin
@CrossOrigin
@RequestMapping
(
"/pipline"
)
@RequestMapping
(
"/pip
e
line"
)
public
class
PipelineController
{
public
class
PipelineController
{
@Autowired
@Autowired
PipelineService
pipelineService
;
PipelineService
pipelineService
;
@Autowired
DingRobotService
dingRobotService
;
/**
* gitlab webhook
* @param request
*/
@PostMapping
(
"/webhook"
)
@PostMapping
(
"/webhook"
)
public
void
piplineWebhook
(
HttpServletRequest
request
)
{
public
void
piplineWebhook
(
HttpServletRequest
request
)
{
StringBuilder
piplineData
=
new
StringBuilder
();
StringBuilder
piplineData
=
new
StringBuilder
();
...
@@ -39,25 +54,92 @@ public class PipelineController {
...
@@ -39,25 +54,92 @@ public class PipelineController {
pipelineService
.
buildPipelineJob
(
String
.
valueOf
(
piplineData
));
pipelineService
.
buildPipelineJob
(
String
.
valueOf
(
piplineData
));
}
}
@GetMapping
(
"/list"
)
public
JsonResult
getDingRobotAndPipelineList
(
@RequestParam
Integer
pageNum
,
@RequestParam
Integer
pageSize
)
{
IPage
<
DingRobot
>
page
=
new
Page
<>(
pageNum
,
pageSize
);
QueryWrapper
<
DingRobot
>
dingRobotQueryWrapper
=
new
QueryWrapper
();
dingRobotQueryWrapper
.
orderByDesc
(
"id"
);
IPage
<
DingRobot
>
projectRobotIPage
=
dingRobotService
.
page
(
page
,
dingRobotQueryWrapper
);
List
<
DingRobot
>
dingRobotList
=
projectRobotIPage
.
getRecords
();
List
<
DingRobotPipelineVo
>
dingRobotPipelineVoList
=
new
ArrayList
<>();
for
(
DingRobot
dingRobot:
dingRobotList
)
{
DingRobotPipelineVo
dingRobotPipelineVo
=
new
DingRobotPipelineVo
();
dingRobotPipelineVo
.
setDingRobot
(
dingRobot
);
QueryWrapper
<
Pipeline
>
pipelineQueryWrapper
=
new
QueryWrapper
<>();
pipelineQueryWrapper
.
eq
(
"ding_robot_id"
,
dingRobot
.
getId
());
List
<
Pipeline
>
pipelineList
=
pipelineService
.
list
(
pipelineQueryWrapper
);
dingRobotPipelineVo
.
setPipelineList
(
pipelineList
);
dingRobotPipelineVoList
.
add
(
dingRobotPipelineVo
);
}
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"total"
,
projectRobotIPage
.
getTotal
());
map
.
put
(
"list"
,
dingRobotPipelineVoList
);
return
JsonResult
.
buildSuccessResult
(
map
);
}
/**
* 新增ding robot 以及对应的pipeline
* @return
*/
@Transactional
@PostMapping
(
"/add"
)
@PostMapping
(
"/add"
)
public
JsonResult
addPipeline
(
@RequestBody
List
<
Pipeline
>
pipelineList
)
{
public
JsonResult
addRobotAndPipeline
(
@RequestBody
DingRobotPipelineVo
dingRobotPipelineVo
)
{
DingRobot
dingRobot
=
dingRobotPipelineVo
.
getDingRobot
();
String
projectName
=
dingRobot
.
getProjectName
();
String
jiraProjectKey
=
dingRobot
.
getJiraProjectKey
();
QueryWrapper
<
DingRobot
>
dingRobotQueryWrapper
=
new
QueryWrapper
<>();
dingRobotQueryWrapper
.
eq
(
"jira_project_key"
,
jiraProjectKey
);
dingRobotQueryWrapper
.
eq
(
"project_name"
,
projectName
);
// 根据jira project key和项目名判断是否已存在
if
(
dingRobotService
.
getOne
(
dingRobotQueryWrapper
)
!=
null
)
{
return
JsonResult
.
buildErrorStateResult
(
"项目已存在"
,
false
);
}
boolean
dingRobotResult
=
dingRobotService
.
save
(
dingRobot
);
if
(!
dingRobotResult
)
{
return
JsonResult
.
buildErrorStateResult
(
"服务器异常,保存失败!"
,
false
);
}
// 获取该robot id,并赋值给pipelineList
DingRobot
dingRobotNew
=
dingRobotService
.
getOne
(
dingRobotQueryWrapper
);
Integer
dingRobotId
=
dingRobotNew
.
getId
();
List
<
Pipeline
>
pipelineList
=
dingRobotPipelineVo
.
getPipelineList
();
for
(
Pipeline
pipeline:
pipelineList
)
{
pipeline
.
setDingRobotId
(
dingRobotId
);
}
return
JsonResult
.
buildSuccessResult
(
pipelineService
.
saveBatch
(
pipelineList
));
return
JsonResult
.
buildSuccessResult
(
pipelineService
.
saveBatch
(
pipelineList
));
}
}
/**
* 修改pipeline
* @param dingRobotPipelineVo
* @return
*/
@Transactional
@PostMapping
(
"/modify"
)
@PostMapping
(
"/modify"
)
public
JsonResult
modifyPipeline
(
@RequestBody
List
<
Pipeline
>
pipelineList
)
{
public
JsonResult
modifyPipeline
(
@RequestBody
DingRobotPipelineVo
dingRobotPipelineVo
)
{
try
{
DingRobot
dingRobot
=
dingRobotPipelineVo
.
getDingRobot
();
boolean
dingRobotResult
=
dingRobotService
.
saveOrUpdate
(
dingRobot
);
if
(!
dingRobotResult
)
{
return
JsonResult
.
buildErrorStateResult
(
"修改失败!"
,
false
);
}
Integer
dingRobotId
=
dingRobot
.
getId
();
List
<
Pipeline
>
pipelineList
=
dingRobotPipelineVo
.
getPipelineList
();
QueryWrapper
<
Pipeline
>
pipelineQueryWrapper
=
new
QueryWrapper
<>();
pipelineQueryWrapper
.
eq
(
"ding_robot_id"
,
dingRobotId
);
List
<
Pipeline
>
pipelineListInDb
=
pipelineService
.
list
(
pipelineQueryWrapper
);
// 判断是否有删除的部分
for
(
Pipeline
pipelineDb:
pipelineListInDb
)
{
boolean
flag
=
false
;
for
(
Pipeline
pipeline:
pipelineList
)
{
for
(
Pipeline
pipeline:
pipelineList
)
{
if
(
pipelineService
.
getById
(
pipeline
.
getId
())
==
null
)
{
if
(
pipelineDb
.
getId
().
equals
(
pipeline
.
getId
()))
{
pipelineService
.
save
(
pipeline
);
flag
=
true
;
}
else
{
pipelineService
.
updateById
(
pipeline
);
}
}
}
}
return
JsonResult
.
buildSuccessResult
(
true
);
if
(!
flag
)
{
}
catch
(
Exception
e
)
{
pipelineService
.
removeById
(
pipelineDb
.
getId
());
e
.
printStackTrace
();
}
return
JsonResult
.
buildSuccessResult
(
false
);
}
}
// 剩下的直接更新
return
JsonResult
.
buildSuccessResult
(
pipelineService
.
saveOrUpdateBatch
(
pipelineList
));
}
}
}
}
src/main/java/cn/qg/holmes/controller/jira/JiraController.java
View file @
a59f7a76
package
cn
.
qg
.
holmes
.
controller
.
jira
;
package
cn
.
qg
.
holmes
.
controller
.
jira
;
import
cn.qg.holmes.common.JsonResult
;
import
cn.qg.holmes.common.JsonResult
;
import
cn.qg.holmes.entity.jira.
JiraBugPool
;
import
cn.qg.holmes.entity.jira.
DingRobot
;
import
cn.qg.holmes.entity.jira.SendScheduleVo
;
import
cn.qg.holmes.entity.jira.SendScheduleVo
;
import
cn.qg.holmes.entity.jira.SendSmokingResultVo
;
import
cn.qg.holmes.service.jira.DingRobotService
;
import
cn.qg.holmes.service.jira.JiraBugPoolService
;
import
cn.qg.holmes.service.jira.JiraBugPoolService
;
import
cn.qg.holmes.service.jira.JiraIssueService
;
import
cn.qg.holmes.service.jira.JiraIssueService
;
import
cn.qg.holmes.utils.DingdingUtils
;
import
cn.qg.holmes.utils.DingdingUtils
;
import
com.atlassian.jira.rest.client.api.domain.BasicProject
;
import
com.atlassian.jira.rest.client.api.domain.Issue
;
import
com.atlassian.jira.rest.client.api.domain.Issue
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
org.joda.time.DateTime
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
java.text.SimpleDateFormat
;
import
javax.servlet.http.HttpServletRequest
;
import
java.io.BufferedReader
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
...
@@ -29,6 +34,114 @@ public class JiraController {
...
@@ -29,6 +34,114 @@ public class JiraController {
@Autowired
@Autowired
JiraBugPoolService
jiraBugPoolService
;
JiraBugPoolService
jiraBugPoolService
;
@Autowired
DingRobotService
dingRobotService
;
/**
* jira webhook
* @param request
*/
@PostMapping
(
"/webhook"
)
public
void
jiraWebhook
(
HttpServletRequest
request
)
{
try
{
BufferedReader
br
=
request
.
getReader
();
StringBuilder
jiraData
=
new
StringBuilder
();
String
str
=
""
;
while
((
str
=
br
.
readLine
())
!=
null
){
jiraData
.
append
(
str
);
}
br
.
close
();
dingRobotService
.
sendMsgToDing
(
String
.
valueOf
(
jiraData
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
/**
* 获取Jira项目列表
* @return
* @throws Exception
*/
@GetMapping
(
"/list/project"
)
public
JsonResult
getJiraProjectKey
()
throws
Exception
{
List
<
Map
<
String
,
String
>>
jiraKeyList
=
new
ArrayList
<>();
Iterable
<
BasicProject
>
projects
=
jiraIssueService
.
getJiraProjectList
();
for
(
BasicProject
project:
projects
)
{
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"id"
,
project
.
getId
().
toString
());
map
.
put
(
"key"
,
project
.
getKey
());
map
.
put
(
"name"
,
project
.
getName
());
jiraKeyList
.
add
(
map
);
}
return
JsonResult
.
buildSuccessResult
(
jiraKeyList
);
}
/**
* 项目机器人列表
* @param pageNum 第几页
* @param pageSize 每页多少个
* @return
*/
@GetMapping
(
"/list/robot"
)
public
JsonResult
getProjectRobotList
(
Integer
pageNum
,
Integer
pageSize
)
{
IPage
<
DingRobot
>
page
=
new
Page
<>(
pageNum
,
pageSize
);
QueryWrapper
<
DingRobot
>
dingRobotQueryWrapper
=
new
QueryWrapper
();
dingRobotQueryWrapper
.
orderByDesc
(
"id"
);
IPage
<
DingRobot
>
projectRobotIPage
=
dingRobotService
.
page
(
page
,
dingRobotQueryWrapper
);
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"total"
,
projectRobotIPage
.
getTotal
());
map
.
put
(
"list"
,
projectRobotIPage
.
getRecords
());
return
JsonResult
.
buildSuccessResult
(
map
);
}
/**
* 新增项目机器人
* @param dingRobot 项目机器人实体
* @return
*/
@PostMapping
(
"/add/robot"
)
public
JsonResult
addProjectRobot
(
@RequestBody
DingRobot
dingRobot
)
{
if
(
dingRobot
.
getProjectName
()
==
null
)
{
return
JsonResult
.
buildErrorStateResult
(
"项目名称不能为空!"
,
false
);
}
if
(
dingRobot
.
getDingUrl
()
==
null
)
{
return
JsonResult
.
buildErrorStateResult
(
"钉钉url不能为空!"
,
false
);
}
return
JsonResult
.
buildSuccessResult
(
dingRobotService
.
save
(
dingRobot
));
}
/**
* 修改项目机器人
* @param dingRobot 项目机器人实体
* @return
*/
@PostMapping
(
"/modify/robot"
)
public
JsonResult
editProjectRobot
(
@RequestBody
DingRobot
dingRobot
)
{
if
(
dingRobot
.
getId
()
==
null
)
{
return
JsonResult
.
buildErrorStateResult
(
"id不能为空!"
,
false
);
}
if
(
dingRobot
.
getProjectName
()
==
null
)
{
return
JsonResult
.
buildErrorStateResult
(
"项目名称不能为空!"
,
false
);
}
if
(
dingRobot
.
getDingUrl
()
==
null
)
{
return
JsonResult
.
buildErrorStateResult
(
"钉钉url不能为空!"
,
false
);
}
return
JsonResult
.
buildSuccessResult
(
dingRobotService
.
updateById
(
dingRobot
));
}
/**
* 删除项目机器人
* @param projectRobotId 项目机器人实体id
* @return
*/
@GetMapping
(
"/delete/robot"
)
public
JsonResult
deleteProjectRobot
(
Integer
projectRobotId
)
{
if
(
dingRobotService
.
getById
(
projectRobotId
)
==
null
)
{
return
JsonResult
.
buildErrorStateResult
(
"项目机器人不存在!"
,
false
);
}
return
JsonResult
.
buildSuccessResult
(
dingRobotService
.
removeById
(
projectRobotId
));
}
@GetMapping
(
"/report/project"
)
@GetMapping
(
"/report/project"
)
public
void
sendReportToDingdingGroup
(
String
project
,
String
webhook
)
throws
Exception
{
public
void
sendReportToDingdingGroup
(
String
project
,
String
webhook
)
throws
Exception
{
Iterable
<
Issue
>
issues
=
jiraIssueService
.
getUnsolvedIssueListByProject
(
project
);
Iterable
<
Issue
>
issues
=
jiraIssueService
.
getUnsolvedIssueListByProject
(
project
);
...
@@ -49,53 +162,17 @@ public class JiraController {
...
@@ -49,53 +162,17 @@ public class JiraController {
return
JsonResult
.
buildSuccessResult
(
DingdingUtils
.
sendToDingding
(
markdownMsg
,
sendScheduleVo
.
getWebhook
()));
return
JsonResult
.
buildSuccessResult
(
DingdingUtils
.
sendToDingding
(
markdownMsg
,
sendScheduleVo
.
getWebhook
()));
}
}
@GetMapping
(
"/test"
)
/**
public
JsonResult
test
()
throws
Exception
{
* 发送冒烟测试进度
String
JQL
=
"project = XCX AND text ~ KA乐信 ORDER BY key ASC, priority DESC, updated DESC"
;
* @param sendSmokingResultVo 发送冒烟进度实体
* @return
*/
@PostMapping
(
"/send/smoking"
)
public
JsonResult
sendSmokingResult
(
@RequestBody
SendSmokingResultVo
sendSmokingResultVo
)
throws
Exception
{
String
JQL
=
"project = "
+
sendSmokingResultVo
.
getJiraProjectKey
()
+
" AND resolution = Unresolved AND text ~ \""
+
sendSmokingResultVo
.
getTestProjectName
()
+
"\" ORDER BY priority DESC, updated DESC"
;
Iterable
<
Issue
>
issues
=
jiraIssueService
.
getIssueListByJQL
(
JQL
);
Iterable
<
Issue
>
issues
=
jiraIssueService
.
getIssueListByJQL
(
JQL
);
SimpleDateFormat
simpleDateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
String
markdownMsg
=
DingdingUtils
.
buildSmokingResultMarkdownMsg
(
issues
,
sendSmokingResultVo
.
getResult
(),
sendSmokingResultVo
.
getRisk
());
List
<
Map
<
String
,
Object
>>
result
=
new
ArrayList
<>();
return
JsonResult
.
buildSuccessResult
(
DingdingUtils
.
sendToDingding
(
markdownMsg
,
sendSmokingResultVo
.
getWebhook
()));
for
(
Issue
issue:
issues
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"标题"
,
issue
.
getSummary
());
map
.
put
(
"报告人"
,
issue
.
getReporter
().
getDisplayName
());
map
.
put
(
"经办人"
,
issue
.
getAssignee
().
getDisplayName
());
map
.
put
(
"优先级"
,
issue
.
getPriority
().
getName
());
map
.
put
(
"创建时间"
,
simpleDateFormat
.
format
(
issue
.
getCreationDate
().
toDate
()));
if
(
issue
.
getStatus
().
getName
().
equals
(
"关闭"
)
||
issue
.
getStatus
().
getName
().
equals
(
"已解决"
))
{
map
.
put
(
"解决时间"
,
simpleDateFormat
.
format
(
DateTime
.
parse
(
issue
.
getFieldByName
(
"已解决"
).
getValue
().
toString
()).
toDate
()));
}
else
{
map
.
put
(
"解决时间"
,
null
);
}
map
.
put
(
"解决时长"
,
jiraIssueService
.
calculateBugFixTime
(
issue
.
getCreationDate
(),
DateTime
.
parse
(
issue
.
getFieldByName
(
"已解决"
).
getValue
().
toString
())).
toString
());
result
.
add
(
map
);
}
return
JsonResult
.
buildSuccessResult
(
result
);
}
@GetMapping
(
"/bug/pool/caculate"
)
public
JsonResult
bugPoolCaculateFixTime
()
throws
Exception
{
QueryWrapper
<
JiraBugPool
>
jiraBugPoolQueryWrapper
=
new
QueryWrapper
<>();
jiraBugPoolQueryWrapper
.
eq
(
"enable"
,
1
);
List
<
JiraBugPool
>
jiraBugPoolList
=
jiraBugPoolService
.
list
(
jiraBugPoolQueryWrapper
);
List
<
Map
<
String
,
Object
>>
mapList
=
new
ArrayList
<>();
for
(
JiraBugPool
jiraBugPool
:
jiraBugPoolList
)
{
Issue
issue
=
jiraIssueService
.
getJiraIssueByKey
(
jiraBugPool
.
getKey
());
String
resolveResult
=
issue
.
getStatus
().
getName
();
DateTime
startDate
=
issue
.
getCreationDate
();
DateTime
endDate
;
// 如果已解决或已关闭,仅修改状态
if
(
resolveResult
.
equals
(
"已解决"
)
||
resolveResult
.
equals
(
"关闭"
))
{
endDate
=
DateTime
.
parse
(
issue
.
getFieldByName
(
"已解决"
).
getValue
().
toString
());
}
else
{
endDate
=
new
DateTime
();
}
int
duration
=
jiraIssueService
.
calculateBugFixTime
(
startDate
,
endDate
);
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"title"
,
issue
.
getSummary
());
map
.
put
(
"持续时长"
,
duration
);
mapList
.
add
(
map
);
}
return
JsonResult
.
buildSuccessResult
(
mapList
);
}
}
}
}
src/main/java/cn/qg/holmes/controller/jira/JiraWebhookController.java
deleted
100644 → 0
View file @
ca1b56c3
package
cn
.
qg
.
holmes
.
controller
.
jira
;
import
cn.qg.holmes.common.JsonResult
;
import
cn.qg.holmes.entity.jira.DingRobot
;
import
cn.qg.holmes.service.jira.DingRobotService
;
import
cn.qg.holmes.service.jira.JiraIssueService
;
import
com.atlassian.jira.rest.client.api.domain.BasicProject
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletRequest
;
import
java.io.BufferedReader
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
@Slf4j
@CrossOrigin
@RestController
@RequestMapping
(
"/jira"
)
public
class
JiraWebhookController
{
@Autowired
DingRobotService
dingRobotService
;
@Autowired
JiraIssueService
jiraIssueService
;
/**
* jira webhook
* @param request
*/
@PostMapping
(
"/webhook"
)
public
void
jiraWebhook
(
HttpServletRequest
request
)
{
try
{
BufferedReader
br
=
request
.
getReader
();
StringBuilder
jiraData
=
new
StringBuilder
();
String
str
=
""
;
while
((
str
=
br
.
readLine
())
!=
null
){
jiraData
.
append
(
str
);
}
br
.
close
();
dingRobotService
.
sendMsgToDing
(
String
.
valueOf
(
jiraData
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
/**
* 获取Jira项目列表
* @return
* @throws Exception
*/
@GetMapping
(
"/list/project"
)
public
JsonResult
getJiraProjectKey
()
throws
Exception
{
List
<
Map
<
String
,
String
>>
jiraKeyList
=
new
ArrayList
<>();
Iterable
<
BasicProject
>
projects
=
jiraIssueService
.
getJiraProjectList
();
for
(
BasicProject
project:
projects
)
{
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"id"
,
project
.
getId
().
toString
());
map
.
put
(
"key"
,
project
.
getKey
());
map
.
put
(
"name"
,
project
.
getName
());
jiraKeyList
.
add
(
map
);
}
return
JsonResult
.
buildSuccessResult
(
jiraKeyList
);
}
/**
* 项目机器人列表
* @param pageNum 第几页
* @param pageSize 每页多少个
* @return
*/
@GetMapping
(
"/list/robot"
)
public
JsonResult
getProjectRobotList
(
Integer
pageNum
,
Integer
pageSize
)
{
IPage
<
DingRobot
>
page
=
new
Page
<>(
pageNum
,
pageSize
);
QueryWrapper
<
DingRobot
>
dingRobotQueryWrapper
=
new
QueryWrapper
();
dingRobotQueryWrapper
.
orderByDesc
(
"id"
);
IPage
<
DingRobot
>
projectRobotIPage
=
dingRobotService
.
page
(
page
,
dingRobotQueryWrapper
);
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"total"
,
projectRobotIPage
.
getTotal
());
map
.
put
(
"list"
,
projectRobotIPage
.
getRecords
());
return
JsonResult
.
buildSuccessResult
(
map
);
}
/**
* 新增项目机器人
* @param dingRobot 项目机器人实体
* @return
*/
@PostMapping
(
"/add/robot"
)
public
JsonResult
addProjectRobot
(
@RequestBody
DingRobot
dingRobot
)
{
if
(
dingRobot
.
getProjectName
()
==
null
)
{
return
JsonResult
.
buildErrorStateResult
(
"项目名称不能为空!"
,
false
);
}
if
(
dingRobot
.
getDingUrl
()
==
null
)
{
return
JsonResult
.
buildErrorStateResult
(
"钉钉url不能为空!"
,
false
);
}
return
JsonResult
.
buildSuccessResult
(
dingRobotService
.
save
(
dingRobot
));
}
/**
* 修改项目机器人
* @param dingRobot 项目机器人实体
* @return
*/
@PostMapping
(
"/modify/robot"
)
public
JsonResult
editProjectRobot
(
@RequestBody
DingRobot
dingRobot
)
{
if
(
dingRobot
.
getId
()
==
null
)
{
return
JsonResult
.
buildErrorStateResult
(
"id不能为空!"
,
false
);
}
if
(
dingRobot
.
getProjectName
()
==
null
)
{
return
JsonResult
.
buildErrorStateResult
(
"项目名称不能为空!"
,
false
);
}
if
(
dingRobot
.
getDingUrl
()
==
null
)
{
return
JsonResult
.
buildErrorStateResult
(
"钉钉url不能为空!"
,
false
);
}
return
JsonResult
.
buildSuccessResult
(
dingRobotService
.
updateById
(
dingRobot
));
}
/**
* 删除项目机器人
* @param projectRobotId 项目机器人实体id
* @return
*/
@GetMapping
(
"/delete/robot"
)
public
JsonResult
deleteProjectRobot
(
Integer
projectRobotId
)
{
if
(
dingRobotService
.
getById
(
projectRobotId
)
==
null
)
{
return
JsonResult
.
buildErrorStateResult
(
"项目机器人不存在!"
,
false
);
}
return
JsonResult
.
buildSuccessResult
(
dingRobotService
.
removeById
(
projectRobotId
));
}
}
src/main/java/cn/qg/holmes/entity/gitlab/DingRobotPipelineVo.java
0 → 100644
View file @
a59f7a76
package
cn
.
qg
.
holmes
.
entity
.
gitlab
;
import
cn.qg.holmes.entity.jira.DingRobot
;
import
lombok.Data
;
import
java.util.List
;
/**
* 新增/编辑jira通知-pipeline实体
*/
@Data
public
class
DingRobotPipelineVo
{
private
DingRobot
dingRobot
;
private
List
<
Pipeline
>
pipelineList
;
}
src/main/java/cn/qg/holmes/entity/jira/SendSmokingResultVo.java
0 → 100644
View file @
a59f7a76
package
cn
.
qg
.
holmes
.
entity
.
jira
;
import
lombok.Data
;
@Data
public
class
SendSmokingResultVo
{
private
String
jiraProjectKey
;
private
String
testProjectName
;
private
String
progress
;
private
Boolean
result
;
private
String
risk
;
private
String
webhook
;
}
src/main/java/cn/qg/holmes/utils/DingdingUtils.java
View file @
a59f7a76
...
@@ -2,7 +2,6 @@ package cn.qg.holmes.utils;
...
@@ -2,7 +2,6 @@ package cn.qg.holmes.utils;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.atlassian.jira.rest.client.api.domain.Issue
;
import
com.atlassian.jira.rest.client.api.domain.Issue
;
import
com.jayway.jsonpath.JsonPath
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.joda.time.DateTime
;
import
org.joda.time.DateTime
;
...
@@ -179,6 +178,42 @@ public class DingdingUtils {
...
@@ -179,6 +178,42 @@ public class DingdingUtils {
return
buildMarkdownMsg
(
title
,
content
,
false
);
return
buildMarkdownMsg
(
title
,
content
,
false
);
}
}
/**
* 构建冒烟测试结果的钉钉消息
* @param issues 未解决BUG列表
* @param result 冒烟结果,true-冒烟测试通过,false-冒烟测试未通过
* @param risk 风险点
* @return
*/
public
static
String
buildSmokingResultMarkdownMsg
(
Iterable
<
Issue
>
issues
,
boolean
result
,
String
risk
)
{
String
title
=
""
;
String
content
=
""
;
DateFormat
format
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
String
today
=
format
.
format
(
new
Date
());
content
=
today
+
"\n\n"
;
if
(
result
)
{
title
=
"冒烟测试通过!"
;
content
+=
"冒烟测试结果:✅\n\n亲爱的小伙伴们,经过冒烟测试,您的项目可以正式进入测试阶段,感谢您辛苦的努力,后面的bug还请多多支持呀!\n\n"
;
}
else
{
title
=
"冒烟测试未通过!"
;
content
+=
"冒烟测试结果:❌\n\n亲爱的小伙伴们,经过冒烟测试,您的项目无法正式进入测试阶段。因为有严重问题阻塞流程,请尽快修复后再次提测。由此耽误的时间算做您开发改bug的时间喔,测试时间会顺延到冒烟测试通过后的时间!\n\n"
;
}
content
+=
"冒烟测试BUG列表:\n\n"
;
int
count
=
0
;
for
(
Issue
issue:
issues
)
{
count
=
count
+
1
;
String
issueUrl
=
"http://jira2.quantgroup.cn/browse/"
+
issue
.
getKey
();
content
=
content
+
count
+
"、["
+
issue
.
getSummary
().
replace
(
"\""
,
""
)
+
"]("
+
issueUrl
+
")\n"
;
content
=
content
+
"- 优先级:"
+
issue
.
getPriority
().
getName
()
+
"\n"
;
content
=
content
+
"- 状态:"
+
issue
.
getStatus
().
getName
()
+
"\n"
;
content
=
content
+
"- 经办人:"
+
issue
.
getAssignee
().
getDisplayName
()
+
"\n\n"
;
}
if
(
risk
!=
null
)
{
content
+=
"风险点:"
+
risk
;
}
return
buildMarkdownMsg
(
title
,
content
,
true
);
}
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
// String markdown = buildMarkdownMsg("YXM-1499", "【羊小咩v7.6.00】【VCC首次交易率提升专题】巴拉巴拉", "黎博", "于巧玲", "p1", "kddsp");
// String markdown = buildMarkdownMsg("YXM-1499", "【羊小咩v7.6.00】【VCC首次交易率提升专题】巴拉巴拉", "黎博", "于巧玲", "p1", "kddsp");
// String markdown = buildPipelineMarkdownMsg("holmes", "master", "bo.li", "测试", "2021-06-03 14:59:45", "fe");
// String markdown = buildPipelineMarkdownMsg("holmes", "master", "bo.li", "测试", "2021-06-03 14:59:45", "fe");
...
...
src/main/java/cn/qg/holmes/utils/GitlabService.java
0 → 100644
View file @
a59f7a76
package
cn
.
qg
.
holmes
.
utils
;
import
org.gitlab.api.GitlabAPI
;
import
org.gitlab.api.models.GitlabBranch
;
import
org.gitlab.api.models.GitlabProject
;
import
org.springframework.stereotype.Component
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
@Component
public
class
GitlabService
{
private
static
final
String
URL
=
"http://git.quantgroup.cn/"
;
private
static
final
String
TOKEN
=
"owKJZwenxNaypTAz4Zcd"
;
private
GitlabAPI
gitlabAPI
;
public
GitlabService
()
{
try
{
gitlabAPI
=
GitlabAPI
.
connect
(
URL
,
TOKEN
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
/**
* 获取所有的项目
* @return
*/
public
List
<
Map
<
String
,
Object
>>
getProjectList
()
{
List
<
GitlabProject
>
gitlabProjectList
=
gitlabAPI
.
getProjects
();
List
<
Map
<
String
,
Object
>>
projectMapList
=
new
ArrayList
<>();
for
(
GitlabProject
gitlabProject:
gitlabProjectList
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"id"
,
gitlabProject
.
getId
());
map
.
put
(
"name"
,
gitlabProject
.
getName
());
projectMapList
.
add
(
map
);
}
return
projectMapList
;
}
public
List
<
String
>
getBranchesByProjectName
(
String
projectName
)
{
List
<
Map
<
String
,
Object
>>
projectList
=
getProjectList
();
Integer
projectId
=
null
;
for
(
Map
<
String
,
Object
>
map:
projectList
)
{
if
(
map
.
get
(
"name"
).
toString
().
equals
(
projectName
))
{
projectId
=
(
Integer
)
map
.
get
(
"id"
);
}
}
List
<
GitlabBranch
>
gitlabBranchList
=
gitlabAPI
.
getBranches
(
projectId
);
List
<
String
>
branches
=
new
ArrayList
<>();
for
(
GitlabBranch
gitlabBranch:
gitlabBranchList
)
{
branches
.
add
(
gitlabBranch
.
getName
());
}
return
branches
;
}
public
static
void
main
(
String
[]
args
)
{
GitlabService
gitlabService
=
new
GitlabService
();
List
<
String
>
branches
=
gitlabService
.
getBranchesByProjectName
(
"holmes"
);
System
.
out
.
println
(
branches
);
}
}
src/main/java/cn/qg/holmes/utils/JenkinsService.java
View file @
a59f7a76
...
@@ -5,7 +5,6 @@ import com.offbytwo.jenkins.client.JenkinsHttpClient;
...
@@ -5,7 +5,6 @@ import com.offbytwo.jenkins.client.JenkinsHttpClient;
import
com.offbytwo.jenkins.model.Build
;
import
com.offbytwo.jenkins.model.Build
;
import
com.offbytwo.jenkins.model.Job
;
import
com.offbytwo.jenkins.model.Job
;
import
com.offbytwo.jenkins.model.JobWithDetails
;
import
com.offbytwo.jenkins.model.JobWithDetails
;
import
com.offbytwo.jenkins.model.QueueReference
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
java.io.IOException
;
import
java.io.IOException
;
...
...
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