@@ -1056,104 +1056,116 @@ jobs:
10561056
10571057 }
10581058
1059- # Auto user assignment can be disabled on repos using the $DataTableName table .
1059+ # Auto user assignment can be disabled on repos in the calling workflow .
10601060 If ($AutoAssignUsers -eq $True) {
10611061
1062- # There's a short window between PR open and when Draft is set by the TierManagement workflow where PR reviewers could be added.
1063- # This If statement prevents that from happening.
1064- If (($GitHubAction -ne "opened") -and ($IsPrDraft -eq $False)) {
1062+ # ##################################### Auto reviewer assignment ######################################
10651063
1066- # Get permission level of user who created the comment. Need to use .role_name instead of .permission because .permission provides only legacy values.
1067- # .role_name provides legacy plus triage, maintain, and custom roles like write-elevated.
1068- $UserPermission = $(Invoke-RestMethod -Method GET -Headers $GitHubHeaders -Uri $UserPermissionUrl).role_name
1064+ If ($AutoAssignReviewers -eq $True) {
1065+
1066+ # There's a short window between PR open and when Draft is set by the TierManagement workflow where PR reviewers could be added.
1067+ # This If statement prevents that from happening.
1068+ If (($GitHubAction -ne "opened") -and ($IsPrDraft -eq $False)) {
1069+
1070+ # Get permission level of user who created the comment. Need to use .role_name instead of .permission because .permission provides only legacy values.
1071+ # .role_name provides legacy plus triage, maintain, and custom roles like write-elevated.
1072+ $UserPermission = $(Invoke-RestMethod -Method GET -Headers $GitHubHeaders -Uri $UserPermissionUrl).role_name
1073+
1074+ # Only add reviewers if the submitter can't sign off on their own PR.
1075+ If ($UserPermission -eq "read") {
10691076
1070- # Only add reviewers if the submitter can't sign off on their own PR.
1071- If ($UserPermission -eq "read") {
1077+ # Get the service/subservice to GitHub account map
1078+ $ServiceToAccountMap = Get-ServiceGitHubAccountMappingTable
1079+ $ExpandedServiceSubServiceRows = Expand-ServiceSubServiceRows -CsvContent $ServiceToAccountMap
10721080
1073- # Get the service/subservice to GitHub account map
1074- $ServiceToAccountMap = Get-ServiceGitHubAccountMappingTable
1075- $ExpandedServiceSubServiceRows = Expand-ServiceSubServiceRows -CsvContent $ServiceToAccountMap
1081+ $ReviewerArray = @()
10761082
1077- $ReviewerArray = @()
1083+ ForEach ($File in $FileMetadataArray) {
10781084
1079- ForEach ($File in $FileMetadataArray ) {
1085+ If ($File.Service -ne $Null ) {
10801086
1081- If ($File.Service -ne $Null) {
1087+ $FileReviewers = $Null
10821088
1083- $FileReviewers = $Null
1089+ $FileReviewers = Get-ContentLeadAccounts -DataArray $ExpandedServiceSubServiceRows -Service $File.Service -SubService $File.SubService
10841090
1085- $FileReviewers = Get-ContentLeadAccounts -DataArray $ExpandedServiceSubServiceRows -Service $File.Service -SubService $File.SubService
1091+ If ($FileReviewers -ne $Null) {
1092+
1093+ $ReviewerArray += $FileReviewers
1094+
1095+ }
10861096
1087- If ($FileReviewers -ne $Null) {
1097+ } Else {
10881098
1089- $ReviewerArray += $FileReviewers
1099+ Write-Host "No service found for file $($File.FileName)."
10901100
10911101 }
1092-
1093- } Else {
1094-
1095- Write-Host "No service found for file $($File.FileName)."
10961102
10971103 }
1098-
1099- }
11001104
1101- $ReviewerArray = $ReviewerArray | Select-Object -Unique
1105+ $ReviewerArray = $ReviewerArray | Select-Object -Unique
11021106
1103- If ($ReviewerArray.Count -gt 0) {
1107+ If ($ReviewerArray.Count -gt 0) {
11041108
1105- Write-Host "Checking org membership."
1109+ Write-Host "Checking org membership."
11061110
1107- $TestedReviewerAccounts = Test-OrgMembership -GitHubReviewers $ReviewerArray
1108- $ValidatedReviewerAccounts = $TestedReviewerAccounts.keys | Where-Object { $TestedReviewerAccounts[$_] }
1111+ $TestedReviewerAccounts = Test-OrgMembership -GitHubReviewers $ReviewerArray
1112+ $ValidatedReviewerAccounts = $TestedReviewerAccounts.keys | Where-Object { $TestedReviewerAccounts[$_] }
11091113
1110- $AtMentionedGitHubAccounts = Add-AtPrefix -GitHubReviewers $ValidatedReviewerAccounts
1114+ $AtMentionedGitHubAccounts = Add-AtPrefix -GitHubReviewers $ValidatedReviewerAccounts
11111115
1112- If ($ValidatedReviewerAccounts.Length -gt 0) {
1116+ If ($ValidatedReviewerAccounts.Length -gt 0) {
11131117
1114- $MissingReviewers = Compare-PRIndividualReviewers -GitHubReviewers $ValidatedReviewerAccounts
1118+ $MissingReviewers = Compare-PRIndividualReviewers -GitHubReviewers $ValidatedReviewerAccounts
11151119
1116- If ($MissingReviewers) {
1117-
1118- Write-Host "Additional reviewers found. Setting reviewers and posting PR comment."
1120+ If ($MissingReviewers) {
1121+
1122+ Write-Host "Additional reviewers found. Setting reviewers and posting PR comment."
1123+
1124+ $ReviewerMessage = $AtMentionedGitHubAccounts + $(Get-PrMessage "AutoLabelAssign-ContentLeadReviewNotice")
11191125
1120- $ReviewerMessage = $AtMentionedGitHubAccounts + $(Get-PrMessage "AutoLabelAssign-ContentLeadReviewNotice")
1126+ Set-PrReviewer -PrUrl $PrUrl -GitHubReviewers $ValidatedReviewerAccounts
1127+ Set-PrConversationMessage -Message $ReviewerMessage
11211128
1122- Set-PrReviewer -PrUrl $PrUrl -GitHubReviewers $ValidatedReviewerAccounts
1123- Set-PrConversationMessage -Message $ReviewerMessage
1129+ } Else {
1130+
1131+ Write-Host "No additional reviewers to add. Not setting reviewers or posting PR comment."
11241132
1125- } Else {
1126-
1127- Write-Host "No additional reviewers to add. Not setting reviewers or posting PR comment."
1133+ }
11281134
1129- }
1135+ } Else {
1136+
1137+ Write-Host "No valid reviewers to assign."
1138+ Write-Host $TestedReviewerAccounts
1139+
1140+ }
11301141
11311142 } Else {
1132-
1133- Write-Host "No valid reviewers to assign."
1134- Write-Host $TestedReviewerAccounts
11351143
1144+ Write-Host "No reviewers matched any services or subservices in PR articles."
1145+
11361146 }
11371147
1148+
11381149 } Else {
1139-
1140- Write-Host "No reviewers matched any services or subservices in PR articles ."
1141-
1150+
1151+ Write-Host "Not adding reviewer because submitter can sign off PR. User permission : $UserPermission ."
1152+
11421153 }
11431154
1144-
11451155 } Else {
11461156
1147- Write-Host "Not adding reviewer because submitter can sign off PR. User permission : $UserPermission ."
1157+ Write-Host "Not adding PR reviewers. PR action : $GitHubAction. Draft state : $IsPrDraft ."
11481158
11491159 }
11501160
11511161 } Else {
11521162
1153- Write-Host "Not adding PR reviewers. PR action : $GitHubAction. Draft state: $IsPrDraft ."
1163+ Write-Host "Auto reviewer assignment disabled ."
11541164
11551165 }
11561166
1167+ # ##################################### Auto user assignment ######################################
1168+
11571169 # Don't add assignments to PRs in excluded branches listed in $ExcludedBranchList
11581170 If (!$ExcludedBranchList.Contains($TargetBranch)) {
11591171
0 commit comments