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
ca9530f4
Commit
ca9530f4
authored
Feb 10, 2022
by
黎博
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增BUG池循环定时任务,JIRA线上工单webhook
parent
68be7fb7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
148 additions
and
2 deletions
+148
-2
JiraController.java
.../java/cn/qg/holmes/controller/quality/JiraController.java
+17
-0
BugNotifyTask.java
src/main/java/cn/qg/holmes/task/BugNotifyTask.java
+55
-2
DingdingUtils.java
src/main/java/cn/qg/holmes/utils/DingdingUtils.java
+76
-0
No files found.
src/main/java/cn/qg/holmes/controller/quality/JiraController.java
View file @
ca9530f4
...
...
@@ -9,6 +9,7 @@ import cn.qg.holmes.service.quality.DingRobotService;
import
cn.qg.holmes.service.quality.JiraBugPoolService
;
import
cn.qg.holmes.service.quality.JiraService
;
import
cn.qg.holmes.utils.DingdingUtils
;
import
com.alibaba.fastjson.JSON
;
import
com.atlassian.jira.rest.client.api.domain.BasicProject
;
import
com.atlassian.jira.rest.client.api.domain.Issue
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
...
...
@@ -60,6 +61,22 @@ public class JiraController {
}
}
@PostMapping
(
"/prod/webhook"
)
public
void
prodWebhook
(
HttpServletRequest
request
)
{
try
{
BufferedReader
br
=
request
.
getReader
();
StringBuilder
jiraData
=
new
StringBuilder
();
String
str
=
""
;
while
((
str
=
br
.
readLine
())
!=
null
){
jiraData
.
append
(
str
);
}
br
.
close
();
log
.
info
(
"收到JIRA 推送:{}"
,
JSON
.
toJSONString
(
jiraData
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
/**
* 获取Jira项目列表
* @return
...
...
src/main/java/cn/qg/holmes/task/BugNotifyTask.java
View file @
ca9530f4
...
...
@@ -15,6 +15,7 @@ import org.springframework.beans.factory.annotation.Value;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
...
...
@@ -43,7 +44,7 @@ public class BugNotifyTask {
* 数据工单bug统计
* @throws Exception
*/
@Scheduled
(
cron
=
"0 0 19 * * ?"
)
//
@Scheduled(cron = "0 0 19 * * ?")
public
void
SJGDJiraIssueStatisticsTimedJob
()
throws
Exception
{
if
(
taskDebug
.
equals
(
"true"
))
{
log
.
info
(
"开始执行数据工单BUG统计定时任务!"
);
...
...
@@ -59,7 +60,7 @@ public class BugNotifyTask {
* bug池里BUG循环
* @throws Exception
*/
@Scheduled
(
cron
=
"0 0 10-20 ? * MON-FRI"
)
//
@Scheduled(cron = "0 0 10-20 ? * MON-FRI")
public
void
cycleJiraBugPool
()
throws
Exception
{
if
(
taskDebug
.
equals
(
"true"
))
{
log
.
info
(
"开始执行jira bug pool定时任务!"
);
...
...
@@ -103,4 +104,56 @@ public class BugNotifyTask {
}
}
}
/**
* 每晚6点循环处理jira bug pool里未解决的BUG
*/
// @Scheduled(cron = "0 */1 * * * ?")
@Scheduled
(
cron
=
"0 0 18 ? * MON-FRI"
)
public
void
DailyCycleHandleJiraBugPool
()
{
if
(
taskDebug
.
equals
(
"true"
))
{
// 首先遍历ding_robot, 获取状态是进行中的项目
QueryWrapper
<
DingRobot
>
dingRobotQueryWrapper
=
new
QueryWrapper
<>();
dingRobotQueryWrapper
.
eq
(
"status"
,
1
);
List
<
DingRobot
>
dingRobotList
=
dingRobotService
.
list
(
dingRobotQueryWrapper
);
if
(
dingRobotList
.
size
()
>
0
)
{
// 遍历进行中的项目,从jira_bug_pool里获取对应的状态是未解决的BUG
for
(
DingRobot
dingRobot:
dingRobotList
)
{
QueryWrapper
<
JiraBugPool
>
jiraBugPoolQueryWrapper
=
new
QueryWrapper
<>();
jiraBugPoolQueryWrapper
.
eq
(
"ding_robot_id"
,
dingRobot
.
getId
())
.
eq
(
"enable"
,
1
);
List
<
JiraBugPool
>
jiraBugPools
=
jiraBugPoolService
.
list
(
jiraBugPoolQueryWrapper
);
List
<
Issue
>
issueList
=
new
ArrayList
<>();
for
(
JiraBugPool
jiraBugPool:
jiraBugPools
)
{
Issue
issue
=
jiraService
.
getJiraIssueByKey
(
jiraBugPool
.
getKey
());
if
(
issue
!=
null
)
{
String
resolveResult
=
issue
.
getStatus
().
getName
();
// 如果已关闭,仅修改状态
if
(
resolveResult
.
equals
(
"关闭"
))
{
jiraBugPool
.
setEnable
(
0
);
// 更新状态
jiraBugPoolService
.
saveOrUpdate
(
jiraBugPool
);
}
else
if
(
resolveResult
.
equals
(
"已解决"
))
{
// 暂时只打印日志,不做逻辑处理
log
.
info
(
"BUG:{}已解决"
,
issue
.
getKey
());
}
else
{
// 其他状态的直接加到通知列表
log
.
info
(
"BUG:{}未解决,加到通知列表."
,
jiraBugPool
.
getKey
());
issueList
.
add
(
issue
);
}
}
else
{
log
.
info
(
"JIRA上未找到该issue,将BUG: {} 置为无效"
,
jiraBugPool
.
getKey
());
jiraBugPool
.
setEnable
(
0
);
jiraBugPoolService
.
saveOrUpdate
(
jiraBugPool
);
}
}
// 判断列表是否为空,如果不为空,则忘群里发送通知
if
(
issueList
.
size
()
>
0
)
{
DingdingUtils
.
sendToDingding
(
DingdingUtils
.
buildDailyCycleJiraBugPoolMsg
(
issueList
),
dingRobot
.
getDingUrl
());
}
}
}
}
}
}
src/main/java/cn/qg/holmes/utils/DingdingUtils.java
View file @
ca9530f4
package
cn
.
qg
.
holmes
.
utils
;
import
cn.qg.holmes.entity.quality.DingRobot
;
import
cn.qg.holmes.service.quality.JiraService
;
import
com.alibaba.fastjson.JSON
;
import
com.atlassian.jira.rest.client.api.domain.Issue
;
import
lombok.extern.slf4j.Slf4j
;
import
org.joda.time.DateTime
;
import
org.joda.time.Days
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
java.text.DateFormat
;
import
java.text.SimpleDateFormat
;
...
...
@@ -249,6 +253,78 @@ public class DingdingUtils {
return
buildMarkdownMsg
(
title
,
content
,
true
);
}
/**
* 构建每日循环BUG池发送信息
* @param issues
* @return
*/
public
static
String
buildDailyCycleJiraBugPoolMsg
(
List
<
Issue
>
issues
)
{
String
title
=
"今日未解决BUG统计"
;
String
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"
;
String
assignee
=
""
;
if
(
issue
.
getAssignee
()
==
null
)
{
assignee
=
"未分配"
;
}
else
{
assignee
=
issue
.
getAssignee
().
getDisplayName
();
}
content
=
content
+
"- 经办人:"
+
assignee
+
"\n\n"
;
DateTime
startDate
=
issue
.
getCreationDate
();
DateTime
curDate
=
new
DateTime
();
int
duration
=
calculateBugFixTime
(
startDate
,
curDate
);
content
+=
"- 持续时间:"
+
duration
+
"小时\n\n"
;
}
content
+=
"**截止当前,共有"
+
String
.
valueOf
(
count
)
+
"个BUG未修复,为了不影响测试进度,请对应开发同学尽快跟进解决一下~**"
;
return
buildMarkdownMsg
(
title
,
content
,
true
);
}
/**
* 计算BUG持续时间
* @param startDate 开始日期
* @param endDate 结束日期
* @return
*/
public
static
Integer
calculateBugFixTime
(
DateTime
startDate
,
DateTime
endDate
)
{
int
startHour
=
startDate
.
getHourOfDay
();
int
endHour
=
endDate
.
getHourOfDay
();
int
startMinute
=
startDate
.
getMinuteOfHour
();
int
endMinute
=
endDate
.
getMinuteOfHour
();
int
startSecond
=
startDate
.
getSecondOfMinute
();
int
endSecond
=
endDate
.
getSecondOfMinute
();
boolean
daySubFlag
=
true
;
if
(
endHour
<
startHour
)
{
daySubFlag
=
false
;
}
if
(
endHour
==
startHour
&&
endMinute
<
startMinute
)
{
daySubFlag
=
false
;
}
if
(
endHour
==
startHour
&&
endMinute
==
startMinute
&&
endSecond
<
startSecond
)
{
daySubFlag
=
false
;
}
if
(
startHour
>=
19
)
{
startHour
=
19
;
}
if
(
startHour
<=
10
)
{
startHour
=
10
;
}
if
(
endHour
>=
19
)
{
endHour
=
19
;
}
if
(
endHour
<=
10
)
{
endHour
=
10
;
}
int
hourDiff
=
endHour
-
startHour
;
int
days
=
Days
.
daysBetween
(
startDate
,
endDate
).
getDays
();
return
daySubFlag
?
days
*
8
+
hourDiff
:
(
days
+
1
)
*
8
+
hourDiff
;
}
public
static
void
main
(
String
[]
args
)
{
// 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");
...
...
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