-
Notifications
You must be signed in to change notification settings - Fork 90
add rocket chat client and allure testops integration #163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
507aa3c
8585c51
76eff83
519e49c
b3e19a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,16 @@ | ||
# Allure notifications | ||
**Allure notifications** - это библиотека, позволяющая выполнять автоматическое оповещение о результатах прохождения автотестов, которое направляется в нужный вам мессенджер (Telegram, Slack, Skype, Email, Mattermost). | ||
|
||
| Telegram | Slack | | ||
:-------------------------:|:-------------------------: | ||
 |  | ||
| **Mattermost** | **Email** | | ||
 |  | ||
| **RocketChat** | | ||
 | | ||
| **Skype** | **Icq** | | ||
| Done | Wat? lol | | ||
|
||
Languages: 🇬🇧 🇫🇷 🇷🇺 🇺🇦 🇧🇾 🇨🇳 | ||
|
||
## Содержание | ||
|
@@ -11,6 +21,22 @@ Languages: 🇬🇧 🇫🇷 🇷🇺 🇺🇦 🇧🇾 🇨🇳 | |
+ [для запуска из Jenkins](#Jenkins) | ||
+ [Особенности заполнения файла config.json в зависимости от выбранного мессенджера](#config) | ||
|
||
<h6>How to:</h6> | ||
|
||
- [x] [Telegram config](https://github.com/qa-guru/allure-notifications/wiki/Telegram-configuration) | ||
- [x] [Slack config](https://github.com/qa-guru/allure-notifications/wiki/Slack-configuration) | ||
- [x] [Email config](https://github.com/qa-guru/allure-notifications/wiki/Email-configuration) | ||
- [x] [Skype config](https://github.com/qa-guru/allure-notifications/wiki/Skype-configuration) | ||
- [x] [Mattermost config](https://github.com/qa-guru/allure-notifications/wiki/Mattermost-configuration) | ||
- [x] [Rocket config] | ||
|
||
|
||
<h6>CommandLine options</h6> | ||
All keys should be used with `-D`: <br/> | ||
|
||
| key | description | | ||
|:---:| :---------: | | ||
| configFile | Path to JSON-config file | | ||
|
||
<a name="Принцип"> | ||
|
||
|
@@ -92,6 +118,12 @@ Languages: 🇬🇧 🇫🇷 🇷🇺 🇺🇦 🇧🇾 🇨🇳 | |
"token": "", | ||
"chat": "" | ||
}, | ||
"rocket" : { | ||
"url": "", | ||
"auth_token": "", | ||
"user_id": "", | ||
"channel": "" | ||
}, | ||
"skype": { | ||
"appId": "", | ||
"appSecret": "", | ||
|
@@ -109,6 +141,12 @@ Languages: 🇬🇧 🇫🇷 🇷🇺 🇺🇦 🇧🇾 🇨🇳 | |
"from": "", | ||
"recipient": "" | ||
}, | ||
"testOps": { | ||
"url": "", | ||
"auth_token": "", | ||
"xsrf_token": "", | ||
"project_id": "" | ||
}, | ||
"proxy": { | ||
"host": "", | ||
"port": 0, | ||
|
@@ -117,6 +155,11 @@ Languages: 🇬🇧 🇫🇷 🇷🇺 🇺🇦 🇧🇾 🇨🇳 | |
} | ||
} | ||
``` | ||
You only need: | ||
- to fill needed options in `base` block (please, be careful, `language` field is required!); | ||
- to configure desired destinations for notifications (`telegram`, `slack`, `mattermost`, `skype`, `mail`), keep in mind it's possible to set multiple destinations at once, if no destination is set, then no notification will be sent and no error will occur; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add rocket |
||
- to specify optional proxy configuration in `proxy` block. | ||
- if you need Allure TestOps integration, you must fill field `enableTestOpsIntegration` in `base` block and fill `testOps` block | ||
Блок `proxy` используется если нужно указать дополнительную конфигурацию proxy. | ||
|
||
<a name="Base"> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,8 @@ dependencies { | |
implementation('com.jayway.jsonpath:json-path:2.7.0') | ||
implementation('commons-io:commons-io:2.11.0') | ||
implementation('org.apache.commons:commons-lang3:3.12.0') | ||
implementation('io.rest-assured:rest-assured:4.4.0') | ||
implementation('org.jboss.resteasy:resteasy-jackson2-provider:3.0.6.Final') | ||
Comment on lines
+30
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are these dependencies used somewhere? |
||
|
||
testImplementation('org.junit.jupiter:junit-jupiter:5.9.0') | ||
testImplementation('org.springframework:spring-test:5.3.22') { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package guru.qa.allure.notifications.chart; | ||
|
||
import guru.qa.allure.notifications.config.testops.TestOps; | ||
import guru.qa.allure.notifications.exceptions.MessageBuildException; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.knowm.xchart.BitmapEncoder; | ||
|
@@ -9,6 +10,7 @@ | |
import java.awt.image.BufferedImage; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import javax.imageio.ImageIO; | ||
import java.io.File; | ||
|
@@ -19,14 +21,23 @@ | |
public class Chart { | ||
|
||
public static byte[] createChart(Base base) throws MessageBuildException { | ||
return createChart(base, null); | ||
} | ||
public static byte[] createChart(Base base, TestOps testOps) throws MessageBuildException { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the thing here is generic Chart starts "knowing" about TestOps, which is not good if low coupling is followed |
||
log.info("Creating chart..."); | ||
PieChart chart = ChartBuilder.createBaseChart(base); | ||
log.info("Adding legend to chart..."); | ||
ChartLegend.addLegendTo(chart); | ||
log.info("Adding view to chart..."); | ||
ChartView.addViewTo(chart); | ||
log.info("Adding series to chart..."); | ||
List<Color> colors = new ChartSeries(base).addSeriesTo(chart); | ||
List<Color> colors; | ||
if (base.getEnableTestOpsIntegration()) { | ||
colors = new ChartSeries(base, testOps).addSeriesTo(chart); | ||
} | ||
else { | ||
colors = new ChartSeries(base).addSeriesTo(chart); | ||
} | ||
log.info("Adding colors to series..."); | ||
chart.getStyler().setSeriesColors(colors.toArray(new Color[0])); | ||
BufferedImage chartImage = BitmapEncoder.getBufferedImage(chart); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package guru.qa.allure.notifications.clients.rocket; | ||
|
||
import guru.qa.allure.notifications.clients.Notifier; | ||
import guru.qa.allure.notifications.config.rocket.Rocket; | ||
import guru.qa.allure.notifications.exceptions.MessagingException; | ||
import guru.qa.allure.notifications.json.JSON; | ||
import guru.qa.allure.notifications.template.MarkdownTemplate; | ||
import guru.qa.allure.notifications.template.RocketTemplate; | ||
import guru.qa.allure.notifications.template.data.MessageData; | ||
import kong.unirest.ContentType; | ||
import kong.unirest.Unirest; | ||
|
||
import java.io.ByteArrayInputStream; | ||
public class RocketClient implements Notifier { | ||
private final JSON json = new JSON(); | ||
private final Rocket rocket; | ||
private final RocketTemplate template; | ||
|
||
public RocketClient(MessageData messageData, Rocket rocket) { | ||
this.rocket = rocket; | ||
this.template = new RocketTemplate(messageData); | ||
} | ||
|
||
@Override | ||
public void sendText() throws MessagingException { | ||
String body = String.format("{\"channel\": \"%s\", \"text\": \"%s\" }", | ||
rocket.getChannel(), template.create().replace("\r\n", "\\\n")); | ||
String url = String.format("%s/api/v1/chat.postMessage", rocket.getUrl()); | ||
Unirest.post(url) | ||
.header("X-Auth-Token", rocket.getToken()) | ||
.header("X-User-Id", rocket.getUserId()) | ||
.header("Content-Type", "application/json") | ||
.body(json.prettyPrint(body)) | ||
.asString() | ||
.getBody(); | ||
} | ||
|
||
@Override | ||
public void sendPhoto(byte[] chartImage) throws MessagingException { | ||
sendText(); | ||
String url = String.format("%s/api/v1/rooms.upload/%s", rocket.getUrl(), rocket.getChannel()); | ||
|
||
Unirest.post(url) | ||
.header("X-Auth-Token", rocket.getToken()) | ||
.header("X-User-Id", rocket.getUserId()) | ||
.field("file", new ByteArrayInputStream(chartImage), ContentType.IMAGE_PNG, "chart.png") | ||
.asString() | ||
.getBody(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package guru.qa.allure.notifications.config.rocket; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
import lombok.Data; | ||
|
||
/** | ||
* @author GerasimchukDV | ||
* @since 4.2.2 | ||
* Model class representing Rocket client settings. | ||
*/ | ||
@Data | ||
public class Rocket { | ||
@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,23 @@ | ||
package guru.qa.allure.notifications.config.testops; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
import lombok.Data; | ||
|
||
/** | ||
* @author GerasimchukDV | ||
* @since 4.2.2 | ||
* Model class representing Allure TestOps client settings. | ||
*/ | ||
|
||
@Data | ||
public class TestOps { | ||
@SerializedName("url") | ||
private String url; | ||
@SerializedName("auth_token") | ||
private String auth_token; | ||
|
||
@SerializedName("xsrf_token") | ||
private String xsrf_token; | ||
@SerializedName("project_id") | ||
private String projectId; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,14 @@ | |
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
import com.google.gson.JsonParser; | ||
import com.google.gson.JsonSyntaxException; | ||
import com.google.gson.stream.JsonReader; | ||
import guru.qa.allure.notifications.exceptions.ConfigNotFoundException; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.io.FileNotFoundException; | ||
import java.io.FileReader; | ||
import java.io.StringReader; | ||
|
||
/** | ||
* @author kadehar | ||
|
@@ -28,6 +31,15 @@ public <T> T parse(String file, Class<T> clazz) { | |
} | ||
|
||
public String prettyPrint(String json) { | ||
return GSON.toJson(JsonParser.parseString(json)); | ||
String result = ""; | ||
try { | ||
result = GSON.toJson(JsonParser.parseString(json)); | ||
} | ||
catch (JsonSyntaxException e) { | ||
JsonReader reader = new JsonReader(new StringReader(json)); | ||
reader.setLenient(true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this tweak needed? |
||
result = GSON.toJson(JsonParser.parseReader(reader)); | ||
} | ||
return result; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
broken link