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
9750fbf2
Commit
9750fbf2
authored
Feb 17, 2022
by
黎博
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
线上@具体人
parent
12205123
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
102 additions
and
13 deletions
+102
-13
UserPhoneMap.java
src/main/java/cn/qg/holmes/config/UserPhoneMap.java
+44
-0
WebhookServiceImpl.java
...cn/qg/holmes/service/quality/impl/WebhookServiceImpl.java
+32
-7
DingdingUtils.java
src/main/java/cn/qg/holmes/utils/DingdingUtils.java
+22
-6
user-phone.json
src/main/resources/user-phone.json
+4
-0
No files found.
src/main/java/cn/qg/holmes/config/UserPhoneMap.java
0 → 100644
View file @
9750fbf2
package
cn
.
qg
.
holmes
.
config
;
import
com.alibaba.fastjson.JSON
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.core.io.ClassPathResource
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.PostConstruct
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.util.Map
;
@Slf4j
@Component
public
class
UserPhoneMap
{
public
Map
<
String
,
String
>
USER_PHONE_MAP
;
private
static
String
readJsonile
(
String
file
)
{
String
str
=
""
;
try
{
ClassPathResource
resource
=
new
ClassPathResource
(
file
);
InputStream
in
=
resource
.
getInputStream
();
BufferedReader
br
=
new
BufferedReader
(
new
InputStreamReader
(
in
));
StringBuffer
stringBuffer
=
new
StringBuffer
();
while
((
str
=
br
.
readLine
())
!=
null
)
{
stringBuffer
.
append
(
str
);
}
return
stringBuffer
.
toString
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
return
null
;
}
}
@PostConstruct
public
void
readUserPhoneMap
()
{
log
.
info
(
"开始读取 USER_PHONE_MAP."
);
USER_PHONE_MAP
=
JSON
.
parseObject
(
readJsonile
(
"user-phone.json"
),
Map
.
class
);
log
.
info
(
"读取到 USER_PHONE_MAP:{}"
,
JSON
.
toJSONString
(
USER_PHONE_MAP
));
}
}
src/main/java/cn/qg/holmes/service/quality/impl/WebhookServiceImpl.java
View file @
9750fbf2
package
cn
.
qg
.
holmes
.
service
.
quality
.
impl
;
import
cn.qg.holmes.config.UserPhoneMap
;
import
cn.qg.holmes.entity.quality.DingRobot
;
import
cn.qg.holmes.entity.quality.JiraBugPool
;
import
cn.qg.holmes.mapper.quality.DingRobotMapper
;
...
...
@@ -37,6 +38,9 @@ public class WebhookServiceImpl implements WebhookService {
@Value
(
"${jr.prod.ding.url}"
)
private
String
jrProdDingUrl
;
@Autowired
UserPhoneMap
userPhoneMap
;
/**
* 处理线上jira bug状态变化
* @param jiraData
...
...
@@ -44,6 +48,10 @@ public class WebhookServiceImpl implements WebhookService {
@Override
public
void
handleProdJiraBugUpdate
(
String
jiraData
)
{
String
webhook
=
""
;
// 是否需要@具体的人
boolean
atFlag
=
false
;
// @具体人的手机号
String
atPhoneNo
=
""
;
String
webhookEvent
=
JsonPath
.
read
(
jiraData
,
"$.webhookEvent"
);
String
eventTypeName
=
JsonPath
.
read
(
jiraData
,
"$.issue_event_type_name"
);
String
creator
=
JsonPath
.
read
(
jiraData
,
"$.issue.fields.creator.displayName"
);
...
...
@@ -53,6 +61,12 @@ public class WebhookServiceImpl implements WebhookService {
}
else
{
assignee
=
JsonPath
.
read
(
jiraData
,
"$.issue.fields.assignee.displayName"
);
}
// 将经办人替换
if
(
userPhoneMap
.
USER_PHONE_MAP
.
containsKey
(
assignee
))
{
atPhoneNo
=
userPhoneMap
.
USER_PHONE_MAP
.
get
(
assignee
);
assignee
=
"@"
+
atPhoneNo
;
atFlag
=
true
;
}
String
key
=
JsonPath
.
read
(
jiraData
,
"$.issue.key"
);
String
summary
=
JsonPath
.
read
(
jiraData
,
"$.issue.fields.summary"
);
String
priority
=
JsonPath
.
read
(
jiraData
,
"$.issue.fields.priority.name"
);
...
...
@@ -86,7 +100,14 @@ public class WebhookServiceImpl implements WebhookService {
// content += "> \n" ;
// }
// }
DingdingUtils
.
sendToDingding
(
DingdingUtils
.
buildMarkdownMsg
(
title
,
content
,
true
),
webhook
);
// 构建markdown消息
String
markdownMsg
;
if
(
atFlag
)
{
markdownMsg
=
DingdingUtils
.
buildMarkdownMsgAtSpecifyPhone
(
title
,
content
,
atPhoneNo
,
false
);
}
else
{
markdownMsg
=
DingdingUtils
.
buildMarkdownMsg
(
title
,
content
,
false
);
}
DingdingUtils
.
sendToDingding
(
markdownMsg
,
webhook
);
}
// BUG更新的时候发送通知
if
(
StringUtils
.
equals
(
webhookEvent
,
"jira:issue_updated"
))
{
...
...
@@ -102,7 +123,6 @@ public class WebhookServiceImpl implements WebhookService {
content
+=
"📣研发工单 "
+
key
+
" 状态更新:"
+
"\n\n"
;
content
+=
"概要:["
+
summary
+
"]("
+
issueUrl
+
")"
+
"\n\n"
;
content
+=
"状态变更为:【处理中】\n\n"
;
DingdingUtils
.
sendToDingding
(
DingdingUtils
.
buildMarkdownMsg
(
title
,
content
,
false
),
webhook
);
break
;
case
"issue_resolved"
:
// BUG状态变为【已解决】
...
...
@@ -112,7 +132,6 @@ public class WebhookServiceImpl implements WebhookService {
content
+=
"状态变更为:【已解决】\n\n"
;
// content += "状态变更为:【已解决】, 解决结果为:【" + JsonPath.read(jiraData, "$.changelog.items[0].toString") + "】\n\n";
content
+=
"请相关同学跟进验收~"
;
DingdingUtils
.
sendToDingding
(
DingdingUtils
.
buildMarkdownMsg
(
title
,
content
,
false
),
webhook
);
break
;
case
"issue_reopened"
:
// BUG状态变为【重新打开】
...
...
@@ -121,7 +140,6 @@ public class WebhookServiceImpl implements WebhookService {
content
+=
"概要:["
+
summary
+
"]("
+
issueUrl
+
")"
+
"\n\n"
;
content
+=
"状态变更为:【重新打开】\n\n"
;
content
+=
"请相关同学再跟进一下~"
;
DingdingUtils
.
sendToDingding
(
DingdingUtils
.
buildMarkdownMsg
(
title
,
content
,
false
),
webhook
);
break
;
case
"issue_closed"
:
// BUG状态变为【关闭】
...
...
@@ -140,7 +158,6 @@ public class WebhookServiceImpl implements WebhookService {
content
+=
"> "
+
comment
+
"\n\n"
;
}
}
DingdingUtils
.
sendToDingding
(
DingdingUtils
.
buildMarkdownMsg
(
title
,
content
,
false
),
webhook
);
break
;
case
"issue_updated"
:
// BUG更新
...
...
@@ -150,13 +167,21 @@ public class WebhookServiceImpl implements WebhookService {
content
+=
"📣研发工单 "
+
key
+
" 经办人变更:"
+
"\n\n"
;
content
+=
"概要:["
+
summary
+
"]("
+
issueUrl
+
")"
+
"\n\n"
;
content
+=
"- 原经办人:"
+
JsonPath
.
read
(
jiraData
,
"$.changelog.items[0].fromString"
)
+
"\n"
;
content
+=
"- 新经办人:"
+
JsonPath
.
read
(
jiraData
,
"$.changelog.items[0].toString"
)
+
"\n"
;
DingdingUtils
.
sendToDingding
(
DingdingUtils
.
buildMarkdownMsg
(
title
,
content
,
false
),
webhook
)
;
//
content += "- 新经办人:" + JsonPath.read(jiraData, "$.changelog.items[0].toString") + "\n";
content
+=
"- 新经办人:"
+
assignee
+
"\n"
;
}
break
;
default
:
break
;
}
// 发送消息
String
markdownMsg
;
if
(
atFlag
)
{
markdownMsg
=
DingdingUtils
.
buildMarkdownMsgAtSpecifyPhone
(
title
,
content
,
atPhoneNo
,
false
);
}
else
{
markdownMsg
=
DingdingUtils
.
buildMarkdownMsg
(
title
,
content
,
false
);
}
DingdingUtils
.
sendToDingding
(
markdownMsg
,
webhook
);
}
}
...
...
src/main/java/cn/qg/holmes/utils/DingdingUtils.java
View file @
9750fbf2
...
...
@@ -52,6 +52,22 @@ public class DingdingUtils {
return
JSON
.
toJSONString
(
markdown
);
}
public
static
String
buildMarkdownMsgAtSpecifyPhone
(
String
title
,
String
content
,
String
phoneNo
,
boolean
atAll
)
{
Map
<
String
,
Object
>
markdown
=
new
HashMap
<>();
Map
<
String
,
String
>
contentMap
=
new
HashMap
<>();
Map
<
String
,
Object
>
atMap
=
new
HashMap
<>();
List
<
String
>
atMobileList
=
new
ArrayList
<>();
atMobileList
.
add
(
phoneNo
);
atMap
.
put
(
"atMobiles"
,
atMobileList
);
atMap
.
put
(
"isAtAll"
,
atAll
);
markdown
.
put
(
"at"
,
atMap
);
markdown
.
put
(
"msgtype"
,
"markdown"
);
contentMap
.
put
(
"title"
,
title
);
contentMap
.
put
(
"text"
,
content
);
markdown
.
put
(
"markdown"
,
contentMap
);
return
JSON
.
toJSONString
(
markdown
);
}
/**
* 构建BUG刚提交时,发送给钉钉的markdown消息
* @param key jira issue key
...
...
@@ -361,18 +377,18 @@ public class DingdingUtils {
"详情:客户表示申请借款无法操作,提示存在在途业务,无法申请借款,请处理,谢谢"
;
// attachmentList.add("http://jira2.quantgroup.cn/secure/attachment/17004/%E5%BD%A9%E8%89%B2Q_%E7%94%BB%E6%9D%BF+1.jpg");
// attachmentList.add("http://jira2.quantgroup.cn/secure/attachment/17013/image.png");
attachmentList
.
add
(
"https://gw.alicdn.com/tfs/TB1ut3xxbsrBKNjSZFpXXcXhFXa-846-786.png"
);
//
attachmentList.add("https://gw.alicdn.com/tfs/TB1ut3xxbsrBKNjSZFpXXcXhFXa-846-786.png");
content
+=
"概要:["
+
"【定时推送】啦啦啦"
+
"]("
+
issueUrl
+
")"
+
"\n\n"
+
"- 优先级:"
+
"P3一般"
+
"\n"
+
"- 经办人:"
+
"
王晓彤
"
+
"\n\n"
;
+
"- 经办人:"
+
"
@18311069063
"
+
"\n\n"
;
String
[]
descList
=
description
.
split
(
"\n"
);
for
(
String
desc:
descList
)
{
content
+=
"> "
+
desc
+
"\n\n"
;
}
for
(
String
attachment:
attachmentList
)
{
content
+=
"> 
\n"
;
}
String
msg
=
buildMarkdownMsg
(
title
,
content
,
false
);
//
for (String attachment: attachmentList) {
// content += "> \n
\n";
//
}
String
msg
=
buildMarkdownMsg
AtSpecifyPhone
(
title
,
content
,
"18501033527"
,
false
);
sendToDingding
(
msg
,
"https://oapi.dingtalk.com/robot/send?access_token=835663338d638e40daaf3ab358af741ef0680a826a962c91bedc53b149d85ee1"
);
}
}
src/main/resources/user-phone.json
0 → 100644
View file @
9750fbf2
{
"黎博"
:
"18311069063"
,
"温海元"
:
"18501033527"
}
\ No newline at end of file
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