Skip to content

Commit

Permalink
improve slack msg
Browse files Browse the repository at this point in the history
  • Loading branch information
Chemaclass committed Sep 28, 2024
1 parent a327eb8 commit 464d5b1
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions src/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,27 +80,31 @@ function release::create_github_release() {
--notes "$notes"
fi

local repo_name=$(echo "$repo_info" | cut -d'/' -f2)

local slack_message=$(cat <<EOF
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*$repo_name* :rocket: $release_name\n\n$commits\n<$changelog_url|Full changelog>"
}
if [[ -n $SLACK_CHANNEL_ID && -n $SLACK_OAUTH_TOKEN ]]; then
local repo_name=$(echo "$repo_info" | cut -d'/' -f2)

local slack_message=$(cat <<EOF
[
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*$repo_name* :rocket: $release_name\n\n$commits\n<$changelog_url|Full changelog>"
}
]
}
}
]
EOF
)
if [[ -n $SLACK_CHANNEL_ID && -n $SLACK_OAUTH_TOKEN ]]; then
curl -X POST https://slack.com/api/chat.postMessage \
-d "token=$SLACK_OAUTH_TOKEN" \
-d "channel=$SLACK_CHANNEL_ID" \
-d "blocks=$slack_message"
# Escaping quotes and newlines
local slack_message_escaped="${slack_message//\"/\\\"}"
slack_message_escaped="${slack_message_escaped//$'\n'/\\n}"

curl -s -o /dev/null -X POST https://slack.com/api/chat.postMessage \
-H "Content-Type: application/json; charset=utf-8" \
-H "Authorization: Bearer $SLACK_OAUTH_TOKEN" \
--data "{\"channel\": \"$SLACK_CHANNEL_ID\", \"blocks\": \"$slack_message_escaped\"}"

echo -e "${COLOR_GREEN}Notification sent via slack${COLOR_RESET}"
fi
}

Expand Down

0 comments on commit 464d5b1

Please sign in to comment.