[CI] Refactor code out to a function. (#13672)

Make the code more readable, this is the first step to clean the scripts
and to be able to add a switch so that we can diff between comments for
device tests and general comments.
This commit is contained in:
Manuel de la Pena 2022-01-12 20:09:26 -05:00 коммит произвёл GitHub
Родитель a35ee4e7a6
Коммит c5fb5dfa34
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 62 добавлений и 29 удалений

Просмотреть файл

@ -372,6 +372,65 @@ function Test-JobSuccess {
return $Status -eq "Succeeded"
}
<#
.SYNOPSIS
Helper function used to create the content in the comment with the APIDiff
.PARAMETER APIDiff
The path to the the json that contains the content for the PR API diff.
.PARAMETER APIGeneratorDiffJson
The path to the json that contains the content for the generator diffs with stable.
.PARAMETER APIGeneratorDiff
The path to the json that contains the content for the generator diffs.
#>
function Write-APIDiffContent {
param (
[Parameter(Mandatory)]
[System.Text.StringBuilder]
$StringBuilder,
[String]
$APIDiff="",
[string]
$APIGeneratorDiffJson="",
[string]
$APIGeneratorDiff=""
)
if ([string]::IsNullOrEmpty($APIDiff)) {
$StringBuilder.AppendLine("* :warning: API diff urls have not been provided.")
} else {
Write-Diffs -StringBuilder $sb -Header "API diff" -APIDiff $APIDiff
}
if ([string]::IsNullOrEmpty($APIGeneratorDiffJson)) {
$StringBuilder.AppendLine("* :warning: API Current PR diff urls have not been provided.")
} else {
Write-Diffs -StringBuilder $sb -Header "API Current PR diff" -APIDiff $APIGeneratorDiffJson
}
if (-not [string]::IsNullOrEmpty($APIGeneratorDiff)) {
Write-Host "Parsing Generator diff in path $APIGeneratorDiff"
if (-not (Test-Path $APIGeneratorDiff -PathType Leaf)) {
$StringBuilder.AppendLine("* :warning: Path $APIGeneratorDiff was not found!")
} else {
$StringBuilder.AppendLine("# Generator diff")
$StringBuilder.AppendLine("")
# ugly workaround to get decent new lines
foreach ($line in Get-Content -Path $APIGeneratorDiff)
{
$StringBuilder.AppendLine($line)
}
$StringBuilder.AppendLine($apidiffcomments)
}
} else {
$StringBuilder.AppendLine("Generator diff comments have not been provided.")
}
}
<#
.SYNOPSIS
Add a new comment that contains the summaries to the Html Report as well as set the status accordingly.
@ -444,35 +503,9 @@ function New-GitHubSummaryComment {
# we did generate an index with the files in vsdrops
$sb.AppendLine("* [Html Report (VSDrops)]($Env:VSDROPS_INDEX) [Download]($Env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI$Env:SYSTEM_TEAMPROJECT/_apis/build/builds/$Env:BUILD_BUILDID/artifacts?artifactName=HtmlReport-sim&api-version=6.0&`$format=zip)")
}
$diffHeader = "API diff"
$currentPRHeader = "API Current PR diff"
if ([string]::IsNullOrEmpty($APIDiff)) {
$sb.AppendLine("* :warning: API diff urls have not been provided.")
} else {
Write-Diffs -StringBuilder $sb -Header $diffHeader -APIDiff $APIDiff
}
if ([string]::IsNullOrEmpty($APIGeneratorDiffJson)) {
$sb.AppendLine("* :warning: API Current PR diff urls have not been provided.")
} else {
Write-Diffs -StringBuilder $sb -Header $currentPRHeader -APIDiff $APIGeneratorDiffJson
}
if (-not [string]::IsNullOrEmpty($APIGeneratorDiff)) {
Write-Host "Parsing Generator diff in path $APIGeneratorDiff"
if (-not (Test-Path $APIGeneratorDiff -PathType Leaf)) {
$sb.AppendLine("Path $APIGeneratorDiff was not found!")
} else {
$sb.AppendLine("# Generator diff")
$sb.AppendLine("")
# ugly workaround to get decent new lines
foreach ($line in Get-Content -Path $APIGeneratorDiff)
{
$sb.AppendLine($line)
}
$sb.AppendLine($apidiffcomments)
}
} else {
$sb.AppendLine("* :warning: Generator diff comments have not been provided.")
}
Write-APIDiffContent -StringBuilder $sb -APIDiff $APIDiff -APIGeneratorDiffJson $APIGeneratorDiffJson -APIGeneratorDiff $APIGeneratorDiff
if (-not [string]::IsNullOrEmpty($Artifacts)) {
Write-Host "Parsing artifacts"
if (-not (Test-Path $Artifacts -PathType Leaf)) {