diff --git a/.vscode/cspell.json b/.vscode/cspell.json index 4c116afe3..766423b0b 100644 --- a/.vscode/cspell.json +++ b/.vscode/cspell.json @@ -38,10 +38,12 @@ "adamdebreceni", "Adls", "ahojnnes", + "ahsonkhan", "Aloctl", "AMQP", "AMQPS", "AMQPVALUE", + "antkmsft", "azcore", "azsdk", "azsdkengsys", @@ -124,6 +126,7 @@ "OIDC", "okhttp", "opentelemetry", + "Osterman", "otel", "PBYTE", "pdbs", diff --git a/eng/pipelines/templates/stages/archetype-cpp-release.yml b/eng/pipelines/templates/stages/archetype-cpp-release.yml index 1b807d234..4962c3807 100644 --- a/eng/pipelines/templates/stages/archetype-cpp-release.yml +++ b/eng/pipelines/templates/stages/archetype-cpp-release.yml @@ -193,15 +193,20 @@ stages: OpenAsDraft: ${{ parameters.TestPipeline }} CloseAfterOpenForTesting: '${{ parameters.TestPipeline }}' + # Workaround: -Fallback uses names from CODEOWNERS who + # should be notified about the release in the event of a + # failure to resolve the appropriate aliases. - pwsh: | - $codeOwnersToNotify = $(Build.SourcesDirectory)/eng/common/scripts/get-codeowners.ps1 ` - -TargetDirectory "/sdk/${{ parameters.ServiceDirectory }}/" ` - -CodeownersFileLocation "$(Build.SourcesDirectory)/.github/CODEOWNERS" + $notifyUsers = ./eng/scripts/Get-TriggeringUserGitHubAlias.ps1 ` + -EmailAddress "$($env:BUILD_REQUESTEDFOREMAIL)" ` + -ClientId '$(opensource-aad-app-id)' ` + -ClientSecret '$(opensource-aad-secret)' ` + -TenantId '$(opensource-aad-tenant-id)' ` + -Fallback '@rickwinter @ahsonkhan @antkmsft @gearama @LarryOsterman' $prComment = "Adding ${{ artifact.Name }} to release" - if ($codeOwnersToNotify) { - $codeOwners = $codeOwnersToNotify.ForEach({ "@$_" }) -join ", " - $prComment += "`n`ncc: $codeOwners" + if ($notifyUsers) { + $prComment += "`n`ncc: $notifyUsers" } ./eng/common/scripts/Add-IssueComment.ps1 ` diff --git a/eng/scripts/Get-TriggeringUserGitHubAlias.ps1 b/eng/scripts/Get-TriggeringUserGitHubAlias.ps1 new file mode 100644 index 000000000..a2e309571 --- /dev/null +++ b/eng/scripts/Get-TriggeringUserGitHubAlias.ps1 @@ -0,0 +1,28 @@ +param( + [string] $EmailAddress = $env:BUILD_REQUESTEDFOREMAIL, + [string] $ClientId, + [string] $ClientSecret, + [string] $TenantId, + [string] $Fallback +) + +. "$PSScriptRoot/../common/scripts/Helpers/Metadata-Helpers.ps1" + +$allUsers = GetAllGitHubUsers ` + -TenantId $TenantId ` + -ClientId $ClientId ` + -ClientSecret $ClientSecret + +if (!$allUsers) { + Write-Host "Failed to get all GitHub users" + return $Fallback +} + +$targetUser = $allUsers.Where({ $_.aad.userPrincipalName -eq $EmailAddress -and $_.github.login }, 'First') + +if (!$targetUser) { + Write-Host "Failed to find GitHub user for $EmailAddress" + return $Fallback +} + +return "@$($targetUser.github.login)"