@@ -141,6 +141,47 @@ function shouldSkipCodeownersInPrContext([PSCustomObject] $PackageProperties, [P
141141 return $true
142142}
143143
144+ function getCheckPackageOutputText ([array ] $OutputLines ) {
145+ if (! $OutputLines ) {
146+ return " "
147+ }
148+
149+ return ((@ ($OutputLines ) | ForEach-Object { " $_ " }) -join [Environment ]::NewLine).Trim()
150+ }
151+
152+ function getCheckPackageResponse ([string ] $OutputText ) {
153+ if (! $OutputText ) {
154+ return $null
155+ }
156+
157+ try {
158+ return $OutputText | ConvertFrom-Json - ErrorAction Stop
159+ }
160+ catch {
161+ return $null
162+ }
163+ }
164+
165+ function getCheckPackageIssues ([object ] $CheckPackageResponse ) {
166+ if (! $CheckPackageResponse -or ! $CheckPackageResponse.PSObject.Properties [' issues' ]) {
167+ return , @ ()
168+ }
169+
170+ $issues = @ ()
171+ foreach ($issue in @ ($CheckPackageResponse.issues )) {
172+ if (! $issue ) {
173+ continue
174+ }
175+
176+ $issues += [PSCustomObject ]@ {
177+ Message = $issue.message
178+ Prompt = $issue.next_step
179+ }
180+ }
181+
182+ return , @ ($issues )
183+ }
184+
144185$failedPackages = @ ()
145186$prDiff = $null
146187$isPrCheck = $false
@@ -158,6 +199,8 @@ if ($PrDiffFile) {
158199
159200Write-Host " SDK types to validate: $ ( $SdkTypes -join ' , ' ) "
160201
202+ LogGroupStart " Validating CODEOWNERS for Artifacts"
203+
161204foreach ($pkgPropertiesFile in Get-ChildItem - Path $PackageInfoDirectory - Filter ' *.json' - File) {
162205 $pkgProperties = Get-Content - Raw - Path $pkgPropertiesFile | ConvertFrom-Json
163206 $artifactDetails = $pkgProperties.ArtifactDetails
@@ -173,9 +216,19 @@ foreach ($pkgPropertiesFile in Get-ChildItem -Path $PackageInfoDirectory -Filter
173216
174217 Write-Host " Validating codeowners for package: $ ( $pkgProperties.Name ) $ ( $pkgProperties.DirectoryPath ) "
175218
176- if (! $isPrCheck -and ! $pkgProperties.ReleaseStatus ) {
177- LogError " Package $ ( $pkgProperties.Name ) at $ ( $pkgProperties.DirectoryPath ) is missing a ReleaseStatus property."
178- $failedPackages += $pkgProperties.DirectoryPath
219+ $hasReleaseStatus = $pkgProperties.PSObject.Properties [' ReleaseStatus' ] -and
220+ ! [string ]::IsNullOrWhiteSpace([string ]$pkgProperties.ReleaseStatus )
221+
222+ if (! $isPrCheck -and ! $hasReleaseStatus ) {
223+ $responseError = " Package $ ( $pkgProperties.Name ) at $ ( $pkgProperties.DirectoryPath ) is missing a ReleaseStatus property."
224+ LogError $responseError
225+ $failedPackages += [PSCustomObject ]@ {
226+ Name = $pkgProperties.Name
227+ DirectoryPath = $pkgProperties.DirectoryPath
228+ ResponseError = $responseError
229+ Issues = @ ()
230+ HasParsedResponse = $false
231+ }
179232 continue
180233 }
181234
@@ -188,11 +241,26 @@ foreach ($pkgPropertiesFile in Get-ChildItem -Path $PackageInfoDirectory -Filter
188241 -- directory- path $pkgProperties.DirectoryPath `
189242 -- repo $Repo `
190243 -- output json 2>&1
244+ $checkPackageExitCode = $LASTEXITCODE
245+ $outputText = getCheckPackageOutputText - OutputLines $output
191246
192- if ($LASTEXITCODE ) {
193- LogError " Codeowners validation failed for package: $ ( $pkgProperties.DirectoryPath ) "
194- $output | Write-Host
195- $failedPackages += $pkgProperties.DirectoryPath
247+ Write-Host " check-package output:"
248+ if ($outputText ) {
249+ Write-Host $outputText
250+ } else {
251+ Write-Host " (no output)"
252+ }
253+
254+ if ($checkPackageExitCode ) {
255+ Write-Host " Codeowners validation failed for package: $ ( $pkgProperties.DirectoryPath ) "
256+ $checkPackageResponse = getCheckPackageResponse - OutputText $outputText
257+ $failedPackages += [PSCustomObject ]@ {
258+ Name = $pkgProperties.Name
259+ DirectoryPath = $pkgProperties.DirectoryPath
260+ ResponseError = if ($checkPackageResponse ) { $checkPackageResponse.response_error } else { $null }
261+ Issues = getCheckPackageIssues - CheckPackageResponse $checkPackageResponse
262+ HasParsedResponse = $null -ne $checkPackageResponse
263+ }
196264 } else {
197265 Write-Host " Codeowners validation succeeded for package: $ ( $pkgProperties.DirectoryPath ) "
198266 }
@@ -201,13 +269,31 @@ foreach ($pkgPropertiesFile in Get-ChildItem -Path $PackageInfoDirectory -Filter
201269 }
202270}
203271
272+ LogGroupEnd
273+
204274if ($failedPackages.Count -gt 0 ) {
205275 Write-Host " "
276+ Write-Host " Codeowners validation failed for one or more packages. See https://aka.ms/azsdk/codeowners for instructions to fix the issue."
206277 Write-Host " Failed Packages:"
207- foreach ($directoryPath in $failedPackages ) {
208- LogError " - $directoryPath does not have sufficient code owners coverage"
278+ foreach ($failedPackage in $failedPackages ) {
279+ Write-Host " - $ ( $failedPackage.DirectoryPath ) does not have sufficient code owners coverage"
280+ if ($failedPackage.HasParsedResponse -and @ ($failedPackage.Issues ).Count -gt 0 ) {
281+ Write-Host " Issue details:"
282+ foreach ($issue in $failedPackage.Issues ) {
283+ if ($issue.Message ) {
284+ Write-Host " Error: $ ( $issue.Message ) "
285+ }
286+
287+ if ($issue.Prompt ) {
288+ Write-Host " Use this prompt template to fix: $ ( $issue.Prompt ) "
289+ }
290+ }
291+ } elseif ($failedPackage.ResponseError ) {
292+ Write-Host " $ ( $failedPackage.ResponseError ) "
293+ } elseif (! $failedPackage.HasParsedResponse ) {
294+ Write-Host " Unable to parse check-package output; see grouped output above."
295+ }
209296 }
210- LogError " Codeowners validation failed for one or more packages. See http://aka.ms/azsdk/codeowners for instructions to fix the issue."
211297 exit 1
212298}
213299exit 0
0 commit comments