aboutsummaryrefslogtreecommitdiff
path: root/send.sh
diff options
context:
space:
mode:
authorAlee <alee14498@gmail.com>2018-04-16 11:49:34 -0400
committerAlee <alee14498@gmail.com>2018-04-16 11:49:34 -0400
commitf7017e693ab4c635f4d193e75e393d4204fcdcbf (patch)
treef444b82719cd1fe107092e95ca86f48afdf9c0b5 /send.sh
parent1a35d97d0f8790dcfa6ae6cfc7ce7792546a10d4 (diff)
downloadAleeBot-f7017e693ab4c635f4d193e75e393d4204fcdcbf.tar.gz
AleeBot-f7017e693ab4c635f4d193e75e393d4204fcdcbf.tar.bz2
AleeBot-f7017e693ab4c635f4d193e75e393d4204fcdcbf.zip
Fixes
Diffstat (limited to 'send.sh')
-rw-r--r--send.sh77
1 files changed, 77 insertions, 0 deletions
diff --git a/send.sh b/send.sh
new file mode 100644
index 0000000..2f8004c
--- /dev/null
+++ b/send.sh
@@ -0,0 +1,77 @@
+#!/bin/bash
+
+if [ -z "$2" ]; then
+ echo -e "WARNING!!\nYou need to pass the WEBHOOK_URL environment variable as the second argument to this script.\nFor details & guide, visit: https://github.com/k3rn31p4nic/travis-ci-discord-webhook" && exit
+fi
+
+echo -e "[Webhook]: Sending webhook to Discord...\\n";
+
+case $1 in
+ "success" )
+ EMBED_COLOR=3066993
+ STATUS_MESSAGE="Passed"
+ AVATAR="https://travis-ci.org/images/logos/TravisCI-Mascot-blue.png"
+ ;;
+
+ "failure" )
+ EMBED_COLOR=15158332
+ STATUS_MESSAGE="Failed"
+ AVATAR="https://travis-ci.org/images/logos/TravisCI-Mascot-red.png"
+ ;;
+
+ * )
+ EMBED_COLOR=0
+ STATUS_MESSAGE="Status Unknown"
+ AVATAR="https://travis-ci.org/images/logos/TravisCI-Mascot-1.png"
+ ;;
+esac
+
+AUTHOR_NAME="$(git log -1 "$TRAVIS_COMMIT" --pretty="%aN")"
+COMMITTER_NAME="$(git log -1 "$TRAVIS_COMMIT" --pretty="%cN")"
+COMMIT_SUBJECT="$(git log -1 "$TRAVIS_COMMIT" --pretty="%s")"
+COMMIT_MESSAGE="$(git log -1 "$TRAVIS_COMMIT" --pretty="%b")"
+
+if [ "$AUTHOR_NAME" == "$COMMITTER_NAME" ]; then
+ CREDITS="$AUTHOR_NAME authored & committed"
+else
+ CREDITS="$AUTHOR_NAME authored & $COMMITTER_NAME committed"
+fi
+
+if [[ $TRAVIS_PULL_REQUEST != false ]]; then
+ URL="https://github.com/$TRAVIS_REPO_SLUG/pull/$TRAVIS_PULL_REQUEST"
+else
+ URL=""
+fi
+
+TIMESTAMP=$(date --utc +%FT%TZ)
+WEBHOOK_DATA='{
+ "username": "",
+ "avatar_url": "https://travis-ci.org/images/logos/TravisCI-Mascot-1.png",
+ "embeds": [ {
+ "color": '$EMBED_COLOR',
+ "author": {
+ "name": "Job #'"$TRAVIS_JOB_NUMBER"' (Build #'"$TRAVIS_BUILD_NUMBER"') '"$STATUS_MESSAGE"' - '"$TRAVIS_REPO_SLUG"'",
+ "url": "https://travis-ci.org/'"$TRAVIS_REPO_SLUG"'/builds/'"$TRAVIS_BUILD_ID"'",
+ "icon_url": "'$AVATAR'"
+ },
+ "title": "'"$COMMIT_SUBJECT"'",
+ "url": "'"$URL"'",
+ "description": "'"${COMMIT_MESSAGE//$'\n'/ }"\\n\\n"$CREDITS"'",
+ "fields": [
+ {
+ "name": "Commit",
+ "value": "'"[\`${TRAVIS_COMMIT:0:7}\`](https://github.com/$TRAVIS_REPO_SLUG/commit/$TRAVIS_COMMIT)"'",
+ "inline": true
+ },
+ {
+ "name": "Branch/Tag",
+ "value": "'"[\`$TRAVIS_BRANCH\`](https://github.com/$TRAVIS_REPO_SLUG/tree/$TRAVIS_BRANCH)"'",
+ "inline": true
+ }
+ ],
+ "timestamp": "'"$TIMESTAMP"'"
+ } ]
+}'
+
+(curl --fail --progress-bar -A "TravisCI-Webhook" -H Content-Type:application/json -H X-Author:k3rn31p4nic#8383 -d "$WEBHOOK_DATA" "$2" \
+ && echo -e "\\n[Webhook]: Successfully sent the webhook.") || echo -e "\\n[Webhook]: Unable to send webhook."