From 0a2f5c2e29e17026c6fdccf50c5edc678b2be70f Mon Sep 17 00:00:00 2001 From: sima-zhu Date: Fri, 19 Nov 2021 10:38:31 -0800 Subject: [PATCH 01/36] Install and Run code owner tools in get-codeowner.ps1 --- eng/common/scripts/get-codeowners.ps1 | 96 ++++++++++++++++----------- 1 file changed, 59 insertions(+), 37 deletions(-) diff --git a/eng/common/scripts/get-codeowners.ps1 b/eng/common/scripts/get-codeowners.ps1 index fdf8453ace..1ff6fb2644 100644 --- a/eng/common/scripts/get-codeowners.ps1 +++ b/eng/common/scripts/get-codeowners.ps1 @@ -1,49 +1,71 @@ param ( - $TargetDirectory, # should be in relative form from root of repo. EG: sdk/servicebus - $RootDirectory, # ideally $(Build.SourcesDirectory) - $VsoVariable = "" # target devops output variable + [string]$TargetDirectory, # Code path to code owners. e.g sdk/core/azure-amqp + [string]$RootDirectory = "$env:SYSTEM_DEFAULTWORKINGDIRECTORY", # The repo contains CODEOWNER file. + [string]$CodeOwnerFileLocation = "$PSSCriptRoot/../../../.github/CODEOWNERS", # The absolute path of CODEOWNERS file. + [string]$ToolVersion = "1.0.0-dev.20211118.20", # Placeholder. Will update in next PR + [string]$ToolPath = "$env:AGENT_TOOLSDIRECTORY", # The place to check the tool existence. Put $(Agent.ToolsDirectory) as default + [string]$DevOpsFeed = "https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json", # DevOp tool feeds. + [string]$VsoVariable = "" # Option of write code owners into devop 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 +$LocalCodeOwnerPath = ".github/CODEOWNERS" +$ToolCommandName = "retrieve-codeowners" +$ToolName = "Azure.Sdk.Tools.RetrieveCodeOwners" +function New-TemporaryDirectory { + $parent = [System.IO.Path]::GetTempPath() + [string] $name = [System.Guid]::NewGuid() + [string] $newPath = Join-Path $parent $name + New-Item -ItemType Directory -Path $newPath | Out-Null + return $newPath } -$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 "," +function InstallRetrieveCodeOwnersTool() { + # Check if the retrieve-codeowners tool exsits or not. + if (Get-Command "$ToolPath/$ToolCommandName" -errorAction SilentlyContinue) { + return } -} + if (!$ToolPath -or !(Test-Path $ToolPath)) { + $ToolPath = New-TemporaryDirectory + } + Write-Warning "Installing the ToolCommandName tool under $ToolPath... " + dotnet tool install --tool-path $ToolPath --add-source $DevOpsFeed --version $ToolVersion $ToolName | Out-Null -$results = $ownedFolders[$target] + return Join-Path $ToolPath $ToolCommandName +} -if ($results) { - Write-Host "Found a folder $results to match $target" +function GetCodeOwners ([string] $Command) { + # Run code owner tools to retrieve code owners. + if (!(Get-Command $Command -errorAction SilentlyContinue)) { + Write-Error "The ToolCommandName tool is not properly installed. Please check your tool path. $ToolPath" + return "" + } + + # Params $RootDirectory is already in use in cpp release pipeline. + # Will use $CodeOwnerFileLocation and deprecate $RootDirectory once it is ready to retire $RootDirectory. + if ($RootDirectory -and !(Test-Path $CodeOwnerFileLocation)) { + $CodeOwnerFileLocation = Join-Path $RootDirectory $LocalCodeOwnerPath + } + + $codeOwnersString = & $Command --target-directory "$TargetDirectory" --code-owner-file-path "$CodeOwnerFileLocation" + # Failed at the command of fetching code owners. + if ($LASTEXITCODE -ne 0) { + return "" + } + + $codeOwnersJson = $codeOwnersString | ConvertFrom-Json + if (!$codeOwnersJson) { + Write-Host "No code owners returned from the path: $TargetDirectory" + return "" + } + $codeOwners = $codeOwnersJson.Owners -join "," + Write-Host "Code owners are $codeOwners" if ($VsoVariable) { - $alreadyPresent = [System.Environment]::GetEnvironmentVariable($VsoVariable) - - if ($alreadyPresent) { - $results += ",$alreadyPresent" - } - Write-Host "##vso[task.setvariable variable=$VsoVariable;]$results" + Write-Host "##vso[task.setvariable variable=$VsoVariable;]$codeOwners" } - - return $results -} -else { - Write-Host "Unable to match path $target in CODEOWNERS file located at $codeOwnersLocation." - Write-Host ($ownedFolders | ConvertTo-Json) - return "" } + +# Install the tool first +$output = InstallRetrieveCodeOwnersTool + +return GetCodeOwners -Command $output From eab654491c794a0f0b04c00385ca2e387976436b Mon Sep 17 00:00:00 2001 From: sima-zhu Date: Fri, 19 Nov 2021 10:45:13 -0800 Subject: [PATCH 02/36] return command when exists --- eng/common/scripts/get-codeowners.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/common/scripts/get-codeowners.ps1 b/eng/common/scripts/get-codeowners.ps1 index 1ff6fb2644..a91715e279 100644 --- a/eng/common/scripts/get-codeowners.ps1 +++ b/eng/common/scripts/get-codeowners.ps1 @@ -22,7 +22,7 @@ function New-TemporaryDirectory { function InstallRetrieveCodeOwnersTool() { # Check if the retrieve-codeowners tool exsits or not. if (Get-Command "$ToolPath/$ToolCommandName" -errorAction SilentlyContinue) { - return + return "$ToolPath/$ToolCommandName" } if (!$ToolPath -or !(Test-Path $ToolPath)) { $ToolPath = New-TemporaryDirectory From e76b5362877360ba67abf1b264c3346b68eab71f Mon Sep 17 00:00:00 2001 From: Sima Zhu <48036328+sima-zhu@users.noreply.github.com> Date: Fri, 19 Nov 2021 11:14:17 -0800 Subject: [PATCH 03/36] Update eng/common/scripts/get-codeowners.ps1 Co-authored-by: Wes Haggard --- eng/common/scripts/get-codeowners.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/eng/common/scripts/get-codeowners.ps1 b/eng/common/scripts/get-codeowners.ps1 index a91715e279..4c519712fc 100644 --- a/eng/common/scripts/get-codeowners.ps1 +++ b/eng/common/scripts/get-codeowners.ps1 @@ -33,7 +33,8 @@ function InstallRetrieveCodeOwnersTool() { return Join-Path $ToolPath $ToolCommandName } -function GetCodeOwners ([string] $Command) { +function Get-CodeOwners ([string] $Command) +{ # Run code owner tools to retrieve code owners. if (!(Get-Command $Command -errorAction SilentlyContinue)) { Write-Error "The ToolCommandName tool is not properly installed. Please check your tool path. $ToolPath" From 0aaf34856d7ca4b176c6f1897fe2a86a96fd66a4 Mon Sep 17 00:00:00 2001 From: Sima Zhu <48036328+sima-zhu@users.noreply.github.com> Date: Fri, 19 Nov 2021 11:14:36 -0800 Subject: [PATCH 04/36] Update eng/common/scripts/get-codeowners.ps1 Co-authored-by: Wes Haggard --- eng/common/scripts/get-codeowners.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/eng/common/scripts/get-codeowners.ps1 b/eng/common/scripts/get-codeowners.ps1 index 4c519712fc..10614715bc 100644 --- a/eng/common/scripts/get-codeowners.ps1 +++ b/eng/common/scripts/get-codeowners.ps1 @@ -19,7 +19,8 @@ function New-TemporaryDirectory { return $newPath } -function InstallRetrieveCodeOwnersTool() { +function Get-CodeOwnersTool() +{ # Check if the retrieve-codeowners tool exsits or not. if (Get-Command "$ToolPath/$ToolCommandName" -errorAction SilentlyContinue) { return "$ToolPath/$ToolCommandName" From 5686e12b3ad2911ba67c70c3aff027f860227cb5 Mon Sep 17 00:00:00 2001 From: sima-zhu Date: Fri, 19 Nov 2021 11:32:08 -0800 Subject: [PATCH 05/36] Address comments --- eng/common/scripts/get-codeowners.ps1 | 32 ++++++++++----------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/eng/common/scripts/get-codeowners.ps1 b/eng/common/scripts/get-codeowners.ps1 index 10614715bc..857ab44848 100644 --- a/eng/common/scripts/get-codeowners.ps1 +++ b/eng/common/scripts/get-codeowners.ps1 @@ -8,16 +8,7 @@ param ( [string]$VsoVariable = "" # Option of write code owners into devop variable ) -$LocalCodeOwnerPath = ".github/CODEOWNERS" $ToolCommandName = "retrieve-codeowners" -$ToolName = "Azure.Sdk.Tools.RetrieveCodeOwners" -function New-TemporaryDirectory { - $parent = [System.IO.Path]::GetTempPath() - [string] $name = [System.Guid]::NewGuid() - [string] $newPath = Join-Path $parent $name - New-Item -ItemType Directory -Path $newPath | Out-Null - return $newPath -} function Get-CodeOwnersTool() { @@ -26,26 +17,26 @@ function Get-CodeOwnersTool() return "$ToolPath/$ToolCommandName" } if (!$ToolPath -or !(Test-Path $ToolPath)) { - $ToolPath = New-TemporaryDirectory + $ToolPath = (Join-Path ([System.IO.Path]::GetTempPath()) ([System.IO.Path]::GetRandomFileName())) + New-Item -ItemType Directory -Path $newPath | Out-Null } Write-Warning "Installing the ToolCommandName tool under $ToolPath... " - dotnet tool install --tool-path $ToolPath --add-source $DevOpsFeed --version $ToolVersion $ToolName | Out-Null + dotnet tool install --tool-path $ToolPath --add-source $DevOpsFeed --version $ToolVersion "Azure.Sdk.Tools.RetrieveCodeOwners" | Out-Null + # Test to see if the tool properly installed. + if (!(Get-Command $Command -errorAction SilentlyContinue)) { + Write-Error "The ToolCommandName tool is not properly installed. Please check your tool path. $ToolPath" + return "" + } return Join-Path $ToolPath $ToolCommandName } function Get-CodeOwners ([string] $Command) { - # Run code owner tools to retrieve code owners. - if (!(Get-Command $Command -errorAction SilentlyContinue)) { - Write-Error "The ToolCommandName tool is not properly installed. Please check your tool path. $ToolPath" - return "" - } - # Params $RootDirectory is already in use in cpp release pipeline. # Will use $CodeOwnerFileLocation and deprecate $RootDirectory once it is ready to retire $RootDirectory. if ($RootDirectory -and !(Test-Path $CodeOwnerFileLocation)) { - $CodeOwnerFileLocation = Join-Path $RootDirectory $LocalCodeOwnerPath + $CodeOwnerFileLocation = Join-Path $RootDirectory ".github/CODEOWNERS" } $codeOwnersString = & $Command --target-directory "$TargetDirectory" --code-owner-file-path "$CodeOwnerFileLocation" @@ -60,11 +51,12 @@ function Get-CodeOwners ([string] $Command) return "" } - $codeOwners = $codeOwnersJson.Owners -join "," - Write-Host "Code owners are $codeOwners" if ($VsoVariable) { + $codeOwners = $codeOwnersJson.Owners -join "," Write-Host "##vso[task.setvariable variable=$VsoVariable;]$codeOwners" } + + return $codeOwnersJson.Owners } # Install the tool first From 6eca14a71c9f4b4a302bdebcfa876c8a40caa122 Mon Sep 17 00:00:00 2001 From: sima-zhu Date: Fri, 19 Nov 2021 11:55:35 -0800 Subject: [PATCH 06/36] Added test to script --- eng/common/scripts/get-codeowners.ps1 | 33 +++++++++++++++++++++------ 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/eng/common/scripts/get-codeowners.ps1 b/eng/common/scripts/get-codeowners.ps1 index 857ab44848..dcdf5c933a 100644 --- a/eng/common/scripts/get-codeowners.ps1 +++ b/eng/common/scripts/get-codeowners.ps1 @@ -5,7 +5,8 @@ param ( [string]$ToolVersion = "1.0.0-dev.20211118.20", # Placeholder. Will update in next PR [string]$ToolPath = "$env:AGENT_TOOLSDIRECTORY", # The place to check the tool existence. Put $(Agent.ToolsDirectory) as default [string]$DevOpsFeed = "https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json", # DevOp tool feeds. - [string]$VsoVariable = "" # Option of write code owners into devop variable + [string]$VsoVariable = "", # Option of write code owners into devop variable + [switch]$Test #Run test functions against the script logic ) $ToolCommandName = "retrieve-codeowners" @@ -39,7 +40,7 @@ function Get-CodeOwners ([string] $Command) $CodeOwnerFileLocation = Join-Path $RootDirectory ".github/CODEOWNERS" } - $codeOwnersString = & $Command --target-directory "$TargetDirectory" --code-owner-file-path "$CodeOwnerFileLocation" + $codeOwnersString = & $command --target-directory $targetDirectory --code-owner-file-path $CodeOwnerFileLocation # Failed at the command of fetching code owners. if ($LASTEXITCODE -ne 0) { return "" @@ -47,7 +48,7 @@ function Get-CodeOwners ([string] $Command) $codeOwnersJson = $codeOwnersString | ConvertFrom-Json if (!$codeOwnersJson) { - Write-Host "No code owners returned from the path: $TargetDirectory" + Write-Host "No code owners returned from the path: $targetDirectory" return "" } @@ -55,11 +56,29 @@ function Get-CodeOwners ([string] $Command) $codeOwners = $codeOwnersJson.Owners -join "," Write-Host "##vso[task.setvariable variable=$VsoVariable;]$codeOwners" } - + return $codeOwnersJson.Owners } -# Install the tool first -$output = InstallRetrieveCodeOwnersTool -return GetCodeOwners -Command $output +function TestGetCodeOwner() { + # Install the tool first + $output = InstallRetrieveCodeOwnersTool + $actualReturn = GetCodeOwners -command $output + $expectReturn = @("person1", "person2") + for ($i = 0; $i -lt $expectReturn.Length; $i++) { + if ($actualReturn[$i] -ne $expectReturn[$i]) { + Write-Error "Expect result $expectReturn[$i] is different than actual result $actualReturn[$i]." + exit + } + } +} + +if($Test) { + TestGetCodeOwner +} +else { + # Install the tool first + $output = InstallRetrieveCodeOwnersTool + return GetCodeOwners -command $output +} From 20d33152f93cb29716e6c1ccb449ff50ee4802e0 Mon Sep 17 00:00:00 2001 From: sima-zhu Date: Fri, 19 Nov 2021 12:43:54 -0800 Subject: [PATCH 07/36] change return type --- eng/common/scripts/get-codeowners.ps1 | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/eng/common/scripts/get-codeowners.ps1 b/eng/common/scripts/get-codeowners.ps1 index dcdf5c933a..dd11641012 100644 --- a/eng/common/scripts/get-codeowners.ps1 +++ b/eng/common/scripts/get-codeowners.ps1 @@ -27,13 +27,16 @@ function Get-CodeOwnersTool() # Test to see if the tool properly installed. if (!(Get-Command $Command -errorAction SilentlyContinue)) { Write-Error "The ToolCommandName tool is not properly installed. Please check your tool path. $ToolPath" - return "" + return } return Join-Path $ToolPath $ToolCommandName } -function Get-CodeOwners ([string] $Command) +function Get-CodeOwners ([string] $command) { + if (!$command) { + return @() + } # Params $RootDirectory is already in use in cpp release pipeline. # Will use $CodeOwnerFileLocation and deprecate $RootDirectory once it is ready to retire $RootDirectory. if ($RootDirectory -and !(Test-Path $CodeOwnerFileLocation)) { @@ -43,13 +46,13 @@ function Get-CodeOwners ([string] $Command) $codeOwnersString = & $command --target-directory $targetDirectory --code-owner-file-path $CodeOwnerFileLocation # Failed at the command of fetching code owners. if ($LASTEXITCODE -ne 0) { - return "" + return @() } $codeOwnersJson = $codeOwnersString | ConvertFrom-Json if (!$codeOwnersJson) { Write-Host "No code owners returned from the path: $targetDirectory" - return "" + return @() } if ($VsoVariable) { @@ -61,9 +64,10 @@ function Get-CodeOwners ([string] $Command) } -function TestGetCodeOwner() { - # Install the tool first - $output = InstallRetrieveCodeOwnersTool +function TestGetCodeOwner([string] $command) { + if (!$output) { + exit + } $actualReturn = GetCodeOwners -command $output $expectReturn = @("person1", "person2") for ($i = 0; $i -lt $expectReturn.Length; $i++) { @@ -74,11 +78,13 @@ function TestGetCodeOwner() { } } +# Install the tool first +$output = Get-CodeOwnersTool + if($Test) { - TestGetCodeOwner + TestGetCodeOwner -command $output } else { - # Install the tool first - $output = InstallRetrieveCodeOwnersTool + return GetCodeOwners -command $output } From a6aff83449048c3d17bd844d37b0b911d0e45c6f Mon Sep 17 00:00:00 2001 From: sima-zhu Date: Fri, 19 Nov 2021 12:54:01 -0800 Subject: [PATCH 08/36] change wrong params --- eng/common/scripts/get-codeowners.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eng/common/scripts/get-codeowners.ps1 b/eng/common/scripts/get-codeowners.ps1 index dd11641012..76040754d5 100644 --- a/eng/common/scripts/get-codeowners.ps1 +++ b/eng/common/scripts/get-codeowners.ps1 @@ -65,10 +65,10 @@ function Get-CodeOwners ([string] $command) function TestGetCodeOwner([string] $command) { - if (!$output) { + if (!$command) { exit } - $actualReturn = GetCodeOwners -command $output + $actualReturn = GetCodeOwners -command $command $expectReturn = @("person1", "person2") for ($i = 0; $i -lt $expectReturn.Length; $i++) { if ($actualReturn[$i] -ne $expectReturn[$i]) { From def7ab3d191d9c3619dd000399e88c9458722e3c Mon Sep 17 00:00:00 2001 From: sima-zhu Date: Fri, 19 Nov 2021 12:57:18 -0800 Subject: [PATCH 09/36] default to toolpath --- eng/common/scripts/get-codeowners.ps1 | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/eng/common/scripts/get-codeowners.ps1 b/eng/common/scripts/get-codeowners.ps1 index 76040754d5..b778c5d906 100644 --- a/eng/common/scripts/get-codeowners.ps1 +++ b/eng/common/scripts/get-codeowners.ps1 @@ -3,7 +3,7 @@ param ( [string]$RootDirectory = "$env:SYSTEM_DEFAULTWORKINGDIRECTORY", # The repo contains CODEOWNER file. [string]$CodeOwnerFileLocation = "$PSSCriptRoot/../../../.github/CODEOWNERS", # The absolute path of CODEOWNERS file. [string]$ToolVersion = "1.0.0-dev.20211118.20", # Placeholder. Will update in next PR - [string]$ToolPath = "$env:AGENT_TOOLSDIRECTORY", # The place to check the tool existence. Put $(Agent.ToolsDirectory) as default + [string]$ToolPath = (Join-Path [System.IO.Path]::GetTempPath(), "codeowners-tool-path"), # The place to check the tool existence. Put temp path as default [string]$DevOpsFeed = "https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json", # DevOp tool feeds. [string]$VsoVariable = "", # Option of write code owners into devop variable [switch]$Test #Run test functions against the script logic @@ -17,9 +17,8 @@ function Get-CodeOwnersTool() if (Get-Command "$ToolPath/$ToolCommandName" -errorAction SilentlyContinue) { return "$ToolPath/$ToolCommandName" } - if (!$ToolPath -or !(Test-Path $ToolPath)) { - $ToolPath = (Join-Path ([System.IO.Path]::GetTempPath()) ([System.IO.Path]::GetRandomFileName())) - New-Item -ItemType Directory -Path $newPath | Out-Null + if (!(Test-Path $ToolPath)) { + New-Item -ItemType Directory -Path $ToolPath | Out-Null } Write-Warning "Installing the ToolCommandName tool under $ToolPath... " dotnet tool install --tool-path $ToolPath --add-source $DevOpsFeed --version $ToolVersion "Azure.Sdk.Tools.RetrieveCodeOwners" | Out-Null From 07968c952c77da3f07514d528181b855161e0cc2 Mon Sep 17 00:00:00 2001 From: sima-zhu Date: Fri, 19 Nov 2021 13:01:49 -0800 Subject: [PATCH 10/36] typo --- eng/common/scripts/get-codeowners.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/common/scripts/get-codeowners.ps1 b/eng/common/scripts/get-codeowners.ps1 index b778c5d906..3fe033e290 100644 --- a/eng/common/scripts/get-codeowners.ps1 +++ b/eng/common/scripts/get-codeowners.ps1 @@ -3,7 +3,7 @@ param ( [string]$RootDirectory = "$env:SYSTEM_DEFAULTWORKINGDIRECTORY", # The repo contains CODEOWNER file. [string]$CodeOwnerFileLocation = "$PSSCriptRoot/../../../.github/CODEOWNERS", # The absolute path of CODEOWNERS file. [string]$ToolVersion = "1.0.0-dev.20211118.20", # Placeholder. Will update in next PR - [string]$ToolPath = (Join-Path [System.IO.Path]::GetTempPath(), "codeowners-tool-path"), # The place to check the tool existence. Put temp path as default + [string]$ToolPath = (Join-Path ([System.IO.Path]::GetTempPath()) "codeowners-tool-path"), # The place to check the tool existence. Put temp path as default [string]$DevOpsFeed = "https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json", # DevOp tool feeds. [string]$VsoVariable = "", # Option of write code owners into devop variable [switch]$Test #Run test functions against the script logic From 1c565a6e4ee637dfeb420fda39d046932258ecc1 Mon Sep 17 00:00:00 2001 From: sima-zhu Date: Fri, 19 Nov 2021 13:09:17 -0800 Subject: [PATCH 11/36] correct exit on Test --- eng/common/scripts/get-codeowners.ps1 | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/eng/common/scripts/get-codeowners.ps1 b/eng/common/scripts/get-codeowners.ps1 index 3fe033e290..4de543b005 100644 --- a/eng/common/scripts/get-codeowners.ps1 +++ b/eng/common/scripts/get-codeowners.ps1 @@ -23,12 +23,13 @@ function Get-CodeOwnersTool() Write-Warning "Installing the ToolCommandName tool under $ToolPath... " dotnet tool install --tool-path $ToolPath --add-source $DevOpsFeed --version $ToolVersion "Azure.Sdk.Tools.RetrieveCodeOwners" | Out-Null + $command = Join-Path $ToolPath $ToolCommandName # Test to see if the tool properly installed. - if (!(Get-Command $Command -errorAction SilentlyContinue)) { + if (!(Get-Command $command -errorAction SilentlyContinue)) { Write-Error "The ToolCommandName tool is not properly installed. Please check your tool path. $ToolPath" return } - return Join-Path $ToolPath $ToolCommandName + return $command } function Get-CodeOwners ([string] $command) @@ -65,16 +66,17 @@ function Get-CodeOwners ([string] $command) function TestGetCodeOwner([string] $command) { if (!$command) { - exit + exit 1 } $actualReturn = GetCodeOwners -command $command $expectReturn = @("person1", "person2") for ($i = 0; $i -lt $expectReturn.Length; $i++) { if ($actualReturn[$i] -ne $expectReturn[$i]) { Write-Error "Expect result $expectReturn[$i] is different than actual result $actualReturn[$i]." - exit + exit 1 } } + exit 0 } # Install the tool first @@ -84,6 +86,5 @@ if($Test) { TestGetCodeOwner -command $output } else { - return GetCodeOwners -command $output } From f454d282f945d25a9ef5c550716e71c6bebf756c Mon Sep 17 00:00:00 2001 From: sima-zhu Date: Fri, 19 Nov 2021 13:12:33 -0800 Subject: [PATCH 12/36] change to right function name --- eng/common/scripts/get-codeowners.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/common/scripts/get-codeowners.ps1 b/eng/common/scripts/get-codeowners.ps1 index 4de543b005..7697dd7877 100644 --- a/eng/common/scripts/get-codeowners.ps1 +++ b/eng/common/scripts/get-codeowners.ps1 @@ -68,7 +68,7 @@ function TestGetCodeOwner([string] $command) { if (!$command) { exit 1 } - $actualReturn = GetCodeOwners -command $command + $actualReturn = Get-CodeOwners -command $command $expectReturn = @("person1", "person2") for ($i = 0; $i -lt $expectReturn.Length; $i++) { if ($actualReturn[$i] -ne $expectReturn[$i]) { From b0b9e06eacaadb0f59cd11c58184eb6665de01a6 Mon Sep 17 00:00:00 2001 From: sima-zhu Date: Fri, 19 Nov 2021 13:16:03 -0800 Subject: [PATCH 13/36] Fixed log message --- eng/common/scripts/get-codeowners.ps1 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/eng/common/scripts/get-codeowners.ps1 b/eng/common/scripts/get-codeowners.ps1 index 7697dd7877..bb811dc670 100644 --- a/eng/common/scripts/get-codeowners.ps1 +++ b/eng/common/scripts/get-codeowners.ps1 @@ -70,8 +70,12 @@ function TestGetCodeOwner([string] $command) { } $actualReturn = Get-CodeOwners -command $command $expectReturn = @("person1", "person2") + if ($actualReturn.Length -ne $expectReturn.Length) { + Write-Error "The length of actual result is not as expected. Expected length: $expectReturn.Length, Actual length: $actualReturn.Length." + exit 1 + } for ($i = 0; $i -lt $expectReturn.Length; $i++) { - if ($actualReturn[$i] -ne $expectReturn[$i]) { + if ($expectReturn[$i] -ne $actualReturn[$i]) { Write-Error "Expect result $expectReturn[$i] is different than actual result $actualReturn[$i]." exit 1 } From 5dec9f4425ecb0867a616f8ee58936b59409ca30 Mon Sep 17 00:00:00 2001 From: sima-zhu Date: Fri, 19 Nov 2021 13:29:41 -0800 Subject: [PATCH 14/36] log message --- eng/common/scripts/get-codeowners.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/common/scripts/get-codeowners.ps1 b/eng/common/scripts/get-codeowners.ps1 index bb811dc670..d79d841f33 100644 --- a/eng/common/scripts/get-codeowners.ps1 +++ b/eng/common/scripts/get-codeowners.ps1 @@ -26,7 +26,7 @@ function Get-CodeOwnersTool() $command = Join-Path $ToolPath $ToolCommandName # Test to see if the tool properly installed. if (!(Get-Command $command -errorAction SilentlyContinue)) { - Write-Error "The ToolCommandName tool is not properly installed. Please check your tool path. $ToolPath" + Write-Error "The retrieve-codeowners tool is not properly installed. Please check your tool path. $ToolPath" return } return $command From 85dd31c1b78e3d62718f068d59816324d3028597 Mon Sep 17 00:00:00 2001 From: sima-zhu Date: Fri, 19 Nov 2021 14:51:36 -0800 Subject: [PATCH 15/36] Added more test cases --- eng/common/scripts/get-codeowners.ps1 | 43 ++++++++++++--------------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/eng/common/scripts/get-codeowners.ps1 b/eng/common/scripts/get-codeowners.ps1 index d79d841f33..851b9f3862 100644 --- a/eng/common/scripts/get-codeowners.ps1 +++ b/eng/common/scripts/get-codeowners.ps1 @@ -13,9 +13,10 @@ $ToolCommandName = "retrieve-codeowners" function Get-CodeOwnersTool() { + $command = Join-Path $ToolPath $ToolCommandName # Check if the retrieve-codeowners tool exsits or not. - if (Get-Command "$ToolPath/$ToolCommandName" -errorAction SilentlyContinue) { - return "$ToolPath/$ToolCommandName" + if (Get-Command $command -errorAction SilentlyContinue) { + return $command } if (!(Test-Path $ToolPath)) { New-Item -ItemType Directory -Path $ToolPath | Out-Null @@ -23,7 +24,6 @@ function Get-CodeOwnersTool() Write-Warning "Installing the ToolCommandName tool under $ToolPath... " dotnet tool install --tool-path $ToolPath --add-source $DevOpsFeed --version $ToolVersion "Azure.Sdk.Tools.RetrieveCodeOwners" | Out-Null - $command = Join-Path $ToolPath $ToolCommandName # Test to see if the tool properly installed. if (!(Get-Command $command -errorAction SilentlyContinue)) { Write-Error "The retrieve-codeowners tool is not properly installed. Please check your tool path. $ToolPath" @@ -32,27 +32,25 @@ function Get-CodeOwnersTool() return $command } -function Get-CodeOwners ([string] $command) +function Get-CodeOwners ([string]$targetDirectory = $TargetDirectory, [string]$codeOwnerFileLocation = $CodeOwnerFileLocation) { - if (!$command) { - return @() - } + $command = Get-CodeOwnersTool # Params $RootDirectory is already in use in cpp release pipeline. - # Will use $CodeOwnerFileLocation and deprecate $RootDirectory once it is ready to retire $RootDirectory. - if ($RootDirectory -and !(Test-Path $CodeOwnerFileLocation)) { - $CodeOwnerFileLocation = Join-Path $RootDirectory ".github/CODEOWNERS" + # Will use $codeOwnerFileLocation and deprecate $RootDirectory once it is ready to retire $RootDirectory. + if ($RootDirectory -and !(Test-Path $codeOwnerFileLocation)) { + $codeOwnerFileLocation = Join-Path $RootDirectory ".github/CODEOWNERS" } - $codeOwnersString = & $command --target-directory $targetDirectory --code-owner-file-path $CodeOwnerFileLocation + $codeOwnersString = & $command --target-directory $targetDirectory --code-owner-file-path $codeOwnerFileLocation # Failed at the command of fetching code owners. if ($LASTEXITCODE -ne 0) { - return @() + return ,@() } $codeOwnersJson = $codeOwnersString | ConvertFrom-Json if (!$codeOwnersJson) { Write-Host "No code owners returned from the path: $targetDirectory" - return @() + return ,@() } if ($VsoVariable) { @@ -63,13 +61,9 @@ function Get-CodeOwners ([string] $command) return $codeOwnersJson.Owners } +function TestGetCodeOwner([string]$targetDirectory, [string]$codeOwnerFileLocation, [string[]]$expectReturn) { + $actualReturn = Get-CodeOwners -targetDirectory "sdk" -codeOwnerFileLocation $testFile -function TestGetCodeOwner([string] $command) { - if (!$command) { - exit 1 - } - $actualReturn = Get-CodeOwners -command $command - $expectReturn = @("person1", "person2") if ($actualReturn.Length -ne $expectReturn.Length) { Write-Error "The length of actual result is not as expected. Expected length: $expectReturn.Length, Actual length: $actualReturn.Length." exit 1 @@ -83,12 +77,13 @@ function TestGetCodeOwner([string] $command) { exit 0 } -# Install the tool first -$output = Get-CodeOwnersTool - if($Test) { - TestGetCodeOwner -command $output + $testFile = "$PSSCriptRoot\..\..\..\tools\code-owners-parser\Azure.Sdk.Tools.RetrieveCodeOwners.Tests\CODEOWNERS" + TestGetCodeOwner -targetDirectory "sdk" -codeOwnerFileLocation $testFile -expectResult @("person1", "person2") + TestGetCodeOwner -targetDirectory "sdk/noPath" -codeOwnerFileLocation $testFile -expectResult @("person1", "person2") + TestGetCodeOwner -targetDirectory "/sdk/azconfig/" -codeOwnerFileLocation $testFile -expectResult @("person3", "person4") + TestGetCodeOwner -targetDirectory "/sd" -codeOwnerFileLocation $testFile -expectResult @() } else { - return GetCodeOwners -command $output + return Get-CodeOwners } From 515012b11f8920ecb9d20f3d989d627f25f584cc Mon Sep 17 00:00:00 2001 From: sima-zhu Date: Fri, 19 Nov 2021 14:52:49 -0800 Subject: [PATCH 16/36] Correct the parameters --- eng/common/scripts/get-codeowners.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/common/scripts/get-codeowners.ps1 b/eng/common/scripts/get-codeowners.ps1 index 851b9f3862..15768b20fc 100644 --- a/eng/common/scripts/get-codeowners.ps1 +++ b/eng/common/scripts/get-codeowners.ps1 @@ -1,5 +1,5 @@ param ( - [string]$TargetDirectory, # Code path to code owners. e.g sdk/core/azure-amqp + [string]$TargetDirectory = "", # Code path to code owners. e.g sdk/core/azure-amqp [string]$RootDirectory = "$env:SYSTEM_DEFAULTWORKINGDIRECTORY", # The repo contains CODEOWNER file. [string]$CodeOwnerFileLocation = "$PSSCriptRoot/../../../.github/CODEOWNERS", # The absolute path of CODEOWNERS file. [string]$ToolVersion = "1.0.0-dev.20211118.20", # Placeholder. Will update in next PR From 785b8fc7a75756a50f4d0870e09c5e6b2027326d Mon Sep 17 00:00:00 2001 From: Sima Zhu <48036328+sima-zhu@users.noreply.github.com> Date: Fri, 19 Nov 2021 21:44:04 -0800 Subject: [PATCH 17/36] Update eng/common/scripts/get-codeowners.ps1 Co-authored-by: Wes Haggard --- eng/common/scripts/get-codeowners.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/eng/common/scripts/get-codeowners.ps1 b/eng/common/scripts/get-codeowners.ps1 index 15768b20fc..6eb23296b0 100644 --- a/eng/common/scripts/get-codeowners.ps1 +++ b/eng/common/scripts/get-codeowners.ps1 @@ -81,7 +81,8 @@ if($Test) { $testFile = "$PSSCriptRoot\..\..\..\tools\code-owners-parser\Azure.Sdk.Tools.RetrieveCodeOwners.Tests\CODEOWNERS" TestGetCodeOwner -targetDirectory "sdk" -codeOwnerFileLocation $testFile -expectResult @("person1", "person2") TestGetCodeOwner -targetDirectory "sdk/noPath" -codeOwnerFileLocation $testFile -expectResult @("person1", "person2") - TestGetCodeOwner -targetDirectory "/sdk/azconfig/" -codeOwnerFileLocation $testFile -expectResult @("person3", "person4") + TestGetCodeOwner -targetDirectory "/sdk/azconfig" -codeOwnerFileLocation $testFile -expectResult @("person3", "person4") + TestGetCodeOwner -targetDirectory "/sdk/azconfig/package" -codeOwnerFileLocation $testFile -expectResult @("person3", "person4") TestGetCodeOwner -targetDirectory "/sd" -codeOwnerFileLocation $testFile -expectResult @() } else { From f8a770141368f3941aad91b56c3b98d5f53309bb Mon Sep 17 00:00:00 2001 From: Sima Zhu <48036328+sima-zhu@users.noreply.github.com> Date: Fri, 19 Nov 2021 21:45:00 -0800 Subject: [PATCH 18/36] Update eng/common/scripts/get-codeowners.ps1 Co-authored-by: Wes Haggard --- eng/common/scripts/get-codeowners.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/common/scripts/get-codeowners.ps1 b/eng/common/scripts/get-codeowners.ps1 index 6eb23296b0..dccda99e6d 100644 --- a/eng/common/scripts/get-codeowners.ps1 +++ b/eng/common/scripts/get-codeowners.ps1 @@ -13,7 +13,7 @@ $ToolCommandName = "retrieve-codeowners" function Get-CodeOwnersTool() { - $command = Join-Path $ToolPath $ToolCommandName + $command = Join-Path $ToolPath "retrieve-codeowners" # Check if the retrieve-codeowners tool exsits or not. if (Get-Command $command -errorAction SilentlyContinue) { return $command From c0b19284d9108c4e21fbd7d192e0d30805a27d45 Mon Sep 17 00:00:00 2001 From: Sima Zhu <48036328+sima-zhu@users.noreply.github.com> Date: Fri, 19 Nov 2021 21:45:12 -0800 Subject: [PATCH 19/36] Update eng/common/scripts/get-codeowners.ps1 Co-authored-by: Wes Haggard --- eng/common/scripts/get-codeowners.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/common/scripts/get-codeowners.ps1 b/eng/common/scripts/get-codeowners.ps1 index dccda99e6d..f21e4bd542 100644 --- a/eng/common/scripts/get-codeowners.ps1 +++ b/eng/common/scripts/get-codeowners.ps1 @@ -21,7 +21,7 @@ function Get-CodeOwnersTool() if (!(Test-Path $ToolPath)) { New-Item -ItemType Directory -Path $ToolPath | Out-Null } - Write-Warning "Installing the ToolCommandName tool under $ToolPath... " + Write-Host "Installing the retrieve-codeowners tool under $ToolPath... " dotnet tool install --tool-path $ToolPath --add-source $DevOpsFeed --version $ToolVersion "Azure.Sdk.Tools.RetrieveCodeOwners" | Out-Null # Test to see if the tool properly installed. From f48e2f92f87d8a1d850186aded61b7f609d7b977 Mon Sep 17 00:00:00 2001 From: sima-zhu Date: Fri, 19 Nov 2021 21:46:38 -0800 Subject: [PATCH 20/36] Remove exit 0 in test function --- eng/common/scripts/get-codeowners.ps1 | 3 --- 1 file changed, 3 deletions(-) diff --git a/eng/common/scripts/get-codeowners.ps1 b/eng/common/scripts/get-codeowners.ps1 index f21e4bd542..a00f4e415f 100644 --- a/eng/common/scripts/get-codeowners.ps1 +++ b/eng/common/scripts/get-codeowners.ps1 @@ -9,8 +9,6 @@ param ( [switch]$Test #Run test functions against the script logic ) -$ToolCommandName = "retrieve-codeowners" - function Get-CodeOwnersTool() { $command = Join-Path $ToolPath "retrieve-codeowners" @@ -74,7 +72,6 @@ function TestGetCodeOwner([string]$targetDirectory, [string]$codeOwnerFileLocati exit 1 } } - exit 0 } if($Test) { From 080d502132accb572083f8b6e5438702585e49b1 Mon Sep 17 00:00:00 2001 From: sima-zhu Date: Fri, 19 Nov 2021 21:56:22 -0800 Subject: [PATCH 21/36] change the path delimiter --- eng/common/scripts/get-codeowners.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/common/scripts/get-codeowners.ps1 b/eng/common/scripts/get-codeowners.ps1 index a00f4e415f..b6dd6f204c 100644 --- a/eng/common/scripts/get-codeowners.ps1 +++ b/eng/common/scripts/get-codeowners.ps1 @@ -75,7 +75,7 @@ function TestGetCodeOwner([string]$targetDirectory, [string]$codeOwnerFileLocati } if($Test) { - $testFile = "$PSSCriptRoot\..\..\..\tools\code-owners-parser\Azure.Sdk.Tools.RetrieveCodeOwners.Tests\CODEOWNERS" + $testFile = "$PSSCriptRoot/../../../tools/code-owners-parser/Azure.Sdk.Tools.RetrieveCodeOwners.Tests/CODEOWNERS" TestGetCodeOwner -targetDirectory "sdk" -codeOwnerFileLocation $testFile -expectResult @("person1", "person2") TestGetCodeOwner -targetDirectory "sdk/noPath" -codeOwnerFileLocation $testFile -expectResult @("person1", "person2") TestGetCodeOwner -targetDirectory "/sdk/azconfig" -codeOwnerFileLocation $testFile -expectResult @("person3", "person4") From bef68edefea46dbe77e0833476cdaca89e9a62a4 Mon Sep 17 00:00:00 2001 From: sima-zhu Date: Fri, 19 Nov 2021 22:13:17 -0800 Subject: [PATCH 22/36] More changes on var --- eng/common/scripts/get-codeowners.ps1 | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/eng/common/scripts/get-codeowners.ps1 b/eng/common/scripts/get-codeowners.ps1 index b6dd6f204c..927151bbea 100644 --- a/eng/common/scripts/get-codeowners.ps1 +++ b/eng/common/scripts/get-codeowners.ps1 @@ -60,13 +60,13 @@ function Get-CodeOwners ([string]$targetDirectory = $TargetDirectory, [string]$c } function TestGetCodeOwner([string]$targetDirectory, [string]$codeOwnerFileLocation, [string[]]$expectReturn) { - $actualReturn = Get-CodeOwners -targetDirectory "sdk" -codeOwnerFileLocation $testFile + $actualReturn = Get-CodeOwners -targetDirectory $targetDirectory -codeOwnerFileLocation $codeOwnerFileLocation - if ($actualReturn.Length -ne $expectReturn.Length) { - Write-Error "The length of actual result is not as expected. Expected length: $expectReturn.Length, Actual length: $actualReturn.Length." + if ($actualReturn.Count -ne $expectReturn.Count) { + Write-Error "The length of actual result is not as expected. Expected length: $($expectReturn.Count), Actual length: $($actualReturn.Count)." exit 1 } - for ($i = 0; $i -lt $expectReturn.Length; $i++) { + for ($i = 0; $i -lt $expectReturn.Count; $i++) { if ($expectReturn[$i] -ne $actualReturn[$i]) { Write-Error "Expect result $expectReturn[$i] is different than actual result $actualReturn[$i]." exit 1 @@ -76,11 +76,11 @@ function TestGetCodeOwner([string]$targetDirectory, [string]$codeOwnerFileLocati if($Test) { $testFile = "$PSSCriptRoot/../../../tools/code-owners-parser/Azure.Sdk.Tools.RetrieveCodeOwners.Tests/CODEOWNERS" - TestGetCodeOwner -targetDirectory "sdk" -codeOwnerFileLocation $testFile -expectResult @("person1", "person2") - TestGetCodeOwner -targetDirectory "sdk/noPath" -codeOwnerFileLocation $testFile -expectResult @("person1", "person2") - TestGetCodeOwner -targetDirectory "/sdk/azconfig" -codeOwnerFileLocation $testFile -expectResult @("person3", "person4") - TestGetCodeOwner -targetDirectory "/sdk/azconfig/package" -codeOwnerFileLocation $testFile -expectResult @("person3", "person4") - TestGetCodeOwner -targetDirectory "/sd" -codeOwnerFileLocation $testFile -expectResult @() + TestGetCodeOwner -targetDirectory "sdk" -codeOwnerFileLocation $testFile -expectReturn @("person1", "person2") + TestGetCodeOwner -targetDirectory "sdk/noPath" -codeOwnerFileLocation $testFile -expectReturn @("person1", "person2") + TestGetCodeOwner -targetDirectory "/sdk/azconfig" -codeOwnerFileLocation $testFile -expectReturn @("person3", "person4") + TestGetCodeOwner -targetDirectory "/sdk/azconfig/package" -codeOwnerFileLocation $testFile -expectReturn @("person3", "person4") + TestGetCodeOwner -targetDirectory "/sd" -codeOwnerFileLocation $testFile -expectReturn @() } else { return Get-CodeOwners From 4b91d0b395b822d8b7f10beabe2e42f16c3c991a Mon Sep 17 00:00:00 2001 From: sima-zhu Date: Fri, 19 Nov 2021 22:25:47 -0800 Subject: [PATCH 23/36] Hide error behind --- eng/common/scripts/get-codeowners.ps1 | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/eng/common/scripts/get-codeowners.ps1 b/eng/common/scripts/get-codeowners.ps1 index 927151bbea..d0f20fb758 100644 --- a/eng/common/scripts/get-codeowners.ps1 +++ b/eng/common/scripts/get-codeowners.ps1 @@ -39,9 +39,10 @@ function Get-CodeOwners ([string]$targetDirectory = $TargetDirectory, [string]$c $codeOwnerFileLocation = Join-Path $RootDirectory ".github/CODEOWNERS" } - $codeOwnersString = & $command --target-directory $targetDirectory --code-owner-file-path $codeOwnerFileLocation + $codeOwnersString = & $command --target-directory $targetDirectory --code-owner-file-path $codeOwnerFileLocation 2>&1 # Failed at the command of fetching code owners. if ($LASTEXITCODE -ne 0) { + Write-Host $codeOwnersString return ,@() } @@ -76,10 +77,10 @@ function TestGetCodeOwner([string]$targetDirectory, [string]$codeOwnerFileLocati if($Test) { $testFile = "$PSSCriptRoot/../../../tools/code-owners-parser/Azure.Sdk.Tools.RetrieveCodeOwners.Tests/CODEOWNERS" - TestGetCodeOwner -targetDirectory "sdk" -codeOwnerFileLocation $testFile -expectReturn @("person1", "person2") - TestGetCodeOwner -targetDirectory "sdk/noPath" -codeOwnerFileLocation $testFile -expectReturn @("person1", "person2") - TestGetCodeOwner -targetDirectory "/sdk/azconfig" -codeOwnerFileLocation $testFile -expectReturn @("person3", "person4") - TestGetCodeOwner -targetDirectory "/sdk/azconfig/package" -codeOwnerFileLocation $testFile -expectReturn @("person3", "person4") + # TestGetCodeOwner -targetDirectory "sdk" -codeOwnerFileLocation $testFile -expectReturn @("person1", "person2") + # TestGetCodeOwner -targetDirectory "sdk/noPath" -codeOwnerFileLocation $testFile -expectReturn @("person1", "person2") + # TestGetCodeOwner -targetDirectory "/sdk/azconfig" -codeOwnerFileLocation $testFile -expectReturn @("person3", "person4") + # TestGetCodeOwner -targetDirectory "/sdk/azconfig/package" -codeOwnerFileLocation $testFile -expectReturn @("person3", "person4") TestGetCodeOwner -targetDirectory "/sd" -codeOwnerFileLocation $testFile -expectReturn @() } else { From 1cba076c816deff15b18db013a5151a3d0ec5f0e Mon Sep 17 00:00:00 2001 From: sima-zhu Date: Fri, 19 Nov 2021 22:27:47 -0800 Subject: [PATCH 24/36] Comment back all tests --- eng/common/scripts/get-codeowners.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/eng/common/scripts/get-codeowners.ps1 b/eng/common/scripts/get-codeowners.ps1 index d0f20fb758..872826cbd3 100644 --- a/eng/common/scripts/get-codeowners.ps1 +++ b/eng/common/scripts/get-codeowners.ps1 @@ -77,10 +77,10 @@ function TestGetCodeOwner([string]$targetDirectory, [string]$codeOwnerFileLocati if($Test) { $testFile = "$PSSCriptRoot/../../../tools/code-owners-parser/Azure.Sdk.Tools.RetrieveCodeOwners.Tests/CODEOWNERS" - # TestGetCodeOwner -targetDirectory "sdk" -codeOwnerFileLocation $testFile -expectReturn @("person1", "person2") - # TestGetCodeOwner -targetDirectory "sdk/noPath" -codeOwnerFileLocation $testFile -expectReturn @("person1", "person2") - # TestGetCodeOwner -targetDirectory "/sdk/azconfig" -codeOwnerFileLocation $testFile -expectReturn @("person3", "person4") - # TestGetCodeOwner -targetDirectory "/sdk/azconfig/package" -codeOwnerFileLocation $testFile -expectReturn @("person3", "person4") + TestGetCodeOwner -targetDirectory "sdk" -codeOwnerFileLocation $testFile -expectReturn @("person1", "person2") + TestGetCodeOwner -targetDirectory "sdk/noPath" -codeOwnerFileLocation $testFile -expectReturn @("person1", "person2") + TestGetCodeOwner -targetDirectory "/sdk/azconfig" -codeOwnerFileLocation $testFile -expectReturn @("person3", "person4") + TestGetCodeOwner -targetDirectory "/sdk/azconfig/package" -codeOwnerFileLocation $testFile -expectReturn @("person3", "person4") TestGetCodeOwner -targetDirectory "/sd" -codeOwnerFileLocation $testFile -expectReturn @() } else { From 8919c4c524d233e17aa414c6415009a21a3f1d99 Mon Sep 17 00:00:00 2001 From: sima-zhu Date: Fri, 19 Nov 2021 22:34:58 -0800 Subject: [PATCH 25/36] exit 0 --- eng/common/scripts/get-codeowners.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/eng/common/scripts/get-codeowners.ps1 b/eng/common/scripts/get-codeowners.ps1 index 872826cbd3..37e690cbbf 100644 --- a/eng/common/scripts/get-codeowners.ps1 +++ b/eng/common/scripts/get-codeowners.ps1 @@ -82,6 +82,7 @@ if($Test) { TestGetCodeOwner -targetDirectory "/sdk/azconfig" -codeOwnerFileLocation $testFile -expectReturn @("person3", "person4") TestGetCodeOwner -targetDirectory "/sdk/azconfig/package" -codeOwnerFileLocation $testFile -expectReturn @("person3", "person4") TestGetCodeOwner -targetDirectory "/sd" -codeOwnerFileLocation $testFile -expectReturn @() + exit 0 } else { return Get-CodeOwners From 58291656cf6094416fc4dc8f0920aa128400f432 Mon Sep 17 00:00:00 2001 From: Sima Zhu <48036328+sima-zhu@users.noreply.github.com> Date: Mon, 22 Nov 2021 09:24:39 -0800 Subject: [PATCH 26/36] Update eng/common/scripts/get-codeowners.ps1 Co-authored-by: Wes Haggard --- eng/common/scripts/get-codeowners.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/common/scripts/get-codeowners.ps1 b/eng/common/scripts/get-codeowners.ps1 index 37e690cbbf..32a41df5c5 100644 --- a/eng/common/scripts/get-codeowners.ps1 +++ b/eng/common/scripts/get-codeowners.ps1 @@ -30,7 +30,7 @@ function Get-CodeOwnersTool() return $command } -function Get-CodeOwners ([string]$targetDirectory = $TargetDirectory, [string]$codeOwnerFileLocation = $CodeOwnerFileLocation) +function Get-CodeOwners ([string]$targetDirectory, [string]$codeOwnerFileLocation) { $command = Get-CodeOwnersTool # Params $RootDirectory is already in use in cpp release pipeline. From 0be7aff3cb477ae093cad62c69eebb119fb4d029 Mon Sep 17 00:00:00 2001 From: sima-zhu Date: Mon, 22 Nov 2021 10:10:28 -0800 Subject: [PATCH 27/36] remove default value --- eng/common/scripts/get-codeowners.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/common/scripts/get-codeowners.ps1 b/eng/common/scripts/get-codeowners.ps1 index 32a41df5c5..92fc4fa1db 100644 --- a/eng/common/scripts/get-codeowners.ps1 +++ b/eng/common/scripts/get-codeowners.ps1 @@ -85,5 +85,5 @@ if($Test) { exit 0 } else { - return Get-CodeOwners + return Get-CodeOwners -targetDirectory $TargetDirectory -codeOwnerFileLocation $CodeOwnerFileLocation } From 2cbf84776c71c22eaea51b4340cb3f6cba533cb2 Mon Sep 17 00:00:00 2001 From: sima-zhu Date: Mon, 22 Nov 2021 10:41:55 -0800 Subject: [PATCH 28/36] changes for new get-codeowners --- eng/common/scripts/get-codeowners.ps1 | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/eng/common/scripts/get-codeowners.ps1 b/eng/common/scripts/get-codeowners.ps1 index 92fc4fa1db..0cf5959eed 100644 --- a/eng/common/scripts/get-codeowners.ps1 +++ b/eng/common/scripts/get-codeowners.ps1 @@ -1,11 +1,11 @@ param ( [string]$TargetDirectory = "", # Code path to code owners. e.g sdk/core/azure-amqp - [string]$RootDirectory = "$env:SYSTEM_DEFAULTWORKINGDIRECTORY", # The repo contains CODEOWNER file. [string]$CodeOwnerFileLocation = "$PSSCriptRoot/../../../.github/CODEOWNERS", # The absolute path of CODEOWNERS file. [string]$ToolVersion = "1.0.0-dev.20211118.20", # Placeholder. Will update in next PR [string]$ToolPath = (Join-Path ([System.IO.Path]::GetTempPath()) "codeowners-tool-path"), # The place to check the tool existence. Put temp path as default [string]$DevOpsFeed = "https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json", # DevOp tool feeds. [string]$VsoVariable = "", # Option of write code owners into devop variable + [switch]$FilterNonUser, # Option to filter out the team alias in code owner list. e.g. Azure/azure-sdk-team [switch]$Test #Run test functions against the script logic ) @@ -33,13 +33,13 @@ function Get-CodeOwnersTool() function Get-CodeOwners ([string]$targetDirectory, [string]$codeOwnerFileLocation) { $command = Get-CodeOwnersTool - # Params $RootDirectory is already in use in cpp release pipeline. - # Will use $codeOwnerFileLocation and deprecate $RootDirectory once it is ready to retire $RootDirectory. - if ($RootDirectory -and !(Test-Path $codeOwnerFileLocation)) { - $codeOwnerFileLocation = Join-Path $RootDirectory ".github/CODEOWNERS" + # Filter out the non user alias from code owner list. + if($FilterNonUser) { + $codeOwnersString = & $command --target-directory $targetDirectory --code-owner-file-path $codeOwnerFileLocation --filter-out-non-user-aliases 2>&1 + } + else { + $codeOwnersString = & $command --target-directory $targetDirectory --code-owner-file-path $codeOwnerFileLocation 2>&1 } - - $codeOwnersString = & $command --target-directory $targetDirectory --code-owner-file-path $codeOwnerFileLocation 2>&1 # Failed at the command of fetching code owners. if ($LASTEXITCODE -ne 0) { Write-Host $codeOwnersString From b0bd33e558324646ad11aedec7f40aba976de48c Mon Sep 17 00:00:00 2001 From: Sima Zhu <48036328+sima-zhu@users.noreply.github.com> Date: Mon, 22 Nov 2021 11:14:28 -0800 Subject: [PATCH 29/36] Update eng/common/scripts/get-codeowners.ps1 Co-authored-by: Wes Haggard --- eng/common/scripts/get-codeowners.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/common/scripts/get-codeowners.ps1 b/eng/common/scripts/get-codeowners.ps1 index 0cf5959eed..35cbd102e9 100644 --- a/eng/common/scripts/get-codeowners.ps1 +++ b/eng/common/scripts/get-codeowners.ps1 @@ -5,7 +5,7 @@ param ( [string]$ToolPath = (Join-Path ([System.IO.Path]::GetTempPath()) "codeowners-tool-path"), # The place to check the tool existence. Put temp path as default [string]$DevOpsFeed = "https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json", # DevOp tool feeds. [string]$VsoVariable = "", # Option of write code owners into devop variable - [switch]$FilterNonUser, # Option to filter out the team alias in code owner list. e.g. Azure/azure-sdk-team + [switch]$IncludeNonUserAliases, # Option to filter out the team alias in code owner list. e.g. Azure/azure-sdk-team [switch]$Test #Run test functions against the script logic ) From 06a356c7fb4fce5bc7c77f4df361f398649aebce Mon Sep 17 00:00:00 2001 From: sima-zhu Date: Mon, 22 Nov 2021 11:25:31 -0800 Subject: [PATCH 30/36] update version and parameter --- eng/common/scripts/get-codeowners.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/eng/common/scripts/get-codeowners.ps1 b/eng/common/scripts/get-codeowners.ps1 index 35cbd102e9..d203872714 100644 --- a/eng/common/scripts/get-codeowners.ps1 +++ b/eng/common/scripts/get-codeowners.ps1 @@ -1,7 +1,7 @@ param ( [string]$TargetDirectory = "", # Code path to code owners. e.g sdk/core/azure-amqp [string]$CodeOwnerFileLocation = "$PSSCriptRoot/../../../.github/CODEOWNERS", # The absolute path of CODEOWNERS file. - [string]$ToolVersion = "1.0.0-dev.20211118.20", # Placeholder. Will update in next PR + [string]$ToolVersion = "1.0.0-dev.20211122.14", # Placeholder. Will update in next PR [string]$ToolPath = (Join-Path ([System.IO.Path]::GetTempPath()) "codeowners-tool-path"), # The place to check the tool existence. Put temp path as default [string]$DevOpsFeed = "https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json", # DevOp tool feeds. [string]$VsoVariable = "", # Option of write code owners into devop variable @@ -34,11 +34,11 @@ function Get-CodeOwners ([string]$targetDirectory, [string]$codeOwnerFileLocatio { $command = Get-CodeOwnersTool # Filter out the non user alias from code owner list. - if($FilterNonUser) { - $codeOwnersString = & $command --target-directory $targetDirectory --code-owner-file-path $codeOwnerFileLocation --filter-out-non-user-aliases 2>&1 + if($IncludeNonUserAliases) { + $codeOwnersString = & $command --target-directory $targetDirectory --code-owner-file-path $codeOwnerFileLocation 2>&1 } else { - $codeOwnersString = & $command --target-directory $targetDirectory --code-owner-file-path $codeOwnerFileLocation 2>&1 + $codeOwnersString = & $command --target-directory $targetDirectory --code-owner-file-path $codeOwnerFileLocation --filter-out-non-user-aliases 2>&1 } # Failed at the command of fetching code owners. if ($LASTEXITCODE -ne 0) { From 0c9a76207f49d2fc5a9c481d7785b0b422aada6b Mon Sep 17 00:00:00 2001 From: sima-zhu Date: Mon, 22 Nov 2021 12:09:19 -0800 Subject: [PATCH 31/36] add user --- eng/common/scripts/get-codeowners.ps1 | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/eng/common/scripts/get-codeowners.ps1 b/eng/common/scripts/get-codeowners.ps1 index d203872714..9b48cc7e91 100644 --- a/eng/common/scripts/get-codeowners.ps1 +++ b/eng/common/scripts/get-codeowners.ps1 @@ -30,11 +30,11 @@ function Get-CodeOwnersTool() return $command } -function Get-CodeOwners ([string]$targetDirectory, [string]$codeOwnerFileLocation) +function Get-CodeOwners ([string]$targetDirectory, [string]$codeOwnerFileLocation, [bool]$useNonUserAlias = $false) { $command = Get-CodeOwnersTool # Filter out the non user alias from code owner list. - if($IncludeNonUserAliases) { + if($useNonUserAlias) { $codeOwnersString = & $command --target-directory $targetDirectory --code-owner-file-path $codeOwnerFileLocation 2>&1 } else { @@ -60,8 +60,8 @@ function Get-CodeOwners ([string]$targetDirectory, [string]$codeOwnerFileLocatio return $codeOwnersJson.Owners } -function TestGetCodeOwner([string]$targetDirectory, [string]$codeOwnerFileLocation, [string[]]$expectReturn) { - $actualReturn = Get-CodeOwners -targetDirectory $targetDirectory -codeOwnerFileLocation $codeOwnerFileLocation +function TestGetCodeOwner([string]$targetDirectory, [string]$codeOwnerFileLocation, [bool]$useNonUserAlias = $false, [string[]]$expectReturn) { + $actualReturn = Get-CodeOwners -targetDirectory $targetDirectory -codeOwnerFileLocation $codeOwnerFileLocation -useNonUserAlias $useNonUserAlias if ($actualReturn.Count -ne $expectReturn.Count) { Write-Error "The length of actual result is not as expected. Expected length: $($expectReturn.Count), Actual length: $($actualReturn.Count)." @@ -77,13 +77,14 @@ function TestGetCodeOwner([string]$targetDirectory, [string]$codeOwnerFileLocati if($Test) { $testFile = "$PSSCriptRoot/../../../tools/code-owners-parser/Azure.Sdk.Tools.RetrieveCodeOwners.Tests/CODEOWNERS" - TestGetCodeOwner -targetDirectory "sdk" -codeOwnerFileLocation $testFile -expectReturn @("person1", "person2") - TestGetCodeOwner -targetDirectory "sdk/noPath" -codeOwnerFileLocation $testFile -expectReturn @("person1", "person2") - TestGetCodeOwner -targetDirectory "/sdk/azconfig" -codeOwnerFileLocation $testFile -expectReturn @("person3", "person4") - TestGetCodeOwner -targetDirectory "/sdk/azconfig/package" -codeOwnerFileLocation $testFile -expectReturn @("person3", "person4") - TestGetCodeOwner -targetDirectory "/sd" -codeOwnerFileLocation $testFile -expectReturn @() + TestGetCodeOwner -targetDirectory "sdk" -codeOwnerFileLocation $testFile $useNonUserAlias $true -expectReturn @("person1", "person2") + TestGetCodeOwner -targetDirectory "sdk/noPath" -codeOwnerFileLocation $testFile $useNonUserAlias $true -expectReturn @("person1", "person2") + TestGetCodeOwner -targetDirectory "/sdk/azconfig" -codeOwnerFileLocation $testFile $useNonUserAlias $true -expectReturn @("person3", "person4") + TestGetCodeOwner -targetDirectory "/sdk/azconfig/package" -codeOwnerFileLocation $useNonUserAlias $true $testFile -expectReturn @("person3", "person4") + TestGetCodeOwner -targetDirectory "/sd" -codeOwnerFileLocation $testFile $useNonUserAlias $true -expectReturn @() + TestGetCodeOwner -targetDirectory "/sdk/testUser/" -codeOwnerFileLocation $testFile -expectReturn @() exit 0 } else { - return Get-CodeOwners -targetDirectory $TargetDirectory -codeOwnerFileLocation $CodeOwnerFileLocation + return Get-CodeOwners -targetDirectory $TargetDirectory -codeOwnerFileLocation $CodeOwnerFileLocation -useNonUserAlias $IncludeNonUserAliases } From 2ba87a5b760fdfeb4c6326d71e24b21f44b4b63c Mon Sep 17 00:00:00 2001 From: sima-zhu Date: Mon, 22 Nov 2021 12:18:11 -0800 Subject: [PATCH 32/36] more fix --- eng/common/scripts/get-codeowners.ps1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/eng/common/scripts/get-codeowners.ps1 b/eng/common/scripts/get-codeowners.ps1 index 9b48cc7e91..e917900c18 100644 --- a/eng/common/scripts/get-codeowners.ps1 +++ b/eng/common/scripts/get-codeowners.ps1 @@ -77,11 +77,11 @@ function TestGetCodeOwner([string]$targetDirectory, [string]$codeOwnerFileLocati if($Test) { $testFile = "$PSSCriptRoot/../../../tools/code-owners-parser/Azure.Sdk.Tools.RetrieveCodeOwners.Tests/CODEOWNERS" - TestGetCodeOwner -targetDirectory "sdk" -codeOwnerFileLocation $testFile $useNonUserAlias $true -expectReturn @("person1", "person2") - TestGetCodeOwner -targetDirectory "sdk/noPath" -codeOwnerFileLocation $testFile $useNonUserAlias $true -expectReturn @("person1", "person2") - TestGetCodeOwner -targetDirectory "/sdk/azconfig" -codeOwnerFileLocation $testFile $useNonUserAlias $true -expectReturn @("person3", "person4") - TestGetCodeOwner -targetDirectory "/sdk/azconfig/package" -codeOwnerFileLocation $useNonUserAlias $true $testFile -expectReturn @("person3", "person4") - TestGetCodeOwner -targetDirectory "/sd" -codeOwnerFileLocation $testFile $useNonUserAlias $true -expectReturn @() + TestGetCodeOwner -targetDirectory "sdk" -codeOwnerFileLocation $testFile -useNonUserAlias $true -expectReturn @("person1", "person2") + TestGetCodeOwner -targetDirectory "sdk/noPath" -codeOwnerFileLocation $testFile -useNonUserAlias $true -expectReturn @("person1", "person2") + TestGetCodeOwner -targetDirectory "/sdk/azconfig" -codeOwnerFileLocation $testFile -useNonUserAlias $true -expectReturn @("person3", "person4") + TestGetCodeOwner -targetDirectory "/sdk/azconfig/package" -codeOwnerFileLocation $testFile -useNonUserAlias $true $testFile -expectReturn @("person3", "person4") + TestGetCodeOwner -targetDirectory "/sd" -codeOwnerFileLocation $testFile -useNonUserAlias $true -expectReturn @() TestGetCodeOwner -targetDirectory "/sdk/testUser/" -codeOwnerFileLocation $testFile -expectReturn @() exit 0 } From 74b25b0604d64a5bac740492d747750fabe1cf9e Mon Sep 17 00:00:00 2001 From: sima-zhu Date: Mon, 22 Nov 2021 12:31:26 -0800 Subject: [PATCH 33/36] add messages --- eng/common/scripts/get-codeowners.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/eng/common/scripts/get-codeowners.ps1 b/eng/common/scripts/get-codeowners.ps1 index e917900c18..1eec94eee2 100644 --- a/eng/common/scripts/get-codeowners.ps1 +++ b/eng/common/scripts/get-codeowners.ps1 @@ -34,6 +34,7 @@ function Get-CodeOwners ([string]$targetDirectory, [string]$codeOwnerFileLocatio { $command = Get-CodeOwnersTool # Filter out the non user alias from code owner list. + Write-Host "Testing on $targetDirectory..." if($useNonUserAlias) { $codeOwnersString = & $command --target-directory $targetDirectory --code-owner-file-path $codeOwnerFileLocation 2>&1 } From c9c4d4ed1c92287356e58af803d0fbffe77503c9 Mon Sep 17 00:00:00 2001 From: sima-zhu Date: Mon, 22 Nov 2021 14:06:28 -0800 Subject: [PATCH 34/36] Added real cases --- eng/common/scripts/get-codeowners.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/common/scripts/get-codeowners.ps1 b/eng/common/scripts/get-codeowners.ps1 index 1eec94eee2..d0aa8b23ba 100644 --- a/eng/common/scripts/get-codeowners.ps1 +++ b/eng/common/scripts/get-codeowners.ps1 @@ -83,7 +83,7 @@ if($Test) { TestGetCodeOwner -targetDirectory "/sdk/azconfig" -codeOwnerFileLocation $testFile -useNonUserAlias $true -expectReturn @("person3", "person4") TestGetCodeOwner -targetDirectory "/sdk/azconfig/package" -codeOwnerFileLocation $testFile -useNonUserAlias $true $testFile -expectReturn @("person3", "person4") TestGetCodeOwner -targetDirectory "/sd" -codeOwnerFileLocation $testFile -useNonUserAlias $true -expectReturn @() - TestGetCodeOwner -targetDirectory "/sdk/testUser/" -codeOwnerFileLocation $testFile -expectReturn @() + TestGetCodeOwner -targetDirectory "/sdk/testUser/" -codeOwnerFileLocation $testFile -expectReturn @("azuer-sdk") exit 0 } else { From b3a6f3744bd6084f4557391ba2fa8bd7a1f4da78 Mon Sep 17 00:00:00 2001 From: sima-zhu Date: Mon, 22 Nov 2021 14:13:09 -0800 Subject: [PATCH 35/36] fixed typo --- eng/common/scripts/get-codeowners.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/common/scripts/get-codeowners.ps1 b/eng/common/scripts/get-codeowners.ps1 index d0aa8b23ba..cd967691ea 100644 --- a/eng/common/scripts/get-codeowners.ps1 +++ b/eng/common/scripts/get-codeowners.ps1 @@ -83,7 +83,7 @@ if($Test) { TestGetCodeOwner -targetDirectory "/sdk/azconfig" -codeOwnerFileLocation $testFile -useNonUserAlias $true -expectReturn @("person3", "person4") TestGetCodeOwner -targetDirectory "/sdk/azconfig/package" -codeOwnerFileLocation $testFile -useNonUserAlias $true $testFile -expectReturn @("person3", "person4") TestGetCodeOwner -targetDirectory "/sd" -codeOwnerFileLocation $testFile -useNonUserAlias $true -expectReturn @() - TestGetCodeOwner -targetDirectory "/sdk/testUser/" -codeOwnerFileLocation $testFile -expectReturn @("azuer-sdk") + TestGetCodeOwner -targetDirectory "/sdk/testUser/" -codeOwnerFileLocation $testFile -expectReturn @("azure-sdk") exit 0 } else { From 0f3a78ade6f33bf21404ffa3ed8986bb8ef093db Mon Sep 17 00:00:00 2001 From: sima-zhu Date: Mon, 22 Nov 2021 15:00:46 -0800 Subject: [PATCH 36/36] Make program work --- eng/common/scripts/get-codeowners.ps1 | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/eng/common/scripts/get-codeowners.ps1 b/eng/common/scripts/get-codeowners.ps1 index cd967691ea..dff01ecab6 100644 --- a/eng/common/scripts/get-codeowners.ps1 +++ b/eng/common/scripts/get-codeowners.ps1 @@ -30,12 +30,12 @@ function Get-CodeOwnersTool() return $command } -function Get-CodeOwners ([string]$targetDirectory, [string]$codeOwnerFileLocation, [bool]$useNonUserAlias = $false) +function Get-CodeOwners ([string]$targetDirectory, [string]$codeOwnerFileLocation, [bool]$includeNonUserAliases = $false) { $command = Get-CodeOwnersTool # Filter out the non user alias from code owner list. Write-Host "Testing on $targetDirectory..." - if($useNonUserAlias) { + if($includeNonUserAliases) { $codeOwnersString = & $command --target-directory $targetDirectory --code-owner-file-path $codeOwnerFileLocation 2>&1 } else { @@ -58,11 +58,11 @@ function Get-CodeOwners ([string]$targetDirectory, [string]$codeOwnerFileLocatio Write-Host "##vso[task.setvariable variable=$VsoVariable;]$codeOwners" } - return $codeOwnersJson.Owners + return ,@($codeOwnersJson.Owners) } -function TestGetCodeOwner([string]$targetDirectory, [string]$codeOwnerFileLocation, [bool]$useNonUserAlias = $false, [string[]]$expectReturn) { - $actualReturn = Get-CodeOwners -targetDirectory $targetDirectory -codeOwnerFileLocation $codeOwnerFileLocation -useNonUserAlias $useNonUserAlias +function TestGetCodeOwner([string]$targetDirectory, [string]$codeOwnerFileLocation, [bool]$includeNonUserAliases = $false, [string[]]$expectReturn) { + $actualReturn = Get-CodeOwners -targetDirectory $targetDirectory -codeOwnerFileLocation $codeOwnerFileLocation -includeNonUserAliases $IncludeNonUserAliases if ($actualReturn.Count -ne $expectReturn.Count) { Write-Error "The length of actual result is not as expected. Expected length: $($expectReturn.Count), Actual length: $($actualReturn.Count)." @@ -78,14 +78,14 @@ function TestGetCodeOwner([string]$targetDirectory, [string]$codeOwnerFileLocati if($Test) { $testFile = "$PSSCriptRoot/../../../tools/code-owners-parser/Azure.Sdk.Tools.RetrieveCodeOwners.Tests/CODEOWNERS" - TestGetCodeOwner -targetDirectory "sdk" -codeOwnerFileLocation $testFile -useNonUserAlias $true -expectReturn @("person1", "person2") - TestGetCodeOwner -targetDirectory "sdk/noPath" -codeOwnerFileLocation $testFile -useNonUserAlias $true -expectReturn @("person1", "person2") - TestGetCodeOwner -targetDirectory "/sdk/azconfig" -codeOwnerFileLocation $testFile -useNonUserAlias $true -expectReturn @("person3", "person4") - TestGetCodeOwner -targetDirectory "/sdk/azconfig/package" -codeOwnerFileLocation $testFile -useNonUserAlias $true $testFile -expectReturn @("person3", "person4") - TestGetCodeOwner -targetDirectory "/sd" -codeOwnerFileLocation $testFile -useNonUserAlias $true -expectReturn @() + TestGetCodeOwner -targetDirectory "sdk" -codeOwnerFileLocation $testFile -includeNonUserAliases $true -expectReturn @("person1", "person2") + TestGetCodeOwner -targetDirectory "sdk/noPath" -codeOwnerFileLocation $testFile -includeNonUserAliases $true -expectReturn @("person1", "person2") + TestGetCodeOwner -targetDirectory "/sdk/azconfig" -codeOwnerFileLocation $testFile -includeNonUserAliases $true -expectReturn @("person3", "person4") + TestGetCodeOwner -targetDirectory "/sdk/azconfig/package" -codeOwnerFileLocation $testFile -includeNonUserAliases $true $testFile -expectReturn @("person3", "person4") + TestGetCodeOwner -targetDirectory "/sd" -codeOwnerFileLocation $testFile -includeNonUserAliases $true -expectReturn @() TestGetCodeOwner -targetDirectory "/sdk/testUser/" -codeOwnerFileLocation $testFile -expectReturn @("azure-sdk") exit 0 } else { - return Get-CodeOwners -targetDirectory $TargetDirectory -codeOwnerFileLocation $CodeOwnerFileLocation -useNonUserAlias $IncludeNonUserAliases + return Get-CodeOwners -targetDirectory $TargetDirectory -codeOwnerFileLocation $CodeOwnerFileLocation -includeNonUserAliases $IncludeNonUserAliases }