1
0
Fork 0
mirror of https://github.com/Radarr/Radarr synced 2024-12-27 02:09:59 +00:00

Simplify YML for Discord Notification (#4349)

* Simplify YML for Discord Notification

* fixup! Simplify YML for Discord Notification
This commit is contained in:
Qstick 2020-04-24 16:04:28 -04:00 committed by GitHub
parent bb471d2d6d
commit 641d43c6f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -804,87 +804,10 @@ stages:
vmImage: 'ubuntu-18.04' vmImage: 'ubuntu-18.04'
steps: steps:
- checkout: none - checkout: none
- bash: |
env | sort
if [[ $BUILD_REASON == "PullRequest" ]]; then
echo "##vso[task.setvariable variable=buildTypeString][PR $SYSTEM_PULLREQUEST_PULLREQUESTNUMBER]($SYSTEM_PULLREQUEST_SOURCEREPOSITORYURI/pull/$SYSTEM_PULLREQUEST_PULLREQUESTNUMBER) to \`$SYSTEM_PULLREQUEST_TARGETBRANCH\` from \`$SYSTEM_PULLREQUEST_SOURCEBRANCH\`"
COMMIT_SHORT=$(echo $SYSTEM_PULLREQUEST_SOURCECOMMITID | cut -c1-7)
echo "##vso[task.setvariable variable=commitUrl]$SYSTEM_PULLREQUEST_SOURCEREPOSITORYURI/commit/$SYSTEM_PULLREQUEST_SOURCECOMMITID"
else
echo "##vso[task.setvariable variable=buildTypeString]Mainline Branch '$BUILD_SOURCEBRANCHNAME'"
COMMIT_SHORT=$(echo $BUILD_SOURCEVERSION | cut -c1-7)
echo "##vso[task.setvariable variable=commitUrl]$SYSTEM_PULLREQUEST_SOURCEREPOSITORYURI/commit/$BUILD_SOURCEVERSION"
fi
echo "##vso[task.setvariable variable=commitString]$COMMIT_SHORT"
- powershell: | - powershell: |
$bearer_token = "$env:SYSTEM_ACCESSTOKEN" iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/Servarr/AzureDiscordNotify/master/DiscordNotify.ps1'))
$headers = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($bearer_token)")) }
$url = "https://dev.azure.com/Radarr/Radarr/_apis/test/runs?buildUri=$env:BUILD_BUILDURI&api-version=5.1"
$response = (Invoke-RestMethod -Uri $url -Headers $headers).value
$passed_tests = $response | Select passedTests | Measure-Object -Sum PassedTests | Select-Object -expand Sum
$failed_tests = $response | Select unanalyzedTests | Measure-Object -Sum UnanalyzedTests | Select-Object -expand Sum
$skipped_tests = $response | Select notApplicableTests | Measure-Object -Sum NotApplicableTests | Select-Object -expand Sum
$url1 = "https://dev.azure.com/Radarr/Radarr/_apis/test/codeCoverage?buildId=$env:BUILD_BUILDID&api-version=5.1-preview"
$response1 = (Invoke-RestMethod -Uri $url1 -Headers $headers).coverageData.coverageStats
$total_lines = $response1 | Where-Object {$_.Label -eq "Lines"} | Select-Object -expand Total
$covered_lines = $response1 | Where-Object {$_.Label -eq "Lines"} | Select-Object -expand Covered
$coverage_percent = [math]::Round($covered_lines/$total_lines*100,2)
$url2 = "https://dev.azure.com/Radarr/Radarr/_apis/build/builds/$env:BUILD_BUILDID/timeline/?api-version=5.1"
$response2 = (Invoke-RestMethod -Uri $url2 -Headers $headers).records
$failed_tasks = $response2 | Where-Object {$_.Result -eq "failed"} | Measure-Object | Select-Object -expand Count
$error_count = $response2 | Select errorCount | Measure-Object -Sum ErrorCount | Select-Object -expand Sum
$warning_count = $response2 | Select warningCount | Measure-Object -Sum WarningCount | Select-Object -expand Sum
if($failed_tasks -gt 0) {
$status_message = "Failed"
Write-Host "##vso[task.setvariable variable=statusColor;]15158332"
}else {
$status_message = "Success"
Write-Host "##vso[task.setvariable variable=statusColor;]3066993"
}
Write-Host "##vso[task.setvariable variable=testResultString;]$passed_tests Passed, $failed_tests Failed, $skipped_tests Skipped"
Write-Host "##vso[task.setvariable variable=coverageString;]$coverage_percent% ($covered_lines of $total_lines lines)"
Write-Host "##vso[task.setvariable variable=statusString;]$status_message ($error_count Errors, $warning_count Warning)"
env: env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken) SYSTEM_ACCESSTOKEN: $(System.AccessToken)
- task: ado-discord-webhook@1 DISCORDCHANNELID: $(discordChannelId)
displayName: Send Webhook Payload DISCORDWEBHOOKKEY: $(discordWebhookKey)
inputs:
channelId: $(discordChannelId)
webhookKey: $(discordWebhookKey)
name: 'AzureBot'
messageType: 'embeds'
embeds: |
[{
"title": "Build $(Build.BuildNumber) [$(Build.Repository.Name)]",
"url": "$(System.CollectionUri)$(System.TeamProject)/_build/results?buildId=$(Build.BuildId)",
"color": $(statusColor),
"fields": [
{
"name": "Author",
"value": "[$(Build.SourceVersionAuthor)](https://github.com/$(Build.SourceVersionAuthor))",
"inline": true
},
{
"name": "Commit",
"value": "[`$(commitString)`]($(commitUrl))",
"inline": true
},
{
"name": "Build Type",
"value": "$(buildTypeString)"
},
{
"name": "Test Results",
"value": "`$(testResultString)`"
},
{
"name": "Coverage",
"value": "`$(coverageString)`"
},
{
"name": "Status",
"value": "$(statusString)",
"inline": true
}
]
}]