Skip to content

Commit

Permalink
chore: added slack functions
Browse files Browse the repository at this point in the history
  • Loading branch information
tristan-greffe committed Mar 12, 2024
1 parent 42521e2 commit fecf6df
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions kash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,54 @@ slack_color_log() {
curl -X POST -H "Content-type: application/json" --data "$PAYLOAD" "$URL"
}

# Generate a Slack message
# Arg1: the repository root
# Arg2: the repository name (in the format owner/repo)
# Arg3: the build status ("failed" or "passed")
generate_slack_message() {
local ROOT_DIR="$1"
local APP="$2"
local BUILD_STATUS="$3"
local REPO_NAME="${APP##*/}"
local COMMIT_SHA
COMMIT_SHA=$(get_git_commit_sha "$ROOT_DIR")
local COMMIT_URL
COMMIT_URL="https://github.com/kalisio/$REPO_NAME/commit/$COMMIT_SHA"
local COMMIT_CHECKS_URL
COMMIT_CHECKS_URL="https://github.com/kalisio/$REPO_NAME/commit/$COMMIT_SHA/checks"
local AUTHOR
AUTHOR=$(get_git_commit_author_name "$THIS_DIR")

if [ "$CI_ID" = "github" ]; then
echo "<${COMMIT_CHECKS_URL}|Build> <${COMMIT_URL}|${COMMIT_SHA}> of $APP by $AUTHOR $BUILD_STATUS"
else
echo "Build <${COMMIT_URL}|${COMMIT_SHA}> of $APP by $AUTHOR $BUILD_STATUS"
fi
}

# Send a Slack message with conditional formatting based on the build status and Node version
# Arg1: the repository root
# Arg2: the node version to use (16, 18 ...)
# Arg3: the repository name (in the format owner/repo)
# Arg4: the build status ("failed" or "passed")
send_slack_message() {
local ROOT_DIR="$1"
local NODE_VERSION="$2"
local APP="$3"
local BUILD_STATUS="$4"
local MESSAGE
MESSAGE=$(generate_slack_message "$ROOT_DIR" "$APP" "$BUILD_STATUS")
local COLOR
if [ "$BUILD_STATUS" = "failed" ]; then
COLOR="#a30200"
else
COLOR="#2eb886"
fi
if [ "$NODE_VERSION" -eq 16 ]; then
slack_color_log "$SLACK_WEBHOOK_LIBS" "$MESSAGE" "$COLOR"
fi
}

### SOPS
###

Expand Down

0 comments on commit fecf6df

Please sign in to comment.