Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
filter Block-GitHubUserByOrganization {
<#
.SYNOPSIS
Block a user from an organization

.DESCRIPTION
Blocks the given user on behalf of the specified organization and returns a 204. If the organization cannot block the given user a 422 is returned.

.EXAMPLE
Block-GitHubUserByOrganization -OrganizationName 'github' -Username 'octocat'

Blocks the user 'octocat' from the organization 'github'.
Returns $true if successful, $false if not.

.NOTES
https://docs.github.com/rest/orgs/blocking#block-a-user-from-an-organization
#>
[OutputType([bool])]
[CmdletBinding()]
param (
# The organization name. The name is not case sensitive.
[Parameter(
Mandatory,
ValueFromPipeline,
ValueFromPipelineByPropertyName
)]
[Alias('org')]
[Alias('owner')]
[Alias('login')]
[string] $OrganizationName,

# The handle for the GitHub user account.
[Parameter(
Mandatory,
ValueFromPipeline,
ValueFromPipelineByPropertyName
)]
[Alias('login')]
[string] $Username
)

$inputObject = @{
APIEndpoint = "/orgs/$OrganizationName/blocks/$Username"
Method = 'PUT'
}

try {
$null = (Invoke-GitHubAPI @inputObject)
# Should we check if user is already blocked and return true if so?
return $true
} catch {
if ($_.Exception.Response.StatusCode.Value__ -eq 422) {
return $false
} else {
Write-Error $_.Exception.Response
throw $_
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
filter Get-GitHubOrganizationBlockedUser {
filter Get-GitHubBlockedUserByOrganization {
<#
.SYNOPSIS
List users blocked by an organization
Expand All @@ -7,7 +7,7 @@
List the users blocked by an organization.

.EXAMPLE
Get-GitHubOrganizationBlockedUser -OrganizationName 'github'
Get-GitHubBlockedUserByOrganization -OrganizationName 'github'

Lists all users blocked by the organization `github`.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
filter Assert-GitHubOrganizationBlockedUser {
filter Test-GitHubBlockedUserByOrganization {
<#
.SYNOPSIS
Check if a user is blocked by an organization
Expand All @@ -7,16 +7,15 @@
Returns a 204 if the given user is blocked by the given organization. Returns a 404 if the organization is not blocking the user, or if the user account has been identified as spam by GitHub.

.EXAMPLE
Get-GitHubOrganizationBlockedUser -OrganizationName 'github'
Test-GitHubBlockedUserByOrganization -OrganizationName 'PSModule' -Username 'octocat'

Lists all users blocked by the organization `github`.
Checks if the user `octocat` is blocked by the organization `PSModule`.
Returns true if the user is blocked, false if not.

.NOTES
https://docs.github.com/rest/orgs/blocking#check-if-a-user-is-blocked-by-an-organization
#>
[OutputType([pscustomobject])]
[Alias('Is-GitHubOrganizationBlockedUser')]
[Alias('Check-GitHubOrganizationBlockedUser')]
[OutputType([bool])]
[CmdletBinding()]
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,54 @@
filter Unblock-GitHubUserByOrganization {
<#
.SYNOPSIS
Unblock a user from an organization

.DESCRIPTION
Unblocks the given user on behalf of the specified organization.

.EXAMPLE
Unblock-GitHubUserByOrganization -OrganizationName 'github' -Username 'octocat'

Unblocks the user 'octocat' from the organization 'github'.
Returns $true if successful.

.NOTES
https://docs.github.com/rest/orgs/blocking#unblock-a-user-from-an-organization
#>
[OutputType([bool])]
[CmdletBinding()]
param (
# The organization name. The name is not case sensitive.
[Parameter(
Mandatory,
ValueFromPipeline,
ValueFromPipelineByPropertyName
)]
[Alias('org')]
[Alias('owner')]
[Alias('login')]
[string] $OrganizationName,

# The handle for the GitHub user account.
[Parameter(
Mandatory,
ValueFromPipeline,
ValueFromPipelineByPropertyName
)]
[Alias('login')]
[string] $Username
)

$inputObject = @{
APIEndpoint = "/user/blocks/$Username"
Method = 'DELETE'
}

try {
$null = (Invoke-GitHubAPI @inputObject)
return $true
} catch {
Write-Error $_.Exception.Response
throw $_
}
}
48 changes: 48 additions & 0 deletions src/GitHub/private/Users/Blocking/Block-GitHubUserByUser.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
filter Block-GitHubUserByUser {
<#
.SYNOPSIS
Block a user

.DESCRIPTION
Blocks the given user and returns a 204. If the authenticated user cannot block the given user a 422 is returned.

.EXAMPLE
Block-GitHubUserByUser -Username 'octocat'

Blocks the user 'octocat' for the authenticated user.
Returns $true if successful, $false if not.

.NOTES
https://docs.github.com/rest/users/blocking#block-a-user
#>
[OutputType([bool])]
[CmdletBinding()]
param (
# The handle for the GitHub user account.
[Parameter(
Mandatory,
ValueFromPipeline,
ValueFromPipelineByPropertyName
)]
[Alias('login')]
[string] $Username
)

$inputObject = @{
APIEndpoint = "/user/blocks/$Username"
Method = 'PUT'
}

try {
$null = (Invoke-GitHubAPI @inputObject)
# Should we check if user is already blocked and return true if so?
return $true
} catch {
if ($_.Exception.Response.StatusCode.Value__ -eq 422) {
return $false
} else {
Write-Error $_.Exception.Response
throw $_
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
filter Get-GitHubBlockedUserByUser {
<#
.SYNOPSIS
List users blocked by the authenticated user

.DESCRIPTION
List the users you've blocked on your personal account.

.EXAMPLE
Get-GitHubBlockedUserByUser

Returns a list of users blocked by the authenticated user.

.NOTES
https://docs.github.com/rest/users/blocking#list-users-blocked-by-the-authenticated-user
#>
[OutputType([pscustomobject])]
[CmdletBinding()]
param (
# The number of results per page (max 100).
[Parameter()]
[int] $PerPage = 30
)

$body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case

$inputObject = @{
APIEndpoint = "/user/blocks"
Method = 'GET'
Body = $body
}

(Invoke-GitHubAPI @inputObject).Response

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
filter Assert-GitHubBlockedUser {
filter Test-GitHubBlockedUserByUser {
<#
.SYNOPSIS
Check if a user is blocked by the authenticated user
Expand All @@ -7,13 +7,26 @@
Returns a 204 if the given user is blocked by the authenticated user. Returns a 404 if the given user is not blocked by the authenticated user, or if the given user account has been identified as spam by GitHub.

.EXAMPLE
Test-GitHubBlockedUserByUser -Username 'octocat'

Checks if the user `octocat` is blocked by the authenticated user.
Returns true if the user is blocked, false if not.

.NOTES
https://docs.github.com/rest/users/blocking#check-if-a-user-is-blocked-by-the-authenticated-user
#>
[OutputType([pscustomobject])]
[OutputType([bool])]
[CmdletBinding()]
param (
# The handle for the GitHub user account.
[Parameter(
Mandatory,
ValueFromPipeline,
ValueFromPipelineByPropertyName
)]
[Alias('login')]
[string] $Username,

# The number of results per page (max 100).
[Parameter()]
[int] $PerPage = 30
Expand All @@ -22,7 +35,7 @@
$body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case

$inputObject = @{
APIEndpoint = "/user/blocks"
APIEndpoint = "/user/blocks/$Username"
Method = 'GET'
Body = $body
}
Expand Down
43 changes: 43 additions & 0 deletions src/GitHub/private/Users/Blocking/Unblock-GitHubUserByUser.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
filter Unblock-GitHubUserByUser {
<#
.SYNOPSIS
Unblock a user

.DESCRIPTION
Unblocks the given user and returns a 204.

.EXAMPLE
Unblock-GitHubUserByUser -Username 'octocat'

Unblocks the user 'octocat' for the authenticated user.
Returns $true if successful.

.NOTES
https://docs.github.com/rest/users/blocking#unblock-a-user
#>
[OutputType([bool])]
[CmdletBinding()]
param (
# The handle for the GitHub user account.
[Parameter(
Mandatory,
ValueFromPipeline,
ValueFromPipelineByPropertyName
)]
[Alias('login')]
[string] $Username
)

$inputObject = @{
APIEndpoint = "/user/blocks/$Username"
Method = 'DELETE'
}

try {
$null = (Invoke-GitHubAPI @inputObject)
return $true
} catch {
Write-Error $_.Exception.Response
throw $_
}
}
1 change: 0 additions & 1 deletion src/GitHub/private/Users/Get-GitHubUserByName.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
[string] $Username
)


$inputObject = @{
APIEndpoint = "/users/$Username"
Method = 'GET'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
filter Get-GitHubMyUserSocials {
<#
.SYNOPSIS
List social accounts for the authenticated user

.DESCRIPTION
Lists all of your social accounts.

.EXAMPLE
Get-GitHubMyUserSocials

Lists all of your social accounts.

.NOTES
https://docs.github.com/rest/users/social-accounts#list-social-accounts-for-the-authenticated-user
#>
[OutputType([pscustomobject])]
[CmdletBinding()]
param (
# The number of results per page (max 100).
[Parameter()]
[int] $PerPage = 30
)

$body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case

$inputObject = @{
APIEndpoint = '/user/social_accounts'
Method = 'GET'
Body = $body
}

(Invoke-GitHubAPI @inputObject).Response

}
Loading