From e357415e7992ad52c0334f58382c5b9dbccd6c44 Mon Sep 17 00:00:00 2001
From: Tomasz Maczukin <tomasz@maczukin.pl>
Date: Tue, 30 Oct 2018 16:42:56 +0100
Subject: [PATCH] Add slack notification option for 'dep status' check failures

---
 scripts/dep_status_check | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/scripts/dep_status_check b/scripts/dep_status_check
index def36b13e..05257c458 100755
--- a/scripts/dep_status_check
+++ b/scripts/dep_status_check
@@ -14,4 +14,28 @@ if [ "$(cat "${reportFile}")" == "[]" ] ; then
 fi
 
 jq -C . "${reportFile}"
+
+#
+# Borrowed from https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/support/notify_slack.sh
+# and adjusted for our needs:)
+#
+if [[ -z "${CI_DEP_STATUS_NOTIFY_CHANNEL}" ]] || [[ -z "${CI_DEP_STATUS_NOTIFY_SLACK_WEBHOOK}" ]]; then
+    echo "Variables CI_DEP_STATUS_NOTIFY_CHANNEL and CI_DEP_STATUS_NOTIFY_SLACK_WEBHOOK are not defined"
+    echo "Will not send slack notification"
+else
+    messageTmpFile="$(mktemp)"
+
+    cat > "${messageTmpFile}" << EOS
+\`dep status\` check for <${CI_PROJECT_URL}> failed. Some dependencies should be updated:
+\`\`\`
+$(jq -M . "${reportFile}")
+\`\`\`
+See <${CI_JOB_URL}>
+EOS
+
+    message=$(sed -e ':a' -e 'N' -e '$!ba' -e "s/\n/\\\n/g" "${messageTmpFile}")
+    payload='payload={"channel": "'"${CI_DEP_STATUS_NOTIFY_CHANNEL}"'", "username": "GitLab Runner Dep Status Check", "text": "'"${message//\"/\\\"}"'", "icon_emoji": ":mantelpiece_clock:"}'
+    curl -X POST -s -L --data-urlencode "${payload}" "${CI_DEP_STATUS_NOTIFY_SLACK_WEBHOOK}"
+fi
+
 exit 1
-- 
GitLab