109 строки
3.7 KiB
PowerShell
109 строки
3.7 KiB
PowerShell
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
# Licensed under the MIT License.
|
|
|
|
function Get-GitHubRepositoryBranch
|
|
{
|
|
<#
|
|
.SYNOPSIS
|
|
Retrieve branches for a given GitHub repository.
|
|
|
|
.DESCRIPTION
|
|
Retrieve branches for a given GitHub repository.
|
|
|
|
The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub
|
|
|
|
.PARAMETER OwnerName
|
|
Owner of the repository.
|
|
If not supplied here, the DefaultOwnerName configuration property value will be used.
|
|
|
|
.PARAMETER RepositoryName
|
|
Name of the repository.
|
|
If not supplied here, the DefaultRepositoryName configuration property value will be used.
|
|
|
|
.PARAMETER Uri
|
|
Uri for the repository.
|
|
The OwnerName and RepositoryName will be extracted from here instead of needing to provide
|
|
them individually.
|
|
|
|
.PARAMETER Name
|
|
Name of the specific branch to be retrieved. If not supplied, all branches will be retrieved.
|
|
|
|
.PARAMETER AccessToken
|
|
If provided, this will be used as the AccessToken for authentication with the
|
|
REST Api. Otherwise, will attempt to use the configured value or will run unauthenticated.
|
|
|
|
.PARAMETER NoStatus
|
|
If this switch is specified, long-running commands will run on the main thread
|
|
with no commandline status update. When not specified, those commands run in
|
|
the background, enabling the command prompt to provide status information.
|
|
If not supplied here, the DefaultNoStatus configuration property value will be used.
|
|
|
|
.OUTPUTS
|
|
[PSCustomObject[]] List of branches within the given repository.
|
|
|
|
.EXAMPLE
|
|
Get-GitHubRepositoryBranch -OwnerName Microsoft -RepositoryName PowerShellForGitHub
|
|
|
|
Gets all branches for the specified repository.
|
|
|
|
.EXAMPLE
|
|
Get-GitHubRepositoryBranch -Uri 'https://github.com/PowerShell/PowerShellForGitHub' -Name master
|
|
|
|
Gets information only on the master branch for the specified repository.
|
|
#>
|
|
[CmdletBinding(
|
|
SupportsShouldProcess,
|
|
DefaultParameterSetName='Elements')]
|
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
|
|
[Alias('Get-GitHubBranch')]
|
|
param(
|
|
[Parameter(ParameterSetName='Elements')]
|
|
[string] $OwnerName,
|
|
|
|
[Parameter(ParameterSetName='Elements')]
|
|
[string] $RepositoryName,
|
|
|
|
[Parameter(
|
|
Mandatory,
|
|
ParameterSetName='Uri')]
|
|
[string] $Uri,
|
|
|
|
[string] $Name,
|
|
|
|
[switch] $ProtectedOnly,
|
|
|
|
[string] $AccessToken,
|
|
|
|
[switch] $NoStatus
|
|
)
|
|
|
|
Write-InvocationLog
|
|
|
|
$elements = Resolve-RepositoryElements
|
|
$OwnerName = $elements.ownerName
|
|
$RepositoryName = $elements.repositoryName
|
|
|
|
$telemetryProperties = @{
|
|
'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName)
|
|
'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName)
|
|
}
|
|
|
|
$uriFragment = "repos/$OwnerName/$RepositoryName/branches`?"
|
|
if (-not [String]::IsNullOrEmpty($Name)) { $uriFragment = $uriFragment + "/$Name" }
|
|
|
|
$getParams = @()
|
|
if ($ProtectedOnly) { $getParams += 'protected=true' }
|
|
|
|
$params = @{
|
|
'UriFragment' = $uriFragment + '?' + ($getParams -join '&')
|
|
'Description' = "Getting branches for $RepositoryName"
|
|
'AccessToken' = $AccessToken
|
|
'TelemetryEventName' = $MyInvocation.MyCommand.Name
|
|
'TelemetryProperties' = $telemetryProperties
|
|
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus)
|
|
}
|
|
|
|
return Invoke-GHRestMethodMultipleResult @params
|
|
}
|
|
|