This repository has been archived by the owner on Nov 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdiscord.sh
77 lines (67 loc) · 2.46 KB
/
discord.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
# https://github.com/DiscordHooks/travis-ci-discord-webhook
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/DiscordHooks/travis-ci-discord-webhook" && exit
fi
echo -e "[Webhook]: Sending webhook to Discord...\\n";
case $1 in
"success" )
EMBED_COLOR=3066993
STATUS = "Successful"
STATUS_MESSAGE="Successful build! Downloading link: $3"
AVATAR="https://travis-ci.org/images/logos/TravisCI-Mascot-2.png"
;;
"failure" )
EMBED_COLOR=15158332
STATUS = "Failure"
STATUS_MESSAGE="Build failed"
AVATAR="https://travis-ci.org/images/logos/TravisCI-Mascot-red.png"
;;
* )
EMBED_COLOR=0
STATUS = "Unknown"
STATUS_MESSAGE="Status Unknown"
AVATAR="https://travis-ci.org/images/logos/TravisCI-Mascot-1.png"
;;
esac
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")" | sed -E ':a;N;$!ba;s/\r{0,1}\n/\\n/g'
CREDITS="$COMMITTER_NAME committed"
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": "[BOT] Flutter deployer",
"avatar_url": "https://i.ibb.co/LPyJH8c/default3.jpg",
"content": "'"$STATUS_MESSAGE"'",
"embeds": [ {
"color": '$EMBED_COLOR',
"author": {
"name": "Job #'"$TRAVIS_JOB_NUMBER"' (Build #'"$TRAVIS_BUILD_NUMBER"') - '"$TRAVIS_REPO_SLUG"'",
"url": "'"$3"'",
"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",
"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:szepfejuede1#5173 -d "${WEBHOOK_DATA// / }" "$2" \
&& echo -e "\\n[Webhook]: Successfully sent the webhook.") || echo -e "\\n[Webhook]: Unable to send webhook."