microsoft / PowerShellForGitHub

Microsoft PowerShell wrapper for GitHub API
Other
588 stars 185 forks source link

Get-GitHubRepositoryTeamPermission incorrectly reports push permission when maintain is available #360

Closed HowardWolosky closed 1 year ago

HowardWolosky commented 2 years ago

Issue Details

When the feature was introduced in #300, an additional property called permission was added to the returned object which was supposed to summarize the maximum permission level that a team has been granted. This is what that permission table looks like:

name permissions granted
pull pull
triage pull, triage
push pull, triage, push
maintain pull, triage, push, maintain
admin pull, triage, push, maintain, admin

Unfortunately, the logic treated push as more powerful that maintain, and thus it always sets the new permission property to push for both push and maintain teams.

Steps to reproduce the issue

$repoName = [Guid]::NewGuid().Guid
$organizationName = 'PowerShellForGitHubTeamTestOrg'
$repo = New-GitHubRepository -OrganizationName $organizationName -RepositoryName $repoName
$teamName = [Guid]::NewGuid().Guid
$team = New-GitHubTeam -OrganizationName $organizationName -TeamName $teamName -Description 'foo' -Privacy 'closed' -MaintainerName 'PowerShellForGitHubTeam'

Set-GitHubRepositoryTeamPermission -Uri $repo.svn_url -TeamSlug $team.slug -Permission maintain
$permission = Get-GitHubRepositoryTeamPermission -Uri $repo.svn_url -TeamSlug $team.slug

$permission.permissions # Note here that maintain is set to true
$permission.permission # Note that it's returning push instead of maintain

This problem was originally identified by @tigerfansga in #194

Suggested solution to the issue

Switch the order of the conditionals here:

https://github.com/microsoft/PowerShellForGitHub/blob/22e3d7bdf6c3b33fdead74dac831e0bb43beb2c4/GitHubRepositories.ps1#L3928-L3935

Requested Assignment

- If possible, I would like to fix this.

Operating System

OsName               : Microsoft Windows 11 Pro
OsOperatingSystemSKU : EnterpriseEdition
OsArchitecture       : 64-bit
WindowsVersion       : 2009
WindowsBuildLabEx    : 22000.1.amd64fre.co_release.210604-1628
OsLanguage           : en-US
OsMuiLanguages       : {en-US}

PowerShell Version

Name                           Value
----                           -----
PSVersion                      5.1.22000.653
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.22000.653
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Module Version

Running: 0.16.1
Installed: