Skip to content

Commit

Permalink
Add username@channel option
Browse files Browse the repository at this point in the history
  • Loading branch information
jovandeginste committed Sep 20, 2016
1 parent f41aafb commit a72abf6
Showing 1 changed file with 16 additions and 2 deletions.
Expand Up @@ -39,9 +39,23 @@ public boolean publish(String message) {

public boolean publish(String message, String color) {
boolean result = true;
for (String roomId : roomIds) {
for (String userAndRoomId : roomIds) {
String url = endpoint;
String roomId = "";
String userId = "jenkins";
String[] splitUserAndRoomId = userAndRoomId.split("@");
switch (splitUserAndRoomId.length) {
case 1:
roomId = splitUserAndRoomId[0];
break;
case 2:
userId = splitUserAndRoomId[0];
roomId = splitUserAndRoomId[1];
break;
}

String roomIdString = roomId;

if (StringUtils.isEmpty(roomIdString)) {
roomIdString = "(default)";
}
Expand Down Expand Up @@ -72,7 +86,7 @@ public boolean publish(String message, String color) {
json.put("attachments", attachments);

if (!roomId.isEmpty()) json.put("channel", roomId);
json.put("username", "jenkins");
json.put("username", userId);
json.put("icon_url", icon);

post.addParameter("payload", json.toString());
Expand Down

0 comments on commit a72abf6

Please sign in to comment.