Skip to content

Commit 70eb2c6

Browse files
authored
Merge pull request #13900 from MicrosoftDocs/workflows-test
Handle null reviewer array and missing file service
2 parents aa7a4f0 + 8d24517 commit 70eb2c6

1 file changed

Lines changed: 47 additions & 27 deletions

File tree

.github/workflows/Shared-AutoLabelAssign.yml

Lines changed: 47 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,16 @@ jobs:
145145
146146
# Initialize variables.
147147
$FileData = @{}
148+
$FileName = $File.filename
148149
$MetadataFound = $False
150+
149151
# Check to see whether current file is markdown or YAML. Those are the only files we care about. Ignore the rest.
150-
$IsContentFile = ($File.filename.EndsWith(".md") -or $File.filename.EndsWith(".yml")) -and !$File.filename.ToLower().Contains("/toc.")
152+
$IsContentFile = ($FileName.EndsWith(".md") -or $FileName.EndsWith(".yml")) -and !$FileName.ToLower().Contains("/toc.")
151153
152154
# Only process content files.
153155
If ($IsContentFile) {
154156
155-
Write-Host "Processing file $($File.filename)."
157+
Write-Host "Processing file $FileName."
156158
157159
# Retrieve file contents from GitHub. File contents is returned in Base 64 so after contents is retrieved, convert from Base 64 to plain text.
158160
$FileContentsBase64 = Invoke-RestMethod -Method GET -Uri $File.contents_url -Headers $GitHubHeaders
@@ -217,11 +219,12 @@ jobs:
217219
Technology = $Technology
218220
Tier = $Tier
219221
Author = $Author
222+
FileName = $FileName
220223
}
221224
222225
# If any metadata or author data was found, add it to the $FileArray output array.
223226
If ($MetadataFound) {
224-
Write-Host "Metadata or author data found on $($File.filename). Adding to output array."
227+
Write-Host "Metadata or author data found on $FileName. Adding to output array."
225228
$FileArray += $FileData
226229
}
227230
}
@@ -254,6 +257,7 @@ jobs:
254257
If ($File.Tier -ne $Null) {$MetadataArray += $File.Tier.SubString(0,1).ToUpper() + $File.Tier.SubString(1).ToLower()}
255258
If ($File.Author -ne $Null) {$AuthorArray += $File.Author}
256259
260+
257261
}
258262
259263
# Because there might be multiple files in the $MetaDataArray and $AuthorArrays with the same metadata and author data, duplicate values might have been added to the output arrays.
@@ -1073,52 +1077,68 @@ jobs:
10731077
$ReviewerArray = @()
10741078

10751079
ForEach ($File in $FileMetadataArray) {
1076-
1077-
$FileReviewers = $Null
10781080

1079-
$FileReviewers = Get-ContentLeadAccounts -DataArray $ExpandedServiceSubServiceRows -Service $File.Service -SubService $File.SubService
1081+
If ($File.Service -ne $Null) {
10801082

1081-
If ($FileReviewers -ne $Null) {
1082-
1083-
$ReviewerArray += $FileReviewers
1083+
$FileReviewers = $Null
1084+
1085+
$FileReviewers = Get-ContentLeadAccounts -DataArray $ExpandedServiceSubServiceRows -Service $File.Service -SubService $File.SubService
1086+
1087+
If ($FileReviewers -ne $Null) {
1088+
1089+
$ReviewerArray += $FileReviewers
1090+
1091+
}
1092+
1093+
} Else {
1094+
1095+
Write-Host "No service found for file $($File.FileName)."
10841096

10851097
}
10861098

10871099
}
10881100

10891101
$ReviewerArray = $ReviewerArray | Select-Object -Unique
10901102

1091-
Write-Host "Checking org membership."
1103+
If ($ReviewerArray.Count -gt 0) {
10921104

1093-
$TestedReviewerAccounts = Test-OrgMembership -GitHubReviewers $ReviewerArray
1094-
$ValidatedReviewerAccounts = $TestedReviewerAccounts.keys | Where-Object { $TestedReviewerAccounts[$_] }
1105+
Write-Host "Checking org membership."
10951106

1096-
$AtMentionedGitHubAccounts = Add-AtPrefix -GitHubReviewers $ValidatedReviewerAccounts
1107+
$TestedReviewerAccounts = Test-OrgMembership -GitHubReviewers $ReviewerArray
1108+
$ValidatedReviewerAccounts = $TestedReviewerAccounts.keys | Where-Object { $TestedReviewerAccounts[$_] }
10971109

1098-
If ($ValidatedReviewerAccounts.Length -gt 0) {
1110+
$AtMentionedGitHubAccounts = Add-AtPrefix -GitHubReviewers $ValidatedReviewerAccounts
10991111

1100-
$MissingReviewers = Compare-PRIndividualReviewers -GitHubReviewers $ValidatedReviewerAccounts
1112+
If ($ValidatedReviewerAccounts.Length -gt 0) {
11011113

1102-
If ($MissingReviewers) {
1103-
1104-
Write-Host "Additional reviewers found. Setting reviewers and posting PR comment."
1114+
$MissingReviewers = Compare-PRIndividualReviewers -GitHubReviewers $ValidatedReviewerAccounts
11051115

1106-
$ReviewerMessage = $AtMentionedGitHubAccounts + $(Get-PrMessage "AutoLabelAssign-ContentLeadReviewNotice")
1116+
If ($MissingReviewers) {
1117+
1118+
Write-Host "Additional reviewers found. Setting reviewers and posting PR comment."
11071119

1108-
Set-PrReviewer -PrUrl $PrUrl -GitHubReviewers $ValidatedReviewerAccounts
1109-
Set-PrConversationMessage -Message $ReviewerMessage
1120+
$ReviewerMessage = $AtMentionedGitHubAccounts + $(Get-PrMessage "AutoLabelAssign-ContentLeadReviewNotice")
11101121

1111-
} Else {
1122+
Set-PrReviewer -PrUrl $PrUrl -GitHubReviewers $ValidatedReviewerAccounts
1123+
Set-PrConversationMessage -Message $ReviewerMessage
1124+
1125+
} Else {
11121126

1113-
Write-Host "No additional reviewers to add. Not setting reviewers or posting PR comment."
1127+
Write-Host "No additional reviewers to add. Not setting reviewers or posting PR comment."
1128+
1129+
}
11141130

1131+
} Else {
1132+
1133+
Write-Host "No valid reviewers to assign."
1134+
Write-Host $TestedReviewerAccounts
1135+
11151136
}
11161137

11171138
} Else {
1118-
1119-
Write-Host "No valid reviewers to assign."
1120-
Write-Host $TestedReviewerAccounts
1121-
1139+
1140+
Write-Host "No reviewers matched any services or subservices in PR articles."
1141+
11221142
}
11231143

11241144

0 commit comments

Comments
 (0)