Skip to content
This repository was archived by the owner on Aug 22, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions PSGitLab/PSGitLab.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ FunctionsToExport = @(
'Block-GitLabUser',
'Close-GitLabMergeRequest',
'Close-GitLabMilestone',
'Get-GitLabBranch',
'Get-GitLabCommitStats',
'Get-GitLabGroup',
'Get-GitLabIssue',
Expand Down
47 changes: 47 additions & 0 deletions PSGitLab/Public/Branches/Get-GitLabBranch.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<#
.Synopsis
Get-GitLabBranch - Find branches on a specific project
.DESCRIPTION
Function for finding branches on a specific project. Can return all branches, specific branch, or search for branches by name.
.EXAMPLE
Get-GitLabBranch -ProjectId 64 -All
.EXAMPLE
Get-GitLabBranch -ProjectId 64 -Branch Master
.EXAMPLE
Get-GitLabBranch -ProjectId 64 -Search Test
#>
Function Get-GitLabBranch {
[cmdletbinding(DefaultParameterSetName = 'All')]
[OutputType('GitLab.Branch')]
param(

#Id of the project
[Parameter(Mandatory = $true)]
[string]$ProjectId,

#Will return all branches associated to project
[Parameter(ParameterSetName = 'All')]
[switch]$All,

#Specify branch name to return specific branch
[Parameter(ParameterSetName = 'Branch')]
[string]$Branch,

#Search for branch
[Parameter(ParameterSetName = 'Search')]
[string]$Search
)

$Request = @{
URI = ''
Method = 'GET'
}

switch ( $PSCmdlet.ParameterSetName) {
'Branch' { $Request.URI = "/projects/{0}/repository/branches/{1}" -f $ProjectId, $Branch }
'All' { $Request.URI = "/projects/{0}/repository/branches" -f $ProjectId }
'Search' { $Request.URI = "/projects/{0}/repository/branches?search={1}" -f $ProjectId, $Search }
}

QueryGitLabAPI -Request $Request -ObjectType 'GitLab.Branch'
}