1
0
mirror of https://github.com/jenkinsci/mattermost-plugin.git synced 2024-11-24 08:12:36 +02:00

Use the 'attachments' (Mattermost supports this since some time)

This commit is contained in:
Jo Vandeginste 2016-05-02 13:11:35 +02:00
parent bb11e74709
commit 31b0e76fab
2 changed files with 21 additions and 2 deletions

View File

@ -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;
}

View File

@ -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);