From cd719b1d5b79576d6d3dbb2c08747d7aa9caa2db Mon Sep 17 00:00:00 2001 From: stasatdaglabs <39559713+stasatdaglabs@users.noreply.github.com> Date: Mon, 6 Jan 2020 16:36:21 +0200 Subject: [PATCH] [NOD-546] Report build failures to Discord instead of Telegram (#572) * [NOD-546] Report build failures to Discord instead of Telegram. * [NOD-546] Make a temporary compilation error. * [NOD-546] Make a couple of temporary print outs. * [NOD-546] Remove temporary debug stuff. * [NOD-546] Make notify_discord() return early if Discord variables are not set. --- deploy.sh | 16 ++++++++++------ telegram.sh => discord.sh | 19 +++++-------------- 2 files changed, 15 insertions(+), 20 deletions(-) rename telegram.sh => discord.sh (53%) diff --git a/deploy.sh b/deploy.sh index b82f34153..b825b8ea3 100755 --- a/deploy.sh +++ b/deploy.sh @@ -17,12 +17,16 @@ IMAGE_NAME=${ECR_SERVER}/${SERVICE_NAME} # Start atd service atd start -# Sends a Telegram notification with some details about the failure +# Sends a Discord notification with some details about the failure # All variables in this function are set by Jenkins -notify_telegram() { - echo "./telegram.sh \ - '${TELEGRAM_API_TOKEN}' \ - '${TELEGRAM_CHAT_ID}' \ +notify_discord() { + if [ -z "${DISCORD_CLIENT_ID}" ] || [ -z "${DISCORD_API_TOKEN}" ]; then + return + fi + + echo "./discord.sh \ + '${DISCORD_CLIENT_ID}' \ + '${DISCORD_API_TOKEN}' \ '${BUILD_URL}' \ '${ghprbActualCommitAuthor}' \ '${ghprbPullTitle}' \ @@ -32,7 +36,7 @@ notify_telegram() { trap "exit 1" INT fatal() { echo "ERROR: $*" >&2 - notify_telegram + notify_discord exit 1 } diff --git a/telegram.sh b/discord.sh similarity index 53% rename from telegram.sh rename to discord.sh index ca43185e7..6eee8c65b 100755 --- a/telegram.sh +++ b/discord.sh @@ -2,10 +2,10 @@ # This file is part of Continuous Integration. When ran by # the CI agent, it sends a some details about the build failure -# to a Telegram group. +# to a Discord channel. -API_TOKEN="$1" -CHAT_ID="$2" +CLIENT_ID="$1" +API_TOKEN="$2" BUILD_URL="$3" PR_AUTHOR="$4" PR_TITLE="$5" @@ -16,20 +16,11 @@ MESSAGE="*${PR_AUTHOR}*: Build *FAILED* for pull request '${PR_TITLE}' [Github](${PR_LINK}) [Jenkins](${BUILD_URL}console)" -# Send the failure message -curl -s \ - -X POST \ - "https://api.telegram.org/bot${API_TOKEN}/sendMessage" \ - -d chat_id="${CHAT_ID}" \ - -d parse_mode=markdown \ - -d disable_web_page_preview=true \ - -d text="${MESSAGE}" - # Retrieve the build log LOG=$(curl ${BUILD_URL}consoleText) # Send the build log printf "$LOG" | curl \ - "https://api.telegram.org/bot${API_TOKEN}/sendDocument" \ - -F chat_id="${CHAT_ID}" \ + "https://discordapp.com/api/webhooks/${CLIENT_ID}/${API_TOKEN}" \ + -F content="${MESSAGE}" \ -F document="@-;filename=build.log" \ No newline at end of file