From f85cd06f68335174c1547999be1ba750fb569879 Mon Sep 17 00:00:00 2001 From: Azure SDK Bot <53356347+azure-sdk@users.noreply.github.com> Date: Wed, 20 Oct 2021 12:08:00 -0700 Subject: [PATCH] Sync eng/common directory with azure-sdk-tools for PR 2093 (#1063) * Consume Codeowners parser library, ceperate users from teams in codeownerse * Update get-pr-owners and related logic Co-authored-by: Chidozie Ononiwu --- .../templates/steps/get-pr-owners.yml | 48 ++++++++++-------- eng/common/scripts/get-codeowners.ps1 | 50 ------------------- 2 files changed, 28 insertions(+), 70 deletions(-) delete mode 100644 eng/common/scripts/get-codeowners.ps1 diff --git a/eng/common/pipelines/templates/steps/get-pr-owners.yml b/eng/common/pipelines/templates/steps/get-pr-owners.yml index 019bf5aa0..1ea87e856 100644 --- a/eng/common/pipelines/templates/steps/get-pr-owners.yml +++ b/eng/common/pipelines/templates/steps/get-pr-owners.yml @@ -1,16 +1,30 @@ parameters: TargetVariable: '' + TargetUserVariable: 'notspecified' + TargetTeamVariable: 'notspecified' + TargetLabelVariable: 'notspecified' ServiceDirectory: '' + DevOpsFeed: "https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json" steps: - - pwsh: | - git clone https://github.com/Azure/azure-sdk-tools.git $(Build.SourcesDirectory)/tools_repo - cd $(Build.SourcesDirectory)/tools_repo - git checkout azure-sdk-tools_20210114.1 - displayName: Setup Identity Resolver + - task: DotNetCoreCLI@2 + displayName: 'Install Identity Resolver' + inputs: + command: custom + custom: 'tool' + arguments: 'install --global --add-source "${{ parameters.DevOpsFeed }}" --version "1.0.0-dev.20211018.1" "Azure.Sdk.Tools.IdentityResolver"' + workingDirectory: '$(Agent.BuildDirectory)' + + - task: DotNetCoreCLI@2 + displayName: 'Install CodeOwners Retriever' + inputs: + command: custom + custom: 'tool' + arguments: 'install --global --add-source "${{ parameters.DevOpsFeed }}" --version "1.0.0-dev.20211019.1" "Azure.Sdk.Tools.RetrieveCodeOwners"' + workingDirectory: '$(Agent.BuildDirectory)' - pwsh: | - dotnet run -v q -- ` + identity-resolver ` --aad-app-id-var APP_ID ` --aad-app-secret-var APP_SECRET ` --aad-tenant-var AAD_TENANT ` @@ -19,10 +33,9 @@ steps: --kusto-table-var KUSTO_TABLE ` --identity-name "$(Build.QueuedBy)" ` --identity-email "$(Build.RequestedForEmail)" ` - --targetvar "${{ parameters.TargetVariable }}" + --targetvar "${{ coalesce(parameters.TargetVariable, parameters.TargetUserVariable) }}" displayName: 'Resolving Queuing User' continueOnError: true - workingDirectory: $(Build.SourcesDirectory)/tools_repo/tools/notification-configuration/identity-resolver env: APP_ID: $(notification-aad-app-id) APP_SECRET: $(notification-aad-secret) @@ -32,15 +45,10 @@ steps: KUSTO_TABLE: $(notification-kusto-table) - pwsh: | - Remove-Item -Force -Recurse $(Build.SourcesDirectory)/tools_repo - displayName: Clean Up Cloned Tools Repo - - - task: PowerShell@2 - displayName: Add CodeOwners if Present - inputs: - pwsh: true - filePath: $(Build.SourcesDirectory)/eng/common/scripts/get-codeowners.ps1 - arguments: > - -TargetDirectory "/sdk/${{ parameters.ServiceDirectory }}/" - -RootDirectory "$(Build.SourcesDirectory)" - -VsoVariable "${{ parameters.TargetVariable }}" \ No newline at end of file + retrieve-codeowners ` + --target-directory "/sdk/${{ parameters.ServiceDirectory }}/" ` + --root-directory "$(Build.SourcesDirectory)" ` + --vso-owning-users "${{ coalesce(parameters.TargetVariable, parameters.TargetUserVariable) }}" ` + --vso-owning-teams "${{ parameters.TargetTeamVariable }}" ` + --vso-owning-labels "${{ parameters.TargetLabelVariable }}" + displayName: 'Add CodeOwners if Present' \ No newline at end of file diff --git a/eng/common/scripts/get-codeowners.ps1 b/eng/common/scripts/get-codeowners.ps1 deleted file mode 100644 index f28cb3df7..000000000 --- a/eng/common/scripts/get-codeowners.ps1 +++ /dev/null @@ -1,50 +0,0 @@ -param ( - $TargetDirectory, # should be in relative form from root of repo. EG: sdk/servicebus - $RootDirectory, # ideally $(Build.SourcesDirectory) - $VsoVariable = "" # target devops output variable -) -$target = $TargetDirectory.ToLower().Trim("/") -$codeOwnersLocation = Join-Path $RootDirectory -ChildPath ".github/CODEOWNERS" -$ownedFolders = @{} - -if (!(Test-Path $codeOwnersLocation)) { - Write-Host "Unable to find CODEOWNERS file in target directory $RootDirectory" - exit 1 -} - -$codeOwnersContent = Get-Content $codeOwnersLocation - -foreach ($contentLine in $codeOwnersContent) { - if (-not $contentLine.StartsWith("#") -and $contentLine){ - $splitLine = $contentLine -split "\s+" - - # CODEOWNERS file can also have labels present after the owner aliases - # gh aliases start with @ in codeowners. don't pass on to API calls - $ownedFolders[$splitLine[0].ToLower().Trim("/")] = ($splitLine[1..$($splitLine.Length)] ` - | ? { $_.StartsWith("@") } ` - | % { return $_.substring(1) }) -join "," - } -} - -$results = $ownedFolders[$target] - -if ($results) { - Write-Host "Found a folder $results to match $target" - - if ($VsoVariable) { - $alreadyPresent = [System.Environment]::GetEnvironmentVariable($VsoVariable) - - if ($alreadyPresent) { - $results += ",$alreadyPresent" - } - Write-Host "##vso[task.setvariable variable=$VsoVariable;]$results" - } - - return $results -} -else { - Write-Host "Unable to match path $target in CODEOWNERS file located at $codeOwnersLocation." - Write-Host ($ownedFolders | ConvertTo-Json) - return "" -} -