Skip to content

Commit

Permalink
Fix Bug: Repo export fails when repository contains a single branch #97
Browse files Browse the repository at this point in the history
… (#98)
  • Loading branch information
webtonize authored Jan 4, 2024
1 parent 6917d55 commit c63cabc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
11 changes: 6 additions & 5 deletions src/PSRule.Rules.AzureDevOps/Functions/DevOps.Repos.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -437,22 +437,23 @@ function Export-AzDevOpsReposAndBranchPolicies {
$repo | Add-Member -MemberType NoteProperty -Name ReadmeExists -Value $readmeExists

# Get all branches for the repo
$branches = Get-AzDevOpsBranches -Project $Project -Repository $repo.id
$branches = @()
$branches += Get-AzDevOpsBranches -Project $Project -Repository $repo.id
# add branch policies for each branch to the branches object
$branches = $branches | ForEach-Object {
$branches = @($branches | ForEach-Object {
$branch = $_
$branchPolicy = @(Get-AzDevOpsBranchPolicy -Project $Project -Repository $repo.id -Branch $branch.name)
$branch | Add-Member -MemberType NoteProperty -Name BranchPolicy -Value $branchPolicy
$branch
}
})
# Add an ObjectType Azure.DevOps.Repo.Branch to each branch object
$branches = $branches | ForEach-Object {
$branches = @($branches | ForEach-Object {
$branch = $_
$branch | Add-Member -MemberType NoteProperty -Name ObjectType -Value "Azure.DevOps.Repo.Branch"
# Add ObjectName to branch object
$branch | Add-Member -MemberType NoteProperty -Name ObjectName -Value ("{0}.{1}.{2}.{3}" -f $Organization,$Project,$repo.name,$branch.name)
$branch
}
})



Expand Down
6 changes: 2 additions & 4 deletions tests/DevOps.Repos.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,8 @@ Describe "Functions: DevOps.Repos.Tests" {

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

Expand Down

0 comments on commit c63cabc

Please sign in to comment.