Skip to content
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Allure notifications
**Allure notifications** - это библиотека, позволяющая выполнять автоматическое оповещение о результатах прохождения автотестов, которое направляется в нужный вам мессенджер (Telegram, Slack, Skype, Email, Mattermost, Discord, Loop).
**Allure notifications** - это библиотека, позволяющая выполнять автоматическое оповещение о результатах прохождения автотестов, которое направляется в нужный вам мессенджер (Telegram, Slack, Skype, Email, Mattermost, Discord, Loop, Rocket.Chat).

Languages: 🇬🇧 🇫🇷 🇷🇺 🇺🇦 🇧🇾 🇨🇳

Expand Down Expand Up @@ -92,6 +92,12 @@ Languages: 🇬🇧 🇫🇷 🇷🇺 🇺🇦 🇧🇾 🇨🇳
"token": "",
"chat": ""
},
"rocketChat" : {
"url": "",
"auth_token": "",
"user_id": "",
"channel": ""
},
"skype": {
"appId": "",
"appSecret": "",
Expand Down Expand Up @@ -246,4 +252,19 @@ java "-DconfigFile=notifications/config.json" -jar ../allure-notifications-4.2.1
<li>Click "Save".</li>
<li>Copy URL of webhook.</li>
</ul>
</details>
+ <details>
<summary>Rocket.Chat config</summary>
To enable Rocket.Chat notifications it's required to provide 4 configuration parameters:
<code>url</code>, <code>auth_token</code>,<code>user_id</code>,<code>channel</code>
<ul>
<li>
<ol>
<li>First of all you need to generate auth_token from user setting.</li>
<li>After generation you can get auth_token and user_id.</li>
<li>You can get the channel parameter using previously generated tokens and following the documentation.</li>
+ (<a href="https://developer.rocket.chat/reference/api/rest-api/endpoints/rooms/channels-endpoints/info" target="_blank">Channels info docs</a>)
</ol>
</li>
</ul>
</details>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package guru.qa.allure.notifications.clients;

import guru.qa.allure.notifications.clients.rocket.RocketChatClient;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -40,6 +41,9 @@ public static List<Notifier> from(Config config) {
if (config.getLoop() != null) {
notifiers.add(new LoopClient(messageData, config.getLoop()));
}
if (config.getRocketChat() != null) {
notifiers.add(new RocketChatClient(messageData, config.getRocketChat()));
}
return notifiers;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package guru.qa.allure.notifications.clients.rocket;

import guru.qa.allure.notifications.clients.Notifier;
import guru.qa.allure.notifications.config.rocket.RocketChat;
import guru.qa.allure.notifications.exceptions.MessagingException;
import guru.qa.allure.notifications.template.RocketTemplate;
import guru.qa.allure.notifications.template.data.MessageData;
import java.io.ByteArrayInputStream;
import java.util.HashMap;
import java.util.Map;
import kong.unirest.ContentType;
import kong.unirest.Unirest;

public class RocketChatClient implements Notifier {

private final Map<String, Object> body = new HashMap<>();
private final RocketChat rocketChat;
private final RocketTemplate template;

public RocketChatClient(MessageData messageData, RocketChat rocket) {
this.rocketChat = rocket;
this.template = new RocketTemplate(messageData);
}

@Override
public void sendText() throws MessagingException {
body.put("channel", rocketChat.getChannel());
body.put("text", template.create());
Unirest.post(rocketChat.getUrl() + "/api/v1/chat.postMessage")
.header("X-Auth-Token", rocketChat.getToken())
.header("X-User-Id", rocketChat.getUserId())
.header("Content-Type", ContentType.APPLICATION_JSON.getMimeType())
.body(body)
.asString()
.getBody();
}

@Override
public void sendPhoto(byte[] chartImage) throws MessagingException {
sendText();
String url = String.format("%s/api/v1/rooms.upload/%s", rocketChat.getUrl(), rocketChat.getChannel());
Unirest.post(url)
.header("X-Auth-Token", rocketChat.getToken())
.header("X-User-Id", rocketChat.getUserId())
.field("file", new ByteArrayInputStream(chartImage), ContentType.IMAGE_PNG, "chart.png")
.asString()
.getBody();
}
}
3 changes: 3 additions & 0 deletions src/main/java/guru/qa/allure/notifications/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import guru.qa.allure.notifications.config.mail.Mail;
import guru.qa.allure.notifications.config.mattermost.Mattermost;
import guru.qa.allure.notifications.config.proxy.Proxy;
import guru.qa.allure.notifications.config.rocket.RocketChat;
import guru.qa.allure.notifications.config.skype.Skype;
import guru.qa.allure.notifications.config.slack.Slack;
import guru.qa.allure.notifications.config.telegram.Telegram;
Expand Down Expand Up @@ -35,6 +36,8 @@ public class Config {
private Discord discord;
@SerializedName("loop")
private Loop loop;
@SerializedName("rocketChat")
private RocketChat rocketChat;
@SerializedName("proxy")
private Proxy proxy;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package guru.qa.allure.notifications.config.rocket;

import com.google.gson.annotations.SerializedName;
import lombok.Getter;

@Getter
public class RocketChat {

@SerializedName("url")
private String url;
@SerializedName("auth_token")
private String token;
@SerializedName("user_id")
private String userId;
@SerializedName("channel")
private String channel;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package guru.qa.allure.notifications.template;

import guru.qa.allure.notifications.exceptions.MessageBuildException;
import guru.qa.allure.notifications.template.data.MessageData;

public class RocketTemplate {

private final MessageData messageData;

public RocketTemplate(MessageData messageData) {
this.messageData = messageData;
}

public String create() throws MessageBuildException {
return new MessageTemplate(messageData).of("rocket.ftl");
}
}
13 changes: 13 additions & 0 deletions src/main/resources/templates/rocket.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<#compress>
**${results}:**
**-${environment}:** ${env}
**-${comment}:** ${comm}
**-${duration}:** **${time}**
**-${totalScenarios}:** ${total}
<#if passed != 0 > **-${totalPassed}:** ${passed} **(${passedPercentage} %)**</#if>
<#if failed != 0 > **-${totalFailed}:** ${failed} **(${failedPercentage} %)** </#if>
<#if broken != 0 > **-${totalBroken}:** ${broken} </#if>
<#if unknown != 0 > **-${totalUnknown}:** ${unknown} </#if>
<#if skipped != 0 > **-${totalSkipped}:** ${skipped} </#if>
<#if reportLink??>**${reportAvailableAtLink}:** ${reportLink}</#if>
</#compress>