mirror of
https://github.com/craftycodie/OnlineModeFix.git
synced 2025-08-04 09:25:57 -04:00
104 lines
3.3 KiB
PowerShell
104 lines
3.3 KiB
PowerShell
# Author: Sankarsan Kampa (a.k.a. k3rn31p4nic)
|
|
# License: MIT
|
|
|
|
$STATUS=$args[0]
|
|
$DISCORD_WEBHOOK_URL=$args[1]
|
|
|
|
if (!$DISCORD_WEBHOOK_URL) {
|
|
Write-Output "WARNING!!"
|
|
Write-Output "You need to pass the DISCORD_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 "[Discord 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="{
|
|
""username"": """",
|
|
""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"": ""Version"",
|
|
""value"": ""$BUILD_VERSION"",
|
|
""inline"": true
|
|
},
|
|
{
|
|
""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 "$DISCORD_WEBHOOK_URL" -Method "POST" -UserAgent "AppVeyor-Webhook" `
|
|
-ContentType "application/json" -Header @{"X-Author"="k3rn31p4nic#8383"} `
|
|
-Body $WEBHOOK_DATA
|
|
|
|
Write-Output "[Discord Webhook]: Successfully sent the webhook." |