1
+ # Author: Sankarsan Kampa (a.k.a. k3rn31p4nic)
2
+ # License: MIT
3
+
4
+ $STATUS = $args [0 ]
5
+ $WEBHOOK_URL = $args [1 ]
6
+
7
+ if (! $WEBHOOK_URL ) {
8
+ Write-Output " WARNING!!"
9
+ Write-Output " You need to pass the WEBHOOK_URL environment variable as the second argument to this script."
10
+ Write-Output " For details & guide, visit: https://github.com/DiscordHooks/appveyor-discord-webhook"
11
+ Exit
12
+ }
13
+
14
+ Write-Output " [Webhook]: Sending webhook to Discord..."
15
+
16
+ Switch ($STATUS ) {
17
+ " success" {
18
+ $EMBED_COLOR = 3066993
19
+ $STATUS_MESSAGE = " Passed"
20
+ Break
21
+ }
22
+ " failure" {
23
+ $EMBED_COLOR = 15158332
24
+ $STATUS_MESSAGE = " Failed"
25
+ Break
26
+ }
27
+ " start" {
28
+ $EMBED_COLOR = 10181046
29
+ $STATUS_MESSAGE = " Starting"
30
+ Break
31
+ }default {
32
+ Write-Output " Default!"
33
+ Break
34
+ }
35
+ }
36
+ $AVATAR = " https://upload.wikimedia.org/wikipedia/commons/thumb/b/bc/Appveyor_logo.svg/256px-Appveyor_logo.svg.png"
37
+
38
+ if (! $env: APPVEYOR_REPO_COMMIT ) {
39
+ $env: APPVEYOR_REPO_COMMIT = " $ ( git log -1 -- pretty= " %H" ) "
40
+ }
41
+
42
+ $AUTHOR_NAME = " $ ( git log -1 " $env: APPVEYOR_REPO_COMMIT " -- pretty= " %aN" ) "
43
+ $COMMITTER_NAME = " $ ( git log -1 " $env: APPVEYOR_REPO_COMMIT " -- pretty= " %cN" ) "
44
+ $COMMIT_SUBJECT = " $ ( git log -1 " $env: APPVEYOR_REPO_COMMIT " -- pretty= " %s" ) "
45
+ $COMMIT_MESSAGE = " $ ( git log -1 " $env: APPVEYOR_REPO_COMMIT " -- pretty= " %b" ) "
46
+
47
+ if ($AUTHOR_NAME -eq $COMMITTER_NAME ) {
48
+ $CREDITS = " $AUTHOR_NAME authored & committed"
49
+ }
50
+ else {
51
+ $CREDITS = " $AUTHOR_NAME authored & $COMMITTER_NAME committed"
52
+ }
53
+
54
+ if ($env: APPVEYOR_PULL_REQUEST_NUMBER ) {
55
+ $COMMIT_SUBJECT = " PR #$env: APPVEYOR_PULL_REQUEST_NUMBER - $env: APPVEYOR_PULL_REQUEST_TITLE "
56
+ $URL = " https://github.com/$env: APPVEYOR_REPO_NAME /pull/$env: APPVEYOR_PULL_REQUEST_NUMBER "
57
+ }
58
+ else {
59
+ $URL = " "
60
+ }
61
+
62
+ $BUILD_VERSION = [uri ]::EscapeDataString($env: APPVEYOR_BUILD_VERSION )
63
+ $TIMESTAMP = " $ ( Get-Date - format s) Z"
64
+ $WEBHOOK_DATA = " {
65
+ "" username"" : """" ,
66
+ "" avatar_url"" : "" $AVATAR "" ,
67
+ "" embeds"" : [ {
68
+ "" color"" : $EMBED_COLOR ,
69
+ "" author"" : {
70
+ "" name"" : "" Job #$env: APPVEYOR_JOB_NUMBER (Build #$env: APPVEYOR_BUILD_NUMBER ) $STATUS_MESSAGE - $env: APPVEYOR_REPO_NAME "" ,
71
+ "" url"" : "" https://ci.appveyor.com/project/$env: APPVEYOR_ACCOUNT_NAME /$env: APPVEYOR_PROJECT_SLUG /build/$BUILD_VERSION "" ,
72
+ "" icon_url"" : "" $AVATAR ""
73
+ },
74
+ "" title"" : "" $COMMIT_SUBJECT "" ,
75
+ "" url"" : "" $URL "" ,
76
+ "" description"" : "" $COMMIT_MESSAGE $CREDITS "" ,
77
+ "" fields"" : [
78
+ {
79
+ "" name"" : "" Commit"" ,
80
+ "" value"" : "" [`` $ ( $env: APPVEYOR_REPO_COMMIT.substring (0 , 7 )) `` ](https://github.com/$env: APPVEYOR_REPO_NAME /commit/$env: APPVEYOR_REPO_COMMIT )"" ,
81
+ "" inline"" : true
82
+ },
83
+ {
84
+ "" name"" : "" Branch"" ,
85
+ "" value"" : "" [`` $env: APPVEYOR_REPO_BRANCH `` ](https://github.com/$env: APPVEYOR_REPO_NAME /tree/$env: APPVEYOR_REPO_BRANCH )"" ,
86
+ "" inline"" : true
87
+ }
88
+ ],
89
+ "" timestamp"" : "" $TIMESTAMP ""
90
+ } ]
91
+ }"
92
+
93
+ Invoke-RestMethod - Uri " $WEBHOOK_URL " - Method " POST" - UserAgent " AppVeyor-Webhook" `
94
+ - ContentType " application/json" - Header @ {" X-Author" = " k3rn31p4nic#8383" } `
95
+ - Body $WEBHOOK_DATA
96
+
97
+ Write-Output " [Webhook]: Successfully sent the webhook."
0 commit comments