Created
July 31, 2017 18:54
-
-
Save wesleyhf/2b9e10f921d04a73ba45812d9f3a8a6e to your computer and use it in GitHub Desktop.
Send github status to Slack using Incoming Webhook
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 | |
# 0 8,13,18 * * * ./github-status.sh | |
GITHUB_STATUS_RESPONSE=$(curl -s https://status.github.com/api/last-message.json) | |
GITHUB_STATUS=$(echo $GITHUB_STATUS_RESPONSE | jq -r '.status') | |
GITHUB_BODY=$(echo $GITHUB_STATUS_RESPONSE | jq -r '.body') | |
INCOMING_WEBHOOK='https://hooks.slack.com/services/#######' | |
case "$GITHUB_STATUS" in | |
"good") | |
SLACK_COLOR='#4caf50' | |
;; | |
"minor") | |
SLACK_COLOR='#ffeb3b' | |
;; | |
"major") | |
SLACK_COLOR='#f44336' | |
;; | |
*) | |
SLACK_COLOR='#e91e63' | |
;; | |
esac | |
SLACK_TEXT="{\"color\": \"${SLACK_COLOR}\", \"fields\": [{\"title\": \"${GITHUB_BODY}\"}]}"; | |
curl -X POST -H 'Content-type: application/json' --data "$SLACK_TEXT" $INCOMING_WEBHOOK |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment