Skip to content

Commit

Permalink
feat: add enable slack link_names
Browse files Browse the repository at this point in the history
  • Loading branch information
bogaertg committed Mar 16, 2021
1 parent e083b16 commit 4c41b90
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ SLACK_MSG_AUTHOR | `$GITHUB_ACTOR` (The person who triggered action). | GitH
SLACK_ICON | ![rtBot Avatar](https://github.com/rtBot.png?size=32) | User/Bot icon shown with Slack message. It uses the URL supplied to this env variable to display the icon in slack message.
SLACK_ICON_EMOJI | - | User/Bot icon shown with Slack message, in case you do not wish to add a URL for slack icon as above, you can set slack emoji in this env variable. Example value: `:bell:` or any other valid slack emoji.
SLACK_COLOR | `good` (green) | You can pass ${{job.status}} for automatic coloring or an RGB value like `#efefef` which would change color on left side vertical line of Slack message.
SLACK_LINK_NAMES | - | If set to `true`, enable mention in Slack message.
SLACK_MESSAGE | Generated from git commit message. | The main Slack message in attachment. It is advised not to override this.
SLACK_TITLE | Message | Title to use before main Slack message.
SLACK_FOOTER | Powered By rtCamp's GitHub Actions Library | Slack message footer.
Expand Down
3 changes: 1 addition & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ description: 'This action will send a notification to Slack'
author: 'rtCamp'
runs:
using: 'docker'
# image: 'docker://ghcr.io/rtcamp/action-slack-notify:v2.1.3'
image: 'Dockerfile'
image: 'docker://ghcr.io/rtcamp/action-slack-notify:v2.1.3'
branding:
icon: 'bell'
color: 'yellow'
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const (
EnvSiteName = "SITE_NAME"
EnvHostName = "HOST_NAME"
EnvMinimal = "MSG_MINIMAL"
EnvSlackLinkNames = "SLACK_LINK_NAMES"
)

type Webhook struct {
Expand All @@ -31,7 +32,7 @@ type Webhook struct {
IconURL string `json:"icon_url,omitempty"`
IconEmoji string `json:"icon_emoji,omitempty"`
Channel string `json:"channel,omitempty"`
LinkNames int `json:"link_names,omitempty"`
LinkNames string `json:"link_names,omitempty"`
UnfurlLinks bool `json:"unfurl_links"`
Attachments []Attachment `json:"attachments,omitempty"`
}
Expand Down Expand Up @@ -196,7 +197,7 @@ func main() {
IconURL: os.Getenv(EnvSlackIcon),
IconEmoji: os.Getenv(EnvSlackIconEmoji),
Channel: os.Getenv(EnvSlackChannel),
LinkNames: 1,
LinkNames: os.Getenv(EnvSlackLinkNames),
Attachments: []Attachment{
{
Fallback: envOr(EnvSlackMessage, "GITHUB_ACTION="+os.Getenv("GITHUB_ACTION")+" \n GITHUB_ACTOR="+os.Getenv("GITHUB_ACTOR")+" \n GITHUB_EVENT_NAME="+os.Getenv("GITHUB_EVENT_NAME")+" \n GITHUB_REF="+os.Getenv("GITHUB_REF")+" \n GITHUB_REPOSITORY="+os.Getenv("GITHUB_REPOSITORY")+" \n GITHUB_WORKFLOW="+os.Getenv("GITHUB_WORKFLOW")),
Expand Down
9 changes: 3 additions & 6 deletions main.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env bash

export GITHUB_BRANCH=${GITHUB_REF##*heads/}
export SLACK_ICON=${SLACK_ICON}
export SLACK_USERNAME=${SLACK_USERNAME}
export SLACK_ICON=${SLACK_ICON:-"https://avatars0.githubusercontent.com/u/43742164"}
export SLACK_USERNAME=${SLACK_USERNAME:-"rtBot"}
export CI_SCRIPT_OPTIONS="ci_script_options"
export SLACK_TITLE=${SLACK_TITLE:-"Message"}
export COMMIT_MESSAGE=$(cat "$GITHUB_EVENT_PATH" | jq -r '.commits[-1].message')
Expand Down Expand Up @@ -31,10 +31,7 @@ if [[ -n "$VAULT_GITHUB_TOKEN" ]] || [[ -n "$VAULT_TOKEN" ]]; then
fi

if [[ -f "$hosts_file" ]]; then
hostname=$(cat "$hosts_file" | shyaml get-value "$
.hostname")
hostname=$(cat "$hosts_file" | shyaml get-value "$GITHUB_BRANCH.hostname")
user=$(cat "$hosts_file" | shyaml get-value "$GITHUB_BRANCH.user")
export HOST_NAME="\`$user@$hostname\`"
export DEPLOY_PATH=$(cat "$hosts_file" | shyaml get-value "$GITHUB_BRANCH.deploy_path")
Expand Down

0 comments on commit 4c41b90

Please sign in to comment.