GitHubRepositories: Add Get/Set/Remove GitHub Repository Team Permissions (#300)

Adds the following functions:

* `Get-GitHubRepositoryTeamPermission`
* `Set-GitHubRepositoryTeamPermission`
* `Remove-GitHubRepositoryTeamPermission`

References
* [Check team permissions for a repository](https://docs.github.com/en/free-pro-team@latest/rest/reference/teams#check-team-permissions-for-a-repository)
* [Add or update team repository permissions](https://docs.github.com/en/free-pro-team@latest/rest/reference/teams#add-or-update-team-repository-permissions)
* [Remove a repository from a team](https://docs.github.com/en/free-pro-team@latest/rest/reference/teams#remove-a-repository-from-a-team)

Resolves #307
This commit is contained in:
Simon Heather 2020-12-24 20:54:03 +00:00 коммит произвёл GitHub
Родитель 8fd4201020
Коммит 22e3d7bdf6
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
7 изменённых файлов: 1141 добавлений и 0 удалений

Просмотреть файл

@ -204,5 +204,29 @@
</ListEntries>
</ListControl>
</View>
<!--=============== GitHub.RepositoryTeamPermission Type View ===============-->
<View>
<Name>GitHub.RepositoryTeamPermission</Name>
<ViewSelectedBy>
<TypeName>GitHub.RepositoryTeamPermission</TypeName>
</ViewSelectedBy>
<TableControl>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<PropertyName>RepositoryName</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>TeamName</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Permission</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>
</ViewDefinitions>
</Configuration>

Просмотреть файл

@ -15,6 +15,7 @@
mercyAcceptHeader = 'application/vnd.github.mercy-preview+json'
mockingbirdAcceptHeader = 'application/vnd.github.mockingbird-preview'
nebulaAcceptHeader = 'application/vnd.github.nebula-preview+json'
repositoryAcceptHeader = 'application/vnd.github.v3.repository+json'
sailorVAcceptHeader = 'application/vnd.github.sailor-v-preview+json'
scarletWitchAcceptHeader = 'application/vnd.github.scarlet-witch-preview+json'
squirrelGirlAcceptHeader = 'application/vnd.github.squirrel-girl-preview'

Просмотреть файл

@ -10,6 +10,7 @@
GitHubRepositoryContributorStatisticsTypeName = 'GitHub.RepositoryContributorStatistics'
GitHubRepositoryLanguageTypeName = 'GitHub.RepositoryLanguage'
GitHubRepositoryTagTypeName = 'GitHub.RepositoryTag'
GitHubRepositoryTeamPermissionTypeName = 'GitHub.RepositoryTeamPermission'
}.GetEnumerator() | ForEach-Object {
Set-Variable -Scope Script -Option ReadOnly -Name $_.Key -Value $_.Value
}
@ -2944,6 +2945,527 @@ filter Set-GitHubRepositoryActionsPermission
Invoke-GHRestMethod @params | Out-Null
}
filter Get-GitHubRepositoryTeamPermission
{
<#
.SYNOPSIS
Retrieve team permissions for a repository on GitHub.
.DESCRIPTION
Retrieve team permissions for a 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 TeamName
The name of the team.
Note: This will be slower than querying by TeamSlug since it requires retrieving
all teams first.
.PARAMETER TeamSlug
The slug (a unique key based on the team name) of the team.
.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.
.INPUTS
GitHub.Branch
GitHub.Content
GitHub.Event
GitHub.Issue
GitHub.IssueComment
GitHub.Label
GitHub.Milestone
GitHub.Organization
GitHub.PullRequest
GitHub.Project
GitHub.ProjectCard
GitHub.ProjectColumn
GitHub.Reaction
GitHub.Release
GitHub.ReleaseAsset
GitHub.Repository
GitHub.Team
.OUTPUTS
GitHub.RepositoryTeamPermission
.EXAMPLE
Get-GitHubRepositoryTeamPermission -Uri https://github.com/microsoft/PowerShellForGitHub -TeamName Devs
Gets permission for the Devs team on the microsoft/PowerShellForGitHub repository.
.EXAMPLE
Get-GitHubRepositoryTeamPermission -OwnerName microsoft -RepositoryName PowerShellForGitHub -TeamName Admins
Gets permission for the Admin team on the microsoft/PowerShellForGitHub repository.
#>
[CmdletBinding(DefaultParameterSetName = 'TeamNameElements')]
[OutputType(
{ $script:GitHubRepositoryTeamTypeName })]
param
(
[Parameter(ParameterSetName = 'TeamNameElements')]
[Parameter(ParameterSetName = 'TeamSlugElements')]
[string] $OwnerName,
[Parameter(ParameterSetName = 'TeamNameElements')]
[Parameter(ParameterSetName = 'TeamSlugElements')]
[string] $RepositoryName,
[Parameter(
Mandatory,
ValueFromPipelineByPropertyName,
ParameterSetName = 'TeamNameUri')]
[Parameter(
Mandatory,
ValueFromPipelineByPropertyName,
ParameterSetName = 'TeamSlugUri')]
[Alias('RepositoryUrl')]
[string] $Uri,
[Parameter(
Mandatory,
ParameterSetName = 'TeamNameElements')]
[Parameter(
Mandatory,
ParameterSetName = 'TeamNameUri')]
[ValidateNotNullOrEmpty()]
[string] $TeamName,
[Parameter(
Mandatory,
ValueFromPipelineByPropertyName,
ParameterSetName = 'TeamSlugElements')]
[Parameter(
Mandatory,
ValueFromPipelineByPropertyName,
ParameterSetName = 'TeamSlugUri')]
[ValidateNotNullOrEmpty()]
[string] $TeamSlug,
[string] $AccessToken
)
Write-InvocationLog
$telemetryProperties = @{}
$elements = Resolve-RepositoryElements
$OwnerName = $elements.ownerName
$RepositoryName = $elements.repositoryName
if ($PSBoundParameters.ContainsKey('TeamName'))
{
$team = Get-GitHubTeam -OrganizationName $OwnerName |
Where-Object -Property name -eq $TeamName
if ($null -eq $team)
{
$message = "Team '$TeamName' not found"
Write-Log -Message $message -Level Error
throw $message
}
else
{
$TeamSlug = $team.slug
}
}
$telemetryProperties['TeamSlug'] = Get-PiiSafeString -PlainText $TeamSlug
$uriFragment = "/orgs/$OwnerName/teams/$TeamSlug/repos/$OwnerName/$RepositoryName"
$description = "Getting team $TeamSlug permissions for repository $RepositoryName"
$params = @{
UriFragment = $uriFragment
Description = $description
AcceptHeader = $script:repositoryAcceptHeader
Method = 'Get'
AccessToken = $AccessToken
TelemetryEventName = $MyInvocation.MyCommand.Name
TelemetryProperties = $telemetryProperties
}
$result = Invoke-GHRestMethod @params
if ($PSBoundParameters.ContainsKey('TeamSlug'))
{
$team = Get-GitHubTeam -OrganizationName $OwnerName -TeamSlug $TeamSlug
$TeamName = $team.name
}
return ($result |
Add-GitHubRepositoryTeamPermissionAdditionalProperties -TeamName $TeamName -TeamSlug $TeamSlug)
}
filter Set-GitHubRepositoryTeamPermission
{
<#
.SYNOPSIS
Sets team permission for a repository on GitHub.
.DESCRIPTION
Sets team permission for a 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 TeamName
The name of the specific team to retrieve.
Note: This will be slower than querying by TeamSlug since it requires retrieving
all teams first.
.PARAMETER TeamSlug
The slug (a unique key based on the team name) of the specific team to retrieve.
.PARAMETER Permission
The permission to grant the team on this repository.
Can be one of:
* Pull - team members can pull, but not push to or administer this repository.
* Push - team members can pull and push, but not administer this repository.
* Admin - team members can pull, push and administer this repository.
* Maintain - team members can manage the repository without access to sensitive or
destructive actions. Recommended for project managers. Only applies to repositories owned
by organizations.
* Triage - team members can proactively manage issues and pull requests without write access.
Recommended for contributors who triage a repository. Only applies to repositories owned
by organizations.
If no permission is specified, the team's permission attribute will be used to determine
what permission to grant the team on this repository.
.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.
.INPUTS
GitHub.Branch
GitHub.Content
GitHub.Event
GitHub.Issue
GitHub.IssueComment
GitHub.Label
GitHub.Milestone
GitHub.Organization
GitHub.PullRequest
GitHub.Project
GitHub.ProjectCard
GitHub.ProjectColumn
GitHub.Reaction
GitHub.Release
GitHub.ReleaseAsset
GitHub.Repository
GitHub.Team
.EXAMPLE
Set-GitHubRepositoryTeamPermission -Uri https://github.com/microsoft/PowerShellForGitHub -TeamName Devs -Permission Push
Sets the Push permission for the Devs team on the microsoft/PowerShellForGitHub repository.
.EXAMPLE
Set-GitHubRepositoryTeamPermission -OwnerName microsoft -RepositoryName PowerShellForGitHub -TeamName Admins -Permission Admin
Sets the Admin permission for the Admin team on the microsoft/PowerShellForGitHub repository.
#>
[CmdletBinding(
SupportsShouldProcess,
DefaultParameterSetName = 'TeamNameElements')]
param(
[Parameter(ParameterSetName = 'TeamNameElements')]
[Parameter(ParameterSetName = 'TeamSlugElements')]
[string] $OwnerName,
[Parameter(ParameterSetName = 'TeamNameElements')]
[Parameter(ParameterSetName = 'TeamSlugElements')]
[string] $RepositoryName,
[Parameter(
Mandatory,
ValueFromPipelineByPropertyName,
ParameterSetName = 'TeamNameUri')]
[Parameter(
Mandatory,
ValueFromPipelineByPropertyName,
ParameterSetName = 'TeamSlugUri')]
[Alias('RepositoryUrl')]
[string] $Uri,
[Parameter(
Mandatory,
ParameterSetName = 'TeamNameElements')]
[Parameter(
Mandatory,
ParameterSetName = 'TeamNameUri')]
[ValidateNotNullOrEmpty()]
[string] $TeamName,
[Parameter(
Mandatory,
ValueFromPipelineByPropertyName,
ParameterSetName = 'TeamSlugElements')]
[Parameter(
Mandatory,
ValueFromPipelineByPropertyName,
ParameterSetName = 'TeamSlugUri')]
[ValidateNotNullOrEmpty()]
[string] $TeamSlug,
[Parameter()]
[ValidateSet('Pull', 'Push', 'Admin', 'Maintain', 'Triage')]
[string]$Permission,
[string] $AccessToken
)
Write-InvocationLog
$telemetryProperties = @{}
$elements = Resolve-RepositoryElements
$OwnerName = $elements.ownerName
$RepositoryName = $elements.repositoryName
if ($PSBoundParameters.ContainsKey('TeamName'))
{
$team = Get-GitHubTeam -OrganizationName $OwnerName |
Where-Object -Property name -eq $TeamName
if ($null -eq $team)
{
$message = "Team '$TeamName' not found"
Write-Log -Message $message -Level Error
throw $message
}
else
{
$TeamSlug = $team.slug
}
}
$telemetryProperties['TeamSlug'] = Get-PiiSafeString -PlainText $TeamSlug
$hashBody = @{}
if ($PSBoundParameters.ContainsKey('Permission'))
{
$hashBody = @{
permission = $Permission.ToLower()
}
}
if (-not $PSCmdlet.ShouldProcess(
$RepositoryName, "Set GitHub $Permission Repository Permissions for Team $TeamSlug"))
{
return
}
$params = @{
UriFragment = "/orgs/$OwnerName/teams/$TeamSlug/repos/$OwnerName/$RepositoryName"
Description = "Setting team $TeamSlug $Permission permissions for repository $RepositoryName"
Body = (ConvertTo-Json -InputObject $hashBody)
Method = 'Put'
AccessToken = $AccessToken
TelemetryEventName = $MyInvocation.MyCommand.Name
TelemetryProperties = $telemetryProperties
}
Invoke-GHRestMethod @params | Out-Null
}
filter Remove-GitHubRepositoryTeamPermission
{
<#
.SYNOPSIS
Removes team permission for a repository on GitHub.
.DESCRIPTION
Removes team permission for a 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 TeamName
The name of the specific team to remove.
Note: This will be slower than querying by TeamSlug since it requires retrieving
all teams first.
.PARAMETER TeamSlug
The slug (a unique key based on the team name) of the specific team to remove.
.PARAMETER Force
If this switch is specified, you will not be prompted for confirmation of command execution.
.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.
.INPUTS
GitHub.Branch
GitHub.Content
GitHub.Event
GitHub.Issue
GitHub.IssueComment
GitHub.Label
GitHub.Milestone
GitHub.Organization
GitHub.PullRequest
GitHub.Project
GitHub.ProjectCard
GitHub.ProjectColumn
GitHub.Reaction
GitHub.Release
GitHub.ReleaseAsset
GitHub.Repository
GitHub.Team
.EXAMPLE
Remove-GitHubRepositoryTeamPermission -Uri https://github.com/microsoft/PowerShellForGitHub -TeamName Devs
Removes the permission for the Devs team on the microsoft/PowerShellForGitHub repository.
.EXAMPLE
Remove-GitHubRepositoryTeamPermission -OwnerName microsoft -RepositoryName PowerShellForGitHub -TeamName Admins
Removes the permission for the Admin team on the microsoft/PowerShellForGitHub repository.
#>
[CmdletBinding(
SupportsShouldProcess,
DefaultParameterSetName = 'TeamNameElements',
ConfirmImpact='High')]
[Alias('Delete-GitHubRepositoryTeamPermission')]
param(
[Parameter(ParameterSetName = 'TeamNameElements')]
[Parameter(ParameterSetName = 'TeamSlugElements')]
[string] $OwnerName,
[Parameter(ParameterSetName = 'TeamNameElements')]
[Parameter(ParameterSetName = 'TeamSlugElements')]
[string] $RepositoryName,
[Parameter(
Mandatory,
ValueFromPipelineByPropertyName,
ParameterSetName = 'TeamNameUri')]
[Parameter(
Mandatory,
ValueFromPipelineByPropertyName,
ParameterSetName = 'TeamSlugUri')]
[Alias('RepositoryUrl')]
[string] $Uri,
[Parameter(
Mandatory,
ParameterSetName = 'TeamNameElements')]
[Parameter(
Mandatory,
ParameterSetName = 'TeamNameUri')]
[ValidateNotNullOrEmpty()]
[string] $TeamName,
[Parameter(
Mandatory,
ValueFromPipelineByPropertyName,
ParameterSetName = 'TeamSlugElements')]
[Parameter(
Mandatory,
ValueFromPipelineByPropertyName,
ParameterSetName = 'TeamSlugUri')]
[ValidateNotNullOrEmpty()]
[string] $TeamSlug,
[switch] $Force,
[string] $AccessToken
)
Write-InvocationLog
$telemetryProperties = @{}
$elements = Resolve-RepositoryElements
$OwnerName = $elements.ownerName
$RepositoryName = $elements.repositoryName
if ($PSBoundParameters.ContainsKey('TeamName'))
{
$team = Get-GitHubTeam -OrganizationName $OwnerName |
Where-Object -Property name -eq $TeamName
if ($null -eq $team)
{
$message = "Team '$TeamName' not found"
Write-Log -Message $message -Level Error
throw $message
}
else
{
$TeamSlug = $team.slug
}
}
$telemetryProperties['TeamSlug'] = Get-PiiSafeString -PlainText $TeamSlug
if ($Force -and (-not $Confirm))
{
$ConfirmPreference = 'None'
}
if (-not $PSCmdlet.ShouldProcess(
$RepositoryName, "Remove GitHub Repository Permissions for Team $TeamSlug"))
{
return
}
$params = @{
UriFragment = "/orgs/$OwnerName/teams/$TeamSlug/repos/$OwnerName/$RepositoryName"
Description = "Removing team $TeamSlug permissions from repository $RepositoryName"
Method = 'Delete'
AccessToken = $AccessToken
TelemetryEventName = $MyInvocation.MyCommand.Name
TelemetryProperties = $telemetryProperties
}
Invoke-GHRestMethod @params | Out-Null
}
filter Add-GitHubRepositoryAdditionalProperties
{
<#
@ -3295,3 +3817,133 @@ filter Add-GitHubRepositoryActionsPermissionAdditionalProperties
Write-Output $item
}
}
filter Add-GitHubRepositoryTeamPermissionAdditionalProperties
{
<#
.SYNOPSIS
Adds type name and additional properties to ease pipelining to GitHub Repository Team Permission objects.
.PARAMETER InputObject
The GitHub object to add additional properties to.
.PARAMETER OwnerName
Owner of the repository. This information might be obtainable from InputObject, so this
is optional based on what InputObject contains.
.PARAMETER RepositoryName
Name of the repository. This information might be obtainable from InputObject, so this
is optional based on what InputObject contains.
.PARAMETER TeamName
The name of the team.
.PARAMETER TeamSlug
The slug (a unique key based on the team name) of the team.
.PARAMETER TypeName
The type that should be assigned to the object.
.INPUTS
PSCustomObject
.OUTPUTS
GitHub.RepositoryTeamPermission
#>
[CmdletBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "",
Justification="Internal helper that is definitely adding more than one property.")]
param(
[Parameter(
Mandatory,
ValueFromPipeline)]
[AllowNull()]
[AllowEmptyCollection()]
[PSCustomObject[]] $InputObject,
[string] $OwnerName,
[string] $RepositoryName,
[Parameter(Mandatory)]
[string] $TeamName,
[Parameter(Mandatory)]
[string] $TeamSlug,
[ValidateNotNullOrEmpty()]
[string] $TypeName = $script:GitHubRepositoryTeamPermissionTypeName
)
foreach ($item in $InputObject)
{
$item.PSObject.TypeNames.Insert(0, $TypeName)
if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport))
{
$repositoryUrl = [String]::Empty
if ([String]::IsNullOrEmpty($item.html_url))
{
if ($PSBoundParameters.ContainsKey('OwnerName') -and
$PSBoundParameters.ContainsKey('RepositoryName'))
{
$repositoryUrl = (Join-GitHubUri -OwnerName $OwnerName -RepositoryName $RepositoryName)
}
}
else
{
$elements = Split-GitHubUri -Uri $item.html_url
$repositoryUrl = Join-GitHubUri @elements
}
if (-not [String]::IsNullOrEmpty($repositoryUrl))
{
Add-Member -InputObject $item -Name 'RepositoryUrl' -Value $repositoryUrl -MemberType NoteProperty -Force
}
if ($item.id -gt 0)
{
Add-Member -InputObject $item -Name 'RepositoryId' -Value $item.id -MemberType NoteProperty -Force
}
if ($null -ne $item.owner)
{
$null = Add-GitHubUserAdditionalProperties -InputObject $item.owner
}
if ($null -ne $item.organization)
{
$null = Add-GitHubOrganizationAdditionalProperties -InputObject $item.organization
}
Add-Member -InputObject $item -Name 'RepositoryName' -Value $item.full_name -MemberType NoteProperty -Force
Add-Member -InputObject $item -Name 'TeamName' -Value $TeamName -MemberType NoteProperty -Force
Add-Member -InputObject $item -Name 'TeamSlug' -Value $TeamSlug -MemberType NoteProperty -Force
}
if ($result.permissions.admin)
{
$permission = 'admin'
}
elseif ($result.permissions.push)
{
$permission = 'push'
}
elseif ($result.permissions.maintain)
{
$permission = 'maintain'
}
elseif ($result.permissions.triage)
{
$permission = 'triage'
}
elseif ($result.permissions.pull)
{
$permission = 'pull'
}
Add-Member -InputObject $item -Name 'Permission' -Value $permission -MemberType NoteProperty -Force
Write-Output $item
}
}

Просмотреть файл

@ -109,6 +109,7 @@
'Get-GitHubRepositoryFork',
'Get-GitHubRepositoryLanguage',
'Get-GitHubRepositoryTag',
'Get-GitHubRepositoryTeamPermission',
'Get-GitHubRepositoryTopic',
'Get-GitHubRepositoryUniqueContributor',
'Get-GitHubTeam',
@ -163,6 +164,7 @@
'Remove-GitHubRepository',
'Remove-GitHubRepositoryBranch'
'Remove-GitHubRepositoryBranchProtectionRule',
'Remove-GitHubRepositoryTeamPermission',
'Remove-GitHubTeam',
'Rename-GitHubGistFile',
'Rename-GitHubRepository',
@ -190,6 +192,7 @@
'Set-GitHubReleaseAsset',
'Set-GitHubRepository',
'Set-GitHubRepositoryActionsPermission',
'Set-GitHubRepositoryTeamPermission',
'Set-GitHubRepositoryTopic',
'Set-GitHubTeam',
'Split-GitHubUri',
@ -221,6 +224,7 @@
'Delete-GitHubRepository',
'Delete-GitHubRepositoryBranch',
'Delete-GitHubRepositoryBranchProtectionRule',
'Delete-GitHubRepositoryTeamPermission',
'Delete-GitHubTeam',
'Fork-GitHubGist',
'Get-GitHubAsset',

Просмотреть файл

@ -63,6 +63,7 @@ At present, this module can:
* Change repository ownership.
* Query, enable and disable security and vulnerability alerts.
* Query and set GitHub Actions permission.
* Query, set and remove team permissions.
* Query various [traffic reports](https://developer.github.com/v3/repos/traffic/) including
referral sources and paths, page views and clones.
* Query, create, edit, lock/unlock [Issues](https://developer.github.com/v3/issues/) and

Просмотреть файл

@ -1488,6 +1488,444 @@ try
}
}
}
Describe 'GitHubRepositories\Get-GitHubRepositoryTeamPermission' {
BeforeAll {
$repositoryTeamPermissionTypeName = 'GitHub.RepositoryTeamPermission'
$repoName = [Guid]::NewGuid().Guid
$repo = New-GitHubRepository -OrganizationName $script:organizationName -RepositoryName $repoName
$teamName = [Guid]::NewGuid().Guid
$description = 'Team Description'
$privacy = 'closed'
$MaintainerName = $script:ownerName
$newGithubTeamParms = @{
OrganizationName = $script:organizationName
TeamName = $teamName
Description = $description
Privacy = $privacy
MaintainerName = $MaintainerName
}
$team = New-GitHubTeam @newGithubTeamParms
$permissions = 'Push', 'Pull', 'Maintain', 'Triage', 'Admin'
}
Foreach ($permission in $permissions) {
Context "When the Team Permission is $permission" {
BeforeAll {
$setGitHubRepositoryTeamPermissionParms = @{
Uri = $repo.svn_url
TeamSlug = $team.slug
Permission = $permission
}
Set-GitHubRepositoryTeamPermission @setGitHubRepositoryTeamPermissionParms
$getGithubRepositoryTeamPermissionParms = @{
Uri = $repo.svn_url
TeamSlug = $team.slug
}
$repoPermission = Get-GitHubRepositoryTeamPermission @getGithubRepositoryTeamPermissionParms
}
It 'Should have the expected type and additional properties' {
$repoPermission.PSObject.TypeNames[0] | Should -Be $repositoryTeamPermissionTypeName
$repoPermission.RepositoryName | Should -Be $repo.full_name
$repoPermission.RepositoryUrl | Should -Be $repo.svn_url
$repoPermission.RepositoryId | Should -Be $repo.RepositoryId
$repoPermission.TeamName | Should -Be $team.TeamName
$repoPermission.TeamSlug | Should -Be $team.TeamSlug
$repoPermission.Permission | Should -Be $permission
}
}
}
Context "When specifying the 'TeamName' parameter" {
BeforeAll {
$permission = 'Pull'
$setGitHubRepositoryTeamPermissionParms = @{
Uri = $repo.svn_url
TeamSlug = $team.slug
Permission = $permission
}
Set-GitHubRepositoryTeamPermission @setGitHubRepositoryTeamPermissionParms
$getGithubRepositoryTeamPermissionParms = @{
Uri = $repo.svn_url
TeamName = $teamName
}
$repoPermission = Get-GitHubRepositoryTeamPermission @getGithubRepositoryTeamPermissionParms
}
It 'Should have the expected type and additional properties' {
$repoPermission.PSObject.TypeNames[0] | Should -Be $repositoryTeamPermissionTypeName
$repoPermission.RepositoryName | Should -Be $repo.full_name
$repoPermission.RepositoryUrl | Should -Be $repo.svn_url
$repoPermission.RepositoryId | Should -Be $repo.RepositoryId
$repoPermission.TeamName | Should -Be $team.TeamName
$repoPermission.TeamSlug | Should -Be $team.TeamSlug
$repoPermission.Permission | Should -Be $permission
}
Context 'When the specified TeamName does not exist' {
BeforeAll {
$nonExistingTeamName = [Guid]::NewGuid().Guid
$getGithubRepositoryTeamPermissionParms = @{
Uri = $repo.svn_url
TeamName = $nonExistingTeamName
}
}
It 'Should throw the correct exception' {
{ Get-GitHubRepositoryTeamPermission @getGithubRepositoryTeamPermissionParms } |
Should -Throw "Team '$nonExistingTeamName' not found"
}
}
}
Context "When specifying the 'URI' Parameter from the Pipeline" {
BeforeAll -ScriptBlock {
$getGitHubRepositoryTeamPermissionParms = @{
TeamName = $teamName
}
$repoPermission = $repo |
Get-GitHubRepositoryTeamPermission @getGitHubRepositoryTeamPermissionParms
}
It 'Should have the expected type and additional properties' {
$repoPermission.PSObject.TypeNames[0] | Should -Be $repositoryTeamPermissionTypeName
$repoPermission.RepositoryName | Should -Be $repo.full_name
$repoPermission.TeamName | Should -Be $teamName
}
}
Context "When specifying the 'TeamSlug' and 'OrganizationName' Parameters from the Pipeline" {
BeforeAll -ScriptBlock {
$getGitHubRepositoryTeamPermissionParms = @{
Uri = $repo.svn_url
}
$repoPermission = $team |
Get-GitHubRepositoryTeamPermission @getGitHubRepositoryTeamPermissionParms
}
It 'Should have the expected type and additional properties' {
$repoPermission.PSObject.TypeNames[0] | Should -Be $repositoryTeamPermissionTypeName
$repoPermission.RepositoryName | Should -Be $repo.full_name
$repoPermission.TeamName | Should -Be $teamName
$repoPermission.TeamSlug | Should -Be $team.TeamSlug
}
}
AfterAll {
if (Get-Variable -Name team -ErrorAction SilentlyContinue)
{
$team | Remove-GitHubTeam -Force
}
if (Get-Variable -Name repo -ErrorAction SilentlyContinue)
{
$repo | Remove-GitHubRepository -Force
}
}
}
Describe 'GitHubRepositories\Set-GitHubRepositoryTeamPermission' {
BeforeAll {
$repoName = [Guid]::NewGuid().Guid
$repo = New-GitHubRepository -OrganizationName $script:organizationName -RepositoryName $repoName
$teamName = [Guid]::NewGuid().Guid
$description = 'Team Description'
$privacy = 'closed'
$MaintainerName = $script:ownerName
$newGithubTeamParms = @{
OrganizationName = $script:organizationName
TeamName = $teamName
Description = $description
Privacy = $privacy
MaintainerName = $MaintainerName
}
$team = New-GitHubTeam @newGithubTeamParms
$permissions = 'Push', 'Pull', 'Maintain', 'Triage', 'Admin'
}
Foreach ($permission in $permissions) {
Context "When the Team Permission is specified as $permission" {
BeforeAll {
$setGitHubRepositoryTeamPermissionParms = @{
Uri = $repo.svn_url
TeamSlug = $team.slug
Permission = $permission
}
}
It 'Should not throw' {
{ Set-GitHubRepositoryTeamPermission @setGitHubRepositoryTeamPermissionParms } |
Should -Not -Throw
}
It 'Should have set the correct Team permission' {
$getGithubRepositoryTeamPermissionParms = @{
Uri = $repo.svn_url
TeamSlug = $team.slug
}
$repoPermission = Get-GitHubRepositoryTeamPermission @getGithubRepositoryTeamPermissionParms
$repoPermission.Permission | Should -Be $permission
}
}
}
Context "When specifying the 'TeamName' parameter" {
BeforeAll {
$permission = 'Pull'
$setGitHubRepositoryTeamPermissionParms = @{
Uri = $repo.svn_url
TeamName = $teamName
Permission = $permission
}
}
It 'Should not throw' {
{ Set-GitHubRepositoryTeamPermission @setGitHubRepositoryTeamPermissionParms } |
Should -Not -Throw
}
It 'Should have set the correct Team permission' {
$getGithubRepositoryTeamPermissionParms = @{
Uri = $repo.svn_url
TeamSlug = $team.slug
}
$repoPermission = Get-GitHubRepositoryTeamPermission @getGithubRepositoryTeamPermissionParms
$repoPermission.Permission | Should -Be $permission
}
Context 'When the specified TeamName does not exist' {
BeforeAll {
$nonExistingTeamName = [Guid]::NewGuid().Guid
$setGithubRepositoryTeamPermissionParms = @{
Uri = $repo.svn_url
TeamName = $nonExistingTeamName
}
}
It 'Should throw the correct exception' {
{ Set-GitHubRepositoryTeamPermission @setGithubRepositoryTeamPermissionParms } |
Should -Throw "Team '$nonExistingTeamName' not found"
}
}
}
Context "When specifying the 'URI' Parameter from the Pipeline" {
BeforeAll -ScriptBlock {
$setGitHubRepositoryTeamPermissionParms = @{
TeamName = $teamName
}
}
It 'Should not throw' {
{ $repo | Set-GitHubRepositoryTeamPermission @setGitHubRepositoryTeamPermissionParms } |
Should -Not -Throw
}
}
Context "When specifying the 'TeamSlug' and 'OrganizationName' Parameters from the Pipeline" {
BeforeAll -ScriptBlock {
$setGitHubRepositoryTeamPermissionParms = @{
Uri = $repo.svn_url
}
}
It 'Should not throw' {
{ $team | Set-GitHubRepositoryTeamPermission @setGitHubRepositoryTeamPermissionParms } |
Should -Not -Throw
}
}
AfterAll {
if (Get-Variable -Name team -ErrorAction SilentlyContinue)
{
$team | Remove-GitHubTeam -Force
}
if (Get-Variable -Name repo -ErrorAction SilentlyContinue)
{
$repo | Remove-GitHubRepository -Force
}
}
}
Describe 'GitHubRepositories\Remove-GitHubRepositoryTeamPermission' {
BeforeAll {
$repoName = [Guid]::NewGuid().Guid
$repo = New-GitHubRepository -OrganizationName $script:organizationName -RepositoryName $repoName
$teamName = [Guid]::NewGuid().Guid
$description = 'Team Description'
$privacy = 'closed'
$MaintainerName = $script:ownerName
$newGithubTeamParms = @{
OrganizationName = $script:organizationName
TeamName = $teamName
Description = $description
Privacy = $privacy
MaintainerName = $MaintainerName
}
$team = New-GitHubTeam @newGithubTeamParms
$setGitHubRepositoryTeamPermissionParms = @{
Uri = $repo.svn_url
TeamSlug = $team.slug
Permission = 'Pull'
}
Set-GitHubRepositoryTeamPermission @setGitHubRepositoryTeamPermissionParms
}
Context "When specifying the 'TeamSlug' parameter" {
BeforeAll {
$setGitHubRepositoryTeamPermissionParms = @{
Uri = $repo.svn_url
TeamSlug = $team.slug
Permission = 'Pull'
}
Set-GitHubRepositoryTeamPermission @setGitHubRepositoryTeamPermissionParms
}
It 'Should not throw' {
$removeGitHubRepositoryTeamPermissionParms = @{
Uri = $repo.svn_url
TeamSlug = $team.slug
Force = $true
}
{ Remove-GitHubRepositoryTeamPermission @removeGitHubRepositoryTeamPermissionParms } |
Should -Not -Throw
}
It 'Should have removed the Team permission' {
$getGithubRepositoryTeamPermissionParms = @{
Uri = $repo.svn_url
TeamSlug = $team.slug
}
{ Get-GitHubRepositoryTeamPermission @getGithubRepositoryTeamPermissionParms } |
Should -Throw 'Not Found'
}
}
Context "When specifying the 'TeamName' parameter" {
BeforeAll {
$setGitHubRepositoryTeamPermissionParms = @{
Uri = $repo.svn_url
TeamSlug = $team.slug
Permission = 'Pull'
}
Set-GitHubRepositoryTeamPermission @setGitHubRepositoryTeamPermissionParms
}
It 'Should not throw' {
$removeGitHubRepositoryTeamPermissionParms = @{
Uri = $repo.svn_url
TeamName = $teamName
Force = $true
}
{ Remove-GitHubRepositoryTeamPermission @removeGitHubRepositoryTeamPermissionParms } |
Should -Not -Throw
}
It 'Should have removed the Team permission' {
$getGithubRepositoryTeamPermissionParms = @{
Uri = $repo.svn_url
TeamSlug = $team.slug
}
{ Get-GitHubRepositoryTeamPermission @getGithubRepositoryTeamPermissionParms } |
Should -Throw 'Not Found'
}
Context 'When the specified TeamName does not exist' {
BeforeAll {
$nonExistingTeamName = [Guid]::NewGuid().Guid
$removeGithubRepositoryTeamPermissionParms = @{
Uri = $repo.svn_url
TeamName = $nonExistingTeamName
Force = $true
}
}
It 'Should throw the correct exception' {
{ Remove-GitHubRepositoryTeamPermission @removeGithubRepositoryTeamPermissionParms } |
Should -Throw "Team '$nonExistingTeamName' not found"
}
}
}
Context "When specifying the 'URI' Parameter from the Pipeline" {
BeforeAll -ScriptBlock {
$removeGitHubRepositoryTeamPermissionParms = @{
TeamName = $teamName
Force = $true
}
}
It 'Should not throw' {
{ $repo | Remove-GitHubRepositoryTeamPermission @removeGitHubRepositoryTeamPermissionParms } |
Should -Not -Throw
}
}
Context "When specifying the 'TeamSlug' and 'Organization' Parameter from the Pipeline" {
BeforeAll -ScriptBlock {
$removeGitHubRepositoryTeamPermissionParms = @{
RepositoryUrl = $repo.svn_url
Force = $true
}
}
It 'Should not throw' {
{ $team | Remove-GitHubRepositoryTeamPermission @removeGitHubRepositoryTeamPermissionParms } |
Should -Not -Throw
}
}
AfterAll {
if (Get-Variable -Name team -ErrorAction SilentlyContinue)
{
$team | Remove-GitHubTeam -Force
}
if (Get-Variable -Name repo -ErrorAction SilentlyContinue)
{
$repo | Remove-GitHubRepository -Force
}
}
}
}
finally
{

Просмотреть файл

@ -55,6 +55,9 @@
* [Disable repository automatic security fixes](#disable-repository-automatic-security-fixes)
* [Get repository GitHub Actions permissions](#get-repository-github-actions-permissions)
* [Set repository GitHub Actions permissions](#set-repository-github-actions-permissions)
* [Get a repository team permission](#get-a-repository-team-permission)
* [Set a repository team permission](#set-a-repository-team-permission)
* [Remove a repository team permission](#remove-a-repository-team-permission)
* [Branches](#branches)
* [Adding a new Branch to a Repository](#adding-a-new-branch-to-a-repository)
* [Removing a Branch from a Repository](#removing-a-branch-from-a-repository)
@ -660,6 +663,24 @@ Get-GitHubRepositoryActionsPermission -OwnerName microsoft -RepositoryName Power
Set-GitHubRepositoryActionsPermission -OwnerName microsoft -RepositoryName PowerShellForGitHub -AllowedActions All
```
#### Get a repository team permission
```powershell
Get-GitHubRepositoryTeamPermission -OwnerName microsoft -RepositoryName PowerShellForGitHub -TeamName Admins
```
#### Set a repository team permission
```powershell
Set-GitHubRepositoryTeamPermission -OwnerName microsoft -RepositoryName PowerShellForGitHub -TeamName Admins -Permission Admin
```
#### Remove a repository team permission
```powershell
Remove-GitHubRepositoryTeamPermission -OwnerName microsoft -RepositoryName PowerShellForGitHub -TeamName Admins
```
----------
### Branches