forked from DS-Homebrew/discord-webhooks
-
Notifications
You must be signed in to change notification settings - Fork 1
/
send-azure.sh
executable file
·122 lines (112 loc) · 4.19 KB
/
send-azure.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/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/DS-Homebrew/discord-webhooks" && exit
fi
echo -e "[Webhook]: Sending webhook to Discord...\\n";
case $1 in
"success" )
EMBED_COLOR=3066993
STATUS_MESSAGE="Passed"
AVATAR="https://raw.githubusercontent.com/Universal-Team/discord-webhooks/master/azure-logo.png"
;;
"failure" )
EMBED_COLOR=15158332
STATUS_MESSAGE="Failed"
AVATAR="https://raw.githubusercontent.com/Universal-Team/discord-webhooks/master/azure-logo.png"
;;
* )
EMBED_COLOR=0
STATUS_MESSAGE="Status Unknown"
AVATAR="https://raw.githubusercontent.com/Universal-Team/discord-webhooks/master/azure-logo.png"
;;
esac
AUTHOR_NAME="$(git log -1 "$BUILD_SOURCEVERSION" --pretty="%aN")"
COMMITTER_NAME="$(git log -1 "$BUILD_SOURCEVERSION" --pretty="%cN")"
COMMIT_SUBJECT="$(git log -1 "$BUILD_SOURCEVERSION" --pretty="%s")"
COMMIT_MESSAGE="$(git log -1 "$BUILD_SOURCEVERSION" --pretty="%b")"
SOURCEBRANCH=${BUILD_SOURCEBRANCH##*/}
if [ "$AUTHOR_NAME" == "$COMMITTER_NAME" ]; then
CREDITS="$AUTHOR_NAME authored & committed"
else
CREDITS="$AUTHOR_NAME authored & $COMMITTER_NAME committed"
fi
# if [[ $SYSTEM_PULLREQUEST_PULLREQUESTNUMBER != false ]]; then
# URL="https://github.com/$REPOSITORY_NAME/pull/$SYSTEM_PULLREQUEST_PULLREQUESTNUMBER"
# else
# URL=""
# fi
TIMESTAMP=$(date --utc +%FT%TZ)
if [ $IMAGE = "" ]; then
WEBHOOK_DATA='{
"username": "",
"avatar_url": "https://raw.githubusercontent.com/Universal-Team/discord-webhooks/master/azure-logo.png",
"embeds": [ {
"color": '$EMBED_COLOR',
"author": {
"name": "Build '"v$CURRENT_DATE"' '"$STATUS_MESSAGE"' - '"$REPOSITORY_NAME"'",
"url": "'"https://dev.azure.com/universal-team/Builds/_build/results?buildId=$BUILD_BUILDID"'",
"icon_url": "'$AVATAR'"
},
"title": "'"$COMMIT_SUBJECT"'",
"url": "'"$URL"'",
"description": "'"${COMMIT_MESSAGE//$'\n'/ }"\\n\\n"$CREDITS"'",
"fields": [
{
"name": "Commit",
"value": "'"[\`${BUILD_SOURCEVERSION:0:7}\`](https://github.com/$REPOSITORY_NAME/commit/$BUILD_SOURCEVERSION)"'",
"inline": true
},
{
"name": "Branch",
"value": "'"[\`$SOURCEBRANCH\`](https://github.com/$REPOSITORY_NAME/tree/$SOURCEBRANCH)"'",
"inline": true
},
{
"name": "Release",
"value": "'"[\`v$CURRENT_DATE\`](https://github.com/Universal-Team/extras/releases/tag/v$CURRENT_DATE)"'",
"inline": true
}
],
"timestamp": "'"$TIMESTAMP"'"
} ]
}'
else
WEBHOOK_DATA='{
"username": "",
"avatar_url": "https://raw.githubusercontent.com/Universal-Team/discord-webhooks/master/azure-logo.png",
"embeds": [ {
"color": '$EMBED_COLOR',
"author": {
"name": "Build '"v$CURRENT_DATE"' '"$STATUS_MESSAGE"' - '"$REPOSITORY_NAME"'",
"url": "'"https://dev.azure.com/universal-team/Builds/_build/results?buildId=$BUILD_BUILDID"'",
"icon_url": "'$AVATAR'"
},
"title": "'"$COMMIT_SUBJECT"'",
"url": "'"$URL"'",
"description": "'"${COMMIT_MESSAGE//$'\n'/ }"\\n\\n"$CREDITS"'",
"fields": [
{
"name": "Commit",
"value": "'"[\`${BUILD_SOURCEVERSION:0:7}\`](https://github.com/$REPOSITORY_NAME/commit/$BUILD_SOURCEVERSION)"'",
"inline": true
},
{
"name": "Branch",
"value": "'"[\`$SOURCEBRANCH\`](https://github.com/$REPOSITORY_NAME/tree/$SOURCEBRANCH)"'",
"inline": true
},
{
"name": "Release",
"value": "'"[\`v$CURRENT_DATE\`](https://github.com/Universal-Team/extras/releases/tag/v$CURRENT_DATE)"'",
"inline": false
}
],
"image": {
"url": "'"$IMAGE"'"
},
"timestamp": "'"$TIMESTAMP"'"
} ]
}'
fi
(curl --fail --progress-bar -A "Azure-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."