-
Notifications
You must be signed in to change notification settings - Fork 90
add rocket chat client #229
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
Merged
Merged
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
9c80d2b
wip
464a414
wip
65cdddf
Update src/main/java/guru/qa/allure/notifications/clients/rocket/Rock…
exmike 1294728
Update README.md
exmike c3873ab
Update README.md
exmike 67aaf0d
Update README.md
exmike c62bc92
Update README.md
exmike 99c7129
Update README.md
exmike cb50c12
Update src/main/java/guru/qa/allure/notifications/clients/rocket/Rock…
exmike 3de636d
Apply suggestions from code review
exmike 8df98df
fixes after review
27f5f2f
rename
296ce2d
fix README.md
5bf96ef
update rocket.ftl
4dd4a64
review
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/main/java/guru/qa/allure/notifications/clients/rocket/RocketChatClient.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/main/java/guru/qa/allure/notifications/config/rocket/RocketChat.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/guru/qa/allure/notifications/template/RocketTemplate.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
exmike marked this conversation as resolved.
Show resolved
Hide resolved
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.