Skip to content

Commit

Permalink
Merge pull request #2 from L0RD-ZER0/enhancement/escapes
Browse files Browse the repository at this point in the history
Allow use of escape sequences in messages
  • Loading branch information
L0RD-ZER0 authored Mar 11, 2024
2 parents 9500ab2 + 8372d24 commit a711749
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ SLACK_MESSAGE | Generated from git commit message. | The
SLACK_TITLE | Message | Title to use before main Slack message.
SLACK_FOOTER | Powered By rtCamp's GitHub Actions Library | Slack message footer.
MSG_MINIMAL | - | If set to `true`, removes: `Ref`, `Event`, `Actions URL` and `Commit` from the message. You can optionally whitelist any of these 4 removed values by passing it comma separated to the variable instead of `true`. (ex: `MSG_MINIMAL: event` or `MSG_MINIMAL: ref,actions url`, etc.)
ENABLE_ESCAPES | - | If set to `true`, enables backslash escapes in the message such as '\n', '\t', etc.

You can see the action block with all variables as below:

Expand Down
36 changes: 23 additions & 13 deletions main.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#!/usr/bin/env bash

export GITHUB_BRANCH=${GITHUB_REF##*heads/}
export SLACK_ICON=${SLACK_ICON:-"https://avatars0.githubusercontent.com/u/43742164"}
export SLACK_USERNAME=${SLACK_USERNAME:-"rtBot"}
export GITHUB_BRANCH="${GITHUB_REF##*heads/}"
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')
export GITHUB_ACTOR=${SLACK_MSG_AUTHOR:-"$GITHUB_ACTOR"}
export SLACK_TITLE="${SLACK_TITLE:-"Message"}"
export GITHUB_ACTOR="${SLACK_MSG_AUTHOR:-"$GITHUB_ACTOR"}"

COMMIT_MESSAGE="$(cat "$GITHUB_EVENT_PATH" | jq -r '.commits[-1].message')"
export COMMIT_MESSAGE

hosts_file="$GITHUB_WORKSPACE/.github/hosts.yml"

Expand All @@ -30,31 +32,39 @@ if [[ -z "$SLACK_WEBHOOK" ]]; then
fi

if [[ -n "$VAULT_GITHUB_TOKEN" ]] || [[ -n "$VAULT_TOKEN" ]]; then
export SLACK_WEBHOOK=$(vault read -field=webhook secret/slack)
SLACK_WEBHOOK="$(vault read -field=webhook secret/slack)"
export SLACK_WEBHOOK
fi
fi

if [[ -f "$hosts_file" ]]; then
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")
DEPLOY_PATH="$(cat "$hosts_file" | shyaml get-value "$GITHUB_BRANCH.deploy_path")"
export DEPLOY_PATH

temp_url=${DEPLOY_PATH%%/app*}
temp_url="${DEPLOY_PATH%%/app*}"
export SITE_NAME="${temp_url##*sites/}"
export HOST_TITLE="SSH Host"
fi

PR_SHA=$(cat $GITHUB_EVENT_PATH | jq -r .pull_request.head.sha)
[[ 'null' != $PR_SHA ]] && export GITHUB_SHA="$PR_SHA"
PR_SHA="$(cat "$GITHUB_EVENT_PATH" | jq -r .pull_request.head.sha)"
[[ 'null' != "$PR_SHA" ]] && export GITHUB_SHA="$PR_SHA"

if [[ -n "$SITE_NAME" ]]; then
export SITE_TITLE="Site"
fi


if [[ -z "$SLACK_MESSAGE" ]]; then
export SLACK_MESSAGE="$COMMIT_MESSAGE"
SLACK_MESSAGE="$COMMIT_MESSAGE"
fi

if [[ "true" == "$ENABLE_ESCAPES" ]]; then
SLACK_MESSAGE="$(echo -e "$SLACK_MESSAGE")"
fi

slack-notify "$@"
export SLACK_MESSAGE

./slack-notify "$@"

0 comments on commit a711749

Please sign in to comment.