Skip to content

Commit 4dd9c4f

Browse files
[Feature] User Socials - Add ability to manage socials for users (#42)
- Fixes #43 - Fixes #44
1 parent f4898cd commit 4dd9c4f

20 files changed

+625
-32
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
filter Block-GitHubUserByOrganization {
2+
<#
3+
.SYNOPSIS
4+
Block a user from an organization
5+
6+
.DESCRIPTION
7+
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.
8+
9+
.EXAMPLE
10+
Block-GitHubUserByOrganization -OrganizationName 'github' -Username 'octocat'
11+
12+
Blocks the user 'octocat' from the organization 'github'.
13+
Returns $true if successful, $false if not.
14+
15+
.NOTES
16+
https://docs.github.com/rest/orgs/blocking#block-a-user-from-an-organization
17+
#>
18+
[OutputType([bool])]
19+
[CmdletBinding()]
20+
param (
21+
# The organization name. The name is not case sensitive.
22+
[Parameter(
23+
Mandatory,
24+
ValueFromPipeline,
25+
ValueFromPipelineByPropertyName
26+
)]
27+
[Alias('org')]
28+
[Alias('owner')]
29+
[Alias('login')]
30+
[string] $OrganizationName,
31+
32+
# The handle for the GitHub user account.
33+
[Parameter(
34+
Mandatory,
35+
ValueFromPipeline,
36+
ValueFromPipelineByPropertyName
37+
)]
38+
[Alias('login')]
39+
[string] $Username
40+
)
41+
42+
$inputObject = @{
43+
APIEndpoint = "/orgs/$OrganizationName/blocks/$Username"
44+
Method = 'PUT'
45+
}
46+
47+
try {
48+
$null = (Invoke-GitHubAPI @inputObject)
49+
# Should we check if user is already blocked and return true if so?
50+
return $true
51+
} catch {
52+
if ($_.Exception.Response.StatusCode.Value__ -eq 422) {
53+
return $false
54+
} else {
55+
Write-Error $_.Exception.Response
56+
throw $_
57+
}
58+
}
59+
}

src/GitHub/public/Organization/Blocking/Get-GitHubOrganizationBlockedUser.ps1 renamed to src/GitHub/private/Organization/Blocking/Get-GitHubBlockedUserByOrganization.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
filter Get-GitHubOrganizationBlockedUser {
1+
filter Get-GitHubBlockedUserByOrganization {
22
<#
33
.SYNOPSIS
44
List users blocked by an organization
@@ -7,7 +7,7 @@
77
List the users blocked by an organization.
88
99
.EXAMPLE
10-
Get-GitHubOrganizationBlockedUser -OrganizationName 'github'
10+
Get-GitHubBlockedUserByOrganization -OrganizationName 'github'
1111
1212
Lists all users blocked by the organization `github`.
1313

src/GitHub/public/Organization/Blocking/Assert-GitHubOrganizationBlockedUser.ps1 renamed to src/GitHub/private/Organization/Blocking/Test-GitHubBlockedUserByOrganization.ps1

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
filter Assert-GitHubOrganizationBlockedUser {
1+
filter Test-GitHubBlockedUserByOrganization {
22
<#
33
.SYNOPSIS
44
Check if a user is blocked by an organization
@@ -7,16 +7,15 @@
77
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.
88
99
.EXAMPLE
10-
Get-GitHubOrganizationBlockedUser -OrganizationName 'github'
10+
Test-GitHubBlockedUserByOrganization -OrganizationName 'PSModule' -Username 'octocat'
1111
12-
Lists all users blocked by the organization `github`.
12+
Checks if the user `octocat` is blocked by the organization `PSModule`.
13+
Returns true if the user is blocked, false if not.
1314
1415
.NOTES
1516
https://docs.github.com/rest/orgs/blocking#check-if-a-user-is-blocked-by-an-organization
1617
#>
17-
[OutputType([pscustomobject])]
18-
[Alias('Is-GitHubOrganizationBlockedUser')]
19-
[Alias('Check-GitHubOrganizationBlockedUser')]
18+
[OutputType([bool])]
2019
[CmdletBinding()]
2120
param (
2221
# The organization name. The name is not case sensitive.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
filter Unblock-GitHubUserByOrganization {
2+
<#
3+
.SYNOPSIS
4+
Unblock a user from an organization
5+
6+
.DESCRIPTION
7+
Unblocks the given user on behalf of the specified organization.
8+
9+
.EXAMPLE
10+
Unblock-GitHubUserByOrganization -OrganizationName 'github' -Username 'octocat'
11+
12+
Unblocks the user 'octocat' from the organization 'github'.
13+
Returns $true if successful.
14+
15+
.NOTES
16+
https://docs.github.com/rest/orgs/blocking#unblock-a-user-from-an-organization
17+
#>
18+
[OutputType([bool])]
19+
[CmdletBinding()]
20+
param (
21+
# The organization name. The name is not case sensitive.
22+
[Parameter(
23+
Mandatory,
24+
ValueFromPipeline,
25+
ValueFromPipelineByPropertyName
26+
)]
27+
[Alias('org')]
28+
[Alias('owner')]
29+
[Alias('login')]
30+
[string] $OrganizationName,
31+
32+
# The handle for the GitHub user account.
33+
[Parameter(
34+
Mandatory,
35+
ValueFromPipeline,
36+
ValueFromPipelineByPropertyName
37+
)]
38+
[Alias('login')]
39+
[string] $Username
40+
)
41+
42+
$inputObject = @{
43+
APIEndpoint = "/user/blocks/$Username"
44+
Method = 'DELETE'
45+
}
46+
47+
try {
48+
$null = (Invoke-GitHubAPI @inputObject)
49+
return $true
50+
} catch {
51+
Write-Error $_.Exception.Response
52+
throw $_
53+
}
54+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
filter Block-GitHubUserByUser {
2+
<#
3+
.SYNOPSIS
4+
Block a user
5+
6+
.DESCRIPTION
7+
Blocks the given user and returns a 204. If the authenticated user cannot block the given user a 422 is returned.
8+
9+
.EXAMPLE
10+
Block-GitHubUserByUser -Username 'octocat'
11+
12+
Blocks the user 'octocat' for the authenticated user.
13+
Returns $true if successful, $false if not.
14+
15+
.NOTES
16+
https://docs.github.com/rest/users/blocking#block-a-user
17+
#>
18+
[OutputType([bool])]
19+
[CmdletBinding()]
20+
param (
21+
# The handle for the GitHub user account.
22+
[Parameter(
23+
Mandatory,
24+
ValueFromPipeline,
25+
ValueFromPipelineByPropertyName
26+
)]
27+
[Alias('login')]
28+
[string] $Username
29+
)
30+
31+
$inputObject = @{
32+
APIEndpoint = "/user/blocks/$Username"
33+
Method = 'PUT'
34+
}
35+
36+
try {
37+
$null = (Invoke-GitHubAPI @inputObject)
38+
# Should we check if user is already blocked and return true if so?
39+
return $true
40+
} catch {
41+
if ($_.Exception.Response.StatusCode.Value__ -eq 422) {
42+
return $false
43+
} else {
44+
Write-Error $_.Exception.Response
45+
throw $_
46+
}
47+
}
48+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
filter Get-GitHubBlockedUserByUser {
2+
<#
3+
.SYNOPSIS
4+
List users blocked by the authenticated user
5+
6+
.DESCRIPTION
7+
List the users you've blocked on your personal account.
8+
9+
.EXAMPLE
10+
Get-GitHubBlockedUserByUser
11+
12+
Returns a list of users blocked by the authenticated user.
13+
14+
.NOTES
15+
https://docs.github.com/rest/users/blocking#list-users-blocked-by-the-authenticated-user
16+
#>
17+
[OutputType([pscustomobject])]
18+
[CmdletBinding()]
19+
param (
20+
# The number of results per page (max 100).
21+
[Parameter()]
22+
[int] $PerPage = 30
23+
)
24+
25+
$body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case
26+
27+
$inputObject = @{
28+
APIEndpoint = "/user/blocks"
29+
Method = 'GET'
30+
Body = $body
31+
}
32+
33+
(Invoke-GitHubAPI @inputObject).Response
34+
35+
}

src/GitHub/public/Users/Blocking/Assert-GitHubBlockedUser.ps1 renamed to src/GitHub/private/Users/Blocking/Test-GitHubBlockedUserByUser.ps1

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
filter Assert-GitHubBlockedUser {
1+
filter Test-GitHubBlockedUserByUser {
22
<#
33
.SYNOPSIS
44
Check if a user is blocked by the authenticated user
@@ -7,13 +7,26 @@
77
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.
88
99
.EXAMPLE
10+
Test-GitHubBlockedUserByUser -Username 'octocat'
11+
12+
Checks if the user `octocat` is blocked by the authenticated user.
13+
Returns true if the user is blocked, false if not.
1014
1115
.NOTES
1216
https://docs.github.com/rest/users/blocking#check-if-a-user-is-blocked-by-the-authenticated-user
1317
#>
14-
[OutputType([pscustomobject])]
18+
[OutputType([bool])]
1519
[CmdletBinding()]
1620
param (
21+
# The handle for the GitHub user account.
22+
[Parameter(
23+
Mandatory,
24+
ValueFromPipeline,
25+
ValueFromPipelineByPropertyName
26+
)]
27+
[Alias('login')]
28+
[string] $Username,
29+
1730
# The number of results per page (max 100).
1831
[Parameter()]
1932
[int] $PerPage = 30
@@ -22,7 +35,7 @@
2235
$body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case
2336

2437
$inputObject = @{
25-
APIEndpoint = "/user/blocks"
38+
APIEndpoint = "/user/blocks/$Username"
2639
Method = 'GET'
2740
Body = $body
2841
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
filter Unblock-GitHubUserByUser {
2+
<#
3+
.SYNOPSIS
4+
Unblock a user
5+
6+
.DESCRIPTION
7+
Unblocks the given user and returns a 204.
8+
9+
.EXAMPLE
10+
Unblock-GitHubUserByUser -Username 'octocat'
11+
12+
Unblocks the user 'octocat' for the authenticated user.
13+
Returns $true if successful.
14+
15+
.NOTES
16+
https://docs.github.com/rest/users/blocking#unblock-a-user
17+
#>
18+
[OutputType([bool])]
19+
[CmdletBinding()]
20+
param (
21+
# The handle for the GitHub user account.
22+
[Parameter(
23+
Mandatory,
24+
ValueFromPipeline,
25+
ValueFromPipelineByPropertyName
26+
)]
27+
[Alias('login')]
28+
[string] $Username
29+
)
30+
31+
$inputObject = @{
32+
APIEndpoint = "/user/blocks/$Username"
33+
Method = 'DELETE'
34+
}
35+
36+
try {
37+
$null = (Invoke-GitHubAPI @inputObject)
38+
return $true
39+
} catch {
40+
Write-Error $_.Exception.Response
41+
throw $_
42+
}
43+
}

src/GitHub/private/Users/Get-GitHubUserByName.ps1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
[string] $Username
3131
)
3232

33-
3433
$inputObject = @{
3534
APIEndpoint = "/users/$Username"
3635
Method = 'GET'
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
filter Get-GitHubMyUserSocials {
2+
<#
3+
.SYNOPSIS
4+
List social accounts for the authenticated user
5+
6+
.DESCRIPTION
7+
Lists all of your social accounts.
8+
9+
.EXAMPLE
10+
Get-GitHubMyUserSocials
11+
12+
Lists all of your social accounts.
13+
14+
.NOTES
15+
https://docs.github.com/rest/users/social-accounts#list-social-accounts-for-the-authenticated-user
16+
#>
17+
[OutputType([pscustomobject])]
18+
[CmdletBinding()]
19+
param (
20+
# The number of results per page (max 100).
21+
[Parameter()]
22+
[int] $PerPage = 30
23+
)
24+
25+
$body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case
26+
27+
$inputObject = @{
28+
APIEndpoint = '/user/social_accounts'
29+
Method = 'GET'
30+
Body = $body
31+
}
32+
33+
(Invoke-GitHubAPI @inputObject).Response
34+
35+
}

0 commit comments

Comments
 (0)