Last active
February 4, 2016 09:45
-
-
Save fprochazka/b04a92f7566210c200a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
DOMAIN=www.rohlik.cz | |
REMOTE="upstream" | |
BRANCH="production" | |
REVISION=$(git --git-dir=$SOURCE/.git rev-parse HEAD | cut -c1-7) | |
GIT_MERGE_AUTHOR=$(git --git-dir=$SOURCE/.git --no-pager show -s --format='%an' $(git --git-dir=$SOURCE/.git rev-parse HEAD)) | |
function json_escape() { | |
export CHAT_NOTIFY="$1" | |
echo $(php -r 'echo str_replace("\"", "\\\"", substr(json_encode(getenv("CHAT_NOTIFY")), 1, -1));'); | |
} | |
function slack_notify() { | |
DOWNTIME_SEC="$1" | |
FALLBACK=$(json_escape "Deployed <https://github.com/rohlikcz/rohlikcz/commit/${REVISION}|${REMOTE}:${BRANCH}#${REVISION}> to <https://${DOMAIN}|$(hostname)>, downtime was ${DOWNTIME_SEC} seconds") | |
FIELD=$(json_escape "Deployed <https://github.com/rohlikcz/rohlikcz/commit/${REVISION}|${REMOTE}:${BRANCH}#${REVISION}>, downtime was ${DOWNTIME_SEC} seconds") | |
curl -X POST --data-urlencode "payload={\"username\":\"${GIT_MERGE_AUTHOR}\",\"fallback\":\"$FALLBACK\",\"color\":\"#edb431\",\"fields\":[{\"title\":\"$(hostname)\",\"short\":false,\"value\":\"${FIELD}\"}]}" \ | |
https://rohlik.slack.com/services/hooks/incoming-webhook?token=???? | |
} | |
slack_notify $DOWNTIME_SEC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment