-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
send.ps1
98 lines (84 loc) · 3.26 KB
/
send.ps1
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
# Author: Sankarsan Kampa (a.k.a. k3rn31p4nic)
# License: MIT
$STATUS=$args[0]
$WEBHOOK_URL=$args[1]
if (!$WEBHOOK_URL) {
Write-Output "WARNING!!"
Write-Output "You need to pass the WEBHOOK_URL environment variable as the second argument to this script."
Write-Output "For details & guide, visit: https://github.com/DiscordHooks/appveyor-discord-webhook"
Exit
}
Write-Output "[Webhook]: Sending webhook to Discord..."
Switch ($STATUS) {
"success" {
$EMBED_COLOR=3066993
$STATUS_MESSAGE="Passed"
Break
}
"failure" {
$EMBED_COLOR=15158332
$STATUS_MESSAGE="Failed"
Break
}
default {
Write-Output "Default!"
Break
}
}
$AVATAR="https://upload.wikimedia.org/wikipedia/commons/thumb/b/bc/Appveyor_logo.svg/256px-Appveyor_logo.svg.png"
if (!$env:APPVEYOR_REPO_COMMIT) {
$env:APPVEYOR_REPO_COMMIT="$(git log -1 --pretty="%H")"
}
$AUTHOR_NAME="$(git log -1 "$env:APPVEYOR_REPO_COMMIT" --pretty="%aN")"
$COMMITTER_NAME="$(git log -1 "$env:APPVEYOR_REPO_COMMIT" --pretty="%cN")"
$COMMIT_SUBJECT="$(git log -1 "$env:APPVEYOR_REPO_COMMIT" --pretty="%s")" -replace "`"", "'"
$COMMIT_MESSAGE=(git log -1 "$env:APPVEYOR_REPO_COMMIT" --pretty="%b") -replace "`"", "'" | Out-String | ConvertTo-Json
if ($AUTHOR_NAME -eq $COMMITTER_NAME) {
$CREDITS="`n$AUTHOR_NAME authored & committed" | ConvertTo-Json
}
else {
$CREDITS="`n$AUTHOR_NAME authored & $COMMITTER_NAME committed" | ConvertTo-Json
}
# Remove Starting and Ending double quotes by ConvertTo-Json
$COMMIT_MESSAGE = $COMMIT_MESSAGE.Substring(1, $COMMIT_MESSAGE.Length-2)
$CREDITS = $CREDITS.Substring(1, $CREDITS.Length-2)
if ($env:APPVEYOR_PULL_REQUEST_NUMBER) {
$COMMIT_SUBJECT="PR #$env:APPVEYOR_PULL_REQUEST_NUMBER - $env:APPVEYOR_PULL_REQUEST_TITLE"
$URL="https://github.com/$env:APPVEYOR_REPO_NAME/pull/$env:APPVEYOR_PULL_REQUEST_NUMBER"
}
else {
$URL=""
}
$BUILD_VERSION = [uri]::EscapeDataString($env:APPVEYOR_BUILD_VERSION)
$TIMESTAMP="$(Get-Date -format s)Z"
$WEBHOOK_DATA="{
""avatar_url"": ""$AVATAR"",
""embeds"": [ {
""color"": $EMBED_COLOR,
""author"": {
""name"": ""Job #$env:APPVEYOR_JOB_NUMBER (Build #$env:APPVEYOR_BUILD_NUMBER) $STATUS_MESSAGE - $env:APPVEYOR_REPO_NAME"",
""url"": ""https://ci.appveyor.com/project/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/build/$BUILD_VERSION"",
""icon_url"": ""$AVATAR""
},
""title"": ""$COMMIT_SUBJECT"",
""url"": ""$URL"",
""description"": ""$COMMIT_MESSAGE $CREDITS"",
""fields"": [
{
""name"": ""Commit"",
""value"": ""[``$($env:APPVEYOR_REPO_COMMIT.substring(0, 7))``](https://github.com/$env:APPVEYOR_REPO_NAME/commit/$env:APPVEYOR_REPO_COMMIT)"",
""inline"": true
},
{
""name"": ""Branch"",
""value"": ""[``$env:APPVEYOR_REPO_BRANCH``](https://github.com/$env:APPVEYOR_REPO_NAME/tree/$env:APPVEYOR_REPO_BRANCH)"",
""inline"": true
}
],
""timestamp"": ""$TIMESTAMP""
} ]
}"
Invoke-RestMethod -Uri "$WEBHOOK_URL" -Method "POST" -UserAgent "AppVeyor-Webhook" `
-ContentType "application/json" -Header @{"X-Author"="k3rn31p4nic#8383"} `
-Body $WEBHOOK_DATA
Write-Output "[Webhook]: Successfully sent the webhook."