Functions/PlanBranch/Get-BambooPlanBranch.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<#
.SYNOPSIS
    Gets all plan-branches or describes a single plan-branch for a Bamboo Plan.
.DESCRIPTION
    If -BranchName is specified it describes only that plan-branch.
.PARAMETER PlanKey
    Mandatory - Key for the parent Bamboo Plan
.PARAMETER BranchName
    Optional - Name of the branch-plan to be described in details
.EXAMPLE
    Get-BambooPlanBranch -PlanKey 'PRJ-PLANKEY'
.EXAMPLE
    Get-BambooPlanBranch -PlanKey 'PRJ-PLANKEY' -BranchName 'master'
#>

function Get-BambooPlanBranch {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory)]
        [ValidatePattern('\w+-\w+')]
        [string]$PlanKey,

        [ValidatePattern('()|(\w|-)+')]
        [string]$BranchName
    )

    $resource = "plan/$PlanKey/branch"
    if ($BranchName) {
        $resource = "plan/$PlanKey/branch/$BranchName"
    }

    Invoke-BambooRestMethod -Resource $resource -Expand 'branches.branch' |
    Expand-BambooResource -ResourceName 'branch' -PluralResourceName 'branches' |
    Add_ObjectType -TypeName 'PsBamboo.Plan'
}