From 31b0e76fabe061e386951b15f44a55d93ab3e5f3 Mon Sep 17 00:00:00 2001 From: Jo Vandeginste Date: Mon, 2 May 2016 13:11:35 +0200 Subject: [PATCH] Use the 'attachments' (Mattermost supports this since some time) --- .../plugins/mattermost/ActiveNotifier.java | 2 +- .../mattermost/StandardMattermostService.java | 21 ++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main/java/jenkins/plugins/mattermost/ActiveNotifier.java b/src/main/java/jenkins/plugins/mattermost/ActiveNotifier.java index 1ee1f5f..ac46f9c 100755 --- a/src/main/java/jenkins/plugins/mattermost/ActiveNotifier.java +++ b/src/main/java/jenkins/plugins/mattermost/ActiveNotifier.java @@ -272,7 +272,7 @@ public class ActiveNotifier implements FineGrainedNotifier { public MessageBuilder appendOpenLink() { String url = notifier.getBuildServerUrl() + build.getUrl(); - message.append(" (<").append(url).append("|Open>)"); + message.append(" [Open](").append(url).append(")"); return this; } diff --git a/src/main/java/jenkins/plugins/mattermost/StandardMattermostService.java b/src/main/java/jenkins/plugins/mattermost/StandardMattermostService.java index 0bab699..0419abe 100755 --- a/src/main/java/jenkins/plugins/mattermost/StandardMattermostService.java +++ b/src/main/java/jenkins/plugins/mattermost/StandardMattermostService.java @@ -9,6 +9,7 @@ import org.apache.commons.httpclient.auth.AuthScope; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.lang.StringUtils; import org.json.JSONObject; +import org.json.JSONArray; import java.net.MalformedURLException; import java.net.URL; @@ -51,8 +52,26 @@ public class StandardMattermostService implements MattermostService { JSONObject json = new JSONObject(); try { + JSONObject field = new JSONObject(); + field.put("short", false); + field.put("value", message); + JSONArray fields = new JSONArray(); + fields.put(field); + + JSONObject attachment = new JSONObject(); + attachment.put("fallback", message); + attachment.put("color", color); + attachment.put("fields", fields); + JSONArray mrkdwn = new JSONArray(); + mrkdwn.put("pretext"); + mrkdwn.put("text"); + mrkdwn.put("fields"); + attachment.put("mrkdwn_in", mrkdwn); + JSONArray attachments = new JSONArray(); + attachments.put(attachment); + json.put("attachments", attachments); + if (!roomId.isEmpty()) json.put("channel", roomId); - json.put("text", message); json.put("username", "jenkins"); json.put("icon_url", icon);