Skip to content

Commit

Permalink
Updated Get-TasksByCodeOwner.ps1 (#20496)
Browse files Browse the repository at this point in the history
* Update Get-TasksByCodeOwner

* Add more props

* PathName --> DirName

* remove comment

* fix owners pattern in Get-TasksInfo.ps1

* Reuse Get-TasksInfo.ps1
  • Loading branch information
KonstantinTyukalov authored Oct 3, 2024
1 parent 5d53b7e commit 47ee25f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
23 changes: 7 additions & 16 deletions scripts/Get-TasksByCodeOwner.ps1
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
Param(
[Parameter(Mandatory = $true)]
[string]$OwnerName
)

$codeowners = Get-Content (Join-Path $PSScriptRoot .. .github CODEOWNERS)
$tasks = (& "$(Join-Path $PSScriptRoot Get-TasksInfo.ps1)")

$tasks = $()
$codeowners | ForEach-Object {
if ($_ -notlike "* $($OwnerName)*") {
return
$tasksByOwner = @()
foreach ($task in $tasks) {
if ($task.Owners -contains $OwnerName) {
$tasksByOwner += , $task
}
if ($_ -notlike '*Tasks/*') {
return
}

$taskName = $_ -replace 'Tasks/', '' -replace '/.*', ''
$tasks += , $taskName
}

if ($tasks.Count -eq 0) {
Write-Error "No tasks found for owner $OwnerName" -ErrorAction Stop
}

$tasks | Out-File -FilePath (Join-Path $PSScriptRoot "TaskNames_$($OwnerName -replace '(\\|\/)', '_').txt")
return $tasksByOwner
2 changes: 1 addition & 1 deletion scripts/Get-TasksInfo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ foreach ($taskPath in (Get-ChildItem -Path $tasksDir)) {

$owners = @()
$ownersLine = $codeowners
| Where-Object { $_ -like "*$($taskDirName)*" }
| Where-Object { $_ -like "*Tasks/$($taskDirName)*" }
| ForEach-Object { $_ -replace "Tasks/$($taskDirName)( |/)", '' }
if ($null -ne $ownersLine) {
$owners = ($ownersLine.Trim()) -split '\s+'
Expand Down

0 comments on commit 47ee25f

Please sign in to comment.