Skip to content

Commit c63cabc

Browse files
authored
Fix Bug: Repo export fails when repository contains a single branch #97 (#98)
1 parent 6917d55 commit c63cabc

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/PSRule.Rules.AzureDevOps/Functions/DevOps.Repos.ps1

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -437,22 +437,23 @@ function Export-AzDevOpsReposAndBranchPolicies {
437437
$repo | Add-Member -MemberType NoteProperty -Name ReadmeExists -Value $readmeExists
438438

439439
# Get all branches for the repo
440-
$branches = Get-AzDevOpsBranches -Project $Project -Repository $repo.id
440+
$branches = @()
441+
$branches += Get-AzDevOpsBranches -Project $Project -Repository $repo.id
441442
# add branch policies for each branch to the branches object
442-
$branches = $branches | ForEach-Object {
443+
$branches = @($branches | ForEach-Object {
443444
$branch = $_
444445
$branchPolicy = @(Get-AzDevOpsBranchPolicy -Project $Project -Repository $repo.id -Branch $branch.name)
445446
$branch | Add-Member -MemberType NoteProperty -Name BranchPolicy -Value $branchPolicy
446447
$branch
447-
}
448+
})
448449
# Add an ObjectType Azure.DevOps.Repo.Branch to each branch object
449-
$branches = $branches | ForEach-Object {
450+
$branches = @($branches | ForEach-Object {
450451
$branch = $_
451452
$branch | Add-Member -MemberType NoteProperty -Name ObjectType -Value "Azure.DevOps.Repo.Branch"
452453
# Add ObjectName to branch object
453454
$branch | Add-Member -MemberType NoteProperty -Name ObjectName -Value ("{0}.{1}.{2}.{3}" -f $Organization,$Project,$repo.name,$branch.name)
454455
$branch
455-
}
456+
})
456457

457458

458459

tests/DevOps.Repos.Tests.ps1

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -382,10 +382,8 @@ Describe "Functions: DevOps.Repos.Tests" {
382382

383383
It 'Should export all JSON files with an Azure.DevOps.Repo.Branch ObjectType object in it' {
384384
$files = Get-ChildItem -Path $OutputPath -Recurse -File | Where-Object { $_.Name -match "ado.repo.json" }
385-
$files | ForEach-Object {
386-
$json = Get-Content -Path $_.FullName -Raw | ConvertFrom-Json
387-
$json | Where-Object { $_.ObjectType -eq "Azure.DevOps.Repo.Branch" } | Should -Not -BeNullOrEmpty
388-
}
385+
$json = Get-Content -Path $files[0].FullName -Raw | ConvertFrom-Json
386+
$json | Where-Object { $_.ObjectType -eq "Azure.DevOps.Repo.Branch" } | Should -Not -BeNullOrEmpty
389387
}
390388
}
391389

0 commit comments

Comments
 (0)