microsoft / PowerShellForGitHub

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

Set-GitHubRepositoryTeamPermission fails on private repos #353

Closed HanwhaARudolph closed 1 year ago

HanwhaARudolph commented 2 years ago

Issue Details

When using a private repository the Set-GitHubRepositoryTeamPermission throws an error on the collection of teams (teams are part of an org)

Steps to reproduce the issue

    Set-GitHubRepositoryTeamPermission -TeamName $repoName `
        -RepositoryName $repoName `
        -AccessToken $splatParams.AccessToken `
        -Permission "Maintain" `
        -OwnerName $splatParams.OrganizationName

Verbose logs showing the problem

The remote server returned an error: (401) Unauthorized. 401 | Unauthorized Requires authentication | https://docs.github.com/rest/reference/teams#list-teams

Suggested solution to the issue

If present, the -AccessToken param should be passed in on line 3256: $team = Get-GitHubTeam -OrganizationName $OwnerName -AccessToken $AccessToken

PowerShell Version

    5.1.19041.1682

Module Version

Running: 0.16.0 Installed: 0.16.0

HowardWolosky commented 2 years ago

Thanks for the catch, @HanwhaARudolph! It looks like all three related functions have the same issue:

I'll look at getting that fixed in the next day or so.

I'm also curious: Why do you opt to pass-in AccessToken when using the functions as opposed to calling Set-GitHubAuthentication once and having it handled for you. It's certainly more secure to do it with Set-GitHubAuthentication since the access token won't be stored in plaintext in either the console memory or history.

HanwhaARudolph commented 2 years ago

@HowardWolosky I was just testing when ran into it. I plan on using the set-githubauthentication.

Not a high priority fix but something that was inconsistent to the behavior I expected.