diff --git a/src/GitHub/private/Organization/Blocking/Block-GitHubUserByOrganization.ps1 b/src/GitHub/private/Organization/Blocking/Block-GitHubUserByOrganization.ps1 new file mode 100644 index 000000000..14ffea29f --- /dev/null +++ b/src/GitHub/private/Organization/Blocking/Block-GitHubUserByOrganization.ps1 @@ -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 $_ + } + } +} diff --git a/src/GitHub/public/Organization/Blocking/Get-GitHubOrganizationBlockedUser.ps1 b/src/GitHub/private/Organization/Blocking/Get-GitHubBlockedUserByOrganization.ps1 similarity index 88% rename from src/GitHub/public/Organization/Blocking/Get-GitHubOrganizationBlockedUser.ps1 rename to src/GitHub/private/Organization/Blocking/Get-GitHubBlockedUserByOrganization.ps1 index 587152403..96d690692 100644 --- a/src/GitHub/public/Organization/Blocking/Get-GitHubOrganizationBlockedUser.ps1 +++ b/src/GitHub/private/Organization/Blocking/Get-GitHubBlockedUserByOrganization.ps1 @@ -1,4 +1,4 @@ -filter Get-GitHubOrganizationBlockedUser { +filter Get-GitHubBlockedUserByOrganization { <# .SYNOPSIS List users blocked by an organization @@ -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`. diff --git a/src/GitHub/public/Organization/Blocking/Assert-GitHubOrganizationBlockedUser.ps1 b/src/GitHub/private/Organization/Blocking/Test-GitHubBlockedUserByOrganization.ps1 similarity index 80% rename from src/GitHub/public/Organization/Blocking/Assert-GitHubOrganizationBlockedUser.ps1 rename to src/GitHub/private/Organization/Blocking/Test-GitHubBlockedUserByOrganization.ps1 index 9e2a73803..231a29ea3 100644 --- a/src/GitHub/public/Organization/Blocking/Assert-GitHubOrganizationBlockedUser.ps1 +++ b/src/GitHub/private/Organization/Blocking/Test-GitHubBlockedUserByOrganization.ps1 @@ -1,4 +1,4 @@ -filter Assert-GitHubOrganizationBlockedUser { +filter Test-GitHubBlockedUserByOrganization { <# .SYNOPSIS Check if a user is blocked by an organization @@ -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. diff --git a/src/GitHub/private/Organization/Blocking/Unblock-GitHubUserByOrganization.ps1 b/src/GitHub/private/Organization/Blocking/Unblock-GitHubUserByOrganization.ps1 new file mode 100644 index 000000000..3e8d208cd --- /dev/null +++ b/src/GitHub/private/Organization/Blocking/Unblock-GitHubUserByOrganization.ps1 @@ -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 $_ + } +} diff --git a/src/GitHub/private/Users/Blocking/Block-GitHubUserByUser.ps1 b/src/GitHub/private/Users/Blocking/Block-GitHubUserByUser.ps1 new file mode 100644 index 000000000..5afca493d --- /dev/null +++ b/src/GitHub/private/Users/Blocking/Block-GitHubUserByUser.ps1 @@ -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 $_ + } + } +} diff --git a/src/GitHub/private/Users/Blocking/Get-GitHubBlockedUserByUser.ps1 b/src/GitHub/private/Users/Blocking/Get-GitHubBlockedUserByUser.ps1 new file mode 100644 index 000000000..e11fb208e --- /dev/null +++ b/src/GitHub/private/Users/Blocking/Get-GitHubBlockedUserByUser.ps1 @@ -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 + +} diff --git a/src/GitHub/public/Users/Blocking/Assert-GitHubBlockedUser.ps1 b/src/GitHub/private/Users/Blocking/Test-GitHubBlockedUserByUser.ps1 similarity index 65% rename from src/GitHub/public/Users/Blocking/Assert-GitHubBlockedUser.ps1 rename to src/GitHub/private/Users/Blocking/Test-GitHubBlockedUserByUser.ps1 index 9bf24e819..843905aab 100644 --- a/src/GitHub/public/Users/Blocking/Assert-GitHubBlockedUser.ps1 +++ b/src/GitHub/private/Users/Blocking/Test-GitHubBlockedUserByUser.ps1 @@ -1,4 +1,4 @@ -filter Assert-GitHubBlockedUser { +filter Test-GitHubBlockedUserByUser { <# .SYNOPSIS Check if a user is blocked by the authenticated user @@ -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 @@ -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 } diff --git a/src/GitHub/private/Users/Blocking/Unblock-GitHubUserByUser.ps1 b/src/GitHub/private/Users/Blocking/Unblock-GitHubUserByUser.ps1 new file mode 100644 index 000000000..6192d8ea7 --- /dev/null +++ b/src/GitHub/private/Users/Blocking/Unblock-GitHubUserByUser.ps1 @@ -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 $_ + } +} diff --git a/src/GitHub/private/Users/Get-GitHubUserByName.ps1 b/src/GitHub/private/Users/Get-GitHubUserByName.ps1 index 6d78f9716..c4f008817 100644 --- a/src/GitHub/private/Users/Get-GitHubUserByName.ps1 +++ b/src/GitHub/private/Users/Get-GitHubUserByName.ps1 @@ -30,7 +30,6 @@ [string] $Username ) - $inputObject = @{ APIEndpoint = "/users/$Username" Method = 'GET' diff --git a/src/GitHub/private/Users/Social-Accounts/Get-GitHubMyUserSocials.ps1 b/src/GitHub/private/Users/Social-Accounts/Get-GitHubMyUserSocials.ps1 new file mode 100644 index 000000000..fde1e83c2 --- /dev/null +++ b/src/GitHub/private/Users/Social-Accounts/Get-GitHubMyUserSocials.ps1 @@ -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 + +} diff --git a/src/GitHub/private/Users/Social-Accounts/Get-GitHubUserSocialsByName.ps1 b/src/GitHub/private/Users/Social-Accounts/Get-GitHubUserSocialsByName.ps1 new file mode 100644 index 000000000..aea79703d --- /dev/null +++ b/src/GitHub/private/Users/Social-Accounts/Get-GitHubUserSocialsByName.ps1 @@ -0,0 +1,37 @@ +filter Get-GitHubUserSocialsByName { + <# + .SYNOPSIS + List social accounts for a user + + .DESCRIPTION + Lists social media accounts for a user. This endpoint is accessible by anyone. + + .EXAMPLE + Get-GitHubUserSocialsByName -Username 'octocat' + + Lists social media accounts for the user 'octocat'. + + .NOTES + https://docs.github.com/rest/users/social-accounts#list-social-accounts-for-a-user + #> + [OutputType([pscustomobject])] + [CmdletBinding()] + param ( + # The handle for the GitHub user account. + [Parameter( + Mandatory, + ValueFromPipeline, + ValueFromPipelineByPropertyName + )] + [Alias('login')] + [string] $Username + ) + + $inputObject = @{ + APIEndpoint = "/users/$Username/social_accounts" + Method = 'GET' + } + + (Invoke-GitHubAPI @inputObject).Response + +} diff --git a/src/GitHub/public/Users/Blocking/Block-GitHubUser.ps1 b/src/GitHub/public/Users/Blocking/Block-GitHubUser.ps1 new file mode 100644 index 000000000..1a469cf4b --- /dev/null +++ b/src/GitHub/public/Users/Blocking/Block-GitHubUser.ps1 @@ -0,0 +1,55 @@ +filter Block-GitHubUser { + <# + .SYNOPSIS + Block a user from user or an organization. + + .DESCRIPTION + Blocks the given user and returns true. + If the user cannot be blocked false is returned. + + .EXAMPLE + Block-GitHubUser -Username 'octocat' + + Blocks the user 'octocat' for the authenticated user. + Returns $true if successful, $false if not. + + .EXAMPLE + Block-GitHubUser -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/users/blocking#block-a-user + https://docs.github.com/rest/orgs/blocking#block-a-user-from-an-organization + #> + [OutputType([bool])] + [CmdletBinding()] + param ( + # The handle for the GitHub user account. + [Parameter( + Mandatory, + ValueFromPipeline, + ValueFromPipelineByPropertyName + )] + [Alias('login')] + [string] $Username, + + # The organization name. The name is not case sensitive. + [Parameter( + ValueFromPipeline, + ValueFromPipelineByPropertyName + )] + [Alias('org')] + [Alias('owner')] + [Alias('login')] + [string] $OrganizationName + ) + + if ($OrganizationName) { + Block-GitHubUserByOrganization -OrganizationName $OrganizationName -Username $Username + } else { + Block-GitHubUserByUser -Username $Username + } + +} diff --git a/src/GitHub/public/Users/Blocking/Get-GitHubBlockedUser.ps1 b/src/GitHub/public/Users/Blocking/Get-GitHubBlockedUser.ps1 index 3f5187976..664fea731 100644 --- a/src/GitHub/public/Users/Blocking/Get-GitHubBlockedUser.ps1 +++ b/src/GitHub/public/Users/Blocking/Get-GitHubBlockedUser.ps1 @@ -1,32 +1,47 @@ filter Get-GitHubBlockedUser { <# .SYNOPSIS - List users blocked by the authenticated user + List blocked users. .DESCRIPTION - List the users you've blocked on your personal account. + List the users that are blocked on your personal account or a given organization. .EXAMPLE + Get-GitHubBlockedUser + + Returns a list of users blocked by the authenticated user. + + .EXAMPLE + Get-GitHubBlockedUser -OrganizationName 'github' + + Lists all users blocked by the organization `github`. .NOTES https://docs.github.com/rest/users/blocking#list-users-blocked-by-the-authenticated-user + https://docs.github.com/rest/orgs/blocking#list-users-blocked-by-an-organization #> [OutputType([pscustomobject])] [CmdletBinding()] param ( + # The organization name. The name is not case sensitive. + [Parameter( + ValueFromPipeline, + ValueFromPipelineByPropertyName + )] + [Alias('org')] + [Alias('owner')] + [Alias('login')] + [string] $OrganizationName, + # 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 + if ($OrganizationName) { + Get-GitHubBlockedUserByOrganization -OrganizationName $OrganizationName -PerPage $PerPage + } else { + Get-GitHubBlockedUserByUser -PerPage $PerPage } - (Invoke-GitHubAPI @inputObject).Response - } diff --git a/src/GitHub/public/Users/Blocking/Test-GitHubBlockedUser.ps1 b/src/GitHub/public/Users/Blocking/Test-GitHubBlockedUser.ps1 new file mode 100644 index 000000000..7484d2be2 --- /dev/null +++ b/src/GitHub/public/Users/Blocking/Test-GitHubBlockedUser.ps1 @@ -0,0 +1,59 @@ +filter Test-GitHubBlockedUser { + <# + .SYNOPSIS + Check if a user is blocked by the authenticated user or an organization. + + .DESCRIPTION + Returns a 204 if the given user is blocked by the authenticated user or organization. + Returns a 404 if the given user is not blocked, or if the given user account has been identified as spam by GitHub. + + .EXAMPLE + Test-GitHubBlockedUser -Username 'octocat' + + Checks if the user `octocat` is blocked by the authenticated user. + Returns true if the user is blocked, false if not. + + .EXAMPLE + Test-GitHubBlockedUser -OrganizationName 'github' -Username 'octocat' + + Checks if the user `octocat` is blocked by the organization `github`. + 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 + https://docs.github.com/rest/orgs/blocking#check-if-a-user-is-blocked-by-an-organization + #> + [OutputType([bool])] + [CmdletBinding()] + param ( + # The handle for the GitHub user account. + [Parameter( + Mandatory, + ValueFromPipeline, + ValueFromPipelineByPropertyName + )] + [Alias('login')] + [string] $Username, + + # The organization name. The name is not case sensitive. + [Parameter( + ValueFromPipeline, + ValueFromPipelineByPropertyName + )] + [Alias('org')] + [Alias('owner')] + [Alias('login')] + [string] $OrganizationName, + + # The number of results per page (max 100). + [Parameter()] + [int] $PerPage = 30 + ) + + if ($OrganizationName) { + Test-GitHubBlockedUserByOrganization -OrganizationName $OrganizationName -Username $Username -PerPage $PerPage + } else { + Test-GitHubBlockedUserByUser -Username $Username -PerPage $PerPage + } + +} diff --git a/src/GitHub/public/Users/Blocking/Unblock-GitHubUser.ps1 b/src/GitHub/public/Users/Blocking/Unblock-GitHubUser.ps1 new file mode 100644 index 000000000..854a1ef70 --- /dev/null +++ b/src/GitHub/public/Users/Blocking/Unblock-GitHubUser.ps1 @@ -0,0 +1,53 @@ +filter Unblock-GitHubUser { + <# + .SYNOPSIS + Unblock a user + + .DESCRIPTION + Unblocks the given user and returns true. + + .EXAMPLE + Unblock-GitHubUser -Username 'octocat' + + Unblocks the user 'octocat' for the authenticated user. + Returns $true if successful. + + .EXAMPLE + Unblock-GitHubUser -OrganizationName 'github' -Username 'octocat' + + Unblocks the user 'octocat' from the organization 'github'. + Returns $true if successful. + + .NOTES + https://docs.github.com/rest/users/blocking#unblock-a-user + https://docs.github.com/rest/orgs/blocking#unblock-a-user-from-an-organization + #> + [OutputType([bool])] + [CmdletBinding()] + param ( + # The handle for the GitHub user account. + [Parameter( + Mandatory, + ValueFromPipeline, + ValueFromPipelineByPropertyName + )] + [Alias('login')] + [string] $Username, + + # The organization name. The name is not case sensitive. + [Parameter( + ValueFromPipeline, + ValueFromPipelineByPropertyName + )] + [Alias('org')] + [Alias('owner')] + [Alias('login')] + [string] $OrganizationName + ) + + if ($OrganizationName) { + Unblock-GitHubUserByOrganization -OrganizationName $OrganizationName -Username $Username + } else { + Unblock-GitHubUserByUser -Username $Username + } +} diff --git a/src/GitHub/public/Users/Get-GitHubUser.ps1 b/src/GitHub/public/Users/Get-GitHubUser.ps1 index 8efa351fa..d505df4c1 100644 --- a/src/GitHub/public/Users/Get-GitHubUser.ps1 +++ b/src/GitHub/public/Users/Get-GitHubUser.ps1 @@ -55,10 +55,16 @@ switch ($PSCmdlet.ParameterSetName) { '__DefaultSet' { - Get-GitHubMyUser + $user = Get-GitHubMyUser + $social_accounts = Get-GitHubMyUserSocials + $user | Add-Member -MemberType NoteProperty -Name 'social_accounts' -Value $social_accounts -Force + $user } 'NamedUser' { - Get-GitHubUserByName -Username $Username + $user = Get-GitHubUserByName -Username $Username + $social_accounts = Get-GitHubUserSocialsByName -Username $Username + $user | Add-Member -MemberType NoteProperty -Name 'social_accounts' -Value $social_accounts -Force + $user } 'AllUsers' { Get-GitHubAllUsers -Since $Since -PerPage $PerPage diff --git a/src/GitHub/public/Users/Social-Accounts/Add-GitHubUserSocials.ps1 b/src/GitHub/public/Users/Social-Accounts/Add-GitHubUserSocials.ps1 new file mode 100644 index 000000000..89cfdcddf --- /dev/null +++ b/src/GitHub/public/Users/Social-Accounts/Add-GitHubUserSocials.ps1 @@ -0,0 +1,36 @@ +filter Add-GitHubUserSocials { + <# + .SYNOPSIS + Add social accounts for the authenticated user + + .DESCRIPTION + Add one or more social accounts to the authenticated user's profile. This endpoint is accessible with the `user` scope. + + .EXAMPLE + Add-GitHubUserSocials -AccountUrls 'https://twitter.com/MyTwitterAccount', 'https://www.linkedin.com/company/MyCompany' + + Adds the Twitter and LinkedIn accounts to the authenticated user's profile. + + .NOTES + https://docs.github.com/rest/users/social-accounts#add-social-accounts-for-the-authenticated-user + #> + [OutputType([void])] + [CmdletBinding()] + param ( + # Full URLs for the social media profiles to add. + [Parameter(Mandatory)] + [Alias('account_urls')] + [string[]] $AccountUrls + ) + + $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case + + $inputObject = @{ + APIEndpoint = '/user/social_accounts' + Body = $body + Method = 'POST' + } + + (Invoke-GitHubAPI @inputObject).Response + +} diff --git a/src/GitHub/public/Users/Social-Accounts/Remove-GitHubUserSocials.ps1 b/src/GitHub/public/Users/Social-Accounts/Remove-GitHubUserSocials.ps1 new file mode 100644 index 000000000..c7ca4de98 --- /dev/null +++ b/src/GitHub/public/Users/Social-Accounts/Remove-GitHubUserSocials.ps1 @@ -0,0 +1,37 @@ +filter Remove-GitHubUserSocials { + <# + .SYNOPSIS + Delete social accounts for the authenticated user + + .DESCRIPTION + Deletes one or more social accounts from the authenticated user's profile. This endpoint is accessible with the `user` scope. + + .PARAMETER AccountUrls + Parameter description + + .EXAMPLE + Remove-GitHubUserSocials -AccountUrls 'https://twitter.com/MyTwitterAccount' + + .NOTES + https://docs.github.com/rest/users/social-accounts#delete-social-accounts-for-the-authenticated-user + #> + [OutputType([void])] + [CmdletBinding()] + param ( + # Full URLs for the social media profiles to add. + [Parameter(Mandatory)] + [Alias('account_urls')] + [string[]] $AccountUrls + ) + + $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case + + $inputObject = @{ + APIEndpoint = '/user/social_accounts' + Body = $body + Method = 'DELETE' + } + + (Invoke-GitHubAPI @inputObject).Response + +} diff --git a/tools/utilities/GitHubAPI.ps1 b/tools/utilities/GitHubAPI.ps1 index 49bfe0808..dfdec0398 100644 --- a/tools/utilities/GitHubAPI.ps1 +++ b/tools/utilities/GitHubAPI.ps1 @@ -21,8 +21,8 @@ $response.paths.psobject.Properties | Select-Object ` @{n = 'PUT'; e = { (($_.value.psobject.Properties.Name) -contains 'PUT') } }, ` @{n = 'PATCH'; e = { (($_.value.psobject.Properties.Name) -contains 'PATCH') } } | Format-Table -$path = '/user/blocks/{username}' -$method = 'get' +$path = '/orgs/{org}/blocks/{username}' +$method = 'delete' $response.paths.$path.$method $response.paths.$path.$method.tags | clip # -> Namespace/foldername $response.paths.$path.$method.operationId | clip # -> FunctionName diff --git a/tools/utilities/Local-Testing.ps1 b/tools/utilities/Local-Testing.ps1 index cc9a1aa28..9f4d3fb27 100644 --- a/tools/utilities/Local-Testing.ps1 +++ b/tools/utilities/Local-Testing.ps1 @@ -12,6 +12,7 @@ Get-Module -Name GitHub -ListAvailable $VerbosePreference = 'Continue' Install-Module -Name GitHub -Force -Verbose -AllowPrerelease +Get-Module -Name GitHub -ListAvailable # $env:PSModulePath += ';C:\Repos\GitHub\PSModule\Modules\GitHub\outputs' # Import-Module -Name 'C:\Repos\GitHub\PSModule\Modules\GitHub\src\GitHub\GitHub.psm1' -Verbose -Force @@ -38,7 +39,7 @@ $date = [datetime]::ParseExact($str, $format, $null) $date -Get-GitHubOrganization +Get-GitHubOrganization | Select-Object Name, login, id Get-GitHubOrganization -OrganizationName 'PowerShell' Get-GitHubOrganization -OrganizationName 'PSModule' @@ -47,9 +48,18 @@ Get-GitHubOrganizationAppInstallation -OrganizationName 'PSModule' Set-GitHubOrganization -OrganizationName 'PSModule' -Blog 'https://www.psmodule.io' Set-GitHubOrganization -OrganizationName 'PSModule' -Blog '' -Set-GitHubOrganization -OrganizationName 'PSModule' -Company 'PSModule123' -DefaultRepositoryPermission admin -Set-GitHubOrganization -OrganizationName 'PSModule' -Company 'PSModule' -DefaultRepositoryPermission read +Set-GitHubOrganization -OrganizationName 'PSModule' -Company 'PSModule123' -DefaultRepositoryPermission admin | Select-Object name, company, default_repository_permission +Set-GitHubOrganization -OrganizationName 'PSModule' -Company 'PSModule' -DefaultRepositoryPermission read | Select-Object name, company, default_repository_permission + +Get-GitHubUser +Get-GitHubUser | Select-Object Name, login, id, company, blog, twitter_username, location, hireable, bio + +$user = Get-GitHubUser +$user.social_accounts + +Set-GitHubUser -Company '@DNBBank' -Email 'marstor@hotmail.com' -Blog 'https://www.github.com/MariusStorhaug' -TwitterUsername MariusStorhaug -Location 'Norway' -Hireable $false -Bio 'DevOps Engineer at DNB Bank. I ❤️ PowerShell and automation.' +Set-GitHubUser -Company ' ' +Set-GitHubUser -Hireable $true | Select-Object login, hireable +Set-GitHubUser -Hireable $false | Select-Object login, hireable -Set-GitHubUser -Name 'Marius Storhaug' -Company '@DNBBank' -Email 'marstor@hotmail.com' -Blog 'https://www.github.com/MariusStorhaug' -TwitterUsername MariusStorhaug -Location 'Norway' -Hireable $false -Bio 'DevOps Engineer at DNB Bank. I ❤️ PowerShell and automation.' -Set-GitHubUser -Name 'MariusStorhaug' -Company ' ' -Set-GitHubUser -Name 'MariusStorhaug' -Hireable $true +Add-GitHubUserSocials -AccountUrls 'https://www.github.com/MariusStorhaug'