diff --git a/PSGitLab/PSGitLab.psd1 b/PSGitLab/PSGitLab.psd1 index 0377978..c512d20 100644 --- a/PSGitLab/PSGitLab.psd1 +++ b/PSGitLab/PSGitLab.psd1 @@ -71,6 +71,7 @@ FunctionsToExport = @( 'Block-GitLabUser', 'Close-GitLabMergeRequest', 'Close-GitLabMilestone', + 'Get-GitLabBranch', 'Get-GitLabCommitStats', 'Get-GitLabGroup', 'Get-GitLabIssue', diff --git a/PSGitLab/Public/Branches/Get-GitLabBranch.ps1 b/PSGitLab/Public/Branches/Get-GitLabBranch.ps1 new file mode 100644 index 0000000..dee9adb --- /dev/null +++ b/PSGitLab/Public/Branches/Get-GitLabBranch.ps1 @@ -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' +} \ No newline at end of file