Skip to content

Commit

Permalink
fix: false positive when slack bot encounters error
Browse files Browse the repository at this point in the history
- using jq to parse curl output
- replace docker image curl by alpine
  • Loading branch information
Rainui Ly committed Sep 20, 2022
1 parent 1dedd18 commit 2ff0e52
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
FROM curlimages/curl:7.84.0
FROM alpine:3.16

RUN apk --update add --no-cache jq curl && \
rm -rf /var/cache/apk/*

COPY entrypoint.sh /entrypoint.sh

Expand Down
12 changes: 9 additions & 3 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,16 @@ fi
##
payload='{"channel": "'$1'", "text": "'$2'"}'
echo "* Preparing payload: $payload"
curl -X POST \
response=`curl -X POST \
-H "Content-type: application/json" \
-H "Authorization: Bearer $SLACK_BOT_TOKEN" \
-d "$payload" \
https://slack.com/api/chat.postMessage
echo "* Slack channel id '$1' has been notified with '$2'"
https://slack.com/api/chat.postMessage`
is_ok=`echo $response | jq '.ok'`
if [ $is_ok == 'true' ]
then
echo "* Slack channel id '$1' has been notified with '$2'"
else
log_error "`echo $response | jq '.error'`"
fi
exit 0

0 comments on commit 2ff0e52

Please sign in to comment.