Skip to content

Commit

Permalink
2.0.1 (#21)
Browse files Browse the repository at this point in the history
1. fix: 修复关键字显示为 null

2. fix: 修复 timestamp 未更新导致消息发送失败
  • Loading branch information
liuweiGL committed Mar 21, 2020
1 parent f54e9a8 commit e58f958
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>
<groupId>io.jenkins.plugins</groupId>
<artifactId>dingding-notifications</artifactId>
<version>2.0.1-SNAPSHOT</version>
<version>2.0.2-SNAPSHOT</version>
<packaging>hpi</packaging>
<properties>
<!-- 除了 jdk 版本,其他的在 org.jenkins-ci.plugins.plugin 中都定义了 -->
Expand Down
27 changes: 15 additions & 12 deletions src/main/java/io/jenkins/plugins/tools/DingTalkSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,54 +26,57 @@ public class DingTalkSender {
*/
public static final String MSG_TYPE = "actionCard";

private RobotConfigModel robotConfigModel;

/**
* 在标题里包含关键字验证
*/
private String title;

private TaobaoClient client;


public DingTalkSender(DingTalkRobotConfig robot) {
RobotConfigModel robotConfigModel = RobotConfigModel.of(robot);
this.title = "Jenkins 通知:" + robotConfigModel.getKeys();
this.client = new DefaultDingTalkClient(robotConfigModel.getServer());
this.robotConfigModel = RobotConfigModel.of(robot);
String keys = robotConfigModel.getKeys();
this.title = "Jenkins 构建通知";
if (keys != null) {
this.title += "关键字:" + keys;
}
}


public String send(BuildJobModel buildJobModel) {

List<Btns> btnsList = new ArrayList<>();
List<Btns> btnList = new ArrayList<>();
String changeLog = buildJobModel.getChangeLog();
String console = buildJobModel.getConsole();

if (!StringUtils.isEmpty(changeLog)) {
Btns changeLogBtn = new Btns();
changeLogBtn.setTitle("更改记录");
changeLogBtn.setActionURL(changeLog);
btnsList.add(changeLogBtn);
btnList.add(changeLogBtn);
}

if (!StringUtils.isEmpty(console)) {
Btns consoleBtn = new Btns();
consoleBtn.setTitle("控制台");
consoleBtn.setActionURL(console);
btnsList.add(consoleBtn);
btnList.add(consoleBtn);
}

OapiRobotSendRequest.Actioncard actionCard = new OapiRobotSendRequest.Actioncard();
actionCard.setTitle(this.title);
actionCard.setTitle(title);
actionCard.setText(buildJobModel.getText());
actionCard.setBtnOrientation("1");
actionCard.setBtns(btnsList);
actionCard.setBtns(btnList);

OapiRobotSendRequest request = new OapiRobotSendRequest();
request.setMsgtype(MSG_TYPE);
request.setActionCard(actionCard);
request.setAt(buildJobModel.getAt());

try {
OapiRobotSendResponse response = this.client.execute(request);
OapiRobotSendResponse response = new DefaultDingTalkClient(robotConfigModel.getServer())
.execute(request);
if (!response.isSuccess()) {
return response.getErrmsg();
}
Expand Down

0 comments on commit e58f958

Please sign in to comment.