Skip to content

Commit

Permalink
Sync eng/common directory with azure-sdk-tools repository (Azure#12916)
Browse files Browse the repository at this point in the history
  • Loading branch information
azure-sdk authored Aug 6, 2020
1 parent 2f7f59e commit 52e9e1d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion eng/common/pipelines/templates/steps/get-pr-owners.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ steps:
- pwsh: |
$originalValue = "$(${{ parameters.TargetVariable }})"
$result = $(Build.SourcesDirectory)/eng/common/scripts/get-codeowners.ps1 -TargetDirectory sdk/${{ parameters.ServiceDirectory }}/ -RootDirectory $(Build.SourcesDirectory)
$result = $(Build.SourcesDirectory)/eng/common/scripts/get-codeowners.ps1 -TargetDirectory /sdk/${{ parameters.ServiceDirectory }}/ -RootDirectory $(Build.SourcesDirectory)
if ($result) {
Write-Output "##vso[task.setvariable variable=${{ parameters.TargetVariable }}]$originalValue,$result"
}
Expand Down
15 changes: 7 additions & 8 deletions eng/common/scripts/get-codeowners.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ param (
$TargetDirectory, # should be in relative form from root of repo. EG: sdk/servicebus
$RootDirectory # ideally $(Build.SourcesDirectory)
)

$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"
Expand All @@ -12,29 +13,27 @@ if (!(Test-Path $codeOwnersLocation)) {

$codeOwnersContent = Get-Content $codeOwnersLocation

$ownedFolders = @{}

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()] = ($splitLine[1..$($splitLine.Length)] `
$ownedFolders[$splitLine[0].ToLower().Trim("/")] = ($splitLine[1..$($splitLine.Length)] `
| ? { $_.StartsWith("@") } `
| % { return $_.substring(1) }) -join ","
}
}

$results = $ownedFolders[$TargetDirectory.ToLower()]
$results = $ownedFolders[$target]

if ($results) {
Write-Host "Discovered code owners for path $TargetDirectory are $results."
Write-Host "Found a folder $results to match $target"
return $results
}
else {
Write-Host "Unable to match path $TargetDirectory in CODEOWNERS file located at $codeOwnersLocation."
Write-Host $ownedFolders | ConvertTo-Json
Write-Host "Unable to match path $target in CODEOWNERS file located at $codeOwnersLocation."
Write-Host ($ownedFolders | ConvertTo-Json)
return ""
}

0 comments on commit 52e9e1d

Please sign in to comment.