Skip to content

Instantly share code, notes, and snippets.

@fprochazka
Last active February 4, 2016 09:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fprochazka/b04a92f7566210c200a8 to your computer and use it in GitHub Desktop.
Save fprochazka/b04a92f7566210c200a8 to your computer and use it in GitHub Desktop.
#!/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