Skip to content

Commit

Permalink
Add examples to Get-GitHubOrganizationPendingInvitation and New-GitHu…
Browse files Browse the repository at this point in the history
…bOrganizationInvitation functions; implement Remove-GitHubOrganizationInvitation function
  • Loading branch information
MariusStorhaug committed Dec 28, 2024
1 parent 66af62d commit 6ac17a6
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 35 deletions.
8 changes: 4 additions & 4 deletions Coverage.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
</tr>
<tr>
<td>Covered functions</td>
<td>159</td>
<td>160</td>
</tr>
<tr>
<td>Missing functions</td>
<td>839</td>
<td>838</td>
</tr>
<tr>
<td>Coverage</td>
<td>15.93%</td>
<td>16.03%</td>
</tr>
</table>

Expand Down Expand Up @@ -181,7 +181,7 @@
| `/orgs/{org}/installations` | | :white_check_mark: | | | |
| `/orgs/{org}/interaction-limits` | :x: | :x: | | | :x: |
| `/orgs/{org}/invitations` | | :white_check_mark: | | :white_check_mark: | |
| `/orgs/{org}/invitations/{invitation_id}` | :x: | | | | |
| `/orgs/{org}/invitations/{invitation_id}` | :white_check_mark: | | | | |
| `/orgs/{org}/invitations/{invitation_id}/teams` | | :x: | | | |
| `/orgs/{org}/issues` | | :x: | | | |
| `/orgs/{org}/members` | | :white_check_mark: | | | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,19 @@
`billing_manager`, or `hiring_manager`. If the invitee is not a GitHub
member, the `login` field in the return hash will be `null`.
.EXAMPLE
Get-GitHubOrganizationPendingInvitation -Organization 'github'
List all pending organization invitations for the organization `github`.
.EXAMPLE
Get-GitHubOrganizationPendingInvitation -Organization 'github' -Role 'admin'
List all pending organization invitations for the organization `github` with the role `admin`.
.NOTES
[List pending organization invitations](https://docs.github.com/rest/orgs/members#list-pending-organization-invitations)
#>
#SkipTest:FunctionTest:Will add a test for this function in a future PR
[CmdletBinding()]
param(
# The organization name. The name is not case sensitive.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,19 @@
"[Rate limits for the API](https://docs.github.com/rest/using-the-rest-api/rate-limits-for-the-rest-api#about-secondary-rate-limits)"
and "[Best practices for using the REST API](https://docs.github.com/rest/guides/best-practices-for-using-the-rest-api)."
.EXAMPLE
New-GitHubOrganizationInvitation -Organization 'PSModule' -InviteeID 12345679 -Role 'admin'
Invites the user with the ID `12345679` to the organization `PSModule` with the role `admin`.
.EXAMPLE
New-GitHubOrganizationInvitation -Organization 'PSModule' -Email '[email protected]'
Invites the user with the email `[email protected]` to the organization `PSModule`.
.NOTES
[Create an organization invitation](https://docs.github.com/rest/orgs/members#list-pending-organization-invitations)
#>
#SkipTest:FunctionTest:Will add a test for this function in a future PR
[CmdletBinding(SupportsShouldProcess)]
param(
# The organization name. The name is not case sensitive.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
function Remove-GitHubOrganizationInvitation {
<#
.SYNOPSIS
Cancel an organization invitation
.DESCRIPTION
Cancel an organization invitation. In order to cancel an organization invitation, the authenticated user must be an organization owner.
This endpoint triggers [notifications](https://docs.github.com/github/managing-subscriptions-and-notifications-on-github/about-notifications).
.EXAMPLE
Remove-GitHubOrganizationInvitation -Organization 'github' -InvitationID '12345678'
Cancel the invitation with the ID '12345678' for the organization `github`.
.NOTES
[Cancel an organization invitation](https://docs.github.com/rest/orgs/members#cancel-an-organization-invitation)
#>
[OutputType([bool])]
[CmdletBinding(SupportsShouldProcess)]
param(
# The organization name. The name is not case sensitive.
[Parameter(Mandatory)]
[Alias('Org')]
[string] $Organization,

# The unique identifier of the invitation.
[Parameter(Mandatory)]
[Alias('invitation_id')]
[string] $InvitationID,

# The context to run the command in. Used to get the details for the API call.
# Can be either a string or a GitHubContext object.
[Parameter()]
[object] $Context = (Get-GitHubContext)
)

begin {
$stackPath = Get-PSCallStackPath
Write-Debug "[$stackPath] - Start"
$Context = Resolve-GitHubContext -Context $Context
Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT
}

process {
try {
$inputObject = @{
Context = $Context
APIEndpoint = "/orgs/$Organization/invitations/$InvitationID"
Method = 'DELETE'
}

try {
if ($PSCmdlet.ShouldProcess('GitHub Organization invitation', 'Remove')) {
$null = (Invoke-GitHubAPI @inputObject)
}
return $true
} catch {
Write-Error $_.Exception.Response
throw $_
}
} catch {
throw $_
}
}

end {
Write-Debug "[$stackPath] - End"
}
}
103 changes: 74 additions & 29 deletions tests/GitHub.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -365,14 +365,14 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT)
$guid = (New-Guid).Guid
$user = Get-GitHubUser
{ Update-GitHubUser -Name 'Octocat' } | Should -Not -Throw
{ Update-GitHubUser -Blog 'https://example.com' } | Should -Not -Throw
{ Update-GitHubUser -Blog 'https://psmodule.io' } | Should -Not -Throw
{ Update-GitHubUser -TwitterUsername $guid } | Should -Not -Throw
{ Update-GitHubUser -Company 'PSModule' } | Should -Not -Throw
{ Update-GitHubUser -Location 'USA' } | Should -Not -Throw
{ Update-GitHubUser -Bio 'I love programming' } | Should -Not -Throw
$tmpUser = Get-GitHubUser
$tmpUser.name | Should -Be 'Octocat'
$tmpUser.blog | Should -Be 'https://example.com'
$tmpUser.blog | Should -Be 'https://psmodule.io'
$tmpUser.twitter_username | Should -Be $guid
$tmpUser.company | Should -Be 'PSModule'
$tmpUser.location | Should -Be 'USA'
Expand All @@ -383,11 +383,11 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT)
{ Get-GitHubUserEmail } | Should -Not -Throw
}
It 'Add/Remove-GitHubUserEmail - Adds and removes an email to the authenticated user (USER_FG_PAT)' {
$newEmail = (New-Guid).Guid + '@example.com'
{ Add-GitHubUserEmail -Emails $newEmail } | Should -Not -Throw
(Get-GitHubUserEmail).email | Should -Contain $newEmail
{ Remove-GitHubUserEmail -Emails $newEmail } | Should -Not -Throw
(Get-GitHubUserEmail).email | Should -Not -Contain $newEmail
$email = (New-Guid).Guid + '@psmodule.io'
{ Add-GitHubUserEmail -Emails $email } | Should -Not -Throw
(Get-GitHubUserEmail).email | Should -Contain $email
{ Remove-GitHubUserEmail -Emails $email } | Should -Not -Throw
(Get-GitHubUserEmail).email | Should -Not -Contain $email
}
}
}
Expand Down Expand Up @@ -536,13 +536,11 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_
It 'Update-GitHubOrganization - Sets the organization configuration (ORG_FG_PAT)' {
{ Update-GitHubOrganization -Organization 'psmodule-test-org2' -Company 'ABC' } | Should -Not -Throw
{
$guid = (New-Guid).Guid
$email = $guid + '@example.com'
$email = (New-Guid).Guid + '@psmodule.io'
Update-GitHubOrganization -Organization 'psmodule-test-org2' -BillingEmail $email
} | Should -Not -Throw
{
$guid = (New-Guid).Guid
$email = $guid + '@example.com'
$email = (New-Guid).Guid + '@psmodule.io'
Update-GitHubOrganization -Organization 'psmodule-test-org2' -Email $email
} | Should -Not -Throw
{
Expand All @@ -553,7 +551,24 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_
{ Update-GitHubOrganization -Organization 'psmodule-test-org2' -Description 'Test Organization' } | Should -Not -Throw
{ Update-GitHubOrganization -Organization 'psmodule-test-org2' -DefaultRepositoryPermission read } | Should -Not -Throw
{ Update-GitHubOrganization -Organization 'psmodule-test-org2' -MembersCanCreateRepositories $true } | Should -Not -Throw
{ Update-GitHubOrganization -Organization 'psmodule-test-org2' -Blog 'https://example.com' } | Should -Not -Throw
{ Update-GitHubOrganization -Organization 'psmodule-test-org2' -Blog 'https://psmodule.io' } | Should -Not -Throw
}
It 'New-GitHubOrganizationInvitation - Invites a user to an organization (ORG_FG_PAT)' {
{
$email = (New-Guid).Guid + '@psmodule.io'
New-GitHubOrganizationInvitation -Organization 'psmodule-test-org2' -Email $email -Role 'admin'
} | Should -Not -Throw
}
It 'Get-GitHubOrganizationPendingInvitation - Gets the pending invitations for a specific organization (ORG_FG_PAT)' {
{ Get-GitHubOrganizationPendingInvitation -Organization 'psmodule-test-org2' } | Should -Not -Throw
{ Get-GitHubOrganizationPendingInvitation -Organization 'psmodule-test-org2' -Role 'admin' } | Should -Not -Throw
{ Get-GitHubOrganizationPendingInvitation -Organization 'psmodule-test-org2' -InvitationSource 'member' } | Should -Not -Throw
}
It 'Remove-GitHubOrganizationInvitation - Removes a user invitation from an organization (ORG_FG_PAT)' {
{
$invitation = Get-GitHubOrganizationPendingInvitation -Organization 'psmodule-test-org2' | Select-Object -First 1
Remove-GitHubOrganizationInvitation -Organization 'psmodule-test-org2' -ID $invitation.id
} | Should -Not -Throw
}
}
}
Expand Down Expand Up @@ -667,14 +682,14 @@ Describe 'As a user - Classic PAT token (PAT)' {
$guid = (New-Guid).Guid
$user = Get-GitHubUser
{ Update-GitHubUser -Name 'Octocat' } | Should -Not -Throw
{ Update-GitHubUser -Blog 'https://example.com' } | Should -Not -Throw
{ Update-GitHubUser -Blog 'https://psmodule.io' } | Should -Not -Throw
{ Update-GitHubUser -TwitterUsername $guid } | Should -Not -Throw
{ Update-GitHubUser -Company 'PSModule' } | Should -Not -Throw
{ Update-GitHubUser -Location 'USA' } | Should -Not -Throw
{ Update-GitHubUser -Bio 'I love programming' } | Should -Not -Throw
$tmpUser = Get-GitHubUser
$tmpUser.name | Should -Be 'Octocat'
$tmpUser.blog | Should -Be 'https://example.com'
$tmpUser.blog | Should -Be 'https://psmodule.io'
$tmpUser.twitter_username | Should -Be $guid
$tmpUser.company | Should -Be 'PSModule'
$tmpUser.location | Should -Be 'USA'
Expand All @@ -685,11 +700,11 @@ Describe 'As a user - Classic PAT token (PAT)' {
{ Get-GitHubUserEmail } | Should -Not -Throw
}
It 'Add/Remove-GitHubUserEmail - Adds and removes an email to the authenticated user (PAT)' {
$newEmail = (New-Guid).Guid + '@example.com'
{ Add-GitHubUserEmail -Emails $newEmail } | Should -Not -Throw
(Get-GitHubUserEmail).email | Should -Contain $newEmail
{ Remove-GitHubUserEmail -Emails $newEmail } | Should -Not -Throw
(Get-GitHubUserEmail).email | Should -Not -Contain $newEmail
$email = (New-Guid).Guid + '@psmodule.io'
{ Add-GitHubUserEmail -Emails $email } | Should -Not -Throw
(Get-GitHubUserEmail).email | Should -Contain $email
{ Remove-GitHubUserEmail -Emails $email } | Should -Not -Throw
(Get-GitHubUserEmail).email | Should -Not -Contain $email
}
}
}
Expand Down Expand Up @@ -878,13 +893,11 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' {
It 'Update-GitHubOrganization - Sets the organization configuration (APP_ENT)' {
{ Update-GitHubOrganization -Organization 'psmodule-test-org3' -Company 'ABC' } | Should -Not -Throw
{
$guid = (New-Guid).Guid
$email = $guid + '@example.com'
$email = (New-Guid).Guid + '@psmodule.io'
Update-GitHubOrganization -Organization 'psmodule-test-org3' -BillingEmail $email
} | Should -Not -Throw
{
$guid = (New-Guid).Guid
$email = $guid + '@example.com'
$email = (New-Guid).Guid + '@psmodule.io'
Update-GitHubOrganization -Organization 'psmodule-test-org3' -Email $email
} | Should -Not -Throw
{
Expand All @@ -895,7 +908,24 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' {
{ Update-GitHubOrganization -Organization 'psmodule-test-org3' -Description 'Test Organization' } | Should -Not -Throw
{ Update-GitHubOrganization -Organization 'psmodule-test-org3' -DefaultRepositoryPermission read } | Should -Not -Throw
{ Update-GitHubOrganization -Organization 'psmodule-test-org3' -MembersCanCreateRepositories $true } | Should -Not -Throw
{ Update-GitHubOrganization -Organization 'psmodule-test-org3' -Blog 'https://example.com' } | Should -Not -Throw
{ Update-GitHubOrganization -Organization 'psmodule-test-org3' -Blog 'https://psmodule.io' } | Should -Not -Throw
}
It 'New-GitHubOrganizationInvitation - Invites a user to an organization (APP_ENT)' {
{
$email = (New-Guid).Guid + '@psmodule.io'
New-GitHubOrganizationInvitation -Organization 'psmodule-test-org3' -Email $email -Role 'admin'
} | Should -Not -Throw
}
It 'Get-GitHubOrganizationPendingInvitation - Gets the pending invitations for a specific organization (APP_ENT)' {
{ Get-GitHubOrganizationPendingInvitation -Organization 'psmodule-test-org3' } | Should -Not -Throw
{ Get-GitHubOrganizationPendingInvitation -Organization 'psmodule-test-org3' -Role 'admin' } | Should -Not -Throw
{ Get-GitHubOrganizationPendingInvitation -Organization 'psmodule-test-org3' -InvitationSource 'member' } | Should -Not -Throw
}
It 'Remove-GitHubOrganizationInvitation - Removes a user invitation from an organization (APP_ENT)' {
{
$invitation = Get-GitHubOrganizationPendingInvitation -Organization 'psmodule-test-org3' | Select-Object -First 1
Remove-GitHubOrganizationInvitation -Organization 'psmodule-test-org3' -ID $invitation.id
} | Should -Not -Throw
}
}
}
Expand Down Expand Up @@ -1000,13 +1030,11 @@ Describe 'As a GitHub App - Organization (APP_ORG)' {
It 'Update-GitHubOrganization - Sets the organization configuration (APP_ORG)' {
{ Update-GitHubOrganization -Organization 'psmodule-test-org' -Company 'ABC' } | Should -Not -Throw
{
$guid = (New-Guid).Guid
$email = $guid + '@example.com'
$email = (New-Guid).Guid + '@psmodule.io'
Update-GitHubOrganization -Organization 'psmodule-test-org' -BillingEmail $email
} | Should -Not -Throw
{
$guid = (New-Guid).Guid
$email = $guid + '@example.com'
$email = (New-Guid).Guid + '@psmodule.io'
Update-GitHubOrganization -Organization 'psmodule-test-org' -Email $email
} | Should -Not -Throw
{
Expand All @@ -1017,7 +1045,24 @@ Describe 'As a GitHub App - Organization (APP_ORG)' {
{ Update-GitHubOrganization -Organization 'psmodule-test-org' -Description 'Test Organization' } | Should -Not -Throw
{ Update-GitHubOrganization -Organization 'psmodule-test-org' -DefaultRepositoryPermission read } | Should -Not -Throw
{ Update-GitHubOrganization -Organization 'psmodule-test-org' -MembersCanCreateRepositories $true } | Should -Not -Throw
{ Update-GitHubOrganization -Organization 'psmodule-test-org' -Blog 'https://example.com' } | Should -Not -Throw
{ Update-GitHubOrganization -Organization 'psmodule-test-org' -Blog 'https://psmodule.io' } | Should -Not -Throw
}
It 'New-GitHubOrganizationInvitation - Invites a user to an organization (APP_ORG)' {
{
$email = (New-Guid).Guid + '@psmodule.io'
New-GitHubOrganizationInvitation -Organization 'psmodule-test-org' -Email $email -Role 'admin'
} | Should -Not -Throw
}
It 'Get-GitHubOrganizationPendingInvitation - Gets the pending invitations for a specific organization (APP_ORG)' {
{ Get-GitHubOrganizationPendingInvitation -Organization 'psmodule-test-org' } | Should -Not -Throw
{ Get-GitHubOrganizationPendingInvitation -Organization 'psmodule-test-org' -Role 'admin' } | Should -Not -Throw
{ Get-GitHubOrganizationPendingInvitation -Organization 'psmodule-test-org' -InvitationSource 'member' } | Should -Not -Throw
}
It 'Remove-GitHubOrganizationInvitation - Removes a user invitation from an organization (APP_ORG)' {
{
$invitation = Get-GitHubOrganizationPendingInvitation -Organization 'psmodule-test-org' | Select-Object -First 1
Remove-GitHubOrganizationInvitation -Organization 'psmodule-test-org' -ID $invitation.id
} | Should -Not -Throw
}
}
}

0 comments on commit 6ac17a6

Please sign in to comment.