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
4b90dc76
Commit
4b90dc76
authored
May 21, 2021
by
黎博
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
jira bug pool相关
parent
5b1ee5eb
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
183 additions
and
29 deletions
+183
-29
JiraController.java
...ain/java/cn/qg/holmes/controller/jira/JiraController.java
+3
-6
JiraBugPool.java
src/main/java/cn/qg/holmes/entity/jira/JiraBugPool.java
+52
-0
JiraBugPoolMapper.java
...main/java/cn/qg/holmes/mapper/jira/JiraBugPoolMapper.java
+7
-0
JiraBugPoolService.java
...in/java/cn/qg/holmes/service/jira/JiraBugPoolService.java
+7
-0
JiraIssueService.java
...main/java/cn/qg/holmes/service/jira/JiraIssueService.java
+8
-0
DingRobotServiceImpl.java
.../cn/qg/holmes/service/jira/impl/DingRobotServiceImpl.java
+15
-0
JiraBugPoolServiceImpl.java
...n/qg/holmes/service/jira/impl/JiraBugPoolServiceImpl.java
+11
-0
JiraIssueServiceImpl.java
.../cn/qg/holmes/service/jira/impl/JiraIssueServiceImpl.java
+44
-23
JiraToDingding.java
src/main/java/cn/qg/holmes/task/jira/JiraToDingding.java
+36
-0
No files found.
src/main/java/cn/qg/holmes/controller/jira/JiraController.java
View file @
4b90dc76
...
...
@@ -5,15 +5,11 @@ import cn.qg.holmes.entity.jira.SendScheduleVo;
import
cn.qg.holmes.service.jira.JiraIssueService
;
import
cn.qg.holmes.utils.DingdingUtils
;
import
com.atlassian.jira.rest.client.api.domain.Issue
;
import
lombok.Data
;
import
net.sf.jsqlparser.expression.DateTimeLiteralExpression
;
import
org.joda.time.DateTime
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
java.sql.Date
;
import
java.text.SimpleDateFormat
;
import
java.time.format.DateTimeFormatter
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
...
...
@@ -52,9 +48,9 @@ public class JiraController {
String
JQL
=
"project = XCX AND text ~ KA乐信 ORDER BY key ASC, priority DESC, updated DESC"
;
Iterable
<
Issue
>
issues
=
jiraIssueService
.
getIssueListByJQL
(
JQL
);
SimpleDateFormat
simpleDateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
List
<
Map
<
String
,
String
>>
result
=
new
ArrayList
<>();
List
<
Map
<
String
,
Object
>>
result
=
new
ArrayList
<>();
for
(
Issue
issue:
issues
)
{
Map
<
String
,
String
>
map
=
new
HashMap
<>();
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"标题"
,
issue
.
getSummary
());
map
.
put
(
"报告人"
,
issue
.
getReporter
().
getDisplayName
());
map
.
put
(
"经办人"
,
issue
.
getAssignee
().
getDisplayName
());
...
...
@@ -65,6 +61,7 @@ public class JiraController {
}
else
{
map
.
put
(
"解决时间"
,
null
);
}
map
.
put
(
"解决时长"
,
jiraIssueService
.
calculateBugFixTime
(
issue
.
getCreationDate
(),
DateTime
.
parse
(
issue
.
getFieldByName
(
"已解决"
).
getValue
().
toString
())).
toString
());
result
.
add
(
map
);
}
return
JsonResult
.
buildSuccessResult
(
result
);
...
...
src/main/java/cn/qg/holmes/entity/jira/JiraBugPool.java
0 → 100644
View file @
4b90dc76
package
cn
.
qg
.
holmes
.
entity
.
jira
;
import
com.baomidou.mybatisplus.annotation.IdType
;
import
com.baomidou.mybatisplus.annotation.TableField
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
lombok.Data
;
/**
* 未解决JIRA BUG
*/
@Data
public
class
JiraBugPool
{
@TableId
(
type
=
IdType
.
AUTO
)
private
Integer
id
;
/**
* jira关键字
*/
@TableField
(
"`key`"
)
private
String
key
;
/**
* bug标题
*/
private
String
summary
;
/**
* bug优先级
*/
private
String
priority
;
/**
* 报告人
*/
private
String
reporter
;
/**
* 经办人
*/
private
String
assignee
;
/**
* bug链接
*/
private
String
url
;
/**
* 钉钉robot
*/
private
String
dingUrl
;
/**
* 解决结果
*/
private
String
resolveResult
;
/**
* 是否有效,1-有效,0-无效
*/
private
Integer
enable
;
}
src/main/java/cn/qg/holmes/mapper/jira/JiraBugPoolMapper.java
0 → 100644
View file @
4b90dc76
package
cn
.
qg
.
holmes
.
mapper
.
jira
;
import
cn.qg.holmes.entity.jira.JiraBugPool
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
public
interface
JiraBugPoolMapper
extends
BaseMapper
<
JiraBugPool
>
{
}
src/main/java/cn/qg/holmes/service/jira/JiraBugPoolService.java
0 → 100644
View file @
4b90dc76
package
cn
.
qg
.
holmes
.
service
.
jira
;
import
cn.qg.holmes.entity.jira.JiraBugPool
;
import
com.baomidou.mybatisplus.extension.service.IService
;
public
interface
JiraBugPoolService
extends
IService
<
JiraBugPool
>
{
}
src/main/java/cn/qg/holmes/service/jira/JiraIssueService.java
View file @
4b90dc76
...
...
@@ -2,6 +2,9 @@ package cn.qg.holmes.service.jira;
import
com.atlassian.jira.rest.client.api.domain.BasicProject
;
import
com.atlassian.jira.rest.client.api.domain.Issue
;
import
org.joda.time.DateTime
;
import
java.util.concurrent.ExecutionException
;
public
interface
JiraIssueService
{
...
...
@@ -10,4 +13,9 @@ public interface JiraIssueService {
Iterable
<
Issue
>
getIssueListByJQL
(
String
JQL
)
throws
Exception
;
Iterable
<
BasicProject
>
getJiraProjectList
()
throws
Exception
;
Integer
calculateBugFixTime
(
DateTime
startDate
,
DateTime
endDate
);
Issue
getJiraIssueByKey
(
String
key
)
throws
Exception
;
}
src/main/java/cn/qg/holmes/service/jira/impl/DingRobotServiceImpl.java
View file @
4b90dc76
package
cn
.
qg
.
holmes
.
service
.
jira
.
impl
;
import
cn.qg.holmes.entity.jira.DingRobot
;
import
cn.qg.holmes.entity.jira.JiraBugPool
;
import
cn.qg.holmes.mapper.jira.DingRobotMapper
;
import
cn.qg.holmes.service.jira.DingRobotService
;
import
cn.qg.holmes.service.jira.JiraBugPoolService
;
import
cn.qg.holmes.utils.DingdingUtils
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.jayway.jsonpath.JsonPath
;
...
...
@@ -20,6 +22,9 @@ public class DingRobotServiceImpl extends ServiceImpl<DingRobotMapper, DingRobot
@Autowired
DingRobotMapper
dingRobotMapper
;
@Autowired
JiraBugPoolService
jiraBugPoolService
;
@Override
public
Boolean
sendMsgToDing
(
String
jiraData
)
{
log
.
info
(
"收到jira bug提交:{}"
,
jiraData
);
...
...
@@ -40,6 +45,16 @@ public class DingRobotServiceImpl extends ServiceImpl<DingRobotMapper, DingRobot
break
;
}
}
// 首次提交的BUG放入bug池子
JiraBugPool
jiraBugPool
=
new
JiraBugPool
();
jiraBugPool
.
setKey
(
key
);
jiraBugPool
.
setSummary
(
summary
);
jiraBugPool
.
setPriority
(
priority
);
jiraBugPool
.
setReporter
(
creator
);
jiraBugPool
.
setAssignee
(
assignee
);
jiraBugPool
.
setUrl
(
"http://jira2.quantgroup.cn/browse/"
+
key
);
jiraBugPool
.
setDingUrl
(
robotUrl
);
jiraBugPoolService
.
save
(
jiraBugPool
);
if
(
robotUrl
!=
null
)
{
String
markdownMsg
=
DingdingUtils
.
buildMarkdownMsg
(
key
,
summary
,
creator
,
assignee
,
priority
,
module
);
return
DingdingUtils
.
sendToDingding
(
markdownMsg
,
robotUrl
);
...
...
src/main/java/cn/qg/holmes/service/jira/impl/JiraBugPoolServiceImpl.java
0 → 100644
View file @
4b90dc76
package
cn
.
qg
.
holmes
.
service
.
jira
.
impl
;
import
cn.qg.holmes.entity.jira.JiraBugPool
;
import
cn.qg.holmes.mapper.jira.JiraBugPoolMapper
;
import
cn.qg.holmes.service.jira.JiraBugPoolService
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
org.springframework.stereotype.Service
;
@Service
public
class
JiraBugPoolServiceImpl
extends
ServiceImpl
<
JiraBugPoolMapper
,
JiraBugPool
>
implements
JiraBugPoolService
{
}
src/main/java/cn/qg/holmes/service/jira/impl/JiraIssueServiceImpl.java
View file @
4b90dc76
...
...
@@ -14,6 +14,7 @@ import org.springframework.stereotype.Service;
import
java.net.URI
;
import
java.net.URISyntaxException
;
import
java.util.concurrent.ExecutionException
;
@Service
public
class
JiraIssueServiceImpl
implements
JiraIssueService
{
...
...
@@ -36,12 +37,13 @@ public class JiraIssueServiceImpl implements JiraIssueService {
/**
* 根据项目关键字获取未解决BUG列表
*
* @param project 项目关键字,如"YXM"
* @return
* @throws Exception
*/
@Override
public
Iterable
<
Issue
>
getUnsolvedIssueListByProject
(
String
project
)
throws
Exception
{
public
Iterable
<
Issue
>
getUnsolvedIssueListByProject
(
String
project
)
throws
Exception
{
Promise
<
SearchResult
>
resultPromise
=
jiraRestClient
.
getSearchClient
().
searchJql
(
"project = "
+
project
+
" AND resolution = Unresolved ORDER BY priority DESC"
);
Iterable
<
Issue
>
issues
=
resultPromise
.
get
().
getIssues
();
return
issues
;
...
...
@@ -49,6 +51,7 @@ public class JiraIssueServiceImpl implements JiraIssueService {
/**
* 根据JQL获取BUG列表
*
* @param JQL jira JQL
* @return
* @throws Exception
...
...
@@ -72,33 +75,51 @@ public class JiraIssueServiceImpl implements JiraIssueService {
return
basicProjects
;
}
@Override
public
Issue
getJiraIssueByKey
(
String
key
)
throws
Exception
{
return
jiraRestClient
.
getIssueClient
().
getIssue
(
key
).
get
();
}
/**
* 计算BUG修复时间
* @param
create
Date BUG创建时间
* @param
updateDate
BUG最近一次更新时间
* @param
start
Date BUG创建时间
* @param
endDate
BUG最近一次更新时间
* @return
*/
public
Integer
caculBugFixTime
(
DateTime
createDate
,
DateTime
updateDate
)
{
int
createHour
=
createDate
.
getHourOfDay
();
int
updateHour
=
updateDate
.
getHourOfDay
();
if
(
createHour
>
19
)
{
createHour
=
19
;
}
else
if
(
createHour
<
10
)
{
createHour
=
10
;
@Override
public
Integer
calculateBugFixTime
(
DateTime
startDate
,
DateTime
endDate
)
{
int
startHour
=
startDate
.
getHourOfDay
();
int
endHour
=
endDate
.
getHourOfDay
();
int
startMinute
=
startDate
.
getMinuteOfHour
();
int
endMinute
=
endDate
.
getSecondOfMinute
();
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
(
updateHour
>
19
)
{
update
Hour
=
19
;
if
(
endHour
>=
19
)
{
end
Hour
=
19
;
}
int
hourDiff
;
if
(
updateHour
>
createHour
)
{
hourDiff
=
updateHour
-
createHour
-
1
;
}
else
if
(
updateHour
<
createHour
)
{
hourDiff
=
updateHour
-
createHour
+
1
;
}
else
{
hourDiff
=
updateHour
-
createHour
;
if
(
endHour
<=
10
)
{
endHour
=
10
;
}
int
days
=
Days
.
daysBetween
(
createDate
,
updateDate
).
getDays
();
return
(
days
+
1
)
*
8
+
hourDiff
;
int
hourDiff
=
endHour
-
startHour
;
int
days
=
Days
.
daysBetween
(
startDate
,
endDate
).
getDays
();
return
daySubFlag
?
days
*
8
+
hourDiff
:
(
days
+
1
)
*
8
+
hourDiff
;
}
}
src/main/java/cn/qg/holmes/task/jira/JiraToDingding.java
View file @
4b90dc76
package
cn
.
qg
.
holmes
.
task
.
jira
;
import
cn.qg.holmes.entity.jira.JiraBugPool
;
import
cn.qg.holmes.service.jira.JiraBugPoolService
;
import
cn.qg.holmes.service.jira.JiraIssueService
;
import
cn.qg.holmes.utils.DingdingUtils
;
import
com.atlassian.jira.rest.client.api.domain.Issue
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
lombok.extern.slf4j.Slf4j
;
import
org.joda.time.DateTime
;
import
org.springframework.beans.factory.annotation.Autowired
;
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
;
/**
* Jira BUG通知到钉钉定时任务类
*/
...
...
@@ -19,6 +26,9 @@ public class JiraToDingding {
@Autowired
JiraIssueService
jiraIssueService
;
@Autowired
JiraBugPoolService
jiraBugPoolService
;
@Value
(
"${sjgd.ding.url}"
)
private
String
sjgdDingUrl
;
...
...
@@ -40,4 +50,30 @@ public class JiraToDingding {
log
.
info
(
"当前部署的是mock,不执行定时任务!"
);
}
}
@Scheduled
(
cron
=
"0 */1 * * * ?"
)
public
void
cycleJiraBugPool
()
throws
Exception
{
log
.
info
(
"开始执行jira bug pool定时任务!"
);
QueryWrapper
<
JiraBugPool
>
jiraBugPoolQueryWrapper
=
new
QueryWrapper
<>();
jiraBugPoolQueryWrapper
.
eq
(
"enable"
,
1
);
List
<
JiraBugPool
>
jiraBugPoolList
=
jiraBugPoolService
.
list
(
jiraBugPoolQueryWrapper
);
for
(
JiraBugPool
jiraBugPool:
jiraBugPoolList
)
{
Issue
issue
=
jiraIssueService
.
getJiraIssueByKey
(
jiraBugPool
.
getKey
());
String
resolveResult
=
issue
.
getFieldByName
(
"解决结果"
).
getName
();
// 如果已解决或已关闭,仅修改状态
if
(
resolveResult
.
equals
(
"已解决"
)
||
resolveResult
.
equals
(
"已关闭"
))
{
jiraBugPool
.
setEnable
(
0
);
// 更新状态
jiraBugPoolService
.
saveOrUpdate
(
jiraBugPool
);
}
else
{
DateTime
startDate
=
issue
.
getCreationDate
();
DateTime
endDate
=
issue
.
getUpdateDate
();
int
duration
=
jiraIssueService
.
calculateBugFixTime
(
startDate
,
endDate
);
// 如果已超过4个小时,则发送钉钉通知
if
(
duration
>=
4
)
{
DingdingUtils
.
sendToDingding
(
jiraBugPool
.
getSummary
(),
jiraBugPool
.
getDingUrl
());
}
}
}
}
}
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