-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The behavior of the action is similar to the existing GitHub actions, and largely a cookie-cutter clone. (Some common code could be extracted into a base class, but I resisted making unnecessary changes.) Essentially, it accepts a Slack service token, a Slack channel ID, and formatter, and posts the formatted message to the designated Slack channel. Creating a `slack-channel-message` action requires two "config" parameters and one "secrets" parameter: 1 The "channel" conf value 2 The Horreum "formatter" name 3 The "token" secret The Action will always post a "mrkdwn" Slack message using the markdown document generated by the Horreum formatter template. It will post using the name of the Slack app (e.g., "Horreum Server"). Note that there's some incompatibility between GitHub and Slack markdown syntax, specifically for links. Existing Horreum markdown templates for GitHub use the `[text](url)` syntax whereas Slack uses `<url|text>`. This suggests that Horreum may need to extend the templating classes to conditionalize link formatting based on the action context. Resolves issue #838
- Loading branch information
Showing
34 changed files
with
899 additions
and
83 deletions.
There are no files selected for viewing
This file contains 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 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,68 @@ | ||
--- | ||
title: Slack | ||
date: 2024-02-22 | ||
description: Using Actions to post updates to Slack | ||
categories: [Integration] | ||
weight: 1 | ||
--- | ||
|
||
Horreum can be configured to post messages to a Slack channel through the | ||
`slack-channel-message` action. Actions can be triggered on various Horreum | ||
lifecycle events: see [Configure Actions](../../Tasks/configure-actions/index.md) | ||
for details. | ||
|
||
## Configuration | ||
|
||
Before you can configure a Slack action, either globally or for a specific | ||
test, you'll need to create and install a "Slack application" as a bot allowed | ||
to post messages to a specific Slack channel. | ||
|
||
1. Create a Slack App. You can do this through the | ||
[Slack development CLI](https://api.slack.com/automation/cli/install), or | ||
by clicking "Create New App" on the web interface at | ||
[Slack Apps](https://api.slack.com/apps): | ||
|
||
![Create Slack App](slack_app_create.png) | ||
|
||
2. Open the "OAuth & Permissions" tab and scroll down to the "Scopes" header. | ||
Add your scopes by clicking on the "Add an OAuth Scope" button. The Horreum | ||
Slack Action requires the `channels:join` and `chat:write` scopes: | ||
|
||
![Set App Scopes](slack_app_scopes.png) | ||
|
||
3. Once you've created the app, you'll need to install it in your Slack workspace. | ||
Depending on the workspace, you may need to request approval from a workspace | ||
administrator: | ||
|
||
![Install Slack App](slack_app_install.png) | ||
|
||
4. Once installation is complete, Slack will give you a "BotUser OAuth Token"; a | ||
long string that should start with "xoxb-". This token identifies and authenticates | ||
your app (in this case, the Horreum server) to Slack, and you'll need to provide | ||
this value to Horreum as the `token` secret when configuring an Action. | ||
|
||
![Find App OAuth Token](slack_app_token.png) | ||
|
||
5. Now you need to give your app permission to post to your chosen Slack channel | ||
by using your token to "join" the channel. In the Slack UI (either the web UI or | ||
in the Slack app), you can right-click on the channel and choose "View channel | ||
details". At the bottom of the sheet that opens you should see an alphanumeric | ||
string labeled "Channel ID", with a "copy to clipboard" icon following the value. | ||
|
||
![Find Slack Channel ID](slack_channel_id.png) | ||
|
||
Navigate to the online [conversations.join Test API](https://api.slack.com/methods/conversations.join/test) | ||
and enter the OAuth bot token and the Channel ID in the input boxes, and click "Test method". | ||
You should get a success API response, and you (and Horreum) can now use your OAuth token to | ||
post bot messages to the designated Slack channel ID. | ||
|
||
![Join the Conversation](slack_conversation_join.png) | ||
|
||
## Configuring a Horreum Slack Action | ||
|
||
Using either the API or the UI, you can create a Slack Action globally or | ||
for a specific Test. You will supply both the Slack channel ID and the Slack App | ||
bot token you created earlier, along with specifying the particular event and | ||
formatted template you want to post. | ||
|
||
TBD |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+57.1 KB
docs/site/content/en/docs/Integrations/slack/slack_conversation_join.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+54.4 KB
docs/site/content/en/docs/Tasks/configure-actions/githubcommentissue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+49.2 KB
docs/site/content/en/docs/Tasks/configure-actions/githubcreateissue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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 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
40 changes: 40 additions & 0 deletions
40
horreum-api/src/main/java/io/hyperfoil/tools/horreum/api/data/ActionConfig/ActionType.java
This file contains 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,40 @@ | ||
package io.hyperfoil.tools.horreum.api.data.ActionConfig; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; | ||
import org.eclipse.microprofile.openapi.annotations.media.Schema; | ||
|
||
import java.util.Arrays; | ||
|
||
@Schema(type = SchemaType.STRING, required = true, description = "Type of Action") | ||
public enum ActionType { | ||
HTTP("http", new TypeReference<HttpActionConfig>() { | ||
}), | ||
GITHUB_ISSUE_COMMENT("github-issue-comment", new TypeReference<GithubIssueCommentActionConfig>() { | ||
}), | ||
GITHUB_ISSUE_CREATE("github-issue-create", new TypeReference<GithubIssueCreateActionConfig>() { | ||
}), | ||
SLACK_MESSAGE("slack-channel-message", new TypeReference<SlackChannelMessageActionConfig>() { | ||
}); | ||
|
||
private static final ActionType[] VALUES = values(); | ||
|
||
private final String name; | ||
private final TypeReference<? extends BaseActionConfig> typeReference; | ||
|
||
private <T extends BaseActionConfig> ActionType(String name, TypeReference<T> typeReference) { | ||
this.typeReference = typeReference; | ||
this.name = name; | ||
} | ||
|
||
public <T extends BaseActionConfig> TypeReference<T> getTypeReference() { | ||
return (TypeReference<T>) typeReference; | ||
} | ||
|
||
@JsonCreator | ||
public static ActionType fromString(String str) { | ||
return Arrays.stream(VALUES).filter(v -> v.name.equals(str)).findAny() | ||
.orElseThrow(() -> new IllegalArgumentException("Unknown action: " + str)); | ||
} | ||
} |
Oops, something went wrong.