Skip to content

Commit 0624f51

Browse files
committed
Discord CI webhook
1 parent 75cecaf commit 0624f51

File tree

2 files changed

+87
-1
lines changed

2 files changed

+87
-1
lines changed

.travis.yml

+10-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,13 @@ before_install:
1414

1515
script:
1616
- dotnet restore
17-
- dotnet test
17+
- dotnet test
18+
19+
after_success:
20+
- wget https://raw.githubusercontent.com/DiscordHooks/travis-ci-discord-webhook/master/send.sh
21+
- chmod +x send.sh
22+
- ./send.sh success $WEBHOOK_URL
23+
after_failure:
24+
- wget https://raw.githubusercontent.com/DiscordHooks/travis-ci-discord-webhook/master/send.sh
25+
- chmod +x send.sh
26+
- ./send.sh failure $WEBHOOK_URL

send.sh

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/bash
2+
3+
if [ -z "$2" ]; then
4+
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
5+
fi
6+
7+
echo -e "[Webhook]: Sending webhook to Discord...\\n";
8+
9+
case $1 in
10+
"success" )
11+
EMBED_COLOR=3066993
12+
STATUS_MESSAGE="Passed"
13+
AVATAR="https://travis-ci.org/images/logos/TravisCI-Mascot-blue.png"
14+
;;
15+
16+
"failure" )
17+
EMBED_COLOR=15158332
18+
STATUS_MESSAGE="Failed"
19+
AVATAR="https://travis-ci.org/images/logos/TravisCI-Mascot-red.png"
20+
;;
21+
22+
* )
23+
EMBED_COLOR=0
24+
STATUS_MESSAGE="Status Unknown"
25+
AVATAR="https://travis-ci.org/images/logos/TravisCI-Mascot-1.png"
26+
;;
27+
esac
28+
29+
AUTHOR_NAME="$(git log -1 "$TRAVIS_COMMIT" --pretty="%aN")"
30+
COMMITTER_NAME="$(git log -1 "$TRAVIS_COMMIT" --pretty="%cN")"
31+
COMMIT_SUBJECT="$(git log -1 "$TRAVIS_COMMIT" --pretty="%s")"
32+
COMMIT_MESSAGE="$(git log -1 "$TRAVIS_COMMIT" --pretty="%b")"
33+
34+
if [ "$AUTHOR_NAME" == "$COMMITTER_NAME" ]; then
35+
CREDITS="$AUTHOR_NAME authored & committed"
36+
else
37+
CREDITS="$AUTHOR_NAME authored & $COMMITTER_NAME committed"
38+
fi
39+
40+
if [[ $TRAVIS_PULL_REQUEST != false ]]; then
41+
URL="https://github.com/$TRAVIS_REPO_SLUG/pull/$TRAVIS_PULL_REQUEST"
42+
else
43+
URL=""
44+
fi
45+
46+
TIMESTAMP=$(date --utc +%FT%TZ)
47+
WEBHOOK_DATA='{
48+
"username": "",
49+
"avatar_url": "https://travis-ci.org/images/logos/TravisCI-Mascot-1.png",
50+
"embeds": [ {
51+
"color": '$EMBED_COLOR',
52+
"author": {
53+
"name": "Job #'"$TRAVIS_JOB_NUMBER"' (Build #'"$TRAVIS_BUILD_NUMBER"') '"$STATUS_MESSAGE"' - '"$TRAVIS_REPO_SLUG"'",
54+
"url": "'"$TRAVIS_BUILD_WEB_URL"'",
55+
"icon_url": "'$AVATAR'"
56+
},
57+
"title": "'"$COMMIT_SUBJECT"'",
58+
"url": "'"$URL"'",
59+
"description": "'"${COMMIT_MESSAGE//$'\n'/ }"\\n\\n"$CREDITS"'",
60+
"fields": [
61+
{
62+
"name": "Commit",
63+
"value": "'"[\`${TRAVIS_COMMIT:0:7}\`](https://github.com/$TRAVIS_REPO_SLUG/commit/$TRAVIS_COMMIT)"'",
64+
"inline": true
65+
},
66+
{
67+
"name": "Branch/Tag",
68+
"value": "'"[\`$TRAVIS_BRANCH\`](https://github.com/$TRAVIS_REPO_SLUG/tree/$TRAVIS_BRANCH)"'",
69+
"inline": true
70+
}
71+
],
72+
"timestamp": "'"$TIMESTAMP"'"
73+
} ]
74+
}'
75+
76+
(curl --fail --progress-bar -A "TravisCI-Webhook" -H Content-Type:application/json -H X-Author:k3rn31p4nic#8383 -d "$WEBHOOK_DATA" "$2" \
77+
&& echo -e "\\n[Webhook]: Successfully sent the webhook.") || echo -e "\\n[Webhook]: Unable to send webhook."

0 commit comments

Comments
 (0)