209 строки
7.0 KiB
PowerShell
209 строки
7.0 KiB
PowerShell
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
# Licensed under the MIT License.
|
|
|
|
function Get-GitHubTeam
|
|
{
|
|
<#
|
|
.SYNOPSIS
|
|
Retrieve a team or teams within an organization or repository on GitHub.
|
|
|
|
.DESCRIPTION
|
|
Retrieve a team or teams within an organization or repository on GitHub.
|
|
|
|
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 OrganizationName
|
|
The name of the organization
|
|
|
|
.PARAMETER TeamId
|
|
The ID of the speific team to retrieve
|
|
|
|
.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[]] The team(s) that match the user's request.
|
|
|
|
.EXAMPLE
|
|
Get-GitHubTeam -OrganizationName PowerShell
|
|
#>
|
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
|
|
[CmdletBinding(
|
|
SupportsShouldProcess,
|
|
DefaultParametersetName='Elements')]
|
|
param
|
|
(
|
|
[Parameter(ParameterSetName='Elements')]
|
|
[string] $OwnerName,
|
|
|
|
[Parameter(ParameterSetName='Elements')]
|
|
[string] $RepositoryName,
|
|
|
|
[Parameter(
|
|
Mandatory,
|
|
ParameterSetName='Uri')]
|
|
[string] $Uri,
|
|
|
|
[Parameter(
|
|
Mandatory,
|
|
ParameterSetName='Organization')]
|
|
[ValidateNotNullOrEmpty()]
|
|
[string] $OrganizationName,
|
|
|
|
[Parameter(
|
|
Mandatory,
|
|
ParameterSetName='Single')]
|
|
[ValidateNotNullOrEmpty()]
|
|
[string] $TeamId,
|
|
|
|
[string] $AccessToken,
|
|
|
|
[switch] $NoStatus
|
|
)
|
|
|
|
Write-InvocationLog
|
|
|
|
$telemetryProperties = @{}
|
|
|
|
$uriFragment = [String]::Empty
|
|
$description = [String]::Empty
|
|
if ($PSCmdlet.ParameterSetName -in ('Elements', 'Uri'))
|
|
{
|
|
$elements = Resolve-RepositoryElements
|
|
$OwnerName = $elements.ownerName
|
|
$RepositoryName = $elements.repositoryName
|
|
|
|
$telemetryProperties['OwnerName'] = Get-PiiSafeString -PlainText $OwnerName
|
|
$telemetryProperties['RepositoryName'] = Get-PiiSafeString -PlainText $RepositoryName
|
|
|
|
$uriFragment = "/repos/$OwnerName/$RepositoryName/teams"
|
|
$description = "Getting teams for $RepositoryName"
|
|
}
|
|
elseif ($PSCmdlet.ParameterSetName -eq 'Organization')
|
|
{
|
|
$telemetryProperties['OrganizationName'] = Get-PiiSafeString -PlainText $OrganizationName
|
|
|
|
$uriFragment = "/orgs/$OrganizationName/teams"
|
|
$description = "Gettings teams in $OrganizationName"
|
|
}
|
|
else
|
|
{
|
|
$telemetryProperties['TeamId'] = Get-PiiSafeString -PlainText $TeamId
|
|
|
|
$uriFragment = "/teams/$TeamId"
|
|
$description = "Getting team $TeamId"
|
|
}
|
|
|
|
$params = @{
|
|
'UriFragment' = $uriFragment
|
|
'AcceptHeader' = 'application/vnd.github.hellcat-preview+json'
|
|
'Description' = $description
|
|
'AccessToken' = $AccessToken
|
|
'TelemetryEventName' = $MyInvocation.MyCommand.Name
|
|
'TelemetryProperties' = $telemetryProperties
|
|
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus)
|
|
}
|
|
|
|
return Invoke-GHRestMethodMultipleResult @params
|
|
}
|
|
|
|
function Get-GitHubTeamMember
|
|
{
|
|
<#
|
|
.SYNOPSIS
|
|
Retrieve list of team members within an organization.
|
|
|
|
.DESCRIPTION
|
|
Retrieve list of team members within an organization.
|
|
|
|
The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub
|
|
|
|
.PARAMETER OrganizationName
|
|
The name of the organization
|
|
|
|
.PARAMETER TeamName
|
|
The name of the team in the organization
|
|
|
|
.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 members on the team within the organization.
|
|
|
|
.EXAMPLE
|
|
$members = Get-GitHubTeamMember -Organization PowerShell -TeamName Everybody
|
|
#>
|
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
|
|
[CmdletBinding(SupportsShouldProcess)]
|
|
param
|
|
(
|
|
[Parameter(Mandatory)]
|
|
[ValidateNotNullOrEmpty()]
|
|
[String] $OrganizationName,
|
|
|
|
[Parameter(Mandatory)]
|
|
[ValidateNotNullOrEmpty()]
|
|
[String] $TeamName,
|
|
|
|
[string] $AccessToken,
|
|
|
|
[switch] $NoStatus
|
|
)
|
|
|
|
Write-InvocationLog
|
|
|
|
$NoStatus = Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus
|
|
|
|
$teams = Get-GitHubTeam -OrganizationName $OrganizationName -AccessToken $AccessToken -NoStatus:$NoStatus
|
|
$team = $teams | Where-Object {$_.name -eq $TeamName}
|
|
if ($null -eq $team)
|
|
{
|
|
$message = "Unable to find the team [$TeamName] within the organization [$OrganizationName]."
|
|
Write-Log -Message $message -Level Error
|
|
throw $message
|
|
}
|
|
|
|
$telemetryProperties = @{
|
|
'OrganizationName' = (Get-PiiSafeString -PlainText $OrganizationName)
|
|
'TeamName' = (Get-PiiSafeString -PlainText $TeamName)
|
|
}
|
|
|
|
$params = @{
|
|
'UriFragment' = "teams/$($team.id)/members"
|
|
'Description' = "Getting members of the team $TeamName $($team.id)"
|
|
'AccessToken' = $AccessToken
|
|
'TelemetryEventName' = $MyInvocation.MyCommand.Name
|
|
'TelemetryProperties' = $telemetryProperties
|
|
'NoStatus' = $NoStatus
|
|
}
|
|
|
|
return Invoke-GHRestMethodMultipleResult @params
|
|
}
|