diff --git a/.github/workflows/platform.set-avm-github-pr-labels.yml b/.github/workflows/platform.set-avm-github-pr-labels.yml index 07b6cfd236..e273937a9d 100644 --- a/.github/workflows/platform.set-avm-github-pr-labels.yml +++ b/.github/workflows/platform.set-avm-github-pr-labels.yml @@ -3,7 +3,7 @@ name: .Platform - Set AVM GitHub PR labels on: pull_request_target: - types: [opened] + types: [opened, ready_for_review] jobs: SetAvmGitHubPrLabels: diff --git a/avm/utilities/pipelines/platform/Set-AvmGitHubPrLabels.ps1 b/avm/utilities/pipelines/platform/Set-AvmGitHubPrLabels.ps1 index c0ed737877..a22fabe460 100644 --- a/avm/utilities/pipelines/platform/Set-AvmGitHubPrLabels.ps1 +++ b/avm/utilities/pipelines/platform/Set-AvmGitHubPrLabels.ps1 @@ -39,33 +39,35 @@ function Set-AvmGitHubPrLabels { $sanitizedPrUrl = $PrUrl.Replace('api.', '').Replace('repos/', '').Replace('pulls/', 'pull/') $pr = gh pr view $sanitizedPrUrl --json 'author,title,url,body,comments' --repo $Repo | ConvertFrom-Json -Depth 100 - $allTeamNames = [array](Get-GithubPrRequestedReviewerTeamNames -PrUrl $sanitizedPrUrl) + $allTeamNames = [array](Get-GithubPrRequestedReviewerTeamNames -PrUrl $pr.url) $teamNames = [array]($allTeamNames | Where-Object { $_ -ne 'bicep-admins' -and $_ -ne 'avm-core-team-technical-bicep' -and $_ -ne 'avm-module-reviewers-bicep' }) - # core team is already assigned, no or more than one module reviewer team is assigned - if ($allTeamNames.Contains('avm-core-team-technical-bicep') -or $teamNames.Count -eq 0 -or $teamNames.Count -gt 1) { - gh pr edit $pr.url --add-label 'Needs: Core Team :genie:' --repo $Repo - } else { - $teamMembers = [array](Get-GithubTeamMembersLogin -OrgName $Repo.Split('/')[0] -TeamName $teamNames[0]) - - # no members in module team or only one and that user submitted the PR - if (($teamMembers.Count -eq 0) -or ($teamMembers.Count -eq 1 -and $teamMembers[0] -eq $pr.author.login)) { + if ($allTeamNames.Count -gt 0) { + # core team is already assigned, no or more than one module reviewer team is assigned + if ($allTeamNames.Contains('avm-core-team-technical-bicep') -or $teamNames.Count -eq 0 -or $teamNames.Count -gt 1) { gh pr edit $pr.url --add-label 'Needs: Core Team :genie:' --repo $Repo } else { - gh pr edit $pr.url --add-label 'Needs: Module Owner :mega:' --repo $Repo - } + $teamMembers = [array](Get-GithubTeamMembersLogin -OrgName $Repo.Split('/')[0] -TeamName $teamNames[0]) + + # no members in module team or only one and that user submitted the PR + if (($teamMembers.Count -eq 0) -or ($teamMembers.Count -eq 1 -and $teamMembers[0] -eq $pr.author.login)) { + gh pr edit $pr.url --add-label 'Needs: Core Team :genie:' --repo $Repo + } else { + gh pr edit $pr.url --add-label 'Needs: Module Owner :mega:' --repo $Repo + } - # check for orphanded module - $moduleName = $teamNames[0] - $moduleIndex = $moduleName.StartsWith('avm-res') ? 'Bicep-Resource' : ($moduleName.StartsWith('avm-ptn') ? 'Bicep-Pattern' : 'Bicep-Utility') - # get CSV data - $modules = Get-AvmCsvData -ModuleIndex $moduleIndex + # check for orphanded module + $moduleName = $teamNames[0] + $moduleIndex = $moduleName.StartsWith('avm-res') ? 'Bicep-Resource' : ($moduleName.StartsWith('avm-ptn') ? 'Bicep-Pattern' : 'Bicep-Utility') + # get CSV data + $modules = Get-AvmCsvData -ModuleIndex $moduleIndex - foreach ($module in $modules) { - if ($module.ModuleName.Replace('-', '').Replace('/', '-') -eq $moduleName) { - if ($module.ModuleStatus -eq 'Orphaned :eyes:') { - gh pr edit $pr.url --add-label 'Status: Module Orphaned :eyes:' --repo $Repo - break; + foreach ($module in $modules) { + if ($module.ModuleName.Replace('-', '').Replace('/', '-') -eq $moduleName) { + if ($module.ModuleStatus -eq 'Orphaned :eyes:') { + gh pr edit $pr.url --add-label 'Status: Module Orphaned :eyes:' --repo $Repo + break; + } } } }