From c19d7e41dbba8f6f32db81bf05cc376ed181abbe Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 29 Sep 2023 18:26:40 +0200 Subject: [PATCH 01/61] set paging to 30 (as default) --- src/GitHub/public/Actions/Get-GitHubWorkflow.ps1 | 2 +- src/GitHub/public/Actions/Get-GitHubWorkflowRun.ps1 | 2 +- src/GitHub/public/Users/Get-GitHubUserList.ps1 | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/GitHub/public/Actions/Get-GitHubWorkflow.ps1 b/src/GitHub/public/Actions/Get-GitHubWorkflow.ps1 index d5368fac7..87b3698e5 100644 --- a/src/GitHub/public/Actions/Get-GitHubWorkflow.ps1 +++ b/src/GitHub/public/Actions/Get-GitHubWorkflow.ps1 @@ -36,7 +36,7 @@ [string] $ID, [Parameter()] - [int] $PerPage = 100 + [int] $PerPage = 30 ) begin {} diff --git a/src/GitHub/public/Actions/Get-GitHubWorkflowRun.ps1 b/src/GitHub/public/Actions/Get-GitHubWorkflowRun.ps1 index 15206b51c..cf798b871 100644 --- a/src/GitHub/public/Actions/Get-GitHubWorkflowRun.ps1 +++ b/src/GitHub/public/Actions/Get-GitHubWorkflowRun.ps1 @@ -19,7 +19,7 @@ [string] $ID, [Parameter()] - [int] $PerPage = 100 + [int] $PerPage = 30 ) begin {} diff --git a/src/GitHub/public/Users/Get-GitHubUserList.ps1 b/src/GitHub/public/Users/Get-GitHubUserList.ps1 index 960bfbe2c..20f3f8105 100644 --- a/src/GitHub/public/Users/Get-GitHubUserList.ps1 +++ b/src/GitHub/public/Users/Get-GitHubUserList.ps1 @@ -24,7 +24,7 @@ [int] $Since = 0, # The number of results per page (max 100). [Parameter()] - [int] $PerPage = 100 + [int] $PerPage = 30 ) $body = @{ From eb23550bf4b050fffdaf4cd502cf9e7a854c035c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 29 Sep 2023 18:27:16 +0200 Subject: [PATCH 02/61] Add function to get a named org --- .../Organization/Get-GitHubOrganization.ps1 | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/GitHub/public/Organization/Get-GitHubOrganization.ps1 diff --git a/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 b/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 new file mode 100644 index 000000000..4bcee7f95 --- /dev/null +++ b/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 @@ -0,0 +1,34 @@ +function Get-GitHubOrganization { + <# + .SYNOPSIS + Get an organization + + .DESCRIPTION + To see many of the organization response values, you need to be an authenticated organization owner with the `admin:org` scope. When the value of `two_factor_requirement_enabled` is `true`, the organization requires all members, billing managers, and outside collaborators to enable [two-factor authentication](https://docs.github.com/articles/securing-your-account-with-two-factor-authentication-2fa/). + + GitHub Apps with the `Organization plan` permission can use this endpoint to retrieve information about an organization's GitHub plan. See "[Authenticating with GitHub Apps](https://docs.github.com/apps/building-github-apps/authenticating-with-github-apps/)" for details. For an example response, see 'Response with GitHub plan information' below." + + .EXAMPLE + Get-GitHubOrganization -OrganizationName 'github' + + Get the 'GitHub' organization + + .NOTES + https://docs.github.com/rest/orgs/orgs#get-an-organization + #> + [OutputType([pscustomobject])] + [CmdletBinding()] + param ( + # The organization name. The name is not case sensitive. + [Parameter(Mandatory)] + [string] $OrganizationName + ) + + $inputObject = @{ + APIEndpoint = "/orgs/$OrganizationName" + Method = 'GET' + } + + Invoke-GitHubAPI @inputObject + +} From 239fa8776050f7f91b15b93a58d226be95aa4c8d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 29 Sep 2023 18:27:30 +0200 Subject: [PATCH 03/61] Add function to get list of orgs --- .../Get-GitHubOrganizationList.ps1 | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/GitHub/public/Organization/Get-GitHubOrganizationList.ps1 diff --git a/src/GitHub/public/Organization/Get-GitHubOrganizationList.ps1 b/src/GitHub/public/Organization/Get-GitHubOrganizationList.ps1 new file mode 100644 index 000000000..b74a401d7 --- /dev/null +++ b/src/GitHub/public/Organization/Get-GitHubOrganizationList.ps1 @@ -0,0 +1,44 @@ +function Get-GitHubOrganizationList { + <# + .SYNOPSIS + List organizations + + .DESCRIPTION + Lists all organizations, in the order that they were created on GitHub. + + **Note:** Pagination is powered exclusively by the `since` parameter. Use the [Link header](https://docs.github.com/rest/guides/using-pagination-in-the-rest-api#using-link-headers) to get the URL for the next page of organizations. + + .EXAMPLE + Get-GitHubOrganizationList -Since 142951047 + + List organizations, starting with PSModule + + .NOTES + https://docs.github.com/rest/orgs/orgs#list-organizations + + #> + [OutputType([pscustomobject])] + [CmdletBinding()] + param ( + # A organization ID. Only return organizations with an ID greater than this ID. + [Parameter()] + [int] $Since = 0, + # The number of results per page (max 100). + [Parameter()] + [int] $PerPage = 30 + ) + + $body = @{ + since = $Since + per_page = $PerPage + } + + $inputObject = @{ + APIEndpoint = '/organizations' + Method = 'GET' + Body = $body + } + + Invoke-GitHubAPI @inputObject + +} From 5eca5b8669c16281b9ec796df5c7c6bc107caea0 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 29 Sep 2023 19:01:49 +0200 Subject: [PATCH 04/61] Added a param to GHAPI to declare or add, add is default --- src/GitHub/public/API/Invoke-GitHubAPI.ps1 | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 index c8ab7a099..2cd3f714d 100644 --- a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 +++ b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 @@ -63,6 +63,10 @@ # The GitHub API version to be used. By default, it pulls from a configuration script variable. [Parameter()] [string] $Version = (Get-GitHubConfig -Name ApiVersion) + + # Declares the state of a resource by passing all parameters/body properties to Invoke-RestMethod, even if empty + [Parameter()] + [switch] $Declare ) $functionName = $MyInvocation.MyCommand.Name @@ -108,7 +112,10 @@ $APICall | Remove-HashTableEntries -NullOrEmptyValues if ($Body) { - $Body | Remove-HashTableEntries -NullOrEmptyValues + + if (-not $Declare) { + $Body | Remove-HashTableEntries -NullOrEmptyValues + } # Use body to create the query string for GET requests if ($Method -eq 'GET') { From ca50d05b61682c75054f7ed852f7678902c7e045 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 29 Sep 2023 19:15:55 +0200 Subject: [PATCH 05/61] Added function to get a list of all orgs --- src/GitHub/public/Organization/Get-GitHubOrganizationList.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/src/GitHub/public/Organization/Get-GitHubOrganizationList.ps1 b/src/GitHub/public/Organization/Get-GitHubOrganizationList.ps1 index b74a401d7..400b0df33 100644 --- a/src/GitHub/public/Organization/Get-GitHubOrganizationList.ps1 +++ b/src/GitHub/public/Organization/Get-GitHubOrganizationList.ps1 @@ -23,6 +23,7 @@ # A organization ID. Only return organizations with an ID greater than this ID. [Parameter()] [int] $Since = 0, + # The number of results per page (max 100). [Parameter()] [int] $PerPage = 30 From 5c06c6676006e3b909d31ad2a1a7daeba664b58f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 29 Sep 2023 19:16:10 +0200 Subject: [PATCH 06/61] Add function to remove a github org --- .../Remove-GitHubOrganization.ps1 | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/GitHub/public/Organization/Remove-GitHubOrganization.ps1 diff --git a/src/GitHub/public/Organization/Remove-GitHubOrganization.ps1 b/src/GitHub/public/Organization/Remove-GitHubOrganization.ps1 new file mode 100644 index 000000000..cce0a1feb --- /dev/null +++ b/src/GitHub/public/Organization/Remove-GitHubOrganization.ps1 @@ -0,0 +1,36 @@ +function Remove-GitHubOrganization { + <# + .SYNOPSIS + Delete an organization + + .DESCRIPTION + Deletes an organization and all its repositories. + The organization login will be unavailable for 90 days after deletion. + Please review the Terms of Service regarding account deletion before using this endpoint: + https://docs.github.com/site-policy/github-terms/github-terms-of-service + + .EXAMPLE + Remove-GitHubOrganization -OrganizationName 'github' + + Deletes the organization 'github' and all its repositories. + + .NOTES + https://docs.github.com/rest/orgs/orgs#delete-an-organization + #> + [OutputType([pscustomobject])] + [CmdletBinding()] + param ( + # The organization name. The name is not case sensitive. + [Parameter(Mandatory)] + [Alias('org')] + [string] $OrganizationName + ) + + $inputObject = @{ + APIEndpoint = "/orgs/$OrganizationName" + Method = 'DELETE' + } + + Invoke-GitHubAPI @inputObject + +} From 8be249b1dd8934094ad27500d9a08012fc5c7137 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 29 Sep 2023 19:16:24 +0200 Subject: [PATCH 07/61] Add function to update/set a github org --- .../Organization/Set-GitHubOrganization.ps1 | 239 ++++++++++++++++++ 1 file changed, 239 insertions(+) create mode 100644 src/GitHub/public/Organization/Set-GitHubOrganization.ps1 diff --git a/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 b/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 new file mode 100644 index 000000000..c4548a6c2 --- /dev/null +++ b/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 @@ -0,0 +1,239 @@ +function Set-GitHubOrganization { + <# + .SYNOPSIS + Update an organization + + .DESCRIPTION + **Parameter Deprecation Notice:** GitHub will replace and discontinue `members_allowed_repository_creation_type` in favor of more granular permissions. The new input parameters are `members_can_create_public_repositories`, `members_can_create_private_repositories` for all organizations and `members_can_create_internal_repositories` for organizations associated with an enterprise account using GitHub Enterprise Cloud or GitHub Enterprise Server 2.20+. For more information, see the [blog post](https://developer.github.com/changes/2019-12-03-internal-visibility-changes). + + Enables an authenticated organization owner with the `admin:org` scope or the `repo` scope to update the organization's profile and member privileges. + + .EXAMPLE + Set-GitHubOrganization -OrganizationName 'github' -Blog 'https://github.blog' + + Sets the blog URL for the organization 'github' to 'https://github.blog'. + + .EXAMPLE + $param = @{ + OrganizationName = 'github' + MembersCanCreatePublicRepositories = $true + MembersCanCreatePrivateRepositories = $true + MembersCanCreateInternalRepositories = $true + } + Set-GitHubOrganization @param + + Sets the repository creation permissions for the organization 'github' to allow all members to create public, private, and internal repositories. + + .NOTES + https://docs.github.com/rest/orgs/orgs#update-an-organization + + #> + [OutputType([pscustomobject])] + [CmdletBinding()] + param ( + # The organization name. The name is not case sensitive. + [Parameter(Mandatory)] + [Alias('org')] + [string] $OrganizationName, + + # Billing email address. This address is not publicized. + [Parameter()] + [Alias('billing_email')] + [string] $BillingEmail, + + # The company name. + [Parameter()] + [Alias('company')] + [string] $Company, + + # The publicly visible email address. + [Parameter()] + [Alias('email')] + [string] $Email, + + # The Twitter username of the company. + [Parameter()] + [Alias('twitter_username')] + [string] $TwitterUsername, + + # The location. + [Parameter()] + [Alias('location')] + [string] $Location, + + # The shorthand name of the company. + [Parameter()] + [Alias('name')] + [string] $Name, + + # The description of the company. + [Parameter()] + [Alias('description')] + [string] $Description, + + # Whether an organization can use organization projects. + [Parameter()] + [Alias('has_organization_projects')] + [bool] $HasOrganizationProjects, + + # Whether repositories that belong to the organization can use repository projects. + [Parameter()] + [Alias('has_repository_projects')] + [bool] $HasRepositoryProjects, + + # Default permission level members have for organization repositories. + [Parameter()] + [Alias('default_repository_permission')] + [ValidateSet('read', 'write', 'admin', 'none')] + [string] $DefaultRepositoryPermission, + + # Whether of non-admin organization members can create repositories. Note: A parameter can override this parameter. See members_allowed_repository_creation_type in this table for details. + [Parameter()] + [Alias('members_can_create_repositories')] + [bool] $MembersCanCreateRepositories = $true, + + # Whether organization members can create internal repositories, which are visible to all enterprise members. You can only allow members to create internal repositories if your organization is associated with an enterprise account using GitHub Enterprise Cloud or GitHub Enterprise Server 2.20+. For more information, see "Restricting repository creation in your organization" in the GitHub Help documentation. + [Parameter()] + [Alias('members_can_create_internal_repositories')] + [bool] $MembersCanCreateInternalRepositories, + + # Whether organization members can create private repositories, which are visible to organization members with permission. For more information, see "Restricting repository creation in your organization" in the GitHub Help documentation. + [Parameter()] + [Alias('members_can_create_private_repositories')] + [bool] $MembersCanCreatePrivateRepositories, + + # Whether organization members can create public repositories, which are visible to anyone. For more information, see "Restricting repository creation in your organization" in the GitHub Help documentation. + [Parameter()] + [Alias('members_can_create_public_repositories')] + [bool] $MembersCanCreatePublicRepositories, + + # Specifies which types of repositories non-admin organization members can create. private is only available to repositories that are part of an organization on GitHub Enterprise Cloud. Note: This parameter is deprecated and will be removed in the future. Its return value ignores internal repositories. Using this parameter overrides values set in members_can_create_repositories. See the parameter deprecation notice in the operation description for details. + [Parameter()] + [Alias('members_allowed_repository_creation_type')] + [ValidateSet('all', 'private', 'none')] + [string] $MembersAllowedRepositoryCreationType, + + # Whether organization members can create GitHub Pages sites. Existing published sites will not be impacted. + [Parameter()] + [Alias('members_can_create_pages')] + [bool] $MembersCanCreatePages = $true, + + # Whether organization members can create public GitHub Pages sites. Existing published sites will not be impacted. + [Parameter()] + [Alias('members_can_create_public_pages')] + [bool] $MembersCanCreatePublicPages = $true, + + # Whether organization members can create private GitHub Pages sites. Existing published sites will not be impacted. + [Parameter()] + [Alias('members_can_create_private_pages')] + [bool] $MembersCanCreatePrivatePages = $true, + + # Whether organization members can fork private organization repositories. + [Parameter()] + [Alias('members_can_fork_private_repositories')] + [bool] $MembersCanForkPrivateRepositories = $false, + + # Whether contributors to organization repositories are required to sign off on commits they make through GitHub's web interface. + [Parameter()] + [Alias('web_commit_signoff_required')] + [bool] $WebCommitSignoffRequired = $false, + + # Path to the organization's blog. + [Parameter()] + [Alias('blog')] + [string] $Blog, + + # Whether GitHub Advanced Security is automatically enabled for new repositories. + # To use this parameter, you must have admin permissions for the repository or be an owner or security manager for the organization that owns the repository. For more information, see "Managing security managers in your organization." + # You can check which security and analysis features are currently enabled by using a GET /orgs/{org} request. + [Parameter()] + [Alias('advanced_security_enabled_for_new_repositories')] + [bool] $AdvancedSecurityEnabledForNewRepositories = $false, + + # Whether Dependabot alerts is automatically enabled for new repositories. + # To use this parameter, you must have admin permissions for the repository or be an owner or security manager for the organization that owns the repository. For more information, see "Managing security managers in your organization." + # You can check which security and analysis features are currently enabled by using a GET /orgs/{org} request. + [Parameter()] + [Alias('dependabot_alerts_enabled_for_new_repositories')] + [bool] $DependabotAlertsEnabledForNewRepositories = $false, + + # Whether Dependabot security updates is automatically enabled for new repositories. + # To use this parameter, you must have admin permissions for the repository or be an owner or security manager for the organization that owns the repository. For more information, see "Managing security managers in your organization." + # You can check which security and analysis features are currently enabled by using a GET /orgs/{org} request. + [Parameter()] + [Alias('dependabot_security_updates_enabled_for_new_repositories')] + [bool] $DependabotSecurityUpdatesEnabledForNewRepositories = $false, + + # Whether dependency graph is automatically enabled for new repositories. + # To use this parameter, you must have admin permissions for the repository or be an owner or security manager for the organization that owns the repository. For more information, see "Managing security managers in your organization." + # You can check which security and analysis features are currently enabled by using a GET /orgs/{org} request. + [Parameter()] + [Alias('dependency_graph_enabled_for_new_repositories')] + [bool] $DependencyGraphEnabledForNewRepositories = $false, + + # Whether secret scanning is automatically enabled for new repositories. + # To use this parameter, you must have admin permissions for the repository or be an owner or security manager for the organization that owns the repository. For more information, see "Managing security managers in your organization." + # You can check which security and analysis features are currently enabled by using a GET /orgs/{org} request. + [Parameter()] + [Alias('secret_scanning_enabled_for_new_repositories')] + [bool] $SecretScanningEnabledForNewRepositories = $false, + + # Whether secret scanning push protection is automatically enabled for new repositories. + # To use this parameter, you must have admin permissions for the repository or be an owner or security manager for the organization that owns the repository. For more information, see "Managing security managers in your organization." + # You can check which security and analysis features are currently enabled by using a GET /orgs/{org} request. + [Parameter()] + [Alias('secret_scanning_push_protection_enabled_for_new_repositories')] + [bool] $SecretScanningPushProtectionEnabledForNewRepositories = $false, + + # Whether a custom link is shown to contributors who are blocked from pushing a secret by push protection. + [Parameter()] + [Alias('secret_scanning_push_protection_custom_link_enabled')] + [bool] $SecretScanningPushProtectionCustomLinkEnabled = $false, + + # If secret_scanning_push_protection_custom_link_enabled is true, the URL that will be displayed to contributors who are blocked from pushing a secret. + [Parameter()] + [Alias('secret_scanning_push_protection_custom_link')] + [string] $SecretScanningPushProtectionCustomLink + ) + + $body = @{ + billing_email = $BillingEmail + company = $Company + email = $Email + twitter_username = $TwitterUsername + location = $Location + name = $Name + description = $Description + has_organization_projects = $HasOrganizationProjects + has_repository_projects = $HasRepositoryProjects + default_repository_permission = $DefaultRepositoryPermission + members_can_create_repositories = $MembersCanCreateRepositories + members_can_create_internal_repositories = $MembersCanCreateInternalRepositories + members_can_create_private_repositories = $MembersCanCreatePrivateRepositories + members_can_create_public_repositories = $MembersCanCreatePublicRepositories + members_allowed_repository_creation_type = $MembersAllowedRepositoryCreationType + members_can_create_pages = $MembersCanCreatePages + members_can_create_public_pages = $MembersCanCreatePublicPages + members_can_create_private_pages = $MembersCanCreatePrivatePages + members_can_fork_private_repositories = $MembersCanForkPrivateRepositories + web_commit_signoff_required = $WebCommitSignoffRequired + blog = $Blog + advanced_security_enabled_for_new_repositories = $AdvancedSecurityEnabledForNewRepositories + dependabot_alerts_enabled_for_new_repositories = $DependabotAlertsEnabledForNewRepositories + dependabot_security_updates_enabled_for_new_repositories = $DependabotSecurityUpdatesEnabledForNewRepositories + dependency_graph_enabled_for_new_repositories = $DependencyGraphEnabledForNewRepositories + secret_scanning_enabled_for_new_repositories = $SecretScanningEnabledForNewRepositories + secret_scanning_push_protection_enabled_for_new_repositories = $SecretScanningPushProtectionEnabledForNewRepositories + secret_scanning_push_protection_custom_link_enabled = $SecretScanningPushProtectionCustomLinkEnabled + secret_scanning_push_protection_custom_link = $SecretScanningPushProtectionCustomLink + } + + $inputObject = @{ + APIEndpoint = "/orgs/$OrganizationName" + Method = 'PATCH' + Body = $body + } + + Invoke-GitHubAPI @inputObject + +} From 76af2036a15532c44e4db5c529d70faa344e8fdd Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 29 Sep 2023 19:16:37 +0200 Subject: [PATCH 08/61] Add function to get a named org --- src/GitHub/public/Organization/Get-GitHubOrganization.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 b/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 index 4bcee7f95..213b1ed3d 100644 --- a/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 +++ b/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 @@ -1,4 +1,4 @@ -function Get-GitHubOrganization { +function Set-GitHubOrganization { <# .SYNOPSIS Get an organization @@ -21,6 +21,7 @@ param ( # The organization name. The name is not case sensitive. [Parameter(Mandatory)] + [Alias('org')] [string] $OrganizationName ) From 240ed803db0fa0da1d89f5209baf1dfe77f52491 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 29 Sep 2023 19:17:01 +0200 Subject: [PATCH 09/61] Add function to get all apps installed in an org --- .../Get-GitHubOrganizationAppInstallation.ps1 | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/GitHub/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 diff --git a/src/GitHub/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 b/src/GitHub/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 new file mode 100644 index 000000000..d3ab5bfb0 --- /dev/null +++ b/src/GitHub/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 @@ -0,0 +1,38 @@ +function Get-GitHubOrganizationAppInstallation { + <# + .SYNOPSIS + List app installations for an organization + + .DESCRIPTION + Lists all GitHub Apps in an organization. The installation count includes all GitHub Apps installed on repositories in the organization. You must be an organization owner with `admin:read` scope to use this endpoint. + + .EXAMPLE + Get-GitHubOrganizationAppInstallation -OrganizationName 'github' + + Gets all GitHub Apps in the organization `github`. + + .NOTES + https://docs.github.com/rest/orgs/orgs#list-app-installations-for-an-organization + + #> + [OutputType([pscustomobject])] + [CmdletBinding()] + param ( + # The organization name. The name is not case sensitive. + [Parameter(Mandatory)] + [Alias('org')] + [string] $OrganizationName, + + # The number of results per page (max 100). + [Parameter()] + [int] $PerPage = 30 + ) + + $inputObject = @{ + APIEndpoint = "/orgs/$OrganizationName/installations" + Method = 'GET' + } + + Invoke-GitHubAPI @inputObject + +} From e570a914df5c7743ec62861e74f878efc4c77fdb Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 29 Sep 2023 20:37:21 +0200 Subject: [PATCH 10/61] Add function to get organizations --- .../Get-GitHubAllOrganization.ps1} | 6 +- .../Organization/Get-GitHubMyOrganization.ps1 | 41 +++++++++ .../Get-GitHubOrganizationByName.ps1 | 36 ++++++++ .../Get-GitHubOrganizationByUser.ps1 | 44 ++++++++++ .../Organization/Get-GitHubOrganization.ps1 | 84 +++++++++++++++---- 5 files changed, 192 insertions(+), 19 deletions(-) rename src/GitHub/{public/Organization/Get-GitHubOrganizationList.ps1 => private/Organization/Get-GitHubAllOrganization.ps1} (91%) create mode 100644 src/GitHub/private/Organization/Get-GitHubMyOrganization.ps1 create mode 100644 src/GitHub/private/Organization/Get-GitHubOrganizationByName.ps1 create mode 100644 src/GitHub/private/Organization/Get-GitHubOrganizationByUser.ps1 diff --git a/src/GitHub/public/Organization/Get-GitHubOrganizationList.ps1 b/src/GitHub/private/Organization/Get-GitHubAllOrganization.ps1 similarity index 91% rename from src/GitHub/public/Organization/Get-GitHubOrganizationList.ps1 rename to src/GitHub/private/Organization/Get-GitHubAllOrganization.ps1 index 400b0df33..905e5e559 100644 --- a/src/GitHub/public/Organization/Get-GitHubOrganizationList.ps1 +++ b/src/GitHub/private/Organization/Get-GitHubAllOrganization.ps1 @@ -1,4 +1,4 @@ -function Get-GitHubOrganizationList { +function Get-GitHubAllOrganization { <# .SYNOPSIS List organizations @@ -9,7 +9,7 @@ **Note:** Pagination is powered exclusively by the `since` parameter. Use the [Link header](https://docs.github.com/rest/guides/using-pagination-in-the-rest-api#using-link-headers) to get the URL for the next page of organizations. .EXAMPLE - Get-GitHubOrganizationList -Since 142951047 + Get-GitHubAllOrganization -Since 142951047 List organizations, starting with PSModule @@ -23,7 +23,7 @@ # A organization ID. Only return organizations with an ID greater than this ID. [Parameter()] [int] $Since = 0, - + # The number of results per page (max 100). [Parameter()] [int] $PerPage = 30 diff --git a/src/GitHub/private/Organization/Get-GitHubMyOrganization.ps1 b/src/GitHub/private/Organization/Get-GitHubMyOrganization.ps1 new file mode 100644 index 000000000..b5321a270 --- /dev/null +++ b/src/GitHub/private/Organization/Get-GitHubMyOrganization.ps1 @@ -0,0 +1,41 @@ +function Get-GitHubMyOrganization { + <# + .SYNOPSIS + List organizations for the authenticated user + + .DESCRIPTION + List organizations for the authenticated user. + + **OAuth scope requirements** + + This only lists organizations that your authorization allows you to operate on in some way (e.g., you can list teams with `read:org` scope, you can publicize your organization membership with `user` scope, etc.). Therefore, this API requires at least `user` or `read:org` scope. OAuth requests with insufficient scope receive a `403 Forbidden` response. + + .EXAMPLE + Get-GitHubMyOrganization + + List organizations for the authenticated user. + + .NOTES + https://docs.github.com/rest/orgs/orgs#list-organizations-for-the-authenticated-user + #> + [OutputType([pscustomobject])] + [CmdletBinding()] + param ( + # The number of results per page (max 100). + [Parameter()] + [int] $PerPage = 30 + ) + + $body = @{ + per_page = $PerPage + } + + $inputObject = @{ + APIEndpoint = '/user/orgs' + Method = 'GET' + Body = $body + } + + Invoke-GitHubAPI @inputObject + +} diff --git a/src/GitHub/private/Organization/Get-GitHubOrganizationByName.ps1 b/src/GitHub/private/Organization/Get-GitHubOrganizationByName.ps1 new file mode 100644 index 000000000..6a843c8d1 --- /dev/null +++ b/src/GitHub/private/Organization/Get-GitHubOrganizationByName.ps1 @@ -0,0 +1,36 @@ +function Get-GitHubOrganizationByName { + <# + .SYNOPSIS + Get an organization + + .DESCRIPTION + To see many of the organization response values, you need to be an authenticated organization owner with the `admin:org` scope. When the value of `two_factor_requirement_enabled` is `true`, the organization requires all members, billing managers, and outside collaborators to enable [two-factor authentication](https://docs.github.com/articles/securing-your-account-with-two-factor-authentication-2fa/). + + GitHub Apps with the `Organization plan` permission can use this endpoint to retrieve information about an organization's GitHub plan. See "[Authenticating with GitHub Apps](https://docs.github.com/apps/building-github-apps/authenticating-with-github-apps/)" for details. For an example response, see 'Response with GitHub plan information' below." + + .EXAMPLE + Get-GitHubOrganizationByName -OrganizationName 'github' + + Get the 'GitHub' organization + + .NOTES + https://docs.github.com/rest/orgs/orgs#get-an-organization + #> + [OutputType([pscustomobject])] + [CmdletBinding()] + param ( + # The organization name. The name is not case sensitive. + [Parameter(Mandatory)] + [Alias('org')] + [Alias('name')] + [string] $OrganizationName + ) + + $inputObject = @{ + APIEndpoint = "/orgs/$OrganizationName" + Method = 'GET' + } + + Invoke-GitHubAPI @inputObject + +} diff --git a/src/GitHub/private/Organization/Get-GitHubOrganizationByUser.ps1 b/src/GitHub/private/Organization/Get-GitHubOrganizationByUser.ps1 new file mode 100644 index 000000000..2446db9ad --- /dev/null +++ b/src/GitHub/private/Organization/Get-GitHubOrganizationByUser.ps1 @@ -0,0 +1,44 @@ +function Get-GitHubOrganizationByUser { + <# + .SYNOPSIS + List organizations for a user + + .DESCRIPTION + List [public organization memberships](https://docs.github.com/articles/publicizing-or-concealing-organization-membership) for the specified user. + + This method only lists _public_ memberships, regardless of authentication. If you need to fetch all of the organization memberships (public and private) for the authenticated user, use the [List organizations for the authenticated user](https://docs.github.com/rest/orgs/orgs#list-organizations-for-the-authenticated-user) API instead. + + .EXAMPLE + Get-GitHubOrganizationByUser -Username 'octocat' + + List public organizations for the user 'octocat'. + + .NOTES + https://docs.github.com/rest/orgs/orgs#list-organizations-for-a-user + #> + [OutputType([pscustomobject])] + [CmdletBinding()] + param ( + # The handle for the GitHub user account. + [Parameter(Mandatory)] + [Alias('username')] + [string] $Username, + + # The number of results per page (max 100). + [Parameter()] + [int] $PerPage = 30 + ) + + $body = @{ + per_page = $PerPage + } + + $inputObject = @{ + APIEndpoint = "/users/$Username/orgs" + Method = 'GET' + Body = $body + } + + Invoke-GitHubAPI @inputObject + +} diff --git a/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 b/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 index 213b1ed3d..734f33c6a 100644 --- a/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 +++ b/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 @@ -1,35 +1,87 @@ -function Set-GitHubOrganization { +function Get-GitHubOrganization { <# .SYNOPSIS - Get an organization + List organization .DESCRIPTION - To see many of the organization response values, you need to be an authenticated organization owner with the `admin:org` scope. When the value of `two_factor_requirement_enabled` is `true`, the organization requires all members, billing managers, and outside collaborators to enable [two-factor authentication](https://docs.github.com/articles/securing-your-account-with-two-factor-authentication-2fa/). + List organizations for the authenticated user - if no parameters are provided. + List organizations for a user - if a username is provided. + Lists all organizations, in the order that they were created on GitHub - if '-All' is provided. + Get an organization - if a organization name is provided. - GitHub Apps with the `Organization plan` permission can use this endpoint to retrieve information about an organization's GitHub plan. See "[Authenticating with GitHub Apps](https://docs.github.com/apps/building-github-apps/authenticating-with-github-apps/)" for details. For an example response, see 'Response with GitHub plan information' below." + .EXAMPLE + Get-GitHubOrganization + + List organizations for the authenticated user. + + .EXAMPLE + Get-GitHubOrganization -Username 'octocat' + + List public organizations for the user 'octocat'. + + .EXAMPLE + Get-GitHubOrganization -All -Since 142951047 + + List organizations, starting with PSModule. .EXAMPLE - Get-GitHubOrganization -OrganizationName 'github' + Get-GitHubOrganization -Name 'PSModule' - Get the 'GitHub' organization + Get the organization 'PSModule'. .NOTES - https://docs.github.com/rest/orgs/orgs#get-an-organization + https://docs.github.com/rest/orgs/orgs#list-organizations-for-the-authenticated-user #> [OutputType([pscustomobject])] - [CmdletBinding()] + [CmdletBinding(DefaultParameterSetName = '__DefaultSet')] param ( # The organization name. The name is not case sensitive. - [Parameter(Mandatory)] + [Parameter( + Mandatory, + ParameterSetName = 'NamedOrg' + )] [Alias('org')] - [string] $OrganizationName - ) + [Alias('name')] + [string] $OrganizationName, - $inputObject = @{ - APIEndpoint = "/orgs/$OrganizationName" - Method = 'GET' - } + # The handle for the GitHub user account. + [Parameter( + Mandatory, + ParameterSetName = 'NamedUser' + )] + [Alias('username')] + [string] $Username, + + # List all organizations. Use '-Since' to start at a specific organization id. + [Parameter( + Mandatory, + ParameterSetName = 'AllOrg' + )] + [switch] $All, - Invoke-GitHubAPI @inputObject + # A organization ID. Only return organizations with an ID greater than this ID. + [Parameter(ParameterSetName = 'AllOrg')] + [int] $Since = 0, + # The number of results per page (max 100). + [Parameter(ParameterSetName = 'AllOrg')] + [Parameter(ParameterSetName = 'UserOrg')] + [Parameter(ParameterSetName = '__DefaultSet')] + [int] $PerPage = 30 + ) + + switch ($Cmdlet.ParameterSetName) { + '__DefaultSet' { + Get-GitHubMyOrganization -PerPage $PerPage + } + 'NamedOrg' { + Get-GitHubOrganizationByName -OrganizationName $OrganizationName + } + 'NamedUser' { + Get-GitHubOrganizationByUser -Username $Username + } + 'AllOrg' { + Get-GitHubAllOrganization -Since $Since -PerPage $PerPage + } + } } From e236d0c2b55496d9963ebb8a9c20d325f339f8b4 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 29 Sep 2023 20:37:36 +0200 Subject: [PATCH 11/61] fix type on api --- src/GitHub/public/API/Invoke-GitHubAPI.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 index 2cd3f714d..c3bb29fbd 100644 --- a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 +++ b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 @@ -62,7 +62,7 @@ # The GitHub API version to be used. By default, it pulls from a configuration script variable. [Parameter()] - [string] $Version = (Get-GitHubConfig -Name ApiVersion) + [string] $Version = (Get-GitHubConfig -Name ApiVersion), # Declares the state of a resource by passing all parameters/body properties to Invoke-RestMethod, even if empty [Parameter()] From 9441dcb4cd1a05236deb598cc768faa5f0034d9b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 29 Sep 2023 20:37:52 +0200 Subject: [PATCH 12/61] Add function to set org sec features --- .../Set-GitHubOrganizationSecurityFeature.ps1 | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/GitHub/public/Organization/Set-GitHubOrganizationSecurityFeature.ps1 diff --git a/src/GitHub/public/Organization/Set-GitHubOrganizationSecurityFeature.ps1 b/src/GitHub/public/Organization/Set-GitHubOrganizationSecurityFeature.ps1 new file mode 100644 index 000000000..3dd6db955 --- /dev/null +++ b/src/GitHub/public/Organization/Set-GitHubOrganizationSecurityFeature.ps1 @@ -0,0 +1,65 @@ +function Set-GitHubOrganizationSecurityFeature { + <# + .SYNOPSIS + Enable or disable a security feature for an organization + + .DESCRIPTION + Enables or disables the specified security feature for all eligible repositories in an organization. + + To use this endpoint, you must be an organization owner or be member of a team with the security manager role. + A token with the 'write:org' scope is also required. + + GitHub Apps must have the `organization_administration:write` permission to use this endpoint. + + For more information, see "[Managing security managers in your organization](https://docs.github.com/organizations/managing-peoples-access-to-your-organization-with-roles/managing-security-managers-in-your-organization)." + + .EXAMPLE + Set-GitHubOrganizationSecurityFeature -OrganizationName 'github' -SecurityProduct 'dependency_graph' -Enablement 'enable_all' + + Enable the dependency graph for all repositories in the organization `github`. + + .NOTES + https://docs.github.com/rest/orgs/orgs#enable-or-disable-a-security-feature-for-an-organization + #> + [OutputType([pscustomobject])] + [CmdletBinding()] + param ( + # The organization name. The name is not case sensitive. + [Parameter(Mandatory)] + [Alias('org')] + [Alias('name')] + [string] $OrganizationName, + + # The security feature to enable or disable. + [Parameter(Mandatory)] + [Alias('security_product')] + [ValidateSet('dependency_graph', 'dependabot_alerts', 'dependabot_security_updates', 'advanced_security', 'code_scanning_default_setup', 'secret_scanning', 'secret_scanning_push_protection')] + [string] $SecurityProduct, + + # The action to take. + # enable_all means to enable the specified security feature for all repositories in the organization. disable_all means to disable the specified security feature for all repositories in the organization. + [Parameter(Mandatory)] + [Alias('enablement')] + [ValidateSet('enable_all', 'disable_all')] + [string] $Enablement, + + # CodeQL query suite to be used. If you specify the query_suite parameter, the default setup will be configured with this query suite only on all repositories that didn't have default setup already configured. It will not change the query suite on repositories that already have default setup configured. If you don't specify any query_suite in your request, the preferred query suite of the organization will be applied. + [Parameter()] + [Alias('query_suite')] + [ValidateSet('default', 'extended')] + [string] $QuerySuite + ) + + $body = @{ + query_suite = $QuerySuite + } + + $inputObject = @{ + APIEndpoint = "/orgs/$OrganizationName/$SecurityProduct/$Enablement" + Method = 'PATCH' + Body = $body + } + + Invoke-GitHubAPI @inputObject + +} From ff17b1d16eef502afb8103fab36b8d329a579605 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 29 Sep 2023 20:38:05 +0200 Subject: [PATCH 13/61] Add function to get app installations on org --- .../Organization/Get-GitHubOrganizationAppInstallation.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/src/GitHub/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 b/src/GitHub/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 index d3ab5bfb0..b97fd8da7 100644 --- a/src/GitHub/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 +++ b/src/GitHub/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 @@ -21,6 +21,7 @@ # The organization name. The name is not case sensitive. [Parameter(Mandatory)] [Alias('org')] + [Alias('name')] [string] $OrganizationName, # The number of results per page (max 100). From 972335c7eecebd040f102af578b0a52e47228b45 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 29 Sep 2023 20:38:13 +0200 Subject: [PATCH 14/61] Fix api script --- tools/utilities/GitHubAPI.ps1 | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/tools/utilities/GitHubAPI.ps1 b/tools/utilities/GitHubAPI.ps1 index a5b3004e9..ca02459ff 100644 --- a/tools/utilities/GitHubAPI.ps1 +++ b/tools/utilities/GitHubAPI.ps1 @@ -21,19 +21,19 @@ $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 = '/users/{username}/hovercard' -$response.paths.$path.get.tags | clip # -> Namespace/foldername -$response.paths.$path.get.operationId | clip # -> FunctionName -$response.paths.$path.get.summary | clip # -> Synopsis -$response.paths.$path.get.description | clip # -> Description -$response.paths.$path.get.externalDocs.url | clip # -> Notes -$response.paths.$path.get.'x-github'.category | clip # -> Namespace/foldername -$response.paths.$path.get.'x-github'.subcategory | clip # -> Namespace/foldername -$response.paths.$path.get.'x-github'.enabledForGitHubApps | clip # -> Note + Warning if running as GitHub App -$response.paths.$path.get.'x-github'.githubCloudOnly | clip # -> Note -$response.paths.$path.get.parameters # -> Parameter list -$response.paths.$path.get.responses.'200'.content.'application/json'.schema # -> OutputType qualifyer -$response.paths.$path.get.responses.'200'.content.'application/json'.schema.items # -> OutputType -$response.paths.$path.get - - +$path = '/users/{username}/orgs' +$method = 'get' +$response.paths.$path.$method +$response.paths.$path.$method.tags | clip # -> Namespace/foldername +$response.paths.$path.$method.operationId | clip # -> FunctionName +$response.paths.$path.$method.summary | clip # -> Synopsis +$response.paths.$path.$method.description | clip # -> Description +$response.paths.$path.$method.externalDocs.url | clip # -> Notes +$response.paths.$path.$method.'x-github'.category | clip # -> Namespace/foldername +$response.paths.$path.$method.'x-github'.subcategory | clip # -> Namespace/foldername +$response.paths.$path.$method.'x-github'.enabledForGitHubApps | clip # -> Note + Warning if running as GitHub App +$response.paths.$path.$method.'x-github'.githubCloudOnly | clip # -> Note +$response.paths.$path.$method.parameters # -> Parameter list +$response.paths.$path.$method.parameters.'$ref' # -> Parameter list +$response.paths.$path.$method.responses.'200'.content.'application/json'.schema # -> OutputType qualifyer +$response.paths.$path.$method.responses.'200'.content.'application/json'.schema.items # -> OutputType From 48901a3da73c0aa045ad78338d162233f39975d5 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 29 Sep 2023 20:45:16 +0200 Subject: [PATCH 15/61] Fix naming collision --- .../private/Organization/Get-GitHubOrganizationByName.ps1 | 1 + .../private/Organization/Get-GitHubOrganizationByUser.ps1 | 1 - src/GitHub/public/Organization/Get-GitHubOrganization.ps1 | 2 +- tools/utilities/Local-Testing.ps1 | 4 ++++ 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/GitHub/private/Organization/Get-GitHubOrganizationByName.ps1 b/src/GitHub/private/Organization/Get-GitHubOrganizationByName.ps1 index 6a843c8d1..866264018 100644 --- a/src/GitHub/private/Organization/Get-GitHubOrganizationByName.ps1 +++ b/src/GitHub/private/Organization/Get-GitHubOrganizationByName.ps1 @@ -22,6 +22,7 @@ # The organization name. The name is not case sensitive. [Parameter(Mandatory)] [Alias('org')] + [Alias('owner')] [Alias('name')] [string] $OrganizationName ) diff --git a/src/GitHub/private/Organization/Get-GitHubOrganizationByUser.ps1 b/src/GitHub/private/Organization/Get-GitHubOrganizationByUser.ps1 index 2446db9ad..975b289ac 100644 --- a/src/GitHub/private/Organization/Get-GitHubOrganizationByUser.ps1 +++ b/src/GitHub/private/Organization/Get-GitHubOrganizationByUser.ps1 @@ -21,7 +21,6 @@ param ( # The handle for the GitHub user account. [Parameter(Mandatory)] - [Alias('username')] [string] $Username, # The number of results per page (max 100). diff --git a/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 b/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 index 734f33c6a..805ad4582 100644 --- a/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 +++ b/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 @@ -41,6 +41,7 @@ ParameterSetName = 'NamedOrg' )] [Alias('org')] + [Alias('owner')] [Alias('name')] [string] $OrganizationName, @@ -49,7 +50,6 @@ Mandatory, ParameterSetName = 'NamedUser' )] - [Alias('username')] [string] $Username, # List all organizations. Use '-Since' to start at a specific organization id. diff --git a/tools/utilities/Local-Testing.ps1 b/tools/utilities/Local-Testing.ps1 index 3157efdae..6599989d5 100644 --- a/tools/utilities/Local-Testing.ps1 +++ b/tools/utilities/Local-Testing.ps1 @@ -35,3 +35,7 @@ $str = '2023-10-27 17:43:40 UTC' $format = "yyyy-MM-dd HH:mm:ss 'UTC'" $date = [datetime]::ParseExact($str, $format, $null) $date + + + +Get-GitHubOrganization -OrganizationName 'github' From e4720c08c43c36f201b29560d38bdd7ebba0976f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 29 Sep 2023 20:51:30 +0200 Subject: [PATCH 16/61] fix for org --- src/GitHub/public/Organization/Get-GitHubOrganization.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 b/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 index 805ad4582..27ead242c 100644 --- a/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 +++ b/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 @@ -70,7 +70,7 @@ [int] $PerPage = 30 ) - switch ($Cmdlet.ParameterSetName) { + switch ($PSCmdlet.ParameterSetName) { '__DefaultSet' { Get-GitHubMyOrganization -PerPage $PerPage } From 4ea30540b61b3760977f537037586feefe8f53ce Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 29 Sep 2023 21:11:38 +0200 Subject: [PATCH 17/61] Get details by default for personal orgs --- .../private/Organization/Get-GitHubOrganizationByName.ps1 | 1 + src/GitHub/public/Organization/Get-GitHubOrganization.ps1 | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/GitHub/private/Organization/Get-GitHubOrganizationByName.ps1 b/src/GitHub/private/Organization/Get-GitHubOrganizationByName.ps1 index 866264018..0b600d0be 100644 --- a/src/GitHub/private/Organization/Get-GitHubOrganizationByName.ps1 +++ b/src/GitHub/private/Organization/Get-GitHubOrganizationByName.ps1 @@ -24,6 +24,7 @@ [Alias('org')] [Alias('owner')] [Alias('name')] + [Alias('login')] [string] $OrganizationName ) diff --git a/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 b/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 index 27ead242c..7bd42a718 100644 --- a/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 +++ b/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 @@ -72,7 +72,7 @@ switch ($PSCmdlet.ParameterSetName) { '__DefaultSet' { - Get-GitHubMyOrganization -PerPage $PerPage + Get-GitHubMyOrganization -PerPage $PerPage | Get-GitHubOrganizationByName } 'NamedOrg' { Get-GitHubOrganizationByName -OrganizationName $OrganizationName From 631e3535d1bde55586178566b15f0dc258ed69ed Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 29 Sep 2023 21:15:50 +0200 Subject: [PATCH 18/61] Fix piping --- .../private/Organization/Get-GitHubOrganizationByName.ps1 | 6 +++++- tools/utilities/Local-Testing.ps1 | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/GitHub/private/Organization/Get-GitHubOrganizationByName.ps1 b/src/GitHub/private/Organization/Get-GitHubOrganizationByName.ps1 index 0b600d0be..0c561ac7e 100644 --- a/src/GitHub/private/Organization/Get-GitHubOrganizationByName.ps1 +++ b/src/GitHub/private/Organization/Get-GitHubOrganizationByName.ps1 @@ -20,7 +20,11 @@ [CmdletBinding()] param ( # The organization name. The name is not case sensitive. - [Parameter(Mandatory)] + [Parameter( + Mandatory, + ValueFromPipeline, + ValueFromPipelineByPropertyName + )] [Alias('org')] [Alias('owner')] [Alias('name')] diff --git a/tools/utilities/Local-Testing.ps1 b/tools/utilities/Local-Testing.ps1 index 6599989d5..669fb7ac9 100644 --- a/tools/utilities/Local-Testing.ps1 +++ b/tools/utilities/Local-Testing.ps1 @@ -37,5 +37,7 @@ $date = [datetime]::ParseExact($str, $format, $null) $date +Get-GitHubOrganization +Get-GitHubOrganization -OrganizationName 'PowerShell' -Get-GitHubOrganization -OrganizationName 'github' +Get-GitHubOrganizationAppInstallation -OrganizationName 'PowerShell' From f1c7fd6113bda6da928577ad5c8d32ed2329d742 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 29 Sep 2023 21:24:08 +0200 Subject: [PATCH 19/61] Enable pipeline streaming --- .../Get-GitHubOrganizationByName.ps1 | 16 ++++++++++++---- ...ByUser.ps1 => Get-GitHubUserOrganization.ps1} | 4 ++-- .../Organization/Get-GitHubOrganization.ps1 | 2 +- tools/utilities/Local-Testing.ps1 | 7 ++----- 4 files changed, 17 insertions(+), 12 deletions(-) rename src/GitHub/private/Organization/{Get-GitHubOrganizationByUser.ps1 => Get-GitHubUserOrganization.ps1} (92%) diff --git a/src/GitHub/private/Organization/Get-GitHubOrganizationByName.ps1 b/src/GitHub/private/Organization/Get-GitHubOrganizationByName.ps1 index 0c561ac7e..0fdbc14b8 100644 --- a/src/GitHub/private/Organization/Get-GitHubOrganizationByName.ps1 +++ b/src/GitHub/private/Organization/Get-GitHubOrganizationByName.ps1 @@ -32,11 +32,19 @@ [string] $OrganizationName ) - $inputObject = @{ - APIEndpoint = "/orgs/$OrganizationName" - Method = 'GET' + begin {} + + process { + + $inputObject = @{ + APIEndpoint = "/orgs/$OrganizationName" + Method = 'GET' + } + + Invoke-GitHubAPI @inputObject + } - Invoke-GitHubAPI @inputObject + end {} } diff --git a/src/GitHub/private/Organization/Get-GitHubOrganizationByUser.ps1 b/src/GitHub/private/Organization/Get-GitHubUserOrganization.ps1 similarity index 92% rename from src/GitHub/private/Organization/Get-GitHubOrganizationByUser.ps1 rename to src/GitHub/private/Organization/Get-GitHubUserOrganization.ps1 index 975b289ac..883c0c6fa 100644 --- a/src/GitHub/private/Organization/Get-GitHubOrganizationByUser.ps1 +++ b/src/GitHub/private/Organization/Get-GitHubUserOrganization.ps1 @@ -1,4 +1,4 @@ -function Get-GitHubOrganizationByUser { +function Get-GitHubUserOrganization { <# .SYNOPSIS List organizations for a user @@ -9,7 +9,7 @@ This method only lists _public_ memberships, regardless of authentication. If you need to fetch all of the organization memberships (public and private) for the authenticated user, use the [List organizations for the authenticated user](https://docs.github.com/rest/orgs/orgs#list-organizations-for-the-authenticated-user) API instead. .EXAMPLE - Get-GitHubOrganizationByUser -Username 'octocat' + Get-GitHubUserOrganization -Username 'octocat' List public organizations for the user 'octocat'. diff --git a/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 b/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 index 7bd42a718..baa9bf9fb 100644 --- a/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 +++ b/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 @@ -78,7 +78,7 @@ Get-GitHubOrganizationByName -OrganizationName $OrganizationName } 'NamedUser' { - Get-GitHubOrganizationByUser -Username $Username + Get-GitHubUserOrganization -Username $Username } 'AllOrg' { Get-GitHubAllOrganization -Since $Since -PerPage $PerPage diff --git a/tools/utilities/Local-Testing.ps1 b/tools/utilities/Local-Testing.ps1 index 669fb7ac9..2bf3a12ad 100644 --- a/tools/utilities/Local-Testing.ps1 +++ b/tools/utilities/Local-Testing.ps1 @@ -13,17 +13,14 @@ Install-Module -Name GitHub -Force -Verbose -AllowPrerelease # Import-Module -Name 'C:\Repos\GitHub\PSModule\Modules\GitHub\src\GitHub\GitHub.psm1' -Verbose -Force Import-Module -Name GitHub -Verbose -Clear-Host Get-Command -Module GitHub -Get-Variable | Where-Object -Property Module -NE $null | Select-Object Name, Module, ModuleName +Clear-Host Connect-GitHubAccount Connect-GitHubAccount -Mode OAuthApp Connect-GitHubAccount -AccessToken +Get-GitHubConfig Get-GitHubConfig -Name AccessToken -Get-GitHubConfig -Name AccessTokenExpirationDate Get-GitHubConfig -Name RefreshToken -Get-GitHubConfig -Name RefreshTokenExpirationDate -Get-GitHubConfig -Name ApiBaseUri Invoke-GitHubAPI -Method Get -ApiEndpoint /user Get-GitHubMeta Get-GitHubOctocat -S 'Hello, World!' From f018c7f42c2e1208ec0b547f496e0f0aaf5c548f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 29 Sep 2023 21:40:57 +0200 Subject: [PATCH 20/61] Fix param collision --- .../public/Organization/Get-GitHubOrganization.ps1 | 1 + .../Get-GitHubOrganizationAppInstallation.ps1 | 4 +++- .../public/Organization/Remove-GitHubOrganization.ps1 | 3 +++ .../public/Organization/Set-GitHubOrganization.ps1 | 9 +++------ .../Set-GitHubOrganizationSecurityFeature.ps1 | 3 ++- tools/utilities/Local-Testing.ps1 | 2 +- 6 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 b/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 index baa9bf9fb..3a2c06c8a 100644 --- a/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 +++ b/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 @@ -42,6 +42,7 @@ )] [Alias('org')] [Alias('owner')] + [Alias('login')] [Alias('name')] [string] $OrganizationName, diff --git a/src/GitHub/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 b/src/GitHub/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 index b97fd8da7..f924d5534 100644 --- a/src/GitHub/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 +++ b/src/GitHub/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 @@ -21,6 +21,8 @@ # The organization name. The name is not case sensitive. [Parameter(Mandatory)] [Alias('org')] + [Alias('owner')] + [Alias('login')] [Alias('name')] [string] $OrganizationName, @@ -34,6 +36,6 @@ Method = 'GET' } - Invoke-GitHubAPI @inputObject + Invoke-GitHubAPI @inputObject | Select-Object -ExpandProperty 'installations' | Write-Output } diff --git a/src/GitHub/public/Organization/Remove-GitHubOrganization.ps1 b/src/GitHub/public/Organization/Remove-GitHubOrganization.ps1 index cce0a1feb..25f703f77 100644 --- a/src/GitHub/public/Organization/Remove-GitHubOrganization.ps1 +++ b/src/GitHub/public/Organization/Remove-GitHubOrganization.ps1 @@ -23,6 +23,9 @@ # The organization name. The name is not case sensitive. [Parameter(Mandatory)] [Alias('org')] + [Alias('owner')] + [Alias('login')] + [Alias('name')] [string] $OrganizationName ) diff --git a/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 b/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 index c4548a6c2..15b5947e6 100644 --- a/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 +++ b/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 @@ -34,6 +34,9 @@ # The organization name. The name is not case sensitive. [Parameter(Mandatory)] [Alias('org')] + [Alias('owner')] + [Alias('login')] + [Alias('name')] [string] $OrganizationName, # Billing email address. This address is not publicized. @@ -43,12 +46,10 @@ # The company name. [Parameter()] - [Alias('company')] [string] $Company, # The publicly visible email address. [Parameter()] - [Alias('email')] [string] $Email, # The Twitter username of the company. @@ -58,17 +59,14 @@ # The location. [Parameter()] - [Alias('location')] [string] $Location, # The shorthand name of the company. [Parameter()] - [Alias('name')] [string] $Name, # The description of the company. [Parameter()] - [Alias('description')] [string] $Description, # Whether an organization can use organization projects. @@ -140,7 +138,6 @@ # Path to the organization's blog. [Parameter()] - [Alias('blog')] [string] $Blog, # Whether GitHub Advanced Security is automatically enabled for new repositories. diff --git a/src/GitHub/public/Organization/Set-GitHubOrganizationSecurityFeature.ps1 b/src/GitHub/public/Organization/Set-GitHubOrganizationSecurityFeature.ps1 index 3dd6db955..7a7395ded 100644 --- a/src/GitHub/public/Organization/Set-GitHubOrganizationSecurityFeature.ps1 +++ b/src/GitHub/public/Organization/Set-GitHubOrganizationSecurityFeature.ps1 @@ -27,6 +27,8 @@ # The organization name. The name is not case sensitive. [Parameter(Mandatory)] [Alias('org')] + [Alias('owner')] + [Alias('login')] [Alias('name')] [string] $OrganizationName, @@ -39,7 +41,6 @@ # The action to take. # enable_all means to enable the specified security feature for all repositories in the organization. disable_all means to disable the specified security feature for all repositories in the organization. [Parameter(Mandatory)] - [Alias('enablement')] [ValidateSet('enable_all', 'disable_all')] [string] $Enablement, diff --git a/tools/utilities/Local-Testing.ps1 b/tools/utilities/Local-Testing.ps1 index 2bf3a12ad..7fc19b68b 100644 --- a/tools/utilities/Local-Testing.ps1 +++ b/tools/utilities/Local-Testing.ps1 @@ -37,4 +37,4 @@ $date Get-GitHubOrganization Get-GitHubOrganization -OrganizationName 'PowerShell' -Get-GitHubOrganizationAppInstallation -OrganizationName 'PowerShell' +Get-GitHubOrganizationAppInstallation -OrganizationName 'PSModule' | Select-Object -ExpandProperty installations From b8a30c9ec603774d537df18cc06065f34111e7c1 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 29 Sep 2023 21:49:52 +0200 Subject: [PATCH 21/61] Fix name in set-org --- src/GitHub/public/Organization/Set-GitHubOrganization.ps1 | 1 - tools/utilities/Local-Testing.ps1 | 5 ++++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 b/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 index 15b5947e6..321eac3c7 100644 --- a/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 +++ b/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 @@ -36,7 +36,6 @@ [Alias('org')] [Alias('owner')] [Alias('login')] - [Alias('name')] [string] $OrganizationName, # Billing email address. This address is not publicized. diff --git a/tools/utilities/Local-Testing.ps1 b/tools/utilities/Local-Testing.ps1 index 7fc19b68b..ee88f5dc3 100644 --- a/tools/utilities/Local-Testing.ps1 +++ b/tools/utilities/Local-Testing.ps1 @@ -36,5 +36,8 @@ $date Get-GitHubOrganization Get-GitHubOrganization -OrganizationName 'PowerShell' +Get-GitHubOrganization -OrganizationName 'PSModule' -Get-GitHubOrganizationAppInstallation -OrganizationName 'PSModule' | Select-Object -ExpandProperty installations +Get-GitHubOrganizationAppInstallation -OrganizationName 'PSModule' + +Set-GitHubOrganization -OrganizationName 'PSModule' -Blog '' From ccb49feef1288132df6bd8450bfc528b50626f39 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 29 Sep 2023 22:12:02 +0200 Subject: [PATCH 22/61] Fix set-orgsecfeat to post --- .../Organization/Set-GitHubOrganizationSecurityFeature.ps1 | 2 +- tools/utilities/Local-Testing.ps1 | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/GitHub/public/Organization/Set-GitHubOrganizationSecurityFeature.ps1 b/src/GitHub/public/Organization/Set-GitHubOrganizationSecurityFeature.ps1 index 7a7395ded..10e13a0b6 100644 --- a/src/GitHub/public/Organization/Set-GitHubOrganizationSecurityFeature.ps1 +++ b/src/GitHub/public/Organization/Set-GitHubOrganizationSecurityFeature.ps1 @@ -57,7 +57,7 @@ $inputObject = @{ APIEndpoint = "/orgs/$OrganizationName/$SecurityProduct/$Enablement" - Method = 'PATCH' + Method = 'POST' Body = $body } diff --git a/tools/utilities/Local-Testing.ps1 b/tools/utilities/Local-Testing.ps1 index ee88f5dc3..6d258e1c1 100644 --- a/tools/utilities/Local-Testing.ps1 +++ b/tools/utilities/Local-Testing.ps1 @@ -40,4 +40,6 @@ Get-GitHubOrganization -OrganizationName 'PSModule' Get-GitHubOrganizationAppInstallation -OrganizationName 'PSModule' +Set-GitHubOrganization -OrganizationName 'PSModule' -Blog 'https://www.psmodule.io' Set-GitHubOrganization -OrganizationName 'PSModule' -Blog '' +Set-GitHubOrganization -OrganizationName 'PSModule' -Blog ' ' From 822b0c67ee910f0a5e3e4a9c4d8634a54478b18c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 29 Sep 2023 22:29:09 +0200 Subject: [PATCH 23/61] Fix for connect-acc --- src/GitHub/public/Auth/Connect-GitHubAccount.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GitHub/public/Auth/Connect-GitHubAccount.ps1 b/src/GitHub/public/Auth/Connect-GitHubAccount.ps1 index 4b57c307d..5048b13ed 100644 --- a/src/GitHub/public/Auth/Connect-GitHubAccount.ps1 +++ b/src/GitHub/public/Auth/Connect-GitHubAccount.ps1 @@ -89,7 +89,7 @@ $accessTokenIsValid = $accessTokenValidity.Seconds -gt 0 $accessTokenValidityText = "$($accessTokenValidity.Hours):$($accessTokenValidity.Minutes):$($accessTokenValidity.Seconds)" if ($accessTokenIsValid) { - if ($accessTokenValidity -gt 4) { + if ($accessTokenValidity.TotalHours -gt 4) { Write-Host '✓ ' -ForegroundColor Green -NoNewline Write-Host "Access token is still valid for $accessTokenValidityText ..." return From 5468bd0ba51ff9061d017e1251c014bb9be513af Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 30 Sep 2023 08:56:37 +0200 Subject: [PATCH 24/61] Adding status code and responseheader to api response --- src/GitHub/public/API/Invoke-GitHubAPI.ps1 | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 index c3bb29fbd..10c207d1d 100644 --- a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 +++ b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 @@ -133,9 +133,14 @@ } try { - Invoke-RestMethod @APICall | Write-Output - Write-Verbose ($StatusCode | ConvertTo-Json -Depth 100) - Write-Verbose ($responseHeaders | ConvertTo-Json -Depth 100) + Invoke-RestMethod @APICall | ForEach-Object { + # Add the StatusCode and ResponseHeaders to the output + $_ | Add-Member -MemberType NoteProperty -Name StatusCode -Value $StatusCode -PassThru + $_ | Add-Member -MemberType NoteProperty -Name ResponseHeaders -Value $ResponseHeaders -PassThru + } | Write-Output + + Write-Verbose ($StatusCode | Format-List | Out-String) + Write-Verbose ($responseHeaders | Format-List | Out-String) } catch { Write-Error "[$functionName] - Status code - [$StatusCode]" $err = $_ | ConvertFrom-Json -Depth 10 From 4390940ae6d6652b1295f2a7f96a40c574c9a53e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 30 Sep 2023 08:57:03 +0200 Subject: [PATCH 25/61] Add paging to app installation --- .../Organization/Get-GitHubOrganizationAppInstallation.ps1 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/GitHub/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 b/src/GitHub/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 index f924d5534..293004c8a 100644 --- a/src/GitHub/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 +++ b/src/GitHub/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 @@ -31,9 +31,14 @@ [int] $PerPage = 30 ) + $body = @{ + per_page = $PerPage + } + $inputObject = @{ APIEndpoint = "/orgs/$OrganizationName/installations" Method = 'GET' + Body = $body } Invoke-GitHubAPI @inputObject | Select-Object -ExpandProperty 'installations' | Write-Output From f0f439480308ed0316d4274daac7678f227a90ef Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 30 Sep 2023 08:57:18 +0200 Subject: [PATCH 26/61] add assert blocked user on org --- .../Assert-GitHubOrganizationBlockedUser.ps1 | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/GitHub/public/Organization/Blocking/Assert-GitHubOrganizationBlockedUser.ps1 diff --git a/src/GitHub/public/Organization/Blocking/Assert-GitHubOrganizationBlockedUser.ps1 b/src/GitHub/public/Organization/Blocking/Assert-GitHubOrganizationBlockedUser.ps1 new file mode 100644 index 000000000..b60f42068 --- /dev/null +++ b/src/GitHub/public/Organization/Blocking/Assert-GitHubOrganizationBlockedUser.ps1 @@ -0,0 +1,42 @@ +function Assert-GitHubOrganizationBlockedUser { + <# + .SYNOPSIS + Check if a user is blocked by an organization + + .DESCRIPTION + 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' + + Lists all users blocked by the organization `github`. + + .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')] + [CmdletBinding()] + param ( + # The organization name. The name is not case sensitive. + [Parameter(Mandatory)] + [Alias('org')] + [Alias('owner')] + [Alias('login')] + [Alias('name')] + [string] $OrganizationName, + + # The handle for the GitHub user account. + [Parameter(Mandatory)] + [string] $Username + ) + + $inputObject = @{ + APIEndpoint = "/orgs/$OrganizationName/blocks/$Username" + Method = 'GET' + } + + Invoke-GitHubAPI @inputObject -Verbose + +} From 43404fb33f3d2982d847d880e7c2f076c40adcc8 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 30 Sep 2023 08:57:41 +0200 Subject: [PATCH 27/61] add function to get blocked users in an org --- .../Get-GitHubOrganizationBlockedUser.ps1 | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/GitHub/public/Organization/Blocking/Get-GitHubOrganizationBlockedUser.ps1 diff --git a/src/GitHub/public/Organization/Blocking/Get-GitHubOrganizationBlockedUser.ps1 b/src/GitHub/public/Organization/Blocking/Get-GitHubOrganizationBlockedUser.ps1 new file mode 100644 index 000000000..1794768d4 --- /dev/null +++ b/src/GitHub/public/Organization/Blocking/Get-GitHubOrganizationBlockedUser.ps1 @@ -0,0 +1,45 @@ +function Get-GitHubOrganizationBlockedUser { + <# + .SYNOPSIS + List users blocked by an organization + + .DESCRIPTION + List the users blocked by an organization. + + .EXAMPLE + Get-GitHubOrganizationBlockedUser -OrganizationName 'github' + + Lists all users blocked by the organization `github`. + + .NOTES + 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(Mandatory)] + [Alias('org')] + [Alias('owner')] + [Alias('login')] + [Alias('name')] + [string] $OrganizationName, + + # The number of results per page (max 100). + [Parameter()] + [int] $PerPage = 30 + ) + + $body = @{ + per_page = $PerPage + } + + $inputObject = @{ + APIEndpoint = "/orgs/$OrganizationName/blocks" + Method = 'GET' + Body = $body + } + + Invoke-GitHubAPI @inputObject + +} From fbb7be8e0e5657e430ecef61a74985dbe4a76622 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 30 Sep 2023 08:57:49 +0200 Subject: [PATCH 28/61] Test file updates --- tools/utilities/GitHubAPI.ps1 | 2 +- tools/utilities/Local-Testing.ps1 | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/utilities/GitHubAPI.ps1 b/tools/utilities/GitHubAPI.ps1 index ca02459ff..f8840a4a8 100644 --- a/tools/utilities/GitHubAPI.ps1 +++ b/tools/utilities/GitHubAPI.ps1 @@ -21,7 +21,7 @@ $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 = '/users/{username}/orgs' +$path = '/orgs/{org}/blocks/{username}' $method = 'get' $response.paths.$path.$method $response.paths.$path.$method.tags | clip # -> Namespace/foldername diff --git a/tools/utilities/Local-Testing.ps1 b/tools/utilities/Local-Testing.ps1 index 6d258e1c1..70750413d 100644 --- a/tools/utilities/Local-Testing.ps1 +++ b/tools/utilities/Local-Testing.ps1 @@ -43,3 +43,5 @@ Get-GitHubOrganizationAppInstallation -OrganizationName 'PSModule' Set-GitHubOrganization -OrganizationName 'PSModule' -Blog 'https://www.psmodule.io' Set-GitHubOrganization -OrganizationName 'PSModule' -Blog '' Set-GitHubOrganization -OrganizationName 'PSModule' -Blog ' ' + +Set-GitHubOrganization -OrganizationName 'PSModule' -Company 'PSModule' -DefaultRepositoryPermission read From 4260f3e00ee0326838a4a87998e7ed6dc0486157 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 30 Sep 2023 11:51:31 +0200 Subject: [PATCH 29/61] Add statusCode + responseheaders to return Restructure querystring --- .../Utilities/Web/ConvertTo-QueryString.ps1 | 50 +++++++++++++++++++ src/GitHub/public/API/Invoke-GitHubAPI.ps1 | 25 +++++----- 2 files changed, 63 insertions(+), 12 deletions(-) create mode 100644 src/GitHub/private/Utilities/Web/ConvertTo-QueryString.ps1 diff --git a/src/GitHub/private/Utilities/Web/ConvertTo-QueryString.ps1 b/src/GitHub/private/Utilities/Web/ConvertTo-QueryString.ps1 new file mode 100644 index 000000000..b7300a612 --- /dev/null +++ b/src/GitHub/private/Utilities/Web/ConvertTo-QueryString.ps1 @@ -0,0 +1,50 @@ +function ConvertTo-QueryString { + <# + .SYNOPSIS + Convert an object to a query string + + .DESCRIPTION + Convert an object to a query string + + .EXAMPLE + ConvertTo-QueryString -InputObject @{a=1;b=2} + + ?a=1&b=2 + + .EXAMPLE + ConvertTo-QueryString -InputObject @{a='this is value of a';b='valueOfB'} + + ?a=this%20is%20value%20of%20a&b=valueOfB + + .EXAMPLE + ConvertTo-QueryString -InputObject @{a='this is value of a';b='valueOfB'} -AsURLEncoded + + ?a=this+is+value+of+a&b=valueOfB + #> + [OutputType([string])] + [CmdletBinding()] + param( + [Parameter( + Mandatory, + ValueFromPipeline + )] + [object] $InputObject, + + [Parameter()] + [switch] $AsURLEncoded + ) + + if ($InputObject -isnot [hashtable]) { + $InputObject = $InputObject | ConvertTo-HashTable + } + + $parameters = if ($AsURLEncoded) { + ($InputObject.GetEnumerator() | ForEach-Object { "$([System.Web.HttpUtility]::UrlEncode($_.Key))=$([System.Web.HttpUtility]::UrlEncode($_.Value))" }) -join '&' + } else { + ($InputObject.GetEnumerator() | ForEach-Object { "$([System.Uri]::EscapeDataString($_.Key))=$([System.Uri]::EscapeDataString($_.Value))" }) -join '&' + } + + if ($parameters) { + '?' + $parameters + } +} diff --git a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 index 10c207d1d..c668f145a 100644 --- a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 +++ b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 @@ -106,8 +106,8 @@ ContentType = $ContentType HttpVersion = $HttpVersion FollowRelLink = $FollowRelLink - StatusCodeVariable = 'StatusCode' - ResponseHeadersVariable = 'ResponseHeaders' + StatusCodeVariable = 'APICallStatusCode' + ResponseHeadersVariable = 'APICallResponseHeaders' } $APICall | Remove-HashTableEntries -NullOrEmptyValues @@ -119,12 +119,11 @@ # Use body to create the query string for GET requests if ($Method -eq 'GET') { - $queryParams = ($Body.GetEnumerator() | - ForEach-Object { "$([System.Web.HttpUtility]::UrlEncode($_.Key))=$([System.Web.HttpUtility]::UrlEncode($_.Value))" }) -join '&' - if ($queryParams) { - $APICall.Uri = $APICall.Uri + '?' + $queryParams - } + $queryString = $Body = ConvertTo-QueryString + $APICall.Uri = $APICall.Uri + $queryString } + + # Use body to create the form data if ($Body -is [string]) { $APICall.Body = $Body } else { @@ -134,13 +133,15 @@ try { Invoke-RestMethod @APICall | ForEach-Object { - # Add the StatusCode and ResponseHeaders to the output - $_ | Add-Member -MemberType NoteProperty -Name StatusCode -Value $StatusCode -PassThru - $_ | Add-Member -MemberType NoteProperty -Name ResponseHeaders -Value $ResponseHeaders -PassThru + $APICallResponseHeaders = $APICallResponseHeaders | ConvertTo-Json -Depth 100 | ConvertFrom-Json + $_ | Add-Member -MemberType NoteProperty -Name ResponseHeaders -Value $APICallResponseHeaders -Force + + $APICallStatusCode = $APICallStatusCode | ConvertTo-Json -Depth 100 | ConvertFrom-Json + $_ | Add-Member -MemberType NoteProperty -Name StatusCode -Value $APICallStatusCode -Force + + $_ } | Write-Output - Write-Verbose ($StatusCode | Format-List | Out-String) - Write-Verbose ($responseHeaders | Format-List | Out-String) } catch { Write-Error "[$functionName] - Status code - [$StatusCode]" $err = $_ | ConvertFrom-Json -Depth 10 From 212f7d2f17f877fb9f063915161e2ef86430afd8 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 30 Sep 2023 11:56:50 +0200 Subject: [PATCH 30/61] remove write outputs --- src/GitHub/private/Menu/Invoke-Meny.ps1 | 2 +- src/GitHub/public/API/Invoke-GitHubAPI.ps1 | 9 ++++++--- src/GitHub/public/Actions/Get-GitHubWorkflow.ps1 | 2 +- src/GitHub/public/Actions/Get-GitHubWorkflowRun.ps1 | 2 +- src/GitHub/public/Actions/Get-GitHubWorkflowUsage.ps1 | 2 +- .../Get-GitHubOrganizationAppInstallation.ps1 | 2 +- 6 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/GitHub/private/Menu/Invoke-Meny.ps1 b/src/GitHub/private/Menu/Invoke-Meny.ps1 index dcdbe6091..caab756fc 100644 --- a/src/GitHub/private/Menu/Invoke-Meny.ps1 +++ b/src/GitHub/private/Menu/Invoke-Meny.ps1 @@ -18,7 +18,7 @@ if ($pos -ge $menuItems.length) { $pos = $menuItems.length - 1 } Invoke-DrawMenu $menuItems $pos $menuTitel } - Write-Output $($menuItems[$pos]) + $($menuItems[$pos]) } diff --git a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 index c668f145a..721524674 100644 --- a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 +++ b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 @@ -140,12 +140,15 @@ $_ | Add-Member -MemberType NoteProperty -Name StatusCode -Value $APICallStatusCode -Force $_ - } | Write-Output - + } } catch { - Write-Error "[$functionName] - Status code - [$StatusCode]" + Write-Error "[$functionName] - Status code - [$APICallStatusCode]" $err = $_ | ConvertFrom-Json -Depth 10 Write-Error "[$functionName] - $($err.Message)" Write-Error "[$functionName] - For more info please see: [$($err.documentation_url)]" + $APICallResponseHeaders.GetEnumerator() | ForEach-Object { + Write-Error "[$functionName] - $($_.Key): $($_.Value)" + } + return 1 } } diff --git a/src/GitHub/public/Actions/Get-GitHubWorkflow.ps1 b/src/GitHub/public/Actions/Get-GitHubWorkflow.ps1 index 87b3698e5..ae8e9523c 100644 --- a/src/GitHub/public/Actions/Get-GitHubWorkflow.ps1 +++ b/src/GitHub/public/Actions/Get-GitHubWorkflow.ps1 @@ -53,7 +53,7 @@ Body = $body } - Invoke-GitHubAPI @inputObject | Select-Object -ExpandProperty workflows | Write-Output + Invoke-GitHubAPI @inputObject | Select-Object -ExpandProperty workflows } } diff --git a/src/GitHub/public/Actions/Get-GitHubWorkflowRun.ps1 b/src/GitHub/public/Actions/Get-GitHubWorkflowRun.ps1 index cf798b871..e1a4e7c0e 100644 --- a/src/GitHub/public/Actions/Get-GitHubWorkflowRun.ps1 +++ b/src/GitHub/public/Actions/Get-GitHubWorkflowRun.ps1 @@ -46,7 +46,7 @@ Body = $body } - Invoke-GitHubAPI @inputObject | Select-Object -ExpandProperty workflow_runs | Write-Output + Invoke-GitHubAPI @inputObject | Select-Object -ExpandProperty workflow_runs } diff --git a/src/GitHub/public/Actions/Get-GitHubWorkflowUsage.ps1 b/src/GitHub/public/Actions/Get-GitHubWorkflowUsage.ps1 index 4ca08c6ec..8e8ec94af 100644 --- a/src/GitHub/public/Actions/Get-GitHubWorkflowUsage.ps1 +++ b/src/GitHub/public/Actions/Get-GitHubWorkflowUsage.ps1 @@ -47,7 +47,7 @@ APIEndpoint = "/repos/$Owner/$Repo/actions/workflows/$ID/timing" } - Invoke-GitHubAPI @inputObject | Select-Object -ExpandProperty billable | Write-Output + Invoke-GitHubAPI @inputObject | Select-Object -ExpandProperty billable } diff --git a/src/GitHub/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 b/src/GitHub/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 index 293004c8a..405458eb3 100644 --- a/src/GitHub/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 +++ b/src/GitHub/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 @@ -41,6 +41,6 @@ Body = $body } - Invoke-GitHubAPI @inputObject | Select-Object -ExpandProperty 'installations' | Write-Output + Invoke-GitHubAPI @inputObject | Select-Object -ExpandProperty 'installations' } From c1632fbd9bca17a5f84148f004030d6c66b04641 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 30 Sep 2023 12:41:24 +0200 Subject: [PATCH 31/61] TODO add sorting on get-config --- src/GitHub/public/Config/Get-GitHubConfig.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/src/GitHub/public/Config/Get-GitHubConfig.ps1 b/src/GitHub/public/Config/Get-GitHubConfig.ps1 index a279f7989..405d0b15b 100644 --- a/src/GitHub/public/Config/Get-GitHubConfig.ps1 +++ b/src/GitHub/public/Config/Get-GitHubConfig.ps1 @@ -54,6 +54,7 @@ $metadata.$Name } else { $metadata + # TODO: Fix sorting } } } From b804059e8be4ed2207829f9c83097a816289430f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 30 Sep 2023 12:41:54 +0200 Subject: [PATCH 32/61] Troubleshoot statuscode and responseheaders --- src/GitHub/public/API/Invoke-GitHubAPI.ps1 | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 index 721524674..311a40585 100644 --- a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 +++ b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 @@ -110,6 +110,8 @@ ResponseHeadersVariable = 'APICallResponseHeaders' } $APICall | Remove-HashTableEntries -NullOrEmptyValues + $APICallStatusCode = $null + $APICallResponseHeaders = $null if ($Body) { @@ -119,7 +121,7 @@ # Use body to create the query string for GET requests if ($Method -eq 'GET') { - $queryString = $Body = ConvertTo-QueryString + $queryString = $Body | ConvertTo-QueryString $APICall.Uri = $APICall.Uri + $queryString } @@ -133,20 +135,26 @@ try { Invoke-RestMethod @APICall | ForEach-Object { + $APICallStatusCode = $APICallStatusCode | ConvertTo-Json -Depth 100 | ConvertFrom-Json $APICallResponseHeaders = $APICallResponseHeaders | ConvertTo-Json -Depth 100 | ConvertFrom-Json - $_ | Add-Member -MemberType NoteProperty -Name ResponseHeaders -Value $APICallResponseHeaders -Force - $APICallStatusCode = $APICallStatusCode | ConvertTo-Json -Depth 100 | ConvertFrom-Json - $_ | Add-Member -MemberType NoteProperty -Name StatusCode -Value $APICallStatusCode -Force + Write-Verbose "[$functionName] - Status code - [$APICallStatusCode]" + Write-Verbose "[$functionName] - Response headers:" + $APICallResponseHeaders.PSObject.Properties | ForEach-Object { + Write-Verbose "[$functionName] - $($_.Key): $($_.Value)" + } - $_ + (@{ + StatusCode = $APICallStatusCode + ResponseHeaders = $APICallResponseHeaders + } + ($_ | ConvertTo-HashTable) | ConvertFrom-HashTable) } } catch { Write-Error "[$functionName] - Status code - [$APICallStatusCode]" $err = $_ | ConvertFrom-Json -Depth 10 Write-Error "[$functionName] - $($err.Message)" Write-Error "[$functionName] - For more info please see: [$($err.documentation_url)]" - $APICallResponseHeaders.GetEnumerator() | ForEach-Object { + $APICallResponseHeaders.PSObject.Properties | ForEach-Object { Write-Error "[$functionName] - $($_.Key): $($_.Value)" } return 1 From 6517f15c0dc00b3aa4d9e390e962cdc12c6837fc Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 30 Sep 2023 12:42:21 +0200 Subject: [PATCH 33/61] Add new hashtable and object functions --- .../Utilities/ConvertFrom-HashTable.ps1 | 35 ++++++- .../private/Utilities/ConvertTo-HashTable.ps1 | 45 +++++++-- .../private/Utilities/Join-Hashtable.ps1 | 12 +++ src/GitHub/private/Utilities/Join-Object.ps1 | 94 +++++++++++++++++++ 4 files changed, 177 insertions(+), 9 deletions(-) create mode 100644 src/GitHub/private/Utilities/Join-Object.ps1 diff --git a/src/GitHub/private/Utilities/ConvertFrom-HashTable.ps1 b/src/GitHub/private/Utilities/ConvertFrom-HashTable.ps1 index 567e8a276..f3bb4b118 100644 --- a/src/GitHub/private/Utilities/ConvertFrom-HashTable.ps1 +++ b/src/GitHub/private/Utilities/ConvertFrom-HashTable.ps1 @@ -1,11 +1,44 @@ function ConvertFrom-HashTable { + <# + .SYNOPSIS + Converts a hashtable to a pscustomobject + + .DESCRIPTION + This function converts a hashtable to a pscustomobject. + + .EXAMPLE + $object = @{a = 1;b = 2;c = 3} + $object | ConvertFrom-HashTable | Format-Table + + a b c + - - - + 1 2 3 + + Converts the hashtable to a pscustomobject and displays it in a table. + + .EXAMPLE + $object = @{a = 1;b = 2;c = 3} + $object | ConvertFrom-Dictionary | ConvertTo-Json + + { + "a": 1, + "b": 2, + "c": 3 + } + + Converts the hashtable to a pscustomobject and then to JSON. + Using the alias 'ConvertFrom-Dictionary' instead of 'ConvertFrom-HashTable'. + #> + [OutputType([pscustomobject])] + [Alias('ConvertFrom-Dictionary')] [CmdletBinding()] param ( + # The hashtable to be converted. The input takes any type of dictionary. The original dictionary is not modified. [Parameter( Mandatory, ValueFromPipeline )] [object]$InputObject ) - ([pscustomobject](@{} + $InputObject)) + $InputObject | ConvertTo-Json -Depth 100 | ConvertFrom-Json } diff --git a/src/GitHub/private/Utilities/ConvertTo-HashTable.ps1 b/src/GitHub/private/Utilities/ConvertTo-HashTable.ps1 index c750d5f45..6ae4238ab 100644 --- a/src/GitHub/private/Utilities/ConvertTo-HashTable.ps1 +++ b/src/GitHub/private/Utilities/ConvertTo-HashTable.ps1 @@ -1,17 +1,46 @@ function ConvertTo-HashTable { + <# + .SYNOPSIS + Converts an object to a hashtable + + .DESCRIPTION + This function converts an object to a hashtable. + + .EXAMPLE + $object = [pscustomobject]@{a = 1;b = 2;c = 3} + $object | ConvertTo-HashTable | Format-Table + + Name Value + ---- ----- + a 1 + b 2 + c 3 + + Converts the object to a hashtable and displays it in a table. + + .EXAMPLE + $object = [pscustomobject]@{a = 1;b = 2;c = 3} + $object | ConvertTo-Dictionary | ConvertTo-Json + + { + "a": 1, + "b": 2, + "c": 3 + } + + Converts the object to a hashtable and then to JSON. + Using the alias 'ConvertTo-Dictionary' instead of 'ConvertTo-HashTable'. + #> + [OutputType([hashtable])] + [Alias('ConvertTo-Dictionary')] [CmdletBinding()] param ( + # The object to be converted. The input takes any type of object. The original object is not modified. [Parameter( Mandatory, ValueFromPipeline )] - [pscustomobject]$InputObject + [object]$InputObject ) - [hashtable]$hashtable = @{} - - foreach ($item in $InputObject.PSobject.Properties) { - Write-Verbose "$($item.Name) : $($item.Value) : $($item.TypeNameOfValue)" - $hashtable.$($item.Name) = $item.Value - } - $hashtable + $InputObject | ConvertTo-Json -Depth 100 | ConvertFrom-Json -AsHashtable } diff --git a/src/GitHub/private/Utilities/Join-Hashtable.ps1 b/src/GitHub/private/Utilities/Join-Hashtable.ps1 index b53bedb49..496f33f84 100644 --- a/src/GitHub/private/Utilities/Join-Hashtable.ps1 +++ b/src/GitHub/private/Utilities/Join-Hashtable.ps1 @@ -15,3 +15,15 @@ } $hashtable } + +$object = [pscustomobject]@{ + 'a' = '1' + 'b' = '1' +} + +$hashtable = @{ + 'b' = '2' + 'c' = '2' +} + +Join-HashTable -Main $object -Overrides $hashtable diff --git a/src/GitHub/private/Utilities/Join-Object.ps1 b/src/GitHub/private/Utilities/Join-Object.ps1 new file mode 100644 index 000000000..531a0c244 --- /dev/null +++ b/src/GitHub/private/Utilities/Join-Object.ps1 @@ -0,0 +1,94 @@ +function Join-Object { + <# + .SYNOPSIS + Merges two or more objects into a single object + + .DESCRIPTION + Merges two or more objects into a single object. The first object is the main object, and the remaining objects are overrides. The overrides are applied in order, so the last object in the list will override any previous values. + + .EXAMPLE + $main = [pscustomobject]@{a = 1; b = 2; c = 3} + $overrides = [pscustomobject]@{a = 4; b = 5; d = 6} + $overrides2 = [pscustomobject]@{a = 7; b = 8; e = 9} + Join-Object -Main $main -Overrides $overrides, $overrides2 + + a b c d e + - - - - - + 7 8 3 6 9 + + Merges the three objects into a single object. The values from the last object override the values from the previous objects. + + .EXAMPLE + $main = @{a = 1;b = 2} + $overrides = @{a = 3;c = 4} + Merge-Object -Main $main -Overrides $overrides -AsHashtable + + Name Value + ---- ----- + a 3 + b 2 + c 4 + + Merges the two hashtables into a single hashtable. The values from the last hashtable override the values from the previous hashtables. + Using the alias 'Merge-Object' instead of 'Join-Object'. + + .EXAMPLE + $main = @{a = 1;b = 1;c = 1} + $overrides = @{b = 2;d = 2} + $overrides2 = @{c = 3;e = 3} + $main | Join-Object -Overrides $overrides, $overrides2 | Format-Table + + a b c d e + - - - - - + 1 2 3 2 3 + + Merges the three hashtables into a single hashtable. The values from the last hashtable override the values from the previous hashtables. + Using the pipeline to pass the main object instead of the -Main parameter. + #> + [OutputType([pscustomobject])] + [OutputType(ParameterSetName = 'AsHashTable', [hashtable])] + [Alias('Merge-Object')] + [CmdletBinding(DefaultParameterSetName = '__DefaultSet')] + param ( + # The main object to merge into. This object will be cloned, so the original object will not be modified. + [Parameter( + Mandatory, + ValueFromPipeline + )] + [object] $Main, + + # The objects to merge into the main object + [Parameter(Mandatory)] + [object[]] $Overrides, + + # Return the result as a hashtable instead of a pscustomobject + [Parameter( + Mandatory, + ParameterSetName = 'AsHashTable' + )] + [switch] $AsHashtable + ) + + if ($Main -isnot [hashtable]) { + $Main = $Main | ConvertTo-HashTable + } + $hashtable = $Main.clone() + + foreach ($Override in $Overrides) { + if ($Override -isnot [hashtable]) { + $Override = $Override | ConvertTo-HashTable + } + + $Override.Keys | ForEach-Object { + $hashtable[$_] = $Override[$_] + } + } + + if ($AsHashtable) { + return $hashtable + } + + $hashtable | ConvertFrom-HashTable +} + +Join-Object -Main $object -Overrides $hashtable From 9de3991d3f5dc1669f4042f77d258c3bd2b43581 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 30 Sep 2023 12:47:06 +0200 Subject: [PATCH 34/61] Remove Join-Hashtable using Join-Object -AsHashtable --- .../private/Utilities/Join-Hashtable.ps1 | 29 ------------------- src/GitHub/private/Utilities/Join-Object.ps1 | 2 -- src/GitHub/public/Config/Get-GitHubConfig.ps1 | 2 +- src/GitHub/public/Config/Set-GitHubConfig.ps1 | 8 ++--- 4 files changed, 5 insertions(+), 36 deletions(-) delete mode 100644 src/GitHub/private/Utilities/Join-Hashtable.ps1 diff --git a/src/GitHub/private/Utilities/Join-Hashtable.ps1 b/src/GitHub/private/Utilities/Join-Hashtable.ps1 deleted file mode 100644 index 496f33f84..000000000 --- a/src/GitHub/private/Utilities/Join-Hashtable.ps1 +++ /dev/null @@ -1,29 +0,0 @@ -function Join-Hashtable { - [OutputType([void])] - [Alias('Merge-HashTable')] - [CmdletBinding()] - param ( - [hashtable] $Main, - [hashtable] $Overrides - ) - $hashtable = @{} - $Main.Keys | ForEach-Object { - $hashtable[$_] = $Main[$_] - } - $Overrides.Keys | ForEach-Object { - $hashtable[$_] = $Overrides[$_] - } - $hashtable -} - -$object = [pscustomobject]@{ - 'a' = '1' - 'b' = '1' -} - -$hashtable = @{ - 'b' = '2' - 'c' = '2' -} - -Join-HashTable -Main $object -Overrides $hashtable diff --git a/src/GitHub/private/Utilities/Join-Object.ps1 b/src/GitHub/private/Utilities/Join-Object.ps1 index 531a0c244..f29487bcf 100644 --- a/src/GitHub/private/Utilities/Join-Object.ps1 +++ b/src/GitHub/private/Utilities/Join-Object.ps1 @@ -90,5 +90,3 @@ $hashtable | ConvertFrom-HashTable } - -Join-Object -Main $object -Overrides $hashtable diff --git a/src/GitHub/public/Config/Get-GitHubConfig.ps1 b/src/GitHub/public/Config/Get-GitHubConfig.ps1 index 405d0b15b..a0bf05ab7 100644 --- a/src/GitHub/public/Config/Get-GitHubConfig.ps1 +++ b/src/GitHub/public/Config/Get-GitHubConfig.ps1 @@ -40,7 +40,7 @@ $RefreshTokenData = (Get-SecretInfo -Name "$prefix`RefreshToken").Metadata | ConvertFrom-HashTable | ConvertTo-HashTable $AccessTokenData = (Get-SecretInfo -Name "$prefix`AccessToken").Metadata | ConvertFrom-HashTable | ConvertTo-HashTable - $metadata = Join-Hashtable -Main $RefreshTokenData -Overrides $AccessTokenData + $metadata = Join-Object -Main $RefreshTokenData -Overrides $AccessTokenData -AsHashtable switch($Name) { 'AccessToken' { diff --git a/src/GitHub/public/Config/Set-GitHubConfig.ps1 b/src/GitHub/public/Config/Set-GitHubConfig.ps1 index ab215ef15..4f23a7b7a 100644 --- a/src/GitHub/public/Config/Set-GitHubConfig.ps1 +++ b/src/GitHub/public/Config/Set-GitHubConfig.ps1 @@ -89,7 +89,7 @@ $secretInfo = Get-SecretInfo @secretGetInfoParam Write-Verbose "$secretName - secretInfo : $($secretInfo | Out-String)" $secretMetadata = $secretInfo.Metadata | ConvertFrom-HashTable | ConvertTo-HashTable - $newSecretMetadata = Join-Hashtable -Main $newSecretMetadata -Overrides $secretMetadata + $newSecretMetadata = Join-Object -Main $newSecretMetadata -Overrides $secretMetadata -AsHashtable } # Get metadata updates from parameters and clean up unwanted data @@ -99,7 +99,7 @@ Remove-HashTableEntries -Hashtable $updateSecretMetadata -KeepTypes $keepTypes -RemoveNames $removeKeys Write-Verbose "updateSecretMetadata : $($updateSecretMetadata | Out-String)" - $newSecretMetadata = Join-HashTable -Main $newSecretMetadata -Overrides $updateSecretMetadata + $newSecretMetadata = Join-Object -Main $newSecretMetadata -Overrides $updateSecretMetadata -AsHashtable Write-Verbose "newSecretMetadata : $($newSecretMetadata | Out-String)" Write-Verbose "newSecretMetadataType : $($newSecretMetadata.GetType())" @@ -136,7 +136,7 @@ $secretInfo = Get-SecretInfo @secretGetInfoParam Write-Verbose "$secretName - secretInfo : $($secretInfo | Out-String)" $secretMetadata = $secretInfo.Metadata | ConvertFrom-HashTable | ConvertTo-HashTable - $newSecretMetadata = Join-Hashtable -Main $newSecretMetadata -Overrides $secretMetadata + $newSecretMetadata = Join-Object -Main $newSecretMetadata -Overrides $secretMetadata -AsHashtable } # Get metadata updates from parameters and clean up unwanted data @@ -146,7 +146,7 @@ Remove-HashTableEntries -Hashtable $updateSecretMetadata -KeepTypes $keepTypes -RemoveNames $removeKeys Write-Verbose "updateSecretMetadata : $($updateSecretMetadata | Out-String)" - $newSecretMetadata = Join-HashTable -Main $newSecretMetadata -Overrides $updateSecretMetadata + $newSecretMetadata = Join-Object -Main $newSecretMetadata -Overrides $updateSecretMetadata -AsHashtable Write-Verbose "newSecretMetadata : $($newSecretMetadata | Out-String)" Write-Verbose "newSecretMetadataType : $($newSecretMetadata.GetType())" From 4c58ce8e291d970d1b438ee9816cfbf2a0369f9e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 30 Sep 2023 13:05:42 +0200 Subject: [PATCH 35/61] Fixes for ghorg --- .../Get-GitHubOrganizationByName.ps1 | 3 +- src/GitHub/public/API/Invoke-GitHubAPI.ps1 | 34 +++++++++++-------- .../Organization/Get-GitHubOrganization.ps1 | 3 +- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/GitHub/private/Organization/Get-GitHubOrganizationByName.ps1 b/src/GitHub/private/Organization/Get-GitHubOrganizationByName.ps1 index 0fdbc14b8..338017fd4 100644 --- a/src/GitHub/private/Organization/Get-GitHubOrganizationByName.ps1 +++ b/src/GitHub/private/Organization/Get-GitHubOrganizationByName.ps1 @@ -25,10 +25,9 @@ ValueFromPipeline, ValueFromPipelineByPropertyName )] + [Alias('login')] [Alias('org')] [Alias('owner')] - [Alias('name')] - [Alias('login')] [string] $OrganizationName ) diff --git a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 index 311a40585..fbf3893c3 100644 --- a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 +++ b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 @@ -134,21 +134,25 @@ } try { - Invoke-RestMethod @APICall | ForEach-Object { - $APICallStatusCode = $APICallStatusCode | ConvertTo-Json -Depth 100 | ConvertFrom-Json - $APICallResponseHeaders = $APICallResponseHeaders | ConvertTo-Json -Depth 100 | ConvertFrom-Json - - Write-Verbose "[$functionName] - Status code - [$APICallStatusCode]" - Write-Verbose "[$functionName] - Response headers:" - $APICallResponseHeaders.PSObject.Properties | ForEach-Object { - Write-Verbose "[$functionName] - $($_.Key): $($_.Value)" - } - - (@{ - StatusCode = $APICallStatusCode - ResponseHeaders = $APICallResponseHeaders - } + ($_ | ConvertTo-HashTable) | ConvertFrom-HashTable) - } + Invoke-RestMethod @APICall | Write-Output + # | ForEach-Object { + # $APICallStatusCode + # $APICallResponseHeaders + # # $APICallStatusCode = $APICallStatusCode | ConvertTo-Json -Depth 100 | ConvertFrom-Json + # # $APICallResponseHeaders = $APICallResponseHeaders | ConvertTo-Json -Depth 100 | ConvertFrom-Json + + # # Write-Verbose "[$functionName] - Status code - [$APICallStatusCode]" + # # Write-Verbose "[$functionName] - Response headers:" + # # $APICallResponseHeaders.PSObject.Properties | ForEach-Object { + # # Write-Verbose "[$functionName] - $($_.Key): $($_.Value)" + # # } + + # # (@{ + # # StatusCode = $APICallStatusCode + # # ResponseHeaders = $APICallResponseHeaders + # # } + ($_ | ConvertTo-HashTable) | ConvertFrom-HashTable) + # $_ + # } } catch { Write-Error "[$functionName] - Status code - [$APICallStatusCode]" $err = $_ | ConvertFrom-Json -Depth 10 diff --git a/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 b/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 index 3a2c06c8a..e6bd03961 100644 --- a/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 +++ b/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 @@ -40,10 +40,9 @@ Mandatory, ParameterSetName = 'NamedOrg' )] + [Alias('login')] [Alias('org')] [Alias('owner')] - [Alias('login')] - [Alias('name')] [string] $OrganizationName, # The handle for the GitHub user account. From 09f45a99b9ca273933da7cf12f9c27fc90c1a842 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 30 Sep 2023 13:17:40 +0200 Subject: [PATCH 36/61] Fix streaming --- src/GitHub/public/API/Invoke-GitHubAPI.ps1 | 2 -- src/GitHub/public/Actions/Get-GitHubWorkflow.ps1 | 2 +- src/GitHub/public/Actions/Get-GitHubWorkflowRun.ps1 | 2 +- src/GitHub/public/Actions/Get-GitHubWorkflowUsage.ps1 | 2 +- .../Organization/Get-GitHubOrganizationAppInstallation.ps1 | 2 +- 5 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 index fbf3893c3..8c54ed841 100644 --- a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 +++ b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 @@ -110,8 +110,6 @@ ResponseHeadersVariable = 'APICallResponseHeaders' } $APICall | Remove-HashTableEntries -NullOrEmptyValues - $APICallStatusCode = $null - $APICallResponseHeaders = $null if ($Body) { diff --git a/src/GitHub/public/Actions/Get-GitHubWorkflow.ps1 b/src/GitHub/public/Actions/Get-GitHubWorkflow.ps1 index ae8e9523c..87f23f313 100644 --- a/src/GitHub/public/Actions/Get-GitHubWorkflow.ps1 +++ b/src/GitHub/public/Actions/Get-GitHubWorkflow.ps1 @@ -53,7 +53,7 @@ Body = $body } - Invoke-GitHubAPI @inputObject | Select-Object -ExpandProperty workflows + (Invoke-GitHubAPI @inputObject).workflows } } diff --git a/src/GitHub/public/Actions/Get-GitHubWorkflowRun.ps1 b/src/GitHub/public/Actions/Get-GitHubWorkflowRun.ps1 index e1a4e7c0e..9da8c083f 100644 --- a/src/GitHub/public/Actions/Get-GitHubWorkflowRun.ps1 +++ b/src/GitHub/public/Actions/Get-GitHubWorkflowRun.ps1 @@ -46,7 +46,7 @@ Body = $body } - Invoke-GitHubAPI @inputObject | Select-Object -ExpandProperty workflow_runs + (Invoke-GitHubAPI @inputObject).workflow_runs } diff --git a/src/GitHub/public/Actions/Get-GitHubWorkflowUsage.ps1 b/src/GitHub/public/Actions/Get-GitHubWorkflowUsage.ps1 index 8e8ec94af..07c77126a 100644 --- a/src/GitHub/public/Actions/Get-GitHubWorkflowUsage.ps1 +++ b/src/GitHub/public/Actions/Get-GitHubWorkflowUsage.ps1 @@ -47,7 +47,7 @@ APIEndpoint = "/repos/$Owner/$Repo/actions/workflows/$ID/timing" } - Invoke-GitHubAPI @inputObject | Select-Object -ExpandProperty billable + (Invoke-GitHubAPI @inputObject).billable } diff --git a/src/GitHub/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 b/src/GitHub/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 index 405458eb3..aa748d4f0 100644 --- a/src/GitHub/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 +++ b/src/GitHub/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 @@ -41,6 +41,6 @@ Body = $body } - Invoke-GitHubAPI @inputObject | Select-Object -ExpandProperty 'installations' + (Invoke-GitHubAPI @inputObject).installations } From 7518e71135348c521b28f5accf03acc526896775 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 30 Sep 2023 13:24:08 +0200 Subject: [PATCH 37/61] Test body as object --- src/GitHub/public/API/Invoke-GitHubAPI.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 index 8c54ed841..6e2a8a96d 100644 --- a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 +++ b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 @@ -124,11 +124,11 @@ } # Use body to create the form data - if ($Body -is [string]) { + # if ($Body -is [string]) { $APICall.Body = $Body - } else { - $APICall.Body = $Body | ConvertTo-Json -Depth 100 - } + # } else { + # $APICall.Body = $Body | ConvertTo-Json -Depth 100 + # } } try { From 8be1070c38db22c4afe3ca91c3c9e789293b0d4c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 30 Sep 2023 13:54:36 +0200 Subject: [PATCH 38/61] fix json output --- src/GitHub/public/API/Invoke-GitHubAPI.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 index 6e2a8a96d..8c54ed841 100644 --- a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 +++ b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 @@ -124,11 +124,11 @@ } # Use body to create the form data - # if ($Body -is [string]) { + if ($Body -is [string]) { $APICall.Body = $Body - # } else { - # $APICall.Body = $Body | ConvertTo-Json -Depth 100 - # } + } else { + $APICall.Body = $Body | ConvertTo-Json -Depth 100 + } } try { From 01daa276ee5171b33fee8687f4a4633e6997de76 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 30 Sep 2023 14:07:20 +0200 Subject: [PATCH 39/61] Add return for statuscode and responseheader --- src/GitHub/public/API/Invoke-GitHubAPI.ps1 | 26 ++++++---------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 index 8c54ed841..7d298002b 100644 --- a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 +++ b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 @@ -132,25 +132,13 @@ } try { - Invoke-RestMethod @APICall | Write-Output - # | ForEach-Object { - # $APICallStatusCode - # $APICallResponseHeaders - # # $APICallStatusCode = $APICallStatusCode | ConvertTo-Json -Depth 100 | ConvertFrom-Json - # # $APICallResponseHeaders = $APICallResponseHeaders | ConvertTo-Json -Depth 100 | ConvertFrom-Json - - # # Write-Verbose "[$functionName] - Status code - [$APICallStatusCode]" - # # Write-Verbose "[$functionName] - Response headers:" - # # $APICallResponseHeaders.PSObject.Properties | ForEach-Object { - # # Write-Verbose "[$functionName] - $($_.Key): $($_.Value)" - # # } - - # # (@{ - # # StatusCode = $APICallStatusCode - # # ResponseHeaders = $APICallResponseHeaders - # # } + ($_ | ConvertTo-HashTable) | ConvertFrom-HashTable) - # $_ - # } + (Invoke-RestMethod @APICall) | ForEach-Object { + $statusCode = $APICallStatusCode | ConvertTo-Json -Depth 100 | ConvertFrom-Json + $responseHeaders = $APICallResponseHeaders | ConvertTo-Json -Depth 100 | ConvertFrom-Json + $_ | Add-Member -NotePropertyName StatusCode -NotePropertyValue $statusCode -Force + $_ | Add-Member -NotePropertyName ResponseHeaders -NotePropertyValue $responseHeaders -Force + $_ | Write-Output + } } catch { Write-Error "[$functionName] - Status code - [$APICallStatusCode]" $err = $_ | ConvertFrom-Json -Depth 10 From 90faf56d50cb54995c28d6afd96cc84fd26d2095 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 30 Sep 2023 15:01:20 +0200 Subject: [PATCH 40/61] Pack response with status and header --- src/GitHub/public/API/Invoke-GitHubAPI.ps1 | 8 +++++--- src/GitHub/public/Actions/Get-GitHubWorkflow.ps1 | 5 ++++- src/GitHub/public/Actions/Get-GitHubWorkflowRun.ps1 | 2 +- src/GitHub/public/Actions/Get-GitHubWorkflowUsage.ps1 | 2 +- src/GitHub/public/Actions/Remove-GitHubWorkflowRun.ps1 | 2 +- src/GitHub/public/Actions/Start-GitHubWorkflow.ps1 | 2 +- .../public/Actions/Start-GitHubWorkflowReRun.ps1 | 2 +- src/GitHub/public/Actions/Stop-GitHubWorkflowRun.ps1 | 2 +- src/GitHub/public/Branches/Get-GitHubRepoBranch.ps1 | 2 +- .../public/Deployments/Get-GitHubEnvironment.ps1 | 2 +- .../Deployments/Get-GitHubEnvironmentSecrets.ps1 | 2 +- .../public/Deployments/Update-GitHubEnvironment.ps1 | 2 +- src/GitHub/public/Emojis/Get-GitHubEmojis.ps1 | 4 ++-- src/GitHub/public/Markdown/Get-GitHubMarkdown.ps1 | 2 +- src/GitHub/public/Markdown/Get-GitHubMarkdownRaw.ps1 | 2 +- src/GitHub/public/Meta/Get-GitHubApiVersions.ps1 | 2 +- src/GitHub/public/Meta/Get-GitHubMeta.ps1 | 2 +- src/GitHub/public/Meta/Get-GitHubOctocat.ps1 | 2 +- src/GitHub/public/Meta/Get-GitHubRoot.ps1 | 2 +- src/GitHub/public/Meta/Get-GitHubZen.ps1 | 2 +- .../Blocking/Assert-GitHubOrganizationBlockedUser.ps1 | 10 ++++++++-- .../Blocking/Get-GitHubOrganizationBlockedUser.ps1 | 2 +- .../Get-GitHubOrganizationAppInstallation.ps1 | 2 +- .../public/Organization/Remove-GitHubOrganization.ps1 | 2 +- .../public/Organization/Set-GitHubOrganization.ps1 | 2 +- .../Set-GitHubOrganizationSecurityFeature.ps1 | 2 +- src/GitHub/public/Teams/Get-GitHubRepoTeam.ps1 | 2 +- src/GitHub/public/Users/Get-GitHubUser.ps1 | 2 +- src/GitHub/public/Users/Get-GitHubUserCard.ps1 | 2 +- src/GitHub/public/Users/Get-GitHubUserList.ps1 | 2 +- src/GitHub/public/Users/Set-GitHubUser.ps1 | 2 +- 31 files changed, 46 insertions(+), 35 deletions(-) diff --git a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 index 7d298002b..2fb14251f 100644 --- a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 +++ b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 @@ -135,9 +135,11 @@ (Invoke-RestMethod @APICall) | ForEach-Object { $statusCode = $APICallStatusCode | ConvertTo-Json -Depth 100 | ConvertFrom-Json $responseHeaders = $APICallResponseHeaders | ConvertTo-Json -Depth 100 | ConvertFrom-Json - $_ | Add-Member -NotePropertyName StatusCode -NotePropertyValue $statusCode -Force - $_ | Add-Member -NotePropertyName ResponseHeaders -NotePropertyValue $responseHeaders -Force - $_ | Write-Output + [pscustomobject]@{ + Response = $_ + StatusCode = $statusCode + ResponseHeaders = $responseHeaders + } } } catch { Write-Error "[$functionName] - Status code - [$APICallStatusCode]" diff --git a/src/GitHub/public/Actions/Get-GitHubWorkflow.ps1 b/src/GitHub/public/Actions/Get-GitHubWorkflow.ps1 index 87f23f313..a6a1fad3d 100644 --- a/src/GitHub/public/Actions/Get-GitHubWorkflow.ps1 +++ b/src/GitHub/public/Actions/Get-GitHubWorkflow.ps1 @@ -53,7 +53,10 @@ Body = $body } - (Invoke-GitHubAPI @inputObject).workflows + (Invoke-GitHubAPI @inputObject).Response.workflows } + + end {} + } diff --git a/src/GitHub/public/Actions/Get-GitHubWorkflowRun.ps1 b/src/GitHub/public/Actions/Get-GitHubWorkflowRun.ps1 index 9da8c083f..e18fae760 100644 --- a/src/GitHub/public/Actions/Get-GitHubWorkflowRun.ps1 +++ b/src/GitHub/public/Actions/Get-GitHubWorkflowRun.ps1 @@ -46,7 +46,7 @@ Body = $body } - (Invoke-GitHubAPI @inputObject).workflow_runs + (Invoke-GitHubAPI @inputObject).Response.workflow_runs } diff --git a/src/GitHub/public/Actions/Get-GitHubWorkflowUsage.ps1 b/src/GitHub/public/Actions/Get-GitHubWorkflowUsage.ps1 index 07c77126a..480a5cfb3 100644 --- a/src/GitHub/public/Actions/Get-GitHubWorkflowUsage.ps1 +++ b/src/GitHub/public/Actions/Get-GitHubWorkflowUsage.ps1 @@ -47,7 +47,7 @@ APIEndpoint = "/repos/$Owner/$Repo/actions/workflows/$ID/timing" } - (Invoke-GitHubAPI @inputObject).billable + (Invoke-GitHubAPI @inputObject).Response.billable } diff --git a/src/GitHub/public/Actions/Remove-GitHubWorkflowRun.ps1 b/src/GitHub/public/Actions/Remove-GitHubWorkflowRun.ps1 index 6e1438563..e4418d359 100644 --- a/src/GitHub/public/Actions/Remove-GitHubWorkflowRun.ps1 +++ b/src/GitHub/public/Actions/Remove-GitHubWorkflowRun.ps1 @@ -23,7 +23,7 @@ Method = 'DELETE' } - Invoke-GitHubAPI @inputObject + (Invoke-GitHubAPI @inputObject).Response } diff --git a/src/GitHub/public/Actions/Start-GitHubWorkflow.ps1 b/src/GitHub/public/Actions/Start-GitHubWorkflow.ps1 index 1d1ae9a6b..887beb49e 100644 --- a/src/GitHub/public/Actions/Start-GitHubWorkflow.ps1 +++ b/src/GitHub/public/Actions/Start-GitHubWorkflow.ps1 @@ -58,7 +58,7 @@ Body = $body } - Invoke-GitHubAPI @inputObject + (Invoke-GitHubAPI @inputObject).Response } diff --git a/src/GitHub/public/Actions/Start-GitHubWorkflowReRun.ps1 b/src/GitHub/public/Actions/Start-GitHubWorkflowReRun.ps1 index 3c9ddd66a..55058128d 100644 --- a/src/GitHub/public/Actions/Start-GitHubWorkflowReRun.ps1 +++ b/src/GitHub/public/Actions/Start-GitHubWorkflowReRun.ps1 @@ -46,7 +46,7 @@ APIEndpoint = "/repos/$Owner/$Repo/actions/runs/$ID/rerun" } - Invoke-GitHubAPI @inputObject + (Invoke-GitHubAPI @inputObject).Response } diff --git a/src/GitHub/public/Actions/Stop-GitHubWorkflowRun.ps1 b/src/GitHub/public/Actions/Stop-GitHubWorkflowRun.ps1 index 4821d0737..bdc01f606 100644 --- a/src/GitHub/public/Actions/Stop-GitHubWorkflowRun.ps1 +++ b/src/GitHub/public/Actions/Stop-GitHubWorkflowRun.ps1 @@ -47,7 +47,7 @@ APIEndpoint = "/repos/$Owner/$Repo/actions/runs/$ID/cancel" } - Invoke-GitHubAPI @inputObject + (Invoke-GitHubAPI @inputObject).Response } diff --git a/src/GitHub/public/Branches/Get-GitHubRepoBranch.ps1 b/src/GitHub/public/Branches/Get-GitHubRepoBranch.ps1 index a8691d6af..d410c8e8c 100644 --- a/src/GitHub/public/Branches/Get-GitHubRepoBranch.ps1 +++ b/src/GitHub/public/Branches/Get-GitHubRepoBranch.ps1 @@ -13,6 +13,6 @@ Method = 'GET' } - Invoke-GitHubAPI @inputObject + (Invoke-GitHubAPI @inputObject).Response } diff --git a/src/GitHub/public/Deployments/Get-GitHubEnvironment.ps1 b/src/GitHub/public/Deployments/Get-GitHubEnvironment.ps1 index 15a39c62e..543e95ac6 100644 --- a/src/GitHub/public/Deployments/Get-GitHubEnvironment.ps1 +++ b/src/GitHub/public/Deployments/Get-GitHubEnvironment.ps1 @@ -36,7 +36,7 @@ Method = 'GET' } - Invoke-GitHubAPI @inputObject + (Invoke-GitHubAPI @inputObject).Response } diff --git a/src/GitHub/public/Deployments/Get-GitHubEnvironmentSecrets.ps1 b/src/GitHub/public/Deployments/Get-GitHubEnvironmentSecrets.ps1 index 602e2d922..bab155b1d 100644 --- a/src/GitHub/public/Deployments/Get-GitHubEnvironmentSecrets.ps1 +++ b/src/GitHub/public/Deployments/Get-GitHubEnvironmentSecrets.ps1 @@ -47,7 +47,7 @@ Method = 'GET' } - Invoke-GitHubAPI @inputObject + (Invoke-GitHubAPI @inputObject).Response } end {} diff --git a/src/GitHub/public/Deployments/Update-GitHubEnvironment.ps1 b/src/GitHub/public/Deployments/Update-GitHubEnvironment.ps1 index 25da09436..7bc8a0ad1 100644 --- a/src/GitHub/public/Deployments/Update-GitHubEnvironment.ps1 +++ b/src/GitHub/public/Deployments/Update-GitHubEnvironment.ps1 @@ -34,7 +34,7 @@ Body = $body } - Invoke-GitHubAPI @inputObject + (Invoke-GitHubAPI @inputObject).Response } diff --git a/src/GitHub/public/Emojis/Get-GitHubEmojis.ps1 b/src/GitHub/public/Emojis/Get-GitHubEmojis.ps1 index b90763bc8..d159980cf 100644 --- a/src/GitHub/public/Emojis/Get-GitHubEmojis.ps1 +++ b/src/GitHub/public/Emojis/Get-GitHubEmojis.ps1 @@ -14,10 +14,10 @@ Method = 'GET' } - $response = Invoke-GitHubAPI @inputObject + $response = (Invoke-GitHubAPI @inputObject).Response if (Test-Path -Path $Destination) { - $response.PSobject.Properties | ForEach-Object -Parallel { + $response.PSObject.Properties | ForEach-Object -Parallel { Invoke-WebRequest -Uri $_.Value -OutFile "$using:Destination/$($_.Name).png" } } else { diff --git a/src/GitHub/public/Markdown/Get-GitHubMarkdown.ps1 b/src/GitHub/public/Markdown/Get-GitHubMarkdown.ps1 index ebcb6ed92..d758e2b16 100644 --- a/src/GitHub/public/Markdown/Get-GitHubMarkdown.ps1 +++ b/src/GitHub/public/Markdown/Get-GitHubMarkdown.ps1 @@ -28,6 +28,6 @@ Body = $body } - Invoke-GitHubAPI @inputObject + (Invoke-GitHubAPI @inputObject).Response } diff --git a/src/GitHub/public/Markdown/Get-GitHubMarkdownRaw.ps1 b/src/GitHub/public/Markdown/Get-GitHubMarkdownRaw.ps1 index 4316e10a3..cde1d43fb 100644 --- a/src/GitHub/public/Markdown/Get-GitHubMarkdownRaw.ps1 +++ b/src/GitHub/public/Markdown/Get-GitHubMarkdownRaw.ps1 @@ -16,6 +16,6 @@ Method = 'POST' } - Invoke-GitHubAPI @inputObject + (Invoke-GitHubAPI @inputObject).Response } diff --git a/src/GitHub/public/Meta/Get-GitHubApiVersions.ps1 b/src/GitHub/public/Meta/Get-GitHubApiVersions.ps1 index cbb1bc3b6..a18b38313 100644 --- a/src/GitHub/public/Meta/Get-GitHubApiVersions.ps1 +++ b/src/GitHub/public/Meta/Get-GitHubApiVersions.ps1 @@ -23,6 +23,6 @@ Method = 'GET' } - Invoke-GitHubAPI @inputObject + (Invoke-GitHubAPI @inputObject).Response } diff --git a/src/GitHub/public/Meta/Get-GitHubMeta.ps1 b/src/GitHub/public/Meta/Get-GitHubMeta.ps1 index ccc4c9cbf..25dc3e546 100644 --- a/src/GitHub/public/Meta/Get-GitHubMeta.ps1 +++ b/src/GitHub/public/Meta/Get-GitHubMeta.ps1 @@ -29,6 +29,6 @@ Method = 'GET' } - Invoke-GitHubAPI @inputObject + (Invoke-GitHubAPI @inputObject).Response } diff --git a/src/GitHub/public/Meta/Get-GitHubOctocat.ps1 b/src/GitHub/public/Meta/Get-GitHubOctocat.ps1 index 96ce2fa89..6a6558234 100644 --- a/src/GitHub/public/Meta/Get-GitHubOctocat.ps1 +++ b/src/GitHub/public/Meta/Get-GitHubOctocat.ps1 @@ -40,6 +40,6 @@ Body = $body } - Invoke-GitHubAPI @inputObject + (Invoke-GitHubAPI @inputObject).Response } diff --git a/src/GitHub/public/Meta/Get-GitHubRoot.ps1 b/src/GitHub/public/Meta/Get-GitHubRoot.ps1 index c4a52e16a..8a3b9c60e 100644 --- a/src/GitHub/public/Meta/Get-GitHubRoot.ps1 +++ b/src/GitHub/public/Meta/Get-GitHubRoot.ps1 @@ -22,6 +22,6 @@ Method = 'GET' } - Invoke-GitHubAPI @inputObject + (Invoke-GitHubAPI @inputObject).Response } diff --git a/src/GitHub/public/Meta/Get-GitHubZen.ps1 b/src/GitHub/public/Meta/Get-GitHubZen.ps1 index 8ddf4a7e7..b0a973acc 100644 --- a/src/GitHub/public/Meta/Get-GitHubZen.ps1 +++ b/src/GitHub/public/Meta/Get-GitHubZen.ps1 @@ -22,6 +22,6 @@ Method = 'GET' } - Invoke-GitHubAPI @inputObject + (Invoke-GitHubAPI @inputObject).Response } diff --git a/src/GitHub/public/Organization/Blocking/Assert-GitHubOrganizationBlockedUser.ps1 b/src/GitHub/public/Organization/Blocking/Assert-GitHubOrganizationBlockedUser.ps1 index b60f42068..0c3c8ab06 100644 --- a/src/GitHub/public/Organization/Blocking/Assert-GitHubOrganizationBlockedUser.ps1 +++ b/src/GitHub/public/Organization/Blocking/Assert-GitHubOrganizationBlockedUser.ps1 @@ -24,7 +24,6 @@ [Alias('org')] [Alias('owner')] [Alias('login')] - [Alias('name')] [string] $OrganizationName, # The handle for the GitHub user account. @@ -37,6 +36,13 @@ Method = 'GET' } - Invoke-GitHubAPI @inputObject -Verbose + $statusCode = (Invoke-GitHubAPI @inputObject).SatusCode + if ($statusCode -eq 204) { + return $true + } elseif ($statusCode -eq 404) { + return $false + } else { + throw "Unexpected status code: $statusCode" + } } diff --git a/src/GitHub/public/Organization/Blocking/Get-GitHubOrganizationBlockedUser.ps1 b/src/GitHub/public/Organization/Blocking/Get-GitHubOrganizationBlockedUser.ps1 index 1794768d4..2581a6194 100644 --- a/src/GitHub/public/Organization/Blocking/Get-GitHubOrganizationBlockedUser.ps1 +++ b/src/GitHub/public/Organization/Blocking/Get-GitHubOrganizationBlockedUser.ps1 @@ -40,6 +40,6 @@ Body = $body } - Invoke-GitHubAPI @inputObject + (Invoke-GitHubAPI @inputObject).Response } diff --git a/src/GitHub/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 b/src/GitHub/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 index aa748d4f0..f637cb04c 100644 --- a/src/GitHub/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 +++ b/src/GitHub/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 @@ -41,6 +41,6 @@ Body = $body } - (Invoke-GitHubAPI @inputObject).installations + (Invoke-GitHubAPI @inputObject).Response.installations } diff --git a/src/GitHub/public/Organization/Remove-GitHubOrganization.ps1 b/src/GitHub/public/Organization/Remove-GitHubOrganization.ps1 index 25f703f77..846ba146c 100644 --- a/src/GitHub/public/Organization/Remove-GitHubOrganization.ps1 +++ b/src/GitHub/public/Organization/Remove-GitHubOrganization.ps1 @@ -34,6 +34,6 @@ Method = 'DELETE' } - Invoke-GitHubAPI @inputObject + (Invoke-GitHubAPI @inputObject).Response } diff --git a/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 b/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 index 321eac3c7..8a73c80fe 100644 --- a/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 +++ b/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 @@ -230,6 +230,6 @@ Body = $body } - Invoke-GitHubAPI @inputObject + (Invoke-GitHubAPI @inputObject).Response } diff --git a/src/GitHub/public/Organization/Set-GitHubOrganizationSecurityFeature.ps1 b/src/GitHub/public/Organization/Set-GitHubOrganizationSecurityFeature.ps1 index 10e13a0b6..ed58b59bf 100644 --- a/src/GitHub/public/Organization/Set-GitHubOrganizationSecurityFeature.ps1 +++ b/src/GitHub/public/Organization/Set-GitHubOrganizationSecurityFeature.ps1 @@ -61,6 +61,6 @@ Body = $body } - Invoke-GitHubAPI @inputObject + (Invoke-GitHubAPI @inputObject).Response } diff --git a/src/GitHub/public/Teams/Get-GitHubRepoTeam.ps1 b/src/GitHub/public/Teams/Get-GitHubRepoTeam.ps1 index cc3516f1b..2684b0dc9 100644 --- a/src/GitHub/public/Teams/Get-GitHubRepoTeam.ps1 +++ b/src/GitHub/public/Teams/Get-GitHubRepoTeam.ps1 @@ -17,6 +17,6 @@ function Get-GitHubRepoTeam { APIEndpoint = "/repos/$Owner/$Repo/teams" } - Invoke-GitHubAPI @inputObject + (Invoke-GitHubAPI @inputObject).Response } diff --git a/src/GitHub/public/Users/Get-GitHubUser.ps1 b/src/GitHub/public/Users/Get-GitHubUser.ps1 index c1632017c..922574b76 100644 --- a/src/GitHub/public/Users/Get-GitHubUser.ps1 +++ b/src/GitHub/public/Users/Get-GitHubUser.ps1 @@ -25,6 +25,6 @@ Method = 'GET' } - Invoke-GitHubAPI @inputObject + (Invoke-GitHubAPI @inputObject).Response } diff --git a/src/GitHub/public/Users/Get-GitHubUserCard.ps1 b/src/GitHub/public/Users/Get-GitHubUserCard.ps1 index 6617af34e..b71574a13 100644 --- a/src/GitHub/public/Users/Get-GitHubUserCard.ps1 +++ b/src/GitHub/public/Users/Get-GitHubUserCard.ps1 @@ -42,6 +42,6 @@ Body = $body } - Invoke-GitHubAPI @inputObject + (Invoke-GitHubAPI @inputObject).Response } diff --git a/src/GitHub/public/Users/Get-GitHubUserList.ps1 b/src/GitHub/public/Users/Get-GitHubUserList.ps1 index 20f3f8105..be20841bd 100644 --- a/src/GitHub/public/Users/Get-GitHubUserList.ps1 +++ b/src/GitHub/public/Users/Get-GitHubUserList.ps1 @@ -38,6 +38,6 @@ Body = $body } - Invoke-GitHubAPI @inputObject + (Invoke-GitHubAPI @inputObject).Response } diff --git a/src/GitHub/public/Users/Set-GitHubUser.ps1 b/src/GitHub/public/Users/Set-GitHubUser.ps1 index 8a388a937..770b4aab1 100644 --- a/src/GitHub/public/Users/Set-GitHubUser.ps1 +++ b/src/GitHub/public/Users/Set-GitHubUser.ps1 @@ -75,6 +75,6 @@ Method = 'PATCH' } - Invoke-GitHubAPI @inputObject + (Invoke-GitHubAPI @inputObject).Response } From 23ce34ad1df526451e371dd0df2d2c691cd31ea7 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 30 Sep 2023 16:34:28 +0200 Subject: [PATCH 41/61] set all to filter and pass response --- .../Get-GitHubAllOrganization.ps1 | 4 +- .../Organization/Get-GitHubMyOrganization.ps1 | 4 +- .../Get-GitHubOrganizationByName.ps1 | 17 ++--- .../Get-GitHubUserOrganization.ps1 | 4 +- .../Utilities/ConvertFrom-HashTable.ps1 | 2 +- .../private/Utilities/ConvertTo-HashTable.ps1 | 4 +- src/GitHub/private/Utilities/Join-Object.ps1 | 2 +- .../Utilities/Remove-HashTableEntries.ps1 | 7 +- .../Utilities/Web/ConvertTo-QueryString.ps1 | 2 +- src/GitHub/public/API/Invoke-GitHubAPI.ps1 | 18 ++--- .../public/Actions/Disable-GitHubWorkflow.ps1 | 18 ++--- .../public/Actions/Enable-GitHubWorkflow.ps1 | 18 ++--- .../public/Actions/Get-GitHubWorkflow.ps1 | 25 +++---- .../public/Actions/Get-GitHubWorkflowRun.ps1 | 42 +++++------- .../Actions/Get-GitHubWorkflowUsage.ps1 | 19 ++---- .../Actions/Remove-GitHubWorkflowRun.ps1 | 19 ++---- .../public/Actions/Start-GitHubWorkflow.ps1 | 29 ++++---- .../Actions/Start-GitHubWorkflowReRun.ps1 | 19 ++---- .../public/Actions/Stop-GitHubWorkflowRun.ps1 | 18 ++--- .../public/Branches/Get-GitHubRepoBranch.ps1 | 2 +- .../Deployments/Get-GitHubEnvironment.ps1 | 19 ++---- .../Get-GitHubEnvironmentSecrets.ps1 | 21 +++--- .../Deployments/Update-GitHubEnvironment.ps1 | 30 ++++----- src/GitHub/public/Emojis/Get-GitHubEmojis.ps1 | 2 +- .../public/Markdown/Get-GitHubMarkdown.ps1 | 8 ++- .../public/Markdown/Get-GitHubMarkdownRaw.ps1 | 4 +- .../public/Meta/Get-GitHubApiVersions.ps1 | 2 +- src/GitHub/public/Meta/Get-GitHubMeta.ps1 | 2 +- src/GitHub/public/Meta/Get-GitHubOctocat.ps1 | 5 +- src/GitHub/public/Meta/Get-GitHubRoot.ps1 | 2 +- src/GitHub/public/Meta/Get-GitHubZen.ps1 | 2 +- .../Assert-GitHubOrganizationBlockedUser.ps1 | 13 +++- .../Get-GitHubOrganizationBlockedUser.ps1 | 3 +- .../Organization/Get-GitHubOrganization.ps1 | 8 ++- .../Get-GitHubOrganizationAppInstallation.ps1 | 9 ++- .../Remove-GitHubOrganization.ps1 | 9 ++- .../Organization/Set-GitHubOrganization.ps1 | 66 ++++++++++--------- .../Set-GitHubOrganizationSecurityFeature.ps1 | 3 +- .../public/Teams/Get-GitHubRepoTeam.ps1 | 2 +- src/GitHub/public/Users/Get-GitHubUser.ps1 | 2 +- .../public/Users/Get-GitHubUserCard.ps1 | 8 ++- .../public/Users/Get-GitHubUserList.ps1 | 2 +- src/GitHub/public/Users/Set-GitHubUser.ps1 | 2 +- 43 files changed, 220 insertions(+), 277 deletions(-) diff --git a/src/GitHub/private/Organization/Get-GitHubAllOrganization.ps1 b/src/GitHub/private/Organization/Get-GitHubAllOrganization.ps1 index 905e5e559..9448116a1 100644 --- a/src/GitHub/private/Organization/Get-GitHubAllOrganization.ps1 +++ b/src/GitHub/private/Organization/Get-GitHubAllOrganization.ps1 @@ -1,4 +1,4 @@ -function Get-GitHubAllOrganization { +filter Get-GitHubAllOrganization { <# .SYNOPSIS List organizations @@ -40,6 +40,6 @@ Body = $body } - Invoke-GitHubAPI @inputObject + (Invoke-GitHubAPI @inputObject).Response } diff --git a/src/GitHub/private/Organization/Get-GitHubMyOrganization.ps1 b/src/GitHub/private/Organization/Get-GitHubMyOrganization.ps1 index b5321a270..d90f84142 100644 --- a/src/GitHub/private/Organization/Get-GitHubMyOrganization.ps1 +++ b/src/GitHub/private/Organization/Get-GitHubMyOrganization.ps1 @@ -1,4 +1,4 @@ -function Get-GitHubMyOrganization { +filter Get-GitHubMyOrganization { <# .SYNOPSIS List organizations for the authenticated user @@ -36,6 +36,6 @@ Body = $body } - Invoke-GitHubAPI @inputObject + (Invoke-GitHubAPI @inputObject).Response } diff --git a/src/GitHub/private/Organization/Get-GitHubOrganizationByName.ps1 b/src/GitHub/private/Organization/Get-GitHubOrganizationByName.ps1 index 338017fd4..1e7c140fd 100644 --- a/src/GitHub/private/Organization/Get-GitHubOrganizationByName.ps1 +++ b/src/GitHub/private/Organization/Get-GitHubOrganizationByName.ps1 @@ -1,4 +1,4 @@ -function Get-GitHubOrganizationByName { +filter Get-GitHubOrganizationByName { <# .SYNOPSIS Get an organization @@ -31,19 +31,12 @@ [string] $OrganizationName ) - begin {} - - process { - - $inputObject = @{ - APIEndpoint = "/orgs/$OrganizationName" - Method = 'GET' - } - - Invoke-GitHubAPI @inputObject + $inputObject = @{ + APIEndpoint = "/orgs/$OrganizationName" + Method = 'GET' } - end {} + (Invoke-GitHubAPI @inputObject).Response } diff --git a/src/GitHub/private/Organization/Get-GitHubUserOrganization.ps1 b/src/GitHub/private/Organization/Get-GitHubUserOrganization.ps1 index 883c0c6fa..1e815c218 100644 --- a/src/GitHub/private/Organization/Get-GitHubUserOrganization.ps1 +++ b/src/GitHub/private/Organization/Get-GitHubUserOrganization.ps1 @@ -1,4 +1,4 @@ -function Get-GitHubUserOrganization { +filter Get-GitHubUserOrganization { <# .SYNOPSIS List organizations for a user @@ -38,6 +38,6 @@ Body = $body } - Invoke-GitHubAPI @inputObject + (Invoke-GitHubAPI @inputObject).Response } diff --git a/src/GitHub/private/Utilities/ConvertFrom-HashTable.ps1 b/src/GitHub/private/Utilities/ConvertFrom-HashTable.ps1 index f3bb4b118..1db300f69 100644 --- a/src/GitHub/private/Utilities/ConvertFrom-HashTable.ps1 +++ b/src/GitHub/private/Utilities/ConvertFrom-HashTable.ps1 @@ -1,4 +1,4 @@ -function ConvertFrom-HashTable { +filter ConvertFrom-HashTable { <# .SYNOPSIS Converts a hashtable to a pscustomobject diff --git a/src/GitHub/private/Utilities/ConvertTo-HashTable.ps1 b/src/GitHub/private/Utilities/ConvertTo-HashTable.ps1 index 6ae4238ab..7b918881e 100644 --- a/src/GitHub/private/Utilities/ConvertTo-HashTable.ps1 +++ b/src/GitHub/private/Utilities/ConvertTo-HashTable.ps1 @@ -1,4 +1,4 @@ -function ConvertTo-HashTable { +filter ConvertTo-HashTable { <# .SYNOPSIS Converts an object to a hashtable @@ -27,7 +27,7 @@ "b": 2, "c": 3 } - + Converts the object to a hashtable and then to JSON. Using the alias 'ConvertTo-Dictionary' instead of 'ConvertTo-HashTable'. #> diff --git a/src/GitHub/private/Utilities/Join-Object.ps1 b/src/GitHub/private/Utilities/Join-Object.ps1 index f29487bcf..9f4bb4355 100644 --- a/src/GitHub/private/Utilities/Join-Object.ps1 +++ b/src/GitHub/private/Utilities/Join-Object.ps1 @@ -1,4 +1,4 @@ -function Join-Object { +filter Join-Object { <# .SYNOPSIS Merges two or more objects into a single object diff --git a/src/GitHub/private/Utilities/Remove-HashTableEntries.ps1 b/src/GitHub/private/Utilities/Remove-HashTableEntries.ps1 index 3d7a8c411..110bb3ed0 100644 --- a/src/GitHub/private/Utilities/Remove-HashTableEntries.ps1 +++ b/src/GitHub/private/Utilities/Remove-HashTableEntries.ps1 @@ -1,4 +1,4 @@ -function Remove-HashtableEntries { +filter Remove-HashtableEntries { [OutputType([void])] [CmdletBinding()] param ( @@ -7,14 +7,19 @@ ValueFromPipeline )] [hashtable] $Hashtable, + [Parameter()] [switch] $NullOrEmptyValues, + [Parameter()] [string[]] $RemoveTypes, + [Parameter()] [string[]] $RemoveNames, + [Parameter()] [string[]] $KeepTypes, + [Parameter()] [string[]] $KeepNames diff --git a/src/GitHub/private/Utilities/Web/ConvertTo-QueryString.ps1 b/src/GitHub/private/Utilities/Web/ConvertTo-QueryString.ps1 index b7300a612..fed644eef 100644 --- a/src/GitHub/private/Utilities/Web/ConvertTo-QueryString.ps1 +++ b/src/GitHub/private/Utilities/Web/ConvertTo-QueryString.ps1 @@ -1,4 +1,4 @@ -function ConvertTo-QueryString { +filter ConvertTo-QueryString { <# .SYNOPSIS Convert an object to a query string diff --git a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 index 2fb14251f..d6f856911 100644 --- a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 +++ b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 @@ -1,4 +1,4 @@ -function Invoke-GitHubAPI { +filter Invoke-GitHubAPI { <# .SYNOPSIS Calls the GitHub API using the provided parameters. @@ -132,7 +132,7 @@ } try { - (Invoke-RestMethod @APICall) | ForEach-Object { + (Invoke-RestMethod @APICall -ErrorAction SilentlyContinue) | ForEach-Object { $statusCode = $APICallStatusCode | ConvertTo-Json -Depth 100 | ConvertFrom-Json $responseHeaders = $APICallResponseHeaders | ConvertTo-Json -Depth 100 | ConvertFrom-Json [pscustomobject]@{ @@ -143,12 +143,12 @@ } } catch { Write-Error "[$functionName] - Status code - [$APICallStatusCode]" - $err = $_ | ConvertFrom-Json -Depth 10 - Write-Error "[$functionName] - $($err.Message)" - Write-Error "[$functionName] - For more info please see: [$($err.documentation_url)]" - $APICallResponseHeaders.PSObject.Properties | ForEach-Object { - Write-Error "[$functionName] - $($_.Key): $($_.Value)" - } - return 1 + # $err = $_ | ConvertFrom-Json -Depth 10 + # Write-Error "[$functionName] - $($err.Message)" + # Write-Error "[$functionName] - For more info please see: [$($err.documentation_url)]" + # $APICallResponseHeaders.PSObject.Properties | ForEach-Object { + # Write-Error "[$functionName] - $($_.Key): $($_.Value)" + # } + # return 1 } } diff --git a/src/GitHub/public/Actions/Disable-GitHubWorkflow.ps1 b/src/GitHub/public/Actions/Disable-GitHubWorkflow.ps1 index e430c3b64..58a990b83 100644 --- a/src/GitHub/public/Actions/Disable-GitHubWorkflow.ps1 +++ b/src/GitHub/public/Actions/Disable-GitHubWorkflow.ps1 @@ -1,4 +1,4 @@ -Function Disable-GitHubWorkflow { +filter Disable-GitHubWorkflow { <# .NOTES https://docs.github.com/en/rest/reference/actions#disable-a-workflow @@ -18,17 +18,11 @@ [string[]] $ID ) - begin {} - - process { - $inputObject = @{ - APIEndpoint = "/repos/$Owner/$Repo/actions/workflows/$ID/disable" - Method = 'PUT' - } - - Invoke-GitHubAPI @inputObject | Out-Null - + $inputObject = @{ + APIEndpoint = "/repos/$Owner/$Repo/actions/workflows/$ID/disable" + Method = 'PUT' } - end {} + Invoke-GitHubAPI @inputObject | Out-Null + } diff --git a/src/GitHub/public/Actions/Enable-GitHubWorkflow.ps1 b/src/GitHub/public/Actions/Enable-GitHubWorkflow.ps1 index d46c2e569..9fe8b6b2d 100644 --- a/src/GitHub/public/Actions/Enable-GitHubWorkflow.ps1 +++ b/src/GitHub/public/Actions/Enable-GitHubWorkflow.ps1 @@ -1,4 +1,4 @@ -Function Enable-GitHubWorkflow { +filter Enable-GitHubWorkflow { <# .NOTES https://docs.github.com/en/rest/reference/actions#enable-a-workflow @@ -18,17 +18,11 @@ [string[]] $ID ) - begin {} - - process { - $inputObject = @{ - APIEndpoint = "/repos/$Owner/$Repo/actions/workflows/$ID/enable" - Method = 'PUT' - } - - Invoke-GitHubAPI @inputObject | Out-Null - + $inputObject = @{ + APIEndpoint = "/repos/$Owner/$Repo/actions/workflows/$ID/enable" + Method = 'PUT' } - end {} + Invoke-GitHubAPI @inputObject | Out-Null + } diff --git a/src/GitHub/public/Actions/Get-GitHubWorkflow.ps1 b/src/GitHub/public/Actions/Get-GitHubWorkflow.ps1 index a6a1fad3d..70aa401de 100644 --- a/src/GitHub/public/Actions/Get-GitHubWorkflow.ps1 +++ b/src/GitHub/public/Actions/Get-GitHubWorkflow.ps1 @@ -1,4 +1,4 @@ -function Get-GitHubWorkflow { +filter Get-GitHubWorkflow { <# .SYNOPSIS Lists the workflows in a repository. @@ -39,24 +39,17 @@ [int] $PerPage = 30 ) - begin {} - process { - - $body = @{ - per_page = $PerPage - } - - $inputObject = @{ - APIEndpoint = "/repos/$Owner/$Repo/actions/workflows" - Method = 'GET' - Body = $body - } - - (Invoke-GitHubAPI @inputObject).Response.workflows + $body = @{ + per_page = $PerPage + } + $inputObject = @{ + APIEndpoint = "/repos/$Owner/$Repo/actions/workflows" + Method = 'GET' + Body = $body } - end {} + (Invoke-GitHubAPI @inputObject).Response.workflows } diff --git a/src/GitHub/public/Actions/Get-GitHubWorkflowRun.ps1 b/src/GitHub/public/Actions/Get-GitHubWorkflowRun.ps1 index e18fae760..c7b6e26be 100644 --- a/src/GitHub/public/Actions/Get-GitHubWorkflowRun.ps1 +++ b/src/GitHub/public/Actions/Get-GitHubWorkflowRun.ps1 @@ -1,4 +1,4 @@ -Function Get-GitHubWorkflowRun { +filter Get-GitHubWorkflowRun { <# .NOTES https://docs.github.com/en/rest/actions/workflow-runs?apiVersion=2022-11-28#list-workflow-runs-for-a-workflow @@ -22,34 +22,26 @@ [int] $PerPage = 30 ) - begin {} - - process { - - $body = @{ - per_page = $PerPage - } - - if ($Name) { - $ID = (Get-GitHubWorkflow -Owner $Owner -Repo $Repo -Name $Name).id - } - - if ($ID) { - $Uri = "/repos/$Owner/$Repo/actions/workflows/$ID/runs" - } else { - $Uri = "/repos/$Owner/$Repo/actions/runs" - } + $body = @{ + per_page = $PerPage + } - $inputObject = @{ - APIEndpoint = $Uri - Method = 'GET' - Body = $body - } + if ($Name) { + $ID = (Get-GitHubWorkflow -Owner $Owner -Repo $Repo -Name $Name).id + } - (Invoke-GitHubAPI @inputObject).Response.workflow_runs + if ($ID) { + $Uri = "/repos/$Owner/$Repo/actions/workflows/$ID/runs" + } else { + $Uri = "/repos/$Owner/$Repo/actions/runs" + } + $inputObject = @{ + APIEndpoint = $Uri + Method = 'GET' + Body = $body } - end {} + (Invoke-GitHubAPI @inputObject).Response.workflow_runs } diff --git a/src/GitHub/public/Actions/Get-GitHubWorkflowUsage.ps1 b/src/GitHub/public/Actions/Get-GitHubWorkflowUsage.ps1 index 480a5cfb3..030d8ee4e 100644 --- a/src/GitHub/public/Actions/Get-GitHubWorkflowUsage.ps1 +++ b/src/GitHub/public/Actions/Get-GitHubWorkflowUsage.ps1 @@ -1,4 +1,4 @@ -Function Get-GitHubWorkflowUsage { +filter Get-GitHubWorkflowUsage { <# .SYNOPSIS Short description @@ -38,18 +38,11 @@ [string[]] $ID ) - begin {} - - process { - - $inputObject = @{ - Method = 'GET' - APIEndpoint = "/repos/$Owner/$Repo/actions/workflows/$ID/timing" - } - - (Invoke-GitHubAPI @inputObject).Response.billable - + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/repos/$Owner/$Repo/actions/workflows/$ID/timing" } - end {} + (Invoke-GitHubAPI @inputObject).Response.billable + } diff --git a/src/GitHub/public/Actions/Remove-GitHubWorkflowRun.ps1 b/src/GitHub/public/Actions/Remove-GitHubWorkflowRun.ps1 index e4418d359..88fd9d921 100644 --- a/src/GitHub/public/Actions/Remove-GitHubWorkflowRun.ps1 +++ b/src/GitHub/public/Actions/Remove-GitHubWorkflowRun.ps1 @@ -1,4 +1,4 @@ -function Remove-GitHubWorkflowRun { +filter Remove-GitHubWorkflowRun { [CmdletBinding()] param ( [Parameter()] @@ -14,18 +14,11 @@ [string] $ID ) - begin {} - - process { - - $inputObject = @{ - APIEndpoint = "repos/$Owner/$Repo/actions/runs/$ID" - Method = 'DELETE' - } - - (Invoke-GitHubAPI @inputObject).Response - + $inputObject = @{ + APIEndpoint = "repos/$Owner/$Repo/actions/runs/$ID" + Method = 'DELETE' } - end {} + (Invoke-GitHubAPI @inputObject).Response + } diff --git a/src/GitHub/public/Actions/Start-GitHubWorkflow.ps1 b/src/GitHub/public/Actions/Start-GitHubWorkflow.ps1 index 887beb49e..eb19b519e 100644 --- a/src/GitHub/public/Actions/Start-GitHubWorkflow.ps1 +++ b/src/GitHub/public/Actions/Start-GitHubWorkflow.ps1 @@ -1,4 +1,4 @@ -function Start-GitHubWorkflow { +filter Start-GitHubWorkflow { <# .SYNOPSIS Start a workflow run using the workflow's ID. @@ -43,24 +43,17 @@ [hashtable] $Inputs = @{} ) - begin {} - - process { - - $body = @{ - ref = $Ref - inputs = $Inputs - } - - $inputObject = @{ - APIEndpoint = "/repos/$Owner/$Repo/actions/workflows/$ID/dispatches" - Method = 'POST' - Body = $body - } - - (Invoke-GitHubAPI @inputObject).Response + $body = @{ + ref = $Ref + inputs = $Inputs + } + $inputObject = @{ + APIEndpoint = "/repos/$Owner/$Repo/actions/workflows/$ID/dispatches" + Method = 'POST' + Body = $body } - end {} + (Invoke-GitHubAPI @inputObject).Response + } diff --git a/src/GitHub/public/Actions/Start-GitHubWorkflowReRun.ps1 b/src/GitHub/public/Actions/Start-GitHubWorkflowReRun.ps1 index 55058128d..26fde62ca 100644 --- a/src/GitHub/public/Actions/Start-GitHubWorkflowReRun.ps1 +++ b/src/GitHub/public/Actions/Start-GitHubWorkflowReRun.ps1 @@ -1,4 +1,4 @@ -function Start-GitHubWorkflowReRun { +filter Start-GitHubWorkflowReRun { <# .SYNOPSIS Short description @@ -37,18 +37,11 @@ [string] $ID ) - begin {} - - process { - - $inputObject = @{ - Method = 'POST' - APIEndpoint = "/repos/$Owner/$Repo/actions/runs/$ID/rerun" - } - - (Invoke-GitHubAPI @inputObject).Response - + $inputObject = @{ + Method = 'POST' + APIEndpoint = "/repos/$Owner/$Repo/actions/runs/$ID/rerun" } - end {} + (Invoke-GitHubAPI @inputObject).Response + } diff --git a/src/GitHub/public/Actions/Stop-GitHubWorkflowRun.ps1 b/src/GitHub/public/Actions/Stop-GitHubWorkflowRun.ps1 index bdc01f606..5e01d5152 100644 --- a/src/GitHub/public/Actions/Stop-GitHubWorkflowRun.ps1 +++ b/src/GitHub/public/Actions/Stop-GitHubWorkflowRun.ps1 @@ -1,4 +1,4 @@ -function Stop-GitHubWorkflowRun { +filter Stop-GitHubWorkflowRun { <# .SYNOPSIS Short description @@ -38,18 +38,12 @@ [string] $ID ) - begin {} - - process { - - $inputObject = @{ - Method = 'POST' - APIEndpoint = "/repos/$Owner/$Repo/actions/runs/$ID/cancel" - } - - (Invoke-GitHubAPI @inputObject).Response + $inputObject = @{ + Method = 'POST' + APIEndpoint = "/repos/$Owner/$Repo/actions/runs/$ID/cancel" } - end {} + (Invoke-GitHubAPI @inputObject).Response + } diff --git a/src/GitHub/public/Branches/Get-GitHubRepoBranch.ps1 b/src/GitHub/public/Branches/Get-GitHubRepoBranch.ps1 index d410c8e8c..7150c6dad 100644 --- a/src/GitHub/public/Branches/Get-GitHubRepoBranch.ps1 +++ b/src/GitHub/public/Branches/Get-GitHubRepoBranch.ps1 @@ -1,4 +1,4 @@ -function Get-GitHubRepoBranch { +filter Get-GitHubRepoBranch { [CmdletBinding()] param ( [Parameter()] diff --git a/src/GitHub/public/Deployments/Get-GitHubEnvironment.ps1 b/src/GitHub/public/Deployments/Get-GitHubEnvironment.ps1 index 543e95ac6..fe98398ba 100644 --- a/src/GitHub/public/Deployments/Get-GitHubEnvironment.ps1 +++ b/src/GitHub/public/Deployments/Get-GitHubEnvironment.ps1 @@ -1,4 +1,4 @@ -function Get-GitHubEnvironment { +filter Get-GitHubEnvironment { <# .SYNOPSIS Get GitHub environment @@ -27,18 +27,11 @@ [string] $Repo = (Get-GitHubConfig -Name Repo) ) - begin {} - - process { - - $inputObject = @{ - APIEndpoint = "/repos/$Owner/$Repo/environments" - Method = 'GET' - } - - (Invoke-GitHubAPI @inputObject).Response - + $inputObject = @{ + APIEndpoint = "/repos/$Owner/$Repo/environments" + Method = 'GET' } - end {} + (Invoke-GitHubAPI @inputObject).Response + } diff --git a/src/GitHub/public/Deployments/Get-GitHubEnvironmentSecrets.ps1 b/src/GitHub/public/Deployments/Get-GitHubEnvironmentSecrets.ps1 index bab155b1d..9b0fbdf86 100644 --- a/src/GitHub/public/Deployments/Get-GitHubEnvironmentSecrets.ps1 +++ b/src/GitHub/public/Deployments/Get-GitHubEnvironmentSecrets.ps1 @@ -1,4 +1,4 @@ -function Get-GitHubEnvironmentSecrets { +filter Get-GitHubEnvironmentSecrets { <# .SYNOPSIS Get GitHub environment secrets @@ -29,26 +29,21 @@ [Parameter()] [string] $Repo = (Get-GitHubConfig -Name Repo), - [Alias('name')] [Parameter( Mandatory, ValueFromPipelineByPropertyName )] + [Alias('name')] [string] $EnvironmentName ) - begin {} - - process { - $RepoID = (Get-GitHubRepo).id + $RepoID = (Get-GitHubRepo).id - $inputObject = @{ - APIEndpoint = "/repositories/$RepoID/environments/$EnvironmentName/secrets" - Method = 'GET' - } - - (Invoke-GitHubAPI @inputObject).Response + $inputObject = @{ + APIEndpoint = "/repositories/$RepoID/environments/$EnvironmentName/secrets" + Method = 'GET' } - end {} + (Invoke-GitHubAPI @inputObject).Response + } diff --git a/src/GitHub/public/Deployments/Update-GitHubEnvironment.ps1 b/src/GitHub/public/Deployments/Update-GitHubEnvironment.ps1 index 7bc8a0ad1..6b4d3115c 100644 --- a/src/GitHub/public/Deployments/Update-GitHubEnvironment.ps1 +++ b/src/GitHub/public/Deployments/Update-GitHubEnvironment.ps1 @@ -1,4 +1,4 @@ -function Update-GitHubEnvironment { +filter Update-GitHubEnvironment { <# .NOTES https://docs.github.com/en/rest/reference/repos#create-or-update-an-environment @@ -19,24 +19,18 @@ [string] $Name ) - begin {} - - process { - $body = @{ - owner = $Owner - repo = $Repo - environment_name = $Name - } - - $inputObject = @{ - APIEndpoint = "/repos/$Owner/$Repo/environments/$Name" - Method = 'PUT' - Body = $body - } - - (Invoke-GitHubAPI @inputObject).Response + $body = @{ + owner = $Owner + repo = $Repo + environment_name = $Name + } + $inputObject = @{ + APIEndpoint = "/repos/$Owner/$Repo/environments/$Name" + Method = 'PUT' + Body = $body } - end {} + (Invoke-GitHubAPI @inputObject).Response + } diff --git a/src/GitHub/public/Emojis/Get-GitHubEmojis.ps1 b/src/GitHub/public/Emojis/Get-GitHubEmojis.ps1 index d159980cf..5419ec80b 100644 --- a/src/GitHub/public/Emojis/Get-GitHubEmojis.ps1 +++ b/src/GitHub/public/Emojis/Get-GitHubEmojis.ps1 @@ -1,4 +1,4 @@ -function Get-GitHubEmojis { +filter Get-GitHubEmojis { <# .NOTES https://docs.github.com/en/rest/reference/emojis#get-emojis diff --git a/src/GitHub/public/Markdown/Get-GitHubMarkdown.ps1 b/src/GitHub/public/Markdown/Get-GitHubMarkdown.ps1 index d758e2b16..393b4065b 100644 --- a/src/GitHub/public/Markdown/Get-GitHubMarkdown.ps1 +++ b/src/GitHub/public/Markdown/Get-GitHubMarkdown.ps1 @@ -1,11 +1,15 @@ -function Get-GitHubMarkdown { +filter Get-GitHubMarkdown { <# .NOTES https://docs.github.com/en/rest/reference/meta#github-api-root #> [CmdletBinding()] param ( - [Parameter()] + [Parameter( + Mandatory, + ValueFromPipeline, + ValueFromPipelineByPropertyName + )] [switch] $Text, [Parameter()] diff --git a/src/GitHub/public/Markdown/Get-GitHubMarkdownRaw.ps1 b/src/GitHub/public/Markdown/Get-GitHubMarkdownRaw.ps1 index cde1d43fb..d4033d9af 100644 --- a/src/GitHub/public/Markdown/Get-GitHubMarkdownRaw.ps1 +++ b/src/GitHub/public/Markdown/Get-GitHubMarkdownRaw.ps1 @@ -1,4 +1,4 @@ -function Get-GitHubMarkdownRaw { +filter Get-GitHubMarkdownRaw { <# .NOTES https://docs.github.com/en/rest/reference/meta#github-api-root @@ -6,7 +6,7 @@ [CmdletBinding()] param ( [Parameter()] - [switch] $Text + [string] $Text ) $inputObject = @{ diff --git a/src/GitHub/public/Meta/Get-GitHubApiVersions.ps1 b/src/GitHub/public/Meta/Get-GitHubApiVersions.ps1 index a18b38313..20172b44e 100644 --- a/src/GitHub/public/Meta/Get-GitHubApiVersions.ps1 +++ b/src/GitHub/public/Meta/Get-GitHubApiVersions.ps1 @@ -1,4 +1,4 @@ -function Get-GitHubApiVersions { +filter Get-GitHubApiVersions { <# .SYNOPSIS Get all API versions. diff --git a/src/GitHub/public/Meta/Get-GitHubMeta.ps1 b/src/GitHub/public/Meta/Get-GitHubMeta.ps1 index 25dc3e546..0dd7b568e 100644 --- a/src/GitHub/public/Meta/Get-GitHubMeta.ps1 +++ b/src/GitHub/public/Meta/Get-GitHubMeta.ps1 @@ -1,4 +1,4 @@ -function Get-GitHubMeta { +filter Get-GitHubMeta { <# .SYNOPSIS Get GitHub meta information. diff --git a/src/GitHub/public/Meta/Get-GitHubOctocat.ps1 b/src/GitHub/public/Meta/Get-GitHubOctocat.ps1 index 6a6558234..4f9813e99 100644 --- a/src/GitHub/public/Meta/Get-GitHubOctocat.ps1 +++ b/src/GitHub/public/Meta/Get-GitHubOctocat.ps1 @@ -1,4 +1,4 @@ -function Get-GitHubOctocat { +filter Get-GitHubOctocat { <# .SYNOPSIS Get Octocat. @@ -26,8 +26,7 @@ [Parameter()] [Alias('Say')] [Alias('Saying')] - [string] - $S + [string] $S ) $body = @{ diff --git a/src/GitHub/public/Meta/Get-GitHubRoot.ps1 b/src/GitHub/public/Meta/Get-GitHubRoot.ps1 index 8a3b9c60e..5637d66ee 100644 --- a/src/GitHub/public/Meta/Get-GitHubRoot.ps1 +++ b/src/GitHub/public/Meta/Get-GitHubRoot.ps1 @@ -1,4 +1,4 @@ -function Get-GitHubRoot { +filter Get-GitHubRoot { <# .SYNOPSIS GitHub API Root. diff --git a/src/GitHub/public/Meta/Get-GitHubZen.ps1 b/src/GitHub/public/Meta/Get-GitHubZen.ps1 index b0a973acc..b4609085b 100644 --- a/src/GitHub/public/Meta/Get-GitHubZen.ps1 +++ b/src/GitHub/public/Meta/Get-GitHubZen.ps1 @@ -1,4 +1,4 @@ -function Get-GitHubZen { +filter Get-GitHubZen { <# .SYNOPSIS Get the Zen of GitHub. diff --git a/src/GitHub/public/Organization/Blocking/Assert-GitHubOrganizationBlockedUser.ps1 b/src/GitHub/public/Organization/Blocking/Assert-GitHubOrganizationBlockedUser.ps1 index 0c3c8ab06..4c542f1ae 100644 --- a/src/GitHub/public/Organization/Blocking/Assert-GitHubOrganizationBlockedUser.ps1 +++ b/src/GitHub/public/Organization/Blocking/Assert-GitHubOrganizationBlockedUser.ps1 @@ -1,4 +1,4 @@ -function Assert-GitHubOrganizationBlockedUser { +filter Assert-GitHubOrganizationBlockedUser { <# .SYNOPSIS Check if a user is blocked by an organization @@ -20,14 +20,21 @@ [CmdletBinding()] param ( # The organization name. The name is not case sensitive. - [Parameter(Mandatory)] + [Parameter( + Mandatory, + ValueFromPipeline, + ValueFromPipelineByPropertyName + )] [Alias('org')] [Alias('owner')] [Alias('login')] [string] $OrganizationName, # The handle for the GitHub user account. - [Parameter(Mandatory)] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName + )] [string] $Username ) diff --git a/src/GitHub/public/Organization/Blocking/Get-GitHubOrganizationBlockedUser.ps1 b/src/GitHub/public/Organization/Blocking/Get-GitHubOrganizationBlockedUser.ps1 index 2581a6194..587152403 100644 --- a/src/GitHub/public/Organization/Blocking/Get-GitHubOrganizationBlockedUser.ps1 +++ b/src/GitHub/public/Organization/Blocking/Get-GitHubOrganizationBlockedUser.ps1 @@ -1,4 +1,4 @@ -function Get-GitHubOrganizationBlockedUser { +filter Get-GitHubOrganizationBlockedUser { <# .SYNOPSIS List users blocked by an organization @@ -22,7 +22,6 @@ [Alias('org')] [Alias('owner')] [Alias('login')] - [Alias('name')] [string] $OrganizationName, # The number of results per page (max 100). diff --git a/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 b/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 index e6bd03961..e50fb8c67 100644 --- a/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 +++ b/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 @@ -1,4 +1,4 @@ -function Get-GitHubOrganization { +filter Get-GitHubOrganization { <# .SYNOPSIS List organization @@ -38,7 +38,8 @@ # The organization name. The name is not case sensitive. [Parameter( Mandatory, - ParameterSetName = 'NamedOrg' + ParameterSetName = 'NamedOrg', + ValueFromPipelineByPropertyName )] [Alias('login')] [Alias('org')] @@ -48,7 +49,8 @@ # The handle for the GitHub user account. [Parameter( Mandatory, - ParameterSetName = 'NamedUser' + ParameterSetName = 'NamedUser', + ValueFromPipelineByPropertyName )] [string] $Username, diff --git a/src/GitHub/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 b/src/GitHub/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 index f637cb04c..48557d266 100644 --- a/src/GitHub/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 +++ b/src/GitHub/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 @@ -1,4 +1,4 @@ -function Get-GitHubOrganizationAppInstallation { +filter Get-GitHubOrganizationAppInstallation { <# .SYNOPSIS List app installations for an organization @@ -19,11 +19,14 @@ [CmdletBinding()] param ( # The organization name. The name is not case sensitive. - [Parameter(Mandatory)] + [Parameter( + Mandatory, + ValueFromPipeline, + ValueFromPipelineByPropertyName + )] [Alias('org')] [Alias('owner')] [Alias('login')] - [Alias('name')] [string] $OrganizationName, # The number of results per page (max 100). diff --git a/src/GitHub/public/Organization/Remove-GitHubOrganization.ps1 b/src/GitHub/public/Organization/Remove-GitHubOrganization.ps1 index 846ba146c..7789ba0d6 100644 --- a/src/GitHub/public/Organization/Remove-GitHubOrganization.ps1 +++ b/src/GitHub/public/Organization/Remove-GitHubOrganization.ps1 @@ -1,4 +1,4 @@ -function Remove-GitHubOrganization { +filter Remove-GitHubOrganization { <# .SYNOPSIS Delete an organization @@ -21,11 +21,14 @@ [CmdletBinding()] param ( # The organization name. The name is not case sensitive. - [Parameter(Mandatory)] + [Parameter( + Mandatory, + ValueFromPipeline, + ValueFromPipelineByPropertyName + )] [Alias('org')] [Alias('owner')] [Alias('login')] - [Alias('name')] [string] $OrganizationName ) diff --git a/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 b/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 index 8a73c80fe..d47232728 100644 --- a/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 +++ b/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 @@ -1,4 +1,4 @@ -function Set-GitHubOrganization { +filter Set-GitHubOrganization { <# .SYNOPSIS Update an organization @@ -32,162 +32,166 @@ [CmdletBinding()] param ( # The organization name. The name is not case sensitive. - [Parameter(Mandatory)] + [Parameter( + Mandatory, + ValueFromPipeline, + ValueFromPipelineByPropertyName + )] [Alias('org')] [Alias('owner')] [Alias('login')] [string] $OrganizationName, # Billing email address. This address is not publicized. - [Parameter()] + [Parameter(ValueFromPipelineByPropertyName)] [Alias('billing_email')] [string] $BillingEmail, # The company name. - [Parameter()] + [Parameter(ValueFromPipelineByPropertyName)] [string] $Company, # The publicly visible email address. - [Parameter()] + [Parameter(ValueFromPipelineByPropertyName)] [string] $Email, # The Twitter username of the company. - [Parameter()] + [Parameter(ValueFromPipelineByPropertyName)] [Alias('twitter_username')] [string] $TwitterUsername, # The location. - [Parameter()] + [Parameter(ValueFromPipelineByPropertyName)] [string] $Location, # The shorthand name of the company. - [Parameter()] + [Parameter(ValueFromPipelineByPropertyName)] [string] $Name, # The description of the company. - [Parameter()] + [Parameter(ValueFromPipelineByPropertyName)] [string] $Description, # Whether an organization can use organization projects. - [Parameter()] + [Parameter(ValueFromPipelineByPropertyName)] [Alias('has_organization_projects')] [bool] $HasOrganizationProjects, # Whether repositories that belong to the organization can use repository projects. - [Parameter()] + [Parameter(ValueFromPipelineByPropertyName)] [Alias('has_repository_projects')] [bool] $HasRepositoryProjects, # Default permission level members have for organization repositories. - [Parameter()] + [Parameter(ValueFromPipelineByPropertyName)] [Alias('default_repository_permission')] [ValidateSet('read', 'write', 'admin', 'none')] [string] $DefaultRepositoryPermission, # Whether of non-admin organization members can create repositories. Note: A parameter can override this parameter. See members_allowed_repository_creation_type in this table for details. - [Parameter()] + [Parameter(ValueFromPipelineByPropertyName)] [Alias('members_can_create_repositories')] [bool] $MembersCanCreateRepositories = $true, # Whether organization members can create internal repositories, which are visible to all enterprise members. You can only allow members to create internal repositories if your organization is associated with an enterprise account using GitHub Enterprise Cloud or GitHub Enterprise Server 2.20+. For more information, see "Restricting repository creation in your organization" in the GitHub Help documentation. - [Parameter()] + [Parameter(ValueFromPipelineByPropertyName)] [Alias('members_can_create_internal_repositories')] [bool] $MembersCanCreateInternalRepositories, # Whether organization members can create private repositories, which are visible to organization members with permission. For more information, see "Restricting repository creation in your organization" in the GitHub Help documentation. - [Parameter()] + [Parameter(ValueFromPipelineByPropertyName)] [Alias('members_can_create_private_repositories')] [bool] $MembersCanCreatePrivateRepositories, # Whether organization members can create public repositories, which are visible to anyone. For more information, see "Restricting repository creation in your organization" in the GitHub Help documentation. - [Parameter()] + [Parameter(ValueFromPipelineByPropertyName)] [Alias('members_can_create_public_repositories')] [bool] $MembersCanCreatePublicRepositories, # Specifies which types of repositories non-admin organization members can create. private is only available to repositories that are part of an organization on GitHub Enterprise Cloud. Note: This parameter is deprecated and will be removed in the future. Its return value ignores internal repositories. Using this parameter overrides values set in members_can_create_repositories. See the parameter deprecation notice in the operation description for details. - [Parameter()] + [Parameter(ValueFromPipelineByPropertyName)] [Alias('members_allowed_repository_creation_type')] [ValidateSet('all', 'private', 'none')] [string] $MembersAllowedRepositoryCreationType, # Whether organization members can create GitHub Pages sites. Existing published sites will not be impacted. - [Parameter()] + [Parameter(ValueFromPipelineByPropertyName)] [Alias('members_can_create_pages')] [bool] $MembersCanCreatePages = $true, # Whether organization members can create public GitHub Pages sites. Existing published sites will not be impacted. - [Parameter()] + [Parameter(ValueFromPipelineByPropertyName)] [Alias('members_can_create_public_pages')] [bool] $MembersCanCreatePublicPages = $true, # Whether organization members can create private GitHub Pages sites. Existing published sites will not be impacted. - [Parameter()] + [Parameter(ValueFromPipelineByPropertyName)] [Alias('members_can_create_private_pages')] [bool] $MembersCanCreatePrivatePages = $true, # Whether organization members can fork private organization repositories. - [Parameter()] + [Parameter(ValueFromPipelineByPropertyName)] [Alias('members_can_fork_private_repositories')] [bool] $MembersCanForkPrivateRepositories = $false, # Whether contributors to organization repositories are required to sign off on commits they make through GitHub's web interface. - [Parameter()] + [Parameter(ValueFromPipelineByPropertyName)] [Alias('web_commit_signoff_required')] [bool] $WebCommitSignoffRequired = $false, # Path to the organization's blog. - [Parameter()] + [Parameter(ValueFromPipelineByPropertyName)] [string] $Blog, # Whether GitHub Advanced Security is automatically enabled for new repositories. # To use this parameter, you must have admin permissions for the repository or be an owner or security manager for the organization that owns the repository. For more information, see "Managing security managers in your organization." # You can check which security and analysis features are currently enabled by using a GET /orgs/{org} request. - [Parameter()] + [Parameter(ValueFromPipelineByPropertyName)] [Alias('advanced_security_enabled_for_new_repositories')] [bool] $AdvancedSecurityEnabledForNewRepositories = $false, # Whether Dependabot alerts is automatically enabled for new repositories. # To use this parameter, you must have admin permissions for the repository or be an owner or security manager for the organization that owns the repository. For more information, see "Managing security managers in your organization." # You can check which security and analysis features are currently enabled by using a GET /orgs/{org} request. - [Parameter()] + [Parameter(ValueFromPipelineByPropertyName)] [Alias('dependabot_alerts_enabled_for_new_repositories')] [bool] $DependabotAlertsEnabledForNewRepositories = $false, # Whether Dependabot security updates is automatically enabled for new repositories. # To use this parameter, you must have admin permissions for the repository or be an owner or security manager for the organization that owns the repository. For more information, see "Managing security managers in your organization." # You can check which security and analysis features are currently enabled by using a GET /orgs/{org} request. - [Parameter()] + [Parameter(ValueFromPipelineByPropertyName)] [Alias('dependabot_security_updates_enabled_for_new_repositories')] [bool] $DependabotSecurityUpdatesEnabledForNewRepositories = $false, # Whether dependency graph is automatically enabled for new repositories. # To use this parameter, you must have admin permissions for the repository or be an owner or security manager for the organization that owns the repository. For more information, see "Managing security managers in your organization." # You can check which security and analysis features are currently enabled by using a GET /orgs/{org} request. - [Parameter()] + [Parameter(ValueFromPipelineByPropertyName)] [Alias('dependency_graph_enabled_for_new_repositories')] [bool] $DependencyGraphEnabledForNewRepositories = $false, # Whether secret scanning is automatically enabled for new repositories. # To use this parameter, you must have admin permissions for the repository or be an owner or security manager for the organization that owns the repository. For more information, see "Managing security managers in your organization." # You can check which security and analysis features are currently enabled by using a GET /orgs/{org} request. - [Parameter()] + [Parameter(ValueFromPipelineByPropertyName)] [Alias('secret_scanning_enabled_for_new_repositories')] [bool] $SecretScanningEnabledForNewRepositories = $false, # Whether secret scanning push protection is automatically enabled for new repositories. # To use this parameter, you must have admin permissions for the repository or be an owner or security manager for the organization that owns the repository. For more information, see "Managing security managers in your organization." # You can check which security and analysis features are currently enabled by using a GET /orgs/{org} request. - [Parameter()] + [Parameter(ValueFromPipelineByPropertyName)] [Alias('secret_scanning_push_protection_enabled_for_new_repositories')] [bool] $SecretScanningPushProtectionEnabledForNewRepositories = $false, # Whether a custom link is shown to contributors who are blocked from pushing a secret by push protection. - [Parameter()] + [Parameter(ValueFromPipelineByPropertyName)] [Alias('secret_scanning_push_protection_custom_link_enabled')] [bool] $SecretScanningPushProtectionCustomLinkEnabled = $false, # If secret_scanning_push_protection_custom_link_enabled is true, the URL that will be displayed to contributors who are blocked from pushing a secret. - [Parameter()] + [Parameter(ValueFromPipelineByPropertyName)] [Alias('secret_scanning_push_protection_custom_link')] [string] $SecretScanningPushProtectionCustomLink ) diff --git a/src/GitHub/public/Organization/Set-GitHubOrganizationSecurityFeature.ps1 b/src/GitHub/public/Organization/Set-GitHubOrganizationSecurityFeature.ps1 index ed58b59bf..7a7b88429 100644 --- a/src/GitHub/public/Organization/Set-GitHubOrganizationSecurityFeature.ps1 +++ b/src/GitHub/public/Organization/Set-GitHubOrganizationSecurityFeature.ps1 @@ -1,4 +1,4 @@ -function Set-GitHubOrganizationSecurityFeature { +filter Set-GitHubOrganizationSecurityFeature { <# .SYNOPSIS Enable or disable a security feature for an organization @@ -29,7 +29,6 @@ [Alias('org')] [Alias('owner')] [Alias('login')] - [Alias('name')] [string] $OrganizationName, # The security feature to enable or disable. diff --git a/src/GitHub/public/Teams/Get-GitHubRepoTeam.ps1 b/src/GitHub/public/Teams/Get-GitHubRepoTeam.ps1 index 2684b0dc9..f2695ca0b 100644 --- a/src/GitHub/public/Teams/Get-GitHubRepoTeam.ps1 +++ b/src/GitHub/public/Teams/Get-GitHubRepoTeam.ps1 @@ -1,4 +1,4 @@ -function Get-GitHubRepoTeam { +filter Get-GitHubRepoTeam { <# .NOTES https://docs.github.com/en/rest/reference/repos#get-a-repository diff --git a/src/GitHub/public/Users/Get-GitHubUser.ps1 b/src/GitHub/public/Users/Get-GitHubUser.ps1 index 922574b76..3cf281dc7 100644 --- a/src/GitHub/public/Users/Get-GitHubUser.ps1 +++ b/src/GitHub/public/Users/Get-GitHubUser.ps1 @@ -1,4 +1,4 @@ -function Get-GitHubUser { +filter Get-GitHubUser { <# .SYNOPSIS Get the authenticated user diff --git a/src/GitHub/public/Users/Get-GitHubUserCard.ps1 b/src/GitHub/public/Users/Get-GitHubUserCard.ps1 index b71574a13..ee7e7d427 100644 --- a/src/GitHub/public/Users/Get-GitHubUserCard.ps1 +++ b/src/GitHub/public/Users/Get-GitHubUserCard.ps1 @@ -1,4 +1,4 @@ -function Get-GitHubUserCard { +filter Get-GitHubUserCard { <# .SYNOPSIS Get contextual information for a user @@ -22,7 +22,11 @@ [OutputType([pscustomobject])] [CmdletBinding()] param ( - [Parameter(Mandatory)] + [Parameter( + Mandatory, + ValueFromPipeline, + ValueFromPipelineByPropertyName + )] [string] $Username, [Parameter()] [ValidateSet('organization', 'repository', 'issue', 'pull_request')] diff --git a/src/GitHub/public/Users/Get-GitHubUserList.ps1 b/src/GitHub/public/Users/Get-GitHubUserList.ps1 index be20841bd..344a77945 100644 --- a/src/GitHub/public/Users/Get-GitHubUserList.ps1 +++ b/src/GitHub/public/Users/Get-GitHubUserList.ps1 @@ -1,4 +1,4 @@ -function Get-GitHubUserList { +filter Get-GitHubUserList { <# .SYNOPSIS List users diff --git a/src/GitHub/public/Users/Set-GitHubUser.ps1 b/src/GitHub/public/Users/Set-GitHubUser.ps1 index 770b4aab1..f26b340b2 100644 --- a/src/GitHub/public/Users/Set-GitHubUser.ps1 +++ b/src/GitHub/public/Users/Set-GitHubUser.ps1 @@ -1,4 +1,4 @@ -function Set-GitHubUser { +filter Set-GitHubUser { <# .SYNOPSIS Update the authenticated user From 42bf846cefab7da758c603facd4004636cae05c9 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 30 Sep 2023 17:03:17 +0200 Subject: [PATCH 42/61] fix error --- src/GitHub/public/API/Invoke-GitHubAPI.ps1 | 27 +++++++-------- .../Organization/Set-GitHubOrganization.ps1 | 33 ++----------------- src/GitHub/public/Users/Set-GitHubUser.ps1 | 6 +--- tools/utilities/Local-Testing.ps1 | 2 +- 4 files changed, 16 insertions(+), 52 deletions(-) diff --git a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 index d6f856911..0a8891704 100644 --- a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 +++ b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 @@ -113,10 +113,6 @@ if ($Body) { - if (-not $Declare) { - $Body | Remove-HashTableEntries -NullOrEmptyValues - } - # Use body to create the query string for GET requests if ($Method -eq 'GET') { $queryString = $Body | ConvertTo-QueryString @@ -131,7 +127,8 @@ } } - try { + # try { + # (Invoke-RestMethod @APICall) | ForEach-Object { (Invoke-RestMethod @APICall -ErrorAction SilentlyContinue) | ForEach-Object { $statusCode = $APICallStatusCode | ConvertTo-Json -Depth 100 | ConvertFrom-Json $responseHeaders = $APICallResponseHeaders | ConvertTo-Json -Depth 100 | ConvertFrom-Json @@ -141,14 +138,14 @@ ResponseHeaders = $responseHeaders } } - } catch { - Write-Error "[$functionName] - Status code - [$APICallStatusCode]" - # $err = $_ | ConvertFrom-Json -Depth 10 - # Write-Error "[$functionName] - $($err.Message)" - # Write-Error "[$functionName] - For more info please see: [$($err.documentation_url)]" - # $APICallResponseHeaders.PSObject.Properties | ForEach-Object { - # Write-Error "[$functionName] - $($_.Key): $($_.Value)" - # } - # return 1 - } + # } catch { + # Write-Error "[$functionName] - Status code - [$APICallStatusCode]" + # $err = $_ | ConvertFrom-Json -Depth 10 + # Write-Error "[$functionName] - $($err.Message)" + # Write-Error "[$functionName] - For more info please see: [$($err.documentation_url)]" + # $APICallResponseHeaders.PSObject.Properties | ForEach-Object { + # Write-Error "[$functionName] - $($_.Key): $($_.Value)" + # } + # return 1 + # } } diff --git a/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 b/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 index d47232728..1aa7ecc2b 100644 --- a/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 +++ b/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 @@ -196,37 +196,8 @@ [string] $SecretScanningPushProtectionCustomLink ) - $body = @{ - billing_email = $BillingEmail - company = $Company - email = $Email - twitter_username = $TwitterUsername - location = $Location - name = $Name - description = $Description - has_organization_projects = $HasOrganizationProjects - has_repository_projects = $HasRepositoryProjects - default_repository_permission = $DefaultRepositoryPermission - members_can_create_repositories = $MembersCanCreateRepositories - members_can_create_internal_repositories = $MembersCanCreateInternalRepositories - members_can_create_private_repositories = $MembersCanCreatePrivateRepositories - members_can_create_public_repositories = $MembersCanCreatePublicRepositories - members_allowed_repository_creation_type = $MembersAllowedRepositoryCreationType - members_can_create_pages = $MembersCanCreatePages - members_can_create_public_pages = $MembersCanCreatePublicPages - members_can_create_private_pages = $MembersCanCreatePrivatePages - members_can_fork_private_repositories = $MembersCanForkPrivateRepositories - web_commit_signoff_required = $WebCommitSignoffRequired - blog = $Blog - advanced_security_enabled_for_new_repositories = $AdvancedSecurityEnabledForNewRepositories - dependabot_alerts_enabled_for_new_repositories = $DependabotAlertsEnabledForNewRepositories - dependabot_security_updates_enabled_for_new_repositories = $DependabotSecurityUpdatesEnabledForNewRepositories - dependency_graph_enabled_for_new_repositories = $DependencyGraphEnabledForNewRepositories - secret_scanning_enabled_for_new_repositories = $SecretScanningEnabledForNewRepositories - secret_scanning_push_protection_enabled_for_new_repositories = $SecretScanningPushProtectionEnabledForNewRepositories - secret_scanning_push_protection_custom_link_enabled = $SecretScanningPushProtectionCustomLinkEnabled - secret_scanning_push_protection_custom_link = $SecretScanningPushProtectionCustomLink - } + $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable + Remove-HashTableEntries -Hashtable $body -RemoveNames 'OrganizationName' $inputObject = @{ APIEndpoint = "/orgs/$OrganizationName" diff --git a/src/GitHub/public/Users/Set-GitHubUser.ps1 b/src/GitHub/public/Users/Set-GitHubUser.ps1 index f26b340b2..54f710284 100644 --- a/src/GitHub/public/Users/Set-GitHubUser.ps1 +++ b/src/GitHub/public/Users/Set-GitHubUser.ps1 @@ -63,11 +63,7 @@ [string] $Bio ) - $body = @{} - - $PSBoundParameters.GetEnumerator() | ForEach-Object { - $body.($_.Key) = $_.Value - } + $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable $inputObject = @{ APIEndpoint = '/user' diff --git a/tools/utilities/Local-Testing.ps1 b/tools/utilities/Local-Testing.ps1 index 70750413d..ae592f8ae 100644 --- a/tools/utilities/Local-Testing.ps1 +++ b/tools/utilities/Local-Testing.ps1 @@ -41,7 +41,7 @@ Get-GitHubOrganization -OrganizationName 'PSModule' Get-GitHubOrganizationAppInstallation -OrganizationName 'PSModule' Set-GitHubOrganization -OrganizationName 'PSModule' -Blog 'https://www.psmodule.io' -Set-GitHubOrganization -OrganizationName 'PSModule' -Blog '' +# Set-GitHubOrganization -OrganizationName 'PSModule' -Blog '' -> Does not work. Set-GitHubOrganization -OrganizationName 'PSModule' -Blog ' ' Set-GitHubOrganization -OrganizationName 'PSModule' -Company 'PSModule' -DefaultRepositoryPermission read From 7ce1db50cc4720c92a0522f36996c5478c00ebc9 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 30 Sep 2023 17:14:22 +0200 Subject: [PATCH 43/61] Fix timer of accesstoken remaining --- src/GitHub/public/Auth/Connect-GitHubAccount.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GitHub/public/Auth/Connect-GitHubAccount.ps1 b/src/GitHub/public/Auth/Connect-GitHubAccount.ps1 index 5048b13ed..4203160ad 100644 --- a/src/GitHub/public/Auth/Connect-GitHubAccount.ps1 +++ b/src/GitHub/public/Auth/Connect-GitHubAccount.ps1 @@ -87,7 +87,7 @@ } else { $accessTokenValidity = [datetime](Get-GitHubConfig -Name 'AccessTokenExpirationDate') - (Get-Date) $accessTokenIsValid = $accessTokenValidity.Seconds -gt 0 - $accessTokenValidityText = "$($accessTokenValidity.Hours):$($accessTokenValidity.Minutes):$($accessTokenValidity.Seconds)" + $accessTokenValidityText = "$([string]($accessTokenValidity.Hours).PadLeft(2,'0')):$([string]($accessTokenValidity.Minutes).PadLeft(2,'0')):$([string]($accessTokenValidity.Seconds).PadLeft(2,'0'))" if ($accessTokenIsValid) { if ($accessTokenValidity.TotalHours -gt 4) { Write-Host '✓ ' -ForegroundColor Green -NoNewline From 8ee05133adba0815f178952a3b605a8717c9f5ef Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 30 Sep 2023 17:14:49 +0200 Subject: [PATCH 44/61] Fix set user and org --- src/GitHub/public/Organization/Set-GitHubOrganization.ps1 | 2 +- src/GitHub/public/Users/Set-GitHubUser.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 b/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 index 1aa7ecc2b..245566e5c 100644 --- a/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 +++ b/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 @@ -196,7 +196,7 @@ [string] $SecretScanningPushProtectionCustomLink ) - $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable + $body = $PSBoundParameters.GetEnumerator() | ConvertFrom-HashTable | ConvertTo-HashTable Remove-HashTableEntries -Hashtable $body -RemoveNames 'OrganizationName' $inputObject = @{ diff --git a/src/GitHub/public/Users/Set-GitHubUser.ps1 b/src/GitHub/public/Users/Set-GitHubUser.ps1 index 54f710284..87fe0376a 100644 --- a/src/GitHub/public/Users/Set-GitHubUser.ps1 +++ b/src/GitHub/public/Users/Set-GitHubUser.ps1 @@ -63,7 +63,7 @@ [string] $Bio ) - $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable + $body = $PSBoundParameters.GetEnumerator() | ConvertFrom-HashTable | ConvertTo-HashTable $inputObject = @{ APIEndpoint = '/user' From 3c55306f3e73b57ce971ae835899bb2c8193c01c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 30 Sep 2023 17:14:57 +0200 Subject: [PATCH 45/61] Fix some testing --- tools/utilities/Local-Testing.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/utilities/Local-Testing.ps1 b/tools/utilities/Local-Testing.ps1 index ae592f8ae..2ff96cae3 100644 --- a/tools/utilities/Local-Testing.ps1 +++ b/tools/utilities/Local-Testing.ps1 @@ -23,7 +23,7 @@ Get-GitHubConfig -Name AccessToken Get-GitHubConfig -Name RefreshToken Invoke-GitHubAPI -Method Get -ApiEndpoint /user Get-GitHubMeta -Get-GitHubOctocat -S 'Hello, World!' +Get-GitHubOctocat -S 'Hello World' Disconnect-GitHubAccount -Verbose $VerbosePreference = 'SIlentlyContinue' @@ -41,7 +41,7 @@ Get-GitHubOrganization -OrganizationName 'PSModule' Get-GitHubOrganizationAppInstallation -OrganizationName 'PSModule' Set-GitHubOrganization -OrganizationName 'PSModule' -Blog 'https://www.psmodule.io' -# Set-GitHubOrganization -OrganizationName 'PSModule' -Blog '' -> Does not work. +Set-GitHubOrganization -OrganizationName 'PSModule' -Blog '' #-> Does not work. Set-GitHubOrganization -OrganizationName 'PSModule' -Blog ' ' Set-GitHubOrganization -OrganizationName 'PSModule' -Company 'PSModule' -DefaultRepositoryPermission read From 01dbd8884437bba85b3541cab5c563c1fc220ebd Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 30 Sep 2023 17:16:44 +0200 Subject: [PATCH 46/61] Fix octo example to a working one --- src/GitHub/public/Meta/Get-GitHubOctocat.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GitHub/public/Meta/Get-GitHubOctocat.ps1 b/src/GitHub/public/Meta/Get-GitHubOctocat.ps1 index 4f9813e99..49f2fd89c 100644 --- a/src/GitHub/public/Meta/Get-GitHubOctocat.ps1 +++ b/src/GitHub/public/Meta/Get-GitHubOctocat.ps1 @@ -12,7 +12,7 @@ Get the octocat as ASCII art .EXAMPLE - Get-GitHubOctocat -S 'The glass is never half empty. It's just twice as big as it needs to be.' + Get-GitHubOctocat -S "Hello world" Get the octocat as ASCII art with a custom saying From 32c8298276ca888a0fdffbf2188281a93971e1a6 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 30 Sep 2023 17:21:44 +0200 Subject: [PATCH 47/61] Fix for token expir --- src/GitHub/public/Auth/Connect-GitHubAccount.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GitHub/public/Auth/Connect-GitHubAccount.ps1 b/src/GitHub/public/Auth/Connect-GitHubAccount.ps1 index 4203160ad..57f8aa4de 100644 --- a/src/GitHub/public/Auth/Connect-GitHubAccount.ps1 +++ b/src/GitHub/public/Auth/Connect-GitHubAccount.ps1 @@ -87,7 +87,7 @@ } else { $accessTokenValidity = [datetime](Get-GitHubConfig -Name 'AccessTokenExpirationDate') - (Get-Date) $accessTokenIsValid = $accessTokenValidity.Seconds -gt 0 - $accessTokenValidityText = "$([string]($accessTokenValidity.Hours).PadLeft(2,'0')):$([string]($accessTokenValidity.Minutes).PadLeft(2,'0')):$([string]($accessTokenValidity.Seconds).PadLeft(2,'0'))" + $accessTokenValidityText = "$(([string]$accessTokenValidity.Hours).PadLeft(2,'0')):$(([string]$accessTokenValidity.Minutes).PadLeft(2,'0')):$(([string]$accessTokenValidity.Seconds).PadLeft(2,'0'))" if ($accessTokenIsValid) { if ($accessTokenValidity.TotalHours -gt 4) { Write-Host '✓ ' -ForegroundColor Green -NoNewline From 4a36edb2ba272219379c6d73ae707f1a9b77d696 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 30 Sep 2023 17:26:41 +0200 Subject: [PATCH 48/61] Fix acctok timer --- src/GitHub/public/Auth/Connect-GitHubAccount.ps1 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/GitHub/public/Auth/Connect-GitHubAccount.ps1 b/src/GitHub/public/Auth/Connect-GitHubAccount.ps1 index 57f8aa4de..d1f8f19f8 100644 --- a/src/GitHub/public/Auth/Connect-GitHubAccount.ps1 +++ b/src/GitHub/public/Auth/Connect-GitHubAccount.ps1 @@ -87,7 +87,10 @@ } else { $accessTokenValidity = [datetime](Get-GitHubConfig -Name 'AccessTokenExpirationDate') - (Get-Date) $accessTokenIsValid = $accessTokenValidity.Seconds -gt 0 - $accessTokenValidityText = "$(([string]$accessTokenValidity.Hours).PadLeft(2,'0')):$(([string]$accessTokenValidity.Minutes).PadLeft(2,'0')):$(([string]$accessTokenValidity.Seconds).PadLeft(2,'0'))" + $hours = $accessTokenValidity.Hours.ToString().PadLeft(2, '0') + $minutes = $accessTokenValidity.Minutes.ToString().PadLeft(2, '0') + $seconds = $accessTokenValidity.Seconds.ToString().PadLeft(2, '0') + $accessTokenValidityText = "$hours`:$minutes`:$seconds" if ($accessTokenIsValid) { if ($accessTokenValidity.TotalHours -gt 4) { Write-Host '✓ ' -ForegroundColor Green -NoNewline From 1496e1757e104bc39a9851014c95fabb4b5ec9f0 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 30 Sep 2023 18:28:55 +0200 Subject: [PATCH 49/61] Fix hashtable and set org+user --- src/GitHub/private/Utilities/ConvertTo-HashTable.ps1 | 7 ++++++- .../public/Organization/Set-GitHubOrganization.ps1 | 2 +- src/GitHub/public/Users/Set-GitHubUser.ps1 | 2 +- tools/utilities/Local-Testing.ps1 | 9 ++++++++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/GitHub/private/Utilities/ConvertTo-HashTable.ps1 b/src/GitHub/private/Utilities/ConvertTo-HashTable.ps1 index 7b918881e..67b0969b4 100644 --- a/src/GitHub/private/Utilities/ConvertTo-HashTable.ps1 +++ b/src/GitHub/private/Utilities/ConvertTo-HashTable.ps1 @@ -42,5 +42,10 @@ )] [object]$InputObject ) - $InputObject | ConvertTo-Json -Depth 100 | ConvertFrom-Json -AsHashtable + [hashtable]$hashtable = @{} + + foreach ($item in $InputObject.PSObject.Properties) { + $hashtable[$($item.Name)] = $item.Value + } + $hashtable } diff --git a/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 b/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 index 245566e5c..1aa7ecc2b 100644 --- a/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 +++ b/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 @@ -196,7 +196,7 @@ [string] $SecretScanningPushProtectionCustomLink ) - $body = $PSBoundParameters.GetEnumerator() | ConvertFrom-HashTable | ConvertTo-HashTable + $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable Remove-HashTableEntries -Hashtable $body -RemoveNames 'OrganizationName' $inputObject = @{ diff --git a/src/GitHub/public/Users/Set-GitHubUser.ps1 b/src/GitHub/public/Users/Set-GitHubUser.ps1 index 87fe0376a..54f710284 100644 --- a/src/GitHub/public/Users/Set-GitHubUser.ps1 +++ b/src/GitHub/public/Users/Set-GitHubUser.ps1 @@ -63,7 +63,7 @@ [string] $Bio ) - $body = $PSBoundParameters.GetEnumerator() | ConvertFrom-HashTable | ConvertTo-HashTable + $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable $inputObject = @{ APIEndpoint = '/user' diff --git a/tools/utilities/Local-Testing.ps1 b/tools/utilities/Local-Testing.ps1 index 2ff96cae3..da0d7b02a 100644 --- a/tools/utilities/Local-Testing.ps1 +++ b/tools/utilities/Local-Testing.ps1 @@ -25,7 +25,7 @@ Invoke-GitHubAPI -Method Get -ApiEndpoint /user Get-GitHubMeta Get-GitHubOctocat -S 'Hello World' Disconnect-GitHubAccount -Verbose -$VerbosePreference = 'SIlentlyContinue' +$VerbosePreference = 'SilentlyContinue' $str = '2023-10-27 17:43:40 UTC' @@ -45,3 +45,10 @@ Set-GitHubOrganization -OrganizationName 'PSModule' -Blog '' #-> Does not work. Set-GitHubOrganization -OrganizationName 'PSModule' -Blog ' ' Set-GitHubOrganization -OrganizationName 'PSModule' -Company 'PSModule' -DefaultRepositoryPermission read + +Get-GitHubUser +Set-GitHubUser -Name 'MariusStorhaug' -Company 'PSModule' +Set-GitHubUser -Name 'MariusStorhaug' -Company '@DNBBank' +Set-GitHubUser -Name 'MariusStorhaug' -Company ' ' +Set-GitHubUser -Name 'MariusStorhaug' -Hireable $true + From 4b3161d7d25dda36f065499a3d813b60c158d5b4 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 1 Oct 2023 13:49:47 +0200 Subject: [PATCH 50/61] Added casing utilities --- .../Casing/Convert-StringCasingStyle.ps1 | 68 ++++++++++++ .../Casing/Get-StringCasingStyle.ps1 | 97 +++++++++++++++++ .../Casing/Split-StringByCasingStyle.ps1 | 102 ++++++++++++++++++ 3 files changed, 267 insertions(+) create mode 100644 src/GitHub/private/Utilities/Casing/Convert-StringCasingStyle.ps1 create mode 100644 src/GitHub/private/Utilities/Casing/Get-StringCasingStyle.ps1 create mode 100644 src/GitHub/private/Utilities/Casing/Split-StringByCasingStyle.ps1 diff --git a/src/GitHub/private/Utilities/Casing/Convert-StringCasingStyle.ps1 b/src/GitHub/private/Utilities/Casing/Convert-StringCasingStyle.ps1 new file mode 100644 index 000000000..68997f7ef --- /dev/null +++ b/src/GitHub/private/Utilities/Casing/Convert-StringCasingStyle.ps1 @@ -0,0 +1,68 @@ +filter Convert-StringCasingStyle { + <# + .SYNOPSIS + Convert a string to a different casing style + + .DESCRIPTION + This function converts a string to a different casing style. + + .EXAMPLE + 'thisIsCamelCase' | Convert-StringCasingStyle -To 'snake_case' + + Convert the string 'thisIsCamelCase' to 'this_is_camel_case' + + .EXAMPLE + 'thisIsCamelCase' | Convert-StringCasingStyle -To 'UPPER_SNAKE_CASE' + + Convert the string 'thisIsCamelCase' to 'THIS_IS_CAMEL_CASE' + + .EXAMPLE + 'thisIsCamelCase' | Convert-StringCasingStyle -To 'kebab-case' + + .NOTES + General notes + #> + [OutputType([string])] + [CmdletBinding()] + param ( + # The string to convert + [Parameter( + Mandatory, + ValueFromPipeline + )] + [string] $Text, + + # The casing style to convert the string to + [Parameter(Mandatory)] + [ValidateSet( + 'lowercase', + 'UPPERCASE', + 'Title Case', + 'PascalCase', + 'camelCase', + 'kebab-case', + 'UPPER-KEBAB-CASE', + 'snake_case', + 'UPPER_SNAKE_CASE' + )] + [string] $To + ) + + $currentStyle = Get-StringCasingStyle -Text $Text + + $words = Split-StringByCasingStyle -Text $Text -By $currentStyle + + # Convert the words into the target style + switch ($To) { + 'lowercase' { ($words -join '').toLower() } + 'UPPERCASE' { ($words -join '').toUpper() } + 'Title Case' { ($words | ForEach-Object { $_.Substring(0, 1).ToUpper() + $_.Substring(1).ToLower() }) -join ' ' } + 'Wordcase' { $words -join '' | ForEach-Object { $_.Substring(0, 1).ToUpper() + $_.Substring(1).ToLower() } } + 'kebab-case' { ($words -join '-').ToLower() } + 'snake_case' { ($words -join '_').ToLower() } + 'PascalCase' { ($words | ForEach-Object { $_.Substring(0, 1).ToUpper() + $_.Substring(1).ToLower() }) -join '' } + 'camelCase' { $words[0].toLower() + (($words | Select-Object -Skip 1 | ForEach-Object { $_.Substring(0, 1).ToUpper() + $_.Substring(1) }) -join '') } + 'UPPER_SNAKE_CASE' { ($words -join '_').toUpper() } + 'UPPER-KEBAB-CASE' { ($words -join '-').toUpper() } + } +} diff --git a/src/GitHub/private/Utilities/Casing/Get-StringCasingStyle.ps1 b/src/GitHub/private/Utilities/Casing/Get-StringCasingStyle.ps1 new file mode 100644 index 000000000..dcbb7ad65 --- /dev/null +++ b/src/GitHub/private/Utilities/Casing/Get-StringCasingStyle.ps1 @@ -0,0 +1,97 @@ +filter Get-StringCasingStyle { + <# + .SYNOPSIS + Detects the casing style of a string + + .DESCRIPTION + This function detects the casing style of a string. + + .EXAMPLE + 'testtesttest' | Get-StringCasingStyle + + lowercase + + .EXAMPLE + 'TESTTESTTEST' | Get-StringCasingStyle + + UPPERCASE + + .EXAMPLE + 'Testtesttest' | Get-StringCasingStyle + + Titlecase + + .EXAMPLE + 'TestTestTest' | Get-StringCasingStyle + + PascalCase + + .EXAMPLE + 'testTestTest' | Get-StringCasingStyle + + camelCase + + .EXAMPLE + 'test-test-test' | Get-StringCasingStyle + + kebab-case + + .EXAMPLE + 'TEST-TEST-TEST' | Get-StringCasingStyle + + UPPER-KEBAB-CASE + + .EXAMPLE + 'test_test_test' | Get-StringCasingStyle + + snake_case + + .EXAMPLE + 'TEST_TEST_TEST' | Get-StringCasingStyle + + UPPER_SNAKE_CASE + + .EXAMPLE + 'Test_teSt-Test' | Get-StringCasingStyle + + Unknown + #> + [OutputType([string])] + [CmdletBinding()] + param ( + # The string to check the casing style of + [Parameter( + Mandatory, + ValueFromPipeline + )] + [string] $Text + ) + + $style = if ([regex]::Match($Text, '^[a-z][a-z0-9]*$').Success) { + 'lowercase' + } elseif ([regex]::Match($Text, '^[A-Z][A-Z0-9]*$').Success) { + 'UPPERCASE' + } elseif ([regex]::Match($Text, '^[A-Z][a-z0-9]*$').Success) { + 'Wordcase' + } elseif ([regex]::Match($Text, '^([A-Z][a-zA-Z0-9]*)(\s+[A-Z][a-zA-Z0-9]*)*$').Success) { + 'Title Case' + } elseif ([regex]::Match($Text, '^[A-Z][a-z0-9]*((?:[A-Z][a-z0-9]+)+)$').Success) { + 'PascalCase' + } elseif ([regex]::Match($Text, '^[a-z][a-z0-9]*[A-Z][a-z0-9]*((?:[A-Z][a-z0-9]*)+)$').Success) { + 'camelCase' + } elseif ([regex]::Match($Text, '^[a-z][a-z0-9]*-[a-z0-9]+((?:-[a-z0-9]+)+)$').Success) { + 'kebab-case' + } elseif ([regex]::Match($Text, '^[A-Z][A-Z0-9]*-[A-Z0-9]+((?:-[A-Z0-9]+)+)$').Success) { + 'UPPER-KEBAB-CASE' + } elseif ([regex]::Match($Text, '^[a-z][a-z0-9]*_[a-z0-9]+((?:_[a-z0-9]+)+)$').Success) { + 'snake_case' + } elseif ([regex]::Match($Text, '^[A-Z][A-Z0-9]*_[A-Z0-9]+((?:_[A-Z0-9]+)+)$').Success) { + 'UPPER_SNAKE_CASE' + } else { + 'Unknown' + } + + Write-Verbose "Detected casing style: [$style]" + $style + +} diff --git a/src/GitHub/private/Utilities/Casing/Split-StringByCasingStyle.ps1 b/src/GitHub/private/Utilities/Casing/Split-StringByCasingStyle.ps1 new file mode 100644 index 000000000..7c2ee3036 --- /dev/null +++ b/src/GitHub/private/Utilities/Casing/Split-StringByCasingStyle.ps1 @@ -0,0 +1,102 @@ +filter Split-StringByCasingStyle { + <# + .SYNOPSIS + Splits a kebab-case string into an array of words + + .DESCRIPTION + This function splits a kebab-case string into an array of words. + + .EXAMPLE + Split-StringByCasingStyle -Text 'this-is-a-kebab-case-string' -By kebab-case + + this + is + a + kebab + case + string + + .EXAMPLE + Split-StringByCasingStyle -Text 'this_is_a_kebab_case_string' -By 'snake_case' + + this + is + a + kebab + case + string + + .EXAMPLE + Split-StringByCasingStyle -Text 'ThisIsAPascalCaseString' -By 'PascalCase' + + This + Is + A + Pascal + Case + String + + .EXAMPLE + Split-StringByCasingStyle -Text 'thisIsACamelCaseString' -By 'camelCase' + + this + Is + A + Camel + Case + String + + .EXAMPLE + Split-StringByCasingStyle -Text 'this_is_a-CamelCaseString' -By kebab-case | Split-StringByCasingStyle -By snake_case + + this_is_a + camelcasestring + + + #> + [OutputType([string[]])] + [CmdletBinding()] + param ( + [Parameter( + Mandatory, + ValueFromPipeline + )] + [string] $Text, + + [Parameter()] + [ValidateSet( + 'lowercase', + 'UPPERCASE', + 'Wordcase', + 'Title Case', + 'PascalCase', + 'camelCase', + 'kebab-case', + 'UPPER-KEBAB-CASE', + 'snake_case', + 'UPPER_SNAKE_CASE' + )] + [string] $By, + + [Parameter()] + [switch] $ToLowerCase + ) + + $styles = $PSBoundParameters | Where-Object { $_.Value -eq $true } | Select-Object -ExpandProperty Name + + Write-Verbose "Splitting string [$Text] by casing style [$($styles -join ', ' )]" + $splitText = switch ($By) { + 'PascalCase' { [regex]::Matches($Text, '([A-Z][a-z]*)').Value; break } + 'camelCase' { [regex]::Matches($Text, '([A-Z][a-z]*)|^[a-z]+').Value; break } + 'kebab-case' { $Text -split '-'; break } + 'UPPER-KEBAB-CASE' { $Text -split '-'; break } + 'snake_case' { $Text -split '_'; break } + 'UPPER_SNAKE_CASE' { $Text -split '_'; break } + default { + $Text -split ' ' + } + } + + Write-Verbose "Result: [$($splitText -join ', ')]" + $splitText +} From 701e95fa1db238311dffcb88988784dd6d2106e5 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 1 Oct 2023 13:50:03 +0200 Subject: [PATCH 51/61] Moved hashtable and object functions --- .../{ => Hashtable}/ConvertFrom-HashTable.ps1 | 0 .../Utilities/{ => Hashtable}/ConvertTo-HashTable.ps1 | 10 ++++++++-- .../private/Utilities/{ => Hashtable}/Join-Object.ps1 | 0 .../{ => Hashtable}/Remove-HashTableEntries.ps1 | 0 4 files changed, 8 insertions(+), 2 deletions(-) rename src/GitHub/private/Utilities/{ => Hashtable}/ConvertFrom-HashTable.ps1 (100%) rename src/GitHub/private/Utilities/{ => Hashtable}/ConvertTo-HashTable.ps1 (78%) rename src/GitHub/private/Utilities/{ => Hashtable}/Join-Object.ps1 (100%) rename src/GitHub/private/Utilities/{ => Hashtable}/Remove-HashTableEntries.ps1 (100%) diff --git a/src/GitHub/private/Utilities/ConvertFrom-HashTable.ps1 b/src/GitHub/private/Utilities/Hashtable/ConvertFrom-HashTable.ps1 similarity index 100% rename from src/GitHub/private/Utilities/ConvertFrom-HashTable.ps1 rename to src/GitHub/private/Utilities/Hashtable/ConvertFrom-HashTable.ps1 diff --git a/src/GitHub/private/Utilities/ConvertTo-HashTable.ps1 b/src/GitHub/private/Utilities/Hashtable/ConvertTo-HashTable.ps1 similarity index 78% rename from src/GitHub/private/Utilities/ConvertTo-HashTable.ps1 rename to src/GitHub/private/Utilities/Hashtable/ConvertTo-HashTable.ps1 index 67b0969b4..58e876439 100644 --- a/src/GitHub/private/Utilities/ConvertTo-HashTable.ps1 +++ b/src/GitHub/private/Utilities/Hashtable/ConvertTo-HashTable.ps1 @@ -40,12 +40,18 @@ Mandatory, ValueFromPipeline )] - [object]$InputObject + [object]$InputObject, + + # The casing style of the hashtable keys. + [Parameter()] + [ValidateSet('PascalCase', 'CamelCase', 'LowerCase', 'UpperCase')] + [string]$NameCasingStyle ) [hashtable]$hashtable = @{} foreach ($item in $InputObject.PSObject.Properties) { - $hashtable[$($item.Name)] = $item.Value + $name = $NameCasingStyle ? ($item.Name | Convert-StringCasingStyle -Style $NameCasingStyle) : $item.Name + $hashtable[$name] = $item.Value } $hashtable } diff --git a/src/GitHub/private/Utilities/Join-Object.ps1 b/src/GitHub/private/Utilities/Hashtable/Join-Object.ps1 similarity index 100% rename from src/GitHub/private/Utilities/Join-Object.ps1 rename to src/GitHub/private/Utilities/Hashtable/Join-Object.ps1 diff --git a/src/GitHub/private/Utilities/Remove-HashTableEntries.ps1 b/src/GitHub/private/Utilities/Hashtable/Remove-HashTableEntries.ps1 similarity index 100% rename from src/GitHub/private/Utilities/Remove-HashTableEntries.ps1 rename to src/GitHub/private/Utilities/Hashtable/Remove-HashTableEntries.ps1 From 108daf2260b3a5ee8f55ac22bd874ddbbcd1fbdd Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 1 Oct 2023 13:50:48 +0200 Subject: [PATCH 52/61] Update Set org and user to use casing for params --- src/GitHub/public/Organization/Set-GitHubOrganization.ps1 | 2 +- src/GitHub/public/Users/Set-GitHubUser.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 b/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 index 1aa7ecc2b..f50022052 100644 --- a/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 +++ b/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 @@ -196,7 +196,7 @@ [string] $SecretScanningPushProtectionCustomLink ) - $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable + $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case Remove-HashTableEntries -Hashtable $body -RemoveNames 'OrganizationName' $inputObject = @{ diff --git a/src/GitHub/public/Users/Set-GitHubUser.ps1 b/src/GitHub/public/Users/Set-GitHubUser.ps1 index 54f710284..99ceabf61 100644 --- a/src/GitHub/public/Users/Set-GitHubUser.ps1 +++ b/src/GitHub/public/Users/Set-GitHubUser.ps1 @@ -63,7 +63,7 @@ [string] $Bio ) - $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable + $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case $inputObject = @{ APIEndpoint = '/user' From 705c8363a6b2f000658862e5930b05527d461c13 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 1 Oct 2023 14:22:01 +0200 Subject: [PATCH 53/61] UPdate convertion --- .../Casing/Get-StringCasingStyle.ps1 | 19 ++++++++++--------- .../Hashtable/ConvertTo-HashTable.ps1 | 14 ++++++++++++-- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/GitHub/private/Utilities/Casing/Get-StringCasingStyle.ps1 b/src/GitHub/private/Utilities/Casing/Get-StringCasingStyle.ps1 index dcbb7ad65..49e4624e7 100644 --- a/src/GitHub/private/Utilities/Casing/Get-StringCasingStyle.ps1 +++ b/src/GitHub/private/Utilities/Casing/Get-StringCasingStyle.ps1 @@ -19,7 +19,7 @@ .EXAMPLE 'Testtesttest' | Get-StringCasingStyle - Titlecase + Sentencecase .EXAMPLE 'TestTestTest' | Get-StringCasingStyle @@ -64,6 +64,7 @@ Mandatory, ValueFromPipeline )] + [ValidateNotNullOrEmpty()] [string] $Text ) @@ -72,20 +73,20 @@ } elseif ([regex]::Match($Text, '^[A-Z][A-Z0-9]*$').Success) { 'UPPERCASE' } elseif ([regex]::Match($Text, '^[A-Z][a-z0-9]*$').Success) { - 'Wordcase' - } elseif ([regex]::Match($Text, '^([A-Z][a-zA-Z0-9]*)(\s+[A-Z][a-zA-Z0-9]*)*$').Success) { + 'Sentencecase' + } elseif ([regex]::Match($Text, '^([A-Z][a-z]*)(\s+[A-Z][a-z]*)+$').Success) { 'Title Case' - } elseif ([regex]::Match($Text, '^[A-Z][a-z0-9]*((?:[A-Z][a-z0-9]+)+)$').Success) { + } elseif ([regex]::Match($Text, '^[A-Z][a-z0-9]*([A-Z][a-z0-9]*)+$').Success) { 'PascalCase' - } elseif ([regex]::Match($Text, '^[a-z][a-z0-9]*[A-Z][a-z0-9]*((?:[A-Z][a-z0-9]*)+)$').Success) { + } elseif ([regex]::Match($Text, '^[a-z][a-z0-9]*([A-Z][a-z0-9]*)+$').Success) { 'camelCase' - } elseif ([regex]::Match($Text, '^[a-z][a-z0-9]*-[a-z0-9]+((?:-[a-z0-9]+)+)$').Success) { + } elseif ([regex]::Match($Text, '^[a-z][a-z0-9]*(-[a-z0-9]+)+$').Success) { 'kebab-case' - } elseif ([regex]::Match($Text, '^[A-Z][A-Z0-9]*-[A-Z0-9]+((?:-[A-Z0-9]+)+)$').Success) { + } elseif ([regex]::Match($Text, '^[A-Z][A-Z0-9]*(-[A-Z0-9]+)+$').Success) { 'UPPER-KEBAB-CASE' - } elseif ([regex]::Match($Text, '^[a-z][a-z0-9]*_[a-z0-9]+((?:_[a-z0-9]+)+)$').Success) { + } elseif ([regex]::Match($Text, '^[a-z][a-z0-9]*(_[a-z0-9]+)+$').Success) { 'snake_case' - } elseif ([regex]::Match($Text, '^[A-Z][A-Z0-9]*_[A-Z0-9]+((?:_[A-Z0-9]+)+)$').Success) { + } elseif ([regex]::Match($Text, '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)+$').Success) { 'UPPER_SNAKE_CASE' } else { 'Unknown' diff --git a/src/GitHub/private/Utilities/Hashtable/ConvertTo-HashTable.ps1 b/src/GitHub/private/Utilities/Hashtable/ConvertTo-HashTable.ps1 index 58e876439..8b9023554 100644 --- a/src/GitHub/private/Utilities/Hashtable/ConvertTo-HashTable.ps1 +++ b/src/GitHub/private/Utilities/Hashtable/ConvertTo-HashTable.ps1 @@ -44,13 +44,23 @@ # The casing style of the hashtable keys. [Parameter()] - [ValidateSet('PascalCase', 'CamelCase', 'LowerCase', 'UpperCase')] + [ValidateSet( + 'lowercase', + 'UPPERCASE', + 'Title Case', + 'PascalCase', + 'camelCase', + 'kebab-case', + 'UPPER-KEBAB-CASE', + 'snake_case', + 'UPPER_SNAKE_CASE' + )] [string]$NameCasingStyle ) [hashtable]$hashtable = @{} foreach ($item in $InputObject.PSObject.Properties) { - $name = $NameCasingStyle ? ($item.Name | Convert-StringCasingStyle -Style $NameCasingStyle) : $item.Name + $name = $NameCasingStyle ? ($item.Name | Convert-StringCasingStyle -To $NameCasingStyle) : $item.Name $hashtable[$name] = $item.Value } $hashtable From 2e640457104125268305b37c1c1d31eec35bf70a Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 1 Oct 2023 14:32:19 +0200 Subject: [PATCH 54/61] Fix hashtable values to lower --- .../private/Utilities/Casing/Convert-StringCasingStyle.ps1 | 3 ++- .../private/Utilities/Casing/Split-StringByCasingStyle.ps1 | 7 +++---- src/GitHub/public/Organization/Set-GitHubOrganization.ps1 | 2 +- tools/utilities/Local-Testing.ps1 | 1 - 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/GitHub/private/Utilities/Casing/Convert-StringCasingStyle.ps1 b/src/GitHub/private/Utilities/Casing/Convert-StringCasingStyle.ps1 index 68997f7ef..780ebbe75 100644 --- a/src/GitHub/private/Utilities/Casing/Convert-StringCasingStyle.ps1 +++ b/src/GitHub/private/Utilities/Casing/Convert-StringCasingStyle.ps1 @@ -38,6 +38,7 @@ 'lowercase', 'UPPERCASE', 'Title Case', + 'Sentencecase', 'PascalCase', 'camelCase', 'kebab-case', @@ -57,7 +58,7 @@ 'lowercase' { ($words -join '').toLower() } 'UPPERCASE' { ($words -join '').toUpper() } 'Title Case' { ($words | ForEach-Object { $_.Substring(0, 1).ToUpper() + $_.Substring(1).ToLower() }) -join ' ' } - 'Wordcase' { $words -join '' | ForEach-Object { $_.Substring(0, 1).ToUpper() + $_.Substring(1).ToLower() } } + 'Sentencecase' { $words -join '' | ForEach-Object { $_.Substring(0, 1).ToUpper() + $_.Substring(1).ToLower() } } 'kebab-case' { ($words -join '-').ToLower() } 'snake_case' { ($words -join '_').ToLower() } 'PascalCase' { ($words | ForEach-Object { $_.Substring(0, 1).ToUpper() + $_.Substring(1).ToLower() }) -join '' } diff --git a/src/GitHub/private/Utilities/Casing/Split-StringByCasingStyle.ps1 b/src/GitHub/private/Utilities/Casing/Split-StringByCasingStyle.ps1 index 7c2ee3036..df50d5470 100644 --- a/src/GitHub/private/Utilities/Casing/Split-StringByCasingStyle.ps1 +++ b/src/GitHub/private/Utilities/Casing/Split-StringByCasingStyle.ps1 @@ -57,17 +57,19 @@ [OutputType([string[]])] [CmdletBinding()] param ( + # The string to split [Parameter( Mandatory, ValueFromPipeline )] [string] $Text, + # The casing style to split the string by [Parameter()] [ValidateSet( 'lowercase', 'UPPERCASE', - 'Wordcase', + 'Sentencecase', 'Title Case', 'PascalCase', 'camelCase', @@ -77,9 +79,6 @@ 'UPPER_SNAKE_CASE' )] [string] $By, - - [Parameter()] - [switch] $ToLowerCase ) $styles = $PSBoundParameters | Where-Object { $_.Value -eq $true } | Select-Object -ExpandProperty Name diff --git a/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 b/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 index f50022052..4f0e3e6b9 100644 --- a/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 +++ b/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 @@ -197,7 +197,7 @@ ) $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashTableEntries -Hashtable $body -RemoveNames 'OrganizationName' + Remove-HashTableEntries -Hashtable $body -RemoveNames 'organization_name' $inputObject = @{ APIEndpoint = "/orgs/$OrganizationName" diff --git a/tools/utilities/Local-Testing.ps1 b/tools/utilities/Local-Testing.ps1 index da0d7b02a..5598f3b0a 100644 --- a/tools/utilities/Local-Testing.ps1 +++ b/tools/utilities/Local-Testing.ps1 @@ -51,4 +51,3 @@ Set-GitHubUser -Name 'MariusStorhaug' -Company 'PSModule' Set-GitHubUser -Name 'MariusStorhaug' -Company '@DNBBank' Set-GitHubUser -Name 'MariusStorhaug' -Company ' ' Set-GitHubUser -Name 'MariusStorhaug' -Hireable $true - From d3320ff69d4a7df6e96a97a487cd6c186ae1457c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 1 Oct 2023 14:34:19 +0200 Subject: [PATCH 55/61] fix --- .../private/Utilities/Casing/Split-StringByCasingStyle.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GitHub/private/Utilities/Casing/Split-StringByCasingStyle.ps1 b/src/GitHub/private/Utilities/Casing/Split-StringByCasingStyle.ps1 index df50d5470..a3cd8d78b 100644 --- a/src/GitHub/private/Utilities/Casing/Split-StringByCasingStyle.ps1 +++ b/src/GitHub/private/Utilities/Casing/Split-StringByCasingStyle.ps1 @@ -78,7 +78,7 @@ 'snake_case', 'UPPER_SNAKE_CASE' )] - [string] $By, + [string] $By ) $styles = $PSBoundParameters | Where-Object { $_.Value -eq $true } | Select-Object -ExpandProperty Name From 65d2186dbaa5625be798ff3aac214497abf4c6d5 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 1 Oct 2023 16:03:38 +0200 Subject: [PATCH 56/61] Use UTF 8 to support icons + Store request, so it is available from calling function --- src/GitHub/public/API/Invoke-GitHubAPI.ps1 | 5 +++-- tools/utilities/Local-Testing.ps1 | 8 +++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 index 0a8891704..36855c337 100644 --- a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 +++ b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 @@ -42,7 +42,7 @@ # The 'Accept' header for the API request. If not provided, the default will be used by GitHub's API. [Parameter()] - [string] $Accept = 'application/vnd.github+json', + [string] $Accept = 'application/vnd.github+json; charset=utf-8', # Specifies the HTTP version used for the request. [Parameter()] @@ -58,7 +58,7 @@ # The 'Content-Type' header for the API request. The default is 'application/vnd.github+json'. [Parameter()] - [string] $ContentType = 'application/vnd.github+json', + [string] $ContentType = 'application/vnd.github+json; charset=utf-8', # The GitHub API version to be used. By default, it pulls from a configuration script variable. [Parameter()] @@ -133,6 +133,7 @@ $statusCode = $APICallStatusCode | ConvertTo-Json -Depth 100 | ConvertFrom-Json $responseHeaders = $APICallResponseHeaders | ConvertTo-Json -Depth 100 | ConvertFrom-Json [pscustomobject]@{ + Request = $APICall Response = $_ StatusCode = $statusCode ResponseHeaders = $responseHeaders diff --git a/tools/utilities/Local-Testing.ps1 b/tools/utilities/Local-Testing.ps1 index 5598f3b0a..567aa43ee 100644 --- a/tools/utilities/Local-Testing.ps1 +++ b/tools/utilities/Local-Testing.ps1 @@ -41,13 +41,11 @@ Get-GitHubOrganization -OrganizationName 'PSModule' Get-GitHubOrganizationAppInstallation -OrganizationName 'PSModule' Set-GitHubOrganization -OrganizationName 'PSModule' -Blog 'https://www.psmodule.io' -Set-GitHubOrganization -OrganizationName 'PSModule' -Blog '' #-> Does not work. -Set-GitHubOrganization -OrganizationName 'PSModule' -Blog ' ' +Set-GitHubOrganization -OrganizationName 'PSModule' -Blog '' +Set-GitHubOrganization -OrganizationName 'PSModule' -Company 'PSModule123' -DefaultRepositoryPermission admin Set-GitHubOrganization -OrganizationName 'PSModule' -Company 'PSModule' -DefaultRepositoryPermission read -Get-GitHubUser -Set-GitHubUser -Name 'MariusStorhaug' -Company 'PSModule' -Set-GitHubUser -Name 'MariusStorhaug' -Company '@DNBBank' +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 From 7492974c4b3fd3faf59307630b49862592564445 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 1 Oct 2023 16:33:05 +0200 Subject: [PATCH 57/61] Fix for user section --- .../Users/Get-GitHubAllUser.ps1} | 12 ++-- src/GitHub/private/Users/Get-GitHubMyUser.ps1 | 30 +++++++++ .../private/Users/Get-GitHubUserByName.ps1 | 41 ++++++++++++ src/GitHub/public/Users/Get-GitHubUser.ps1 | 63 +++++++++++++++---- 4 files changed, 126 insertions(+), 20 deletions(-) rename src/GitHub/{public/Users/Get-GitHubUserList.ps1 => private/Users/Get-GitHubAllUser.ps1} (80%) create mode 100644 src/GitHub/private/Users/Get-GitHubMyUser.ps1 create mode 100644 src/GitHub/private/Users/Get-GitHubUserByName.ps1 diff --git a/src/GitHub/public/Users/Get-GitHubUserList.ps1 b/src/GitHub/private/Users/Get-GitHubAllUser.ps1 similarity index 80% rename from src/GitHub/public/Users/Get-GitHubUserList.ps1 rename to src/GitHub/private/Users/Get-GitHubAllUser.ps1 index 344a77945..a996a830e 100644 --- a/src/GitHub/public/Users/Get-GitHubUserList.ps1 +++ b/src/GitHub/private/Users/Get-GitHubAllUser.ps1 @@ -1,4 +1,4 @@ -filter Get-GitHubUserList { +filter Get-GitHubAllUser { <# .SYNOPSIS List users @@ -9,9 +9,9 @@ Note: Pagination is powered exclusively by the `since` parameter. Use the [Link header](https://docs.github.com/rest/guides/using-pagination-in-the-rest-api#using-link-headers) to get the URL for the next page of users. .EXAMPLE - Get-GitHubUserList -Since 17722253 + Get-GitHubAllUser -Since 17722253 - Get the authenticated user + Get a list of users, starting with the user 'MariusStorhaug'. .NOTES https://docs.github.com/rest/users/users#list-users @@ -22,15 +22,13 @@ # A user ID. Only return users with an ID greater than this ID. [Parameter()] [int] $Since = 0, + # The number of results per page (max 100). [Parameter()] [int] $PerPage = 30 ) - $body = @{ - since = $Since - per_page = $PerPage - } + $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case $inputObject = @{ APIEndpoint = "/users" diff --git a/src/GitHub/private/Users/Get-GitHubMyUser.ps1 b/src/GitHub/private/Users/Get-GitHubMyUser.ps1 new file mode 100644 index 000000000..3bec059c4 --- /dev/null +++ b/src/GitHub/private/Users/Get-GitHubMyUser.ps1 @@ -0,0 +1,30 @@ +filter Get-GitHubMyUser { + <# + .SYNOPSIS + Get the authenticated user + + .DESCRIPTION + If the authenticated user is authenticated with an OAuth token with the `user` scope, then the response lists public and private profile information. + If the authenticated user is authenticated through OAuth without the `user` scope, then the response lists only public profile information. + + .EXAMPLE + Get-GitHubMyUser + + Get the authenticated user + + .NOTES + https://docs.github.com/rest/users/users#get-the-authenticated-user + #> + [OutputType([pscustomobject])] + [Alias('Get-GitHubContext')] + [CmdletBinding()] + param () + + $inputObject = @{ + APIEndpoint = '/user' + Method = 'GET' + } + + (Invoke-GitHubAPI @inputObject).Response + +} diff --git a/src/GitHub/private/Users/Get-GitHubUserByName.ps1 b/src/GitHub/private/Users/Get-GitHubUserByName.ps1 new file mode 100644 index 000000000..6d78f9716 --- /dev/null +++ b/src/GitHub/private/Users/Get-GitHubUserByName.ps1 @@ -0,0 +1,41 @@ +filter Get-GitHubUserByName { + <# + .SYNOPSIS + Get a user + + .DESCRIPTION + Provides publicly available information about someone with a GitHub account. + GitHub Apps with the `Plan` user permission can use this endpoint to retrieve information about a user's GitHub plan. The GitHub App must be authenticated as a user. See "[Identifying and authorizing users for GitHub Apps](https://docs.github.com/apps/building-github-apps/identifying-and-authorizing-users-for-github-apps/)" for details about authentication. For an example response, see 'Response with GitHub plan information' below" + The `email` key in the following response is the publicly visible email address from your GitHub [profile page](https://github.com/settings/profile). When setting up your profile, you can select a primary email address to be ΓÇ£publicΓÇ¥ which provides an email entry for this endpoint. If you do not set a public email address for `email`, then it will have a value of `null`. You only see publicly visible email addresses when authenticated with GitHub. For more information, see [Authentication](https://docs.github.com/rest/overview/resources-in-the-rest-api#authentication). + The Emails API enables you to list all of your email addresses, and toggle a primary email to be visible publicly. For more information, see "[Emails API](https://docs.github.com/rest/users/emails)". + + .EXAMPLE + Get-GitHubUserByName -Username 'octocat' + + Get the 'octocat' user. + + .NOTES + https://docs.github.com/rest/users/users#get-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" + Method = 'GET' + } + + (Invoke-GitHubAPI @inputObject).Response + +} diff --git a/src/GitHub/public/Users/Get-GitHubUser.ps1 b/src/GitHub/public/Users/Get-GitHubUser.ps1 index 3cf281dc7..6e8ef9dc6 100644 --- a/src/GitHub/public/Users/Get-GitHubUser.ps1 +++ b/src/GitHub/public/Users/Get-GitHubUser.ps1 @@ -1,30 +1,67 @@ filter Get-GitHubUser { <# .SYNOPSIS - Get the authenticated user + List user(s) .DESCRIPTION - If the authenticated user is authenticated with an OAuth token with the `user` scope, then the response lists public and private profile information. - If the authenticated user is authenticated through OAuth without the `user` scope, then the response lists only public profile information. + Get the authenticated user - if no parameters are provided. + Get a given user - if a username is provided. + Lists all users, in the order that they signed up on GitHub - if '-All' is provided. .EXAMPLE Get-GitHubUser - Get the authenticated user + Get the authenticated user. + + .EXAMPLE + Get-GitHubUser -Username 'octocat' + + Get the 'octocat' user. + + .EXAMPLE + Get-GitHubUser -All -Since 17722253 + + Get a list of users, starting with the user 'MariusStorhaug'. .NOTES - https://docs.github.com/rest/users/users#get-the-authenticated-user + https://docs.github.com/en/rest/users/users #> [OutputType([pscustomobject])] - [Alias('Get-GitHubContext')] - [CmdletBinding()] - param () + [CmdletBinding(DefaultParameterSetName = '__DefaultSet')] + param ( + # The handle for the GitHub user account. + [Parameter( + Mandatory, + ParameterSetName = 'NamedUser', + ValueFromPipelineByPropertyName + )] + [string] $Username, - $inputObject = @{ - APIEndpoint = '/user' - Method = 'GET' - } + # List all users. Use '-Since' to start at a specific user id. + [Parameter( + Mandatory, + ParameterSetName = 'AllUsers' + )] + [switch] $All, - (Invoke-GitHubAPI @inputObject).Response + # A user ID. Only return users with an ID greater than this ID. + [Parameter(ParameterSetName = 'AllUsers')] + [int] $Since = 0, + # The number of results per page (max 100). + [Parameter(ParameterSetName = 'AllUsers')] + [int] $PerPage = 30 + ) + + switch ($PSCmdlet.ParameterSetName) { + '__DefaultSet' { + Get-GitHubMyUser + } + 'NamedUser' { + Get-GitHubUserByName -Username $Username + } + 'AllUsers' { + Get-GitHubAllUsers -Since $Since -PerPage $PerPage + } + } } From 15ec1b1254fb905f1b05f4c8c2dec7cde17f56df Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 1 Oct 2023 16:34:58 +0200 Subject: [PATCH 58/61] dont select lang for docs --- src/GitHub/en_US/about_Auth.help.txt | 6 +++--- .../Auth/DeviceFlow/Invoke-GitHubDeviceFlowLogin.ps1 | 6 +++--- .../private/Auth/DeviceFlow/Request-GitHubAccessToken.ps1 | 2 +- .../private/Auth/DeviceFlow/Request-GitHubDeviceCode.ps1 | 4 ++-- .../private/Auth/DeviceFlow/Wait-GitHubAccessToken.ps1 | 2 +- src/GitHub/public/Actions/Disable-GitHubWorkflow.ps1 | 2 +- src/GitHub/public/Actions/Enable-GitHubWorkflow.ps1 | 2 +- src/GitHub/public/Actions/Get-GitHubWorkflow.ps1 | 2 +- src/GitHub/public/Actions/Get-GitHubWorkflowRun.ps1 | 4 ++-- src/GitHub/public/Actions/Get-GitHubWorkflowUsage.ps1 | 2 +- src/GitHub/public/Actions/Start-GitHubWorkflow.ps1 | 2 +- src/GitHub/public/Actions/Start-GitHubWorkflowReRun.ps1 | 2 +- src/GitHub/public/Actions/Stop-GitHubWorkflowRun.ps1 | 2 +- src/GitHub/public/Auth/Connect-GitHubAccount.ps1 | 6 +++--- src/GitHub/public/Deployments/Get-GitHubEnvironment.ps1 | 2 +- .../public/Deployments/Get-GitHubEnvironmentSecrets.ps1 | 2 +- src/GitHub/public/Deployments/Update-GitHubEnvironment.ps1 | 2 +- src/GitHub/public/Emojis/Get-GitHubEmojis.ps1 | 2 +- src/GitHub/public/Markdown/Get-GitHubMarkdown.ps1 | 2 +- src/GitHub/public/Markdown/Get-GitHubMarkdownRaw.ps1 | 2 +- src/GitHub/public/Organization/Get-GitHubOrganization.ps1 | 2 +- src/GitHub/public/Teams/Get-GitHubRepoTeam.ps1 | 2 +- src/GitHub/public/Users/Get-GitHubUser.ps1 | 2 +- tools/utilities/GitHubAPI.ps1 | 2 +- 24 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/GitHub/en_US/about_Auth.help.txt b/src/GitHub/en_US/about_Auth.help.txt index d7bf1793f..2571c556d 100644 --- a/src/GitHub/en_US/about_Auth.help.txt +++ b/src/GitHub/en_US/about_Auth.help.txt @@ -38,8 +38,8 @@ KEYWORDS SEE ALSO For more information on the Device Flow visit: - - https://docs.github.com/en/apps/creating-github-apps/writing-code-for-a-github-app/building-a-cli-with-a-github-app + - https://docs.github.com/apps/creating-github-apps/writing-code-for-a-github-app/building-a-cli-with-a-github-app For information about scopes and other authentication methods on GitHub: - - https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/scopes-for-oauth-apps - - https://docs.github.com/en/rest/overview/other-authentication-methods#authenticating-for-saml-sso + - https://docs.github.com/apps/oauth-apps/building-oauth-apps/scopes-for-oauth-apps + - https://docs.github.com/rest/overview/other-authentication-methods#authenticating-for-saml-sso diff --git a/src/GitHub/private/Auth/DeviceFlow/Invoke-GitHubDeviceFlowLogin.ps1 b/src/GitHub/private/Auth/DeviceFlow/Invoke-GitHubDeviceFlowLogin.ps1 index 712462fbb..6bc64b2d6 100644 --- a/src/GitHub/private/Auth/DeviceFlow/Invoke-GitHubDeviceFlowLogin.ps1 +++ b/src/GitHub/private/Auth/DeviceFlow/Invoke-GitHubDeviceFlowLogin.ps1 @@ -14,8 +14,8 @@ .NOTES For more info about the Device Flow visit: - https://docs.github.com/en/apps/creating-github-apps/writing-code-for-a-github-app/building-a-cli-with-a-github-app - https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/authorizing-oauth-apps#device-flow + https://docs.github.com/apps/creating-github-apps/writing-code-for-a-github-app/building-a-cli-with-a-github-app + https://docs.github.com/apps/oauth-apps/building-oauth-apps/authorizing-oauth-apps#device-flow #> [OutputType([void])] [CmdletBinding()] @@ -27,7 +27,7 @@ # The scope of the access token, when using OAuth authentication. # Provide the list of scopes as space-separated values. # For more information on scopes visit: - # https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/scopes-for-oauth-apps + # https://docs.github.com/apps/oauth-apps/building-oauth-apps/scopes-for-oauth-apps [Parameter()] [string] $Scope, diff --git a/src/GitHub/private/Auth/DeviceFlow/Request-GitHubAccessToken.ps1 b/src/GitHub/private/Auth/DeviceFlow/Request-GitHubAccessToken.ps1 index 171d5bbe1..d920e8f6e 100644 --- a/src/GitHub/private/Auth/DeviceFlow/Request-GitHubAccessToken.ps1 +++ b/src/GitHub/private/Auth/DeviceFlow/Request-GitHubAccessToken.ps1 @@ -14,7 +14,7 @@ .NOTES For more info about the Device Flow visit: - https://docs.github.com/en/apps/creating-github-apps/writing-code-for-a-github-app/building-a-cli-with-a-github-app + https://docs.github.com/apps/creating-github-apps/writing-code-for-a-github-app/building-a-cli-with-a-github-app #> [OutputType([PSCustomObject])] [CmdletBinding(DefaultParameterSetName = 'DeviceFlow')] diff --git a/src/GitHub/private/Auth/DeviceFlow/Request-GitHubDeviceCode.ps1 b/src/GitHub/private/Auth/DeviceFlow/Request-GitHubDeviceCode.ps1 index dc6cdf796..1171229ea 100644 --- a/src/GitHub/private/Auth/DeviceFlow/Request-GitHubDeviceCode.ps1 +++ b/src/GitHub/private/Auth/DeviceFlow/Request-GitHubDeviceCode.ps1 @@ -13,7 +13,7 @@ .NOTES For more info about the Device Flow visit: - https://docs.github.com/en/apps/creating-github-apps/writing-code-for-a-github-app/building-a-cli-with-a-github-app + https://docs.github.com/apps/creating-github-apps/writing-code-for-a-github-app/building-a-cli-with-a-github-app #> [OutputType([PSCustomObject])] [CmdletBinding()] @@ -25,7 +25,7 @@ # The scope of the access token, when using OAuth authentication. # Provide the list of scopes as space-separated values. # For more information on scopes visit: - # https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/scopes-for-oauth-apps + # https://docs.github.com/apps/oauth-apps/building-oauth-apps/scopes-for-oauth-apps [Parameter()] [string] $Scope = 'gist, read:org, repo, workflow' ) diff --git a/src/GitHub/private/Auth/DeviceFlow/Wait-GitHubAccessToken.ps1 b/src/GitHub/private/Auth/DeviceFlow/Wait-GitHubAccessToken.ps1 index 867d5890e..2a45ed719 100644 --- a/src/GitHub/private/Auth/DeviceFlow/Wait-GitHubAccessToken.ps1 +++ b/src/GitHub/private/Auth/DeviceFlow/Wait-GitHubAccessToken.ps1 @@ -17,7 +17,7 @@ .NOTES For more info about the Device Flow visit: - https://docs.github.com/en/apps/creating-github-apps/writing-code-for-a-github-app/building-a-cli-with-a-github-app + https://docs.github.com/apps/creating-github-apps/writing-code-for-a-github-app/building-a-cli-with-a-github-app #> [OutputType([PSCustomObject])] [CmdletBinding(DefaultParameterSetName = 'DeviceFlow')] diff --git a/src/GitHub/public/Actions/Disable-GitHubWorkflow.ps1 b/src/GitHub/public/Actions/Disable-GitHubWorkflow.ps1 index 58a990b83..8ec149a8a 100644 --- a/src/GitHub/public/Actions/Disable-GitHubWorkflow.ps1 +++ b/src/GitHub/public/Actions/Disable-GitHubWorkflow.ps1 @@ -1,7 +1,7 @@ filter Disable-GitHubWorkflow { <# .NOTES - https://docs.github.com/en/rest/reference/actions#disable-a-workflow + https://docs.github.com/rest/reference/actions#disable-a-workflow #> [CmdletBinding()] param ( diff --git a/src/GitHub/public/Actions/Enable-GitHubWorkflow.ps1 b/src/GitHub/public/Actions/Enable-GitHubWorkflow.ps1 index 9fe8b6b2d..681139fe7 100644 --- a/src/GitHub/public/Actions/Enable-GitHubWorkflow.ps1 +++ b/src/GitHub/public/Actions/Enable-GitHubWorkflow.ps1 @@ -1,7 +1,7 @@ filter Enable-GitHubWorkflow { <# .NOTES - https://docs.github.com/en/rest/reference/actions#enable-a-workflow + https://docs.github.com/rest/reference/actions#enable-a-workflow #> [CmdletBinding()] param ( diff --git a/src/GitHub/public/Actions/Get-GitHubWorkflow.ps1 b/src/GitHub/public/Actions/Get-GitHubWorkflow.ps1 index 70aa401de..0be3d2b40 100644 --- a/src/GitHub/public/Actions/Get-GitHubWorkflow.ps1 +++ b/src/GitHub/public/Actions/Get-GitHubWorkflow.ps1 @@ -19,7 +19,7 @@ Gets the 'hello-world.yml' workflow in the 'octocat/hello-world' repository. .NOTES - https://docs.github.com/en/rest/actions/workflows?apiVersion=2022-11-28#list-repository-workflows + https://docs.github.com/rest/actions/workflows?apiVersion=2022-11-28#list-repository-workflows #> [CmdletBinding(DefaultParameterSetName = 'ByName')] param ( diff --git a/src/GitHub/public/Actions/Get-GitHubWorkflowRun.ps1 b/src/GitHub/public/Actions/Get-GitHubWorkflowRun.ps1 index c7b6e26be..eaecf3997 100644 --- a/src/GitHub/public/Actions/Get-GitHubWorkflowRun.ps1 +++ b/src/GitHub/public/Actions/Get-GitHubWorkflowRun.ps1 @@ -1,8 +1,8 @@ filter Get-GitHubWorkflowRun { <# .NOTES - https://docs.github.com/en/rest/actions/workflow-runs?apiVersion=2022-11-28#list-workflow-runs-for-a-workflow - https://docs.github.com/en/rest/actions/workflow-runs?apiVersion=2022-11-28#list-workflow-runs-for-a-repository + https://docs.github.com/rest/actions/workflow-runs?apiVersion=2022-11-28#list-workflow-runs-for-a-workflow + https://docs.github.com/rest/actions/workflow-runs?apiVersion=2022-11-28#list-workflow-runs-for-a-repository #> [CmdletBinding(DefaultParameterSetName = 'Repo')] param ( diff --git a/src/GitHub/public/Actions/Get-GitHubWorkflowUsage.ps1 b/src/GitHub/public/Actions/Get-GitHubWorkflowUsage.ps1 index 030d8ee4e..2d541c094 100644 --- a/src/GitHub/public/Actions/Get-GitHubWorkflowUsage.ps1 +++ b/src/GitHub/public/Actions/Get-GitHubWorkflowUsage.ps1 @@ -19,7 +19,7 @@ An example .NOTES - https://docs.github.com/en/rest/reference/actions#get-workflow-usage + https://docs.github.com/rest/reference/actions#get-workflow-usage #> [CmdletBinding( DefaultParameterSetName = 'ByName' diff --git a/src/GitHub/public/Actions/Start-GitHubWorkflow.ps1 b/src/GitHub/public/Actions/Start-GitHubWorkflow.ps1 index eb19b519e..1dc3a42a8 100644 --- a/src/GitHub/public/Actions/Start-GitHubWorkflow.ps1 +++ b/src/GitHub/public/Actions/Start-GitHubWorkflow.ps1 @@ -16,7 +16,7 @@ .NOTES # API Reference - # https://docs.github.com/en/free-pro-team@latest/rest/actions/workflows?apiVersion=2022-11-28#create-a-workflow-dispatch-event + # https://docs.github.com/free-pro-team@latest/rest/actions/workflows?apiVersion=2022-11-28#create-a-workflow-dispatch-event #> [CmdletBinding()] param ( diff --git a/src/GitHub/public/Actions/Start-GitHubWorkflowReRun.ps1 b/src/GitHub/public/Actions/Start-GitHubWorkflowReRun.ps1 index 26fde62ca..3d4ae80b6 100644 --- a/src/GitHub/public/Actions/Start-GitHubWorkflowReRun.ps1 +++ b/src/GitHub/public/Actions/Start-GitHubWorkflowReRun.ps1 @@ -19,7 +19,7 @@ An example .NOTES - https://docs.github.com/en/rest/reference/actions#re-run-a-workflow + https://docs.github.com/rest/reference/actions#re-run-a-workflow #> [CmdletBinding()] param ( diff --git a/src/GitHub/public/Actions/Stop-GitHubWorkflowRun.ps1 b/src/GitHub/public/Actions/Stop-GitHubWorkflowRun.ps1 index 5e01d5152..7b8eb8ecf 100644 --- a/src/GitHub/public/Actions/Stop-GitHubWorkflowRun.ps1 +++ b/src/GitHub/public/Actions/Stop-GitHubWorkflowRun.ps1 @@ -19,7 +19,7 @@ An example .NOTES - https://docs.github.com/en/rest/reference/actions#cancel-a-workflow-run + https://docs.github.com/rest/reference/actions#cancel-a-workflow-run #> [CmdletBinding()] [alias('Cancel-GitHubWorkflowRun')] diff --git a/src/GitHub/public/Auth/Connect-GitHubAccount.ps1 b/src/GitHub/public/Auth/Connect-GitHubAccount.ps1 index d1f8f19f8..a9f8f77ba 100644 --- a/src/GitHub/public/Auth/Connect-GitHubAccount.ps1 +++ b/src/GitHub/public/Auth/Connect-GitHubAccount.ps1 @@ -31,7 +31,7 @@ Connects to GitHub using a device flow login and sets the scope of the access token. .NOTES - https://docs.github.com/en/rest/overview/other-authentication-methods#authenticating-for-saml-sso + https://docs.github.com/rest/overview/other-authentication-methods#authenticating-for-saml-sso #> [Alias('Connect-GHAccount')] [Alias('Connect-GitHub')] @@ -45,7 +45,7 @@ param ( # Choose between authentication methods, either OAuthApp or GitHubApp. # For more info about the types of authentication visit: - # https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/differences-between-github-apps-and-oauth-apps + # https://docs.github.com/apps/oauth-apps/building-oauth-apps/differences-between-github-apps-and-oauth-apps [Parameter(ParameterSetName = 'DeviceFlow')] [ValidateSet('OAuthApp', 'GitHubApp')] [string] $Mode = 'GitHubApp', @@ -53,7 +53,7 @@ # The scope of the access token, when using OAuth authentication. # Provide the list of scopes as space-separated values. # For more information on scopes visit: - # https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/scopes-for-oauth-apps + # https://docs.github.com/apps/oauth-apps/building-oauth-apps/scopes-for-oauth-apps [Parameter(ParameterSetName = 'DeviceFlow')] [string] $Scope = 'gist read:org repo workflow', diff --git a/src/GitHub/public/Deployments/Get-GitHubEnvironment.ps1 b/src/GitHub/public/Deployments/Get-GitHubEnvironment.ps1 index fe98398ba..0cb07872f 100644 --- a/src/GitHub/public/Deployments/Get-GitHubEnvironment.ps1 +++ b/src/GitHub/public/Deployments/Get-GitHubEnvironment.ps1 @@ -16,7 +16,7 @@ An example .NOTES - https://docs.github.com/en/rest/reference/repos#get-all-environments + https://docs.github.com/rest/reference/repos#get-all-environments #> [CmdletBinding()] param ( diff --git a/src/GitHub/public/Deployments/Get-GitHubEnvironmentSecrets.ps1 b/src/GitHub/public/Deployments/Get-GitHubEnvironmentSecrets.ps1 index 9b0fbdf86..643eb7167 100644 --- a/src/GitHub/public/Deployments/Get-GitHubEnvironmentSecrets.ps1 +++ b/src/GitHub/public/Deployments/Get-GitHubEnvironmentSecrets.ps1 @@ -19,7 +19,7 @@ An example .NOTES - https://docs.github.com/en/rest/reference/repos#get-all-environments + https://docs.github.com/rest/reference/repos#get-all-environments #> [CmdletBinding()] param ( diff --git a/src/GitHub/public/Deployments/Update-GitHubEnvironment.ps1 b/src/GitHub/public/Deployments/Update-GitHubEnvironment.ps1 index 6b4d3115c..c03cc78f2 100644 --- a/src/GitHub/public/Deployments/Update-GitHubEnvironment.ps1 +++ b/src/GitHub/public/Deployments/Update-GitHubEnvironment.ps1 @@ -1,7 +1,7 @@ filter Update-GitHubEnvironment { <# .NOTES - https://docs.github.com/en/rest/reference/repos#create-or-update-an-environment + https://docs.github.com/rest/reference/repos#create-or-update-an-environment #> [CmdletBinding()] param ( diff --git a/src/GitHub/public/Emojis/Get-GitHubEmojis.ps1 b/src/GitHub/public/Emojis/Get-GitHubEmojis.ps1 index 5419ec80b..5342ae458 100644 --- a/src/GitHub/public/Emojis/Get-GitHubEmojis.ps1 +++ b/src/GitHub/public/Emojis/Get-GitHubEmojis.ps1 @@ -1,7 +1,7 @@ filter Get-GitHubEmojis { <# .NOTES - https://docs.github.com/en/rest/reference/emojis#get-emojis + https://docs.github.com/rest/reference/emojis#get-emojis #> [CmdletBinding()] param ( diff --git a/src/GitHub/public/Markdown/Get-GitHubMarkdown.ps1 b/src/GitHub/public/Markdown/Get-GitHubMarkdown.ps1 index 393b4065b..8070f9131 100644 --- a/src/GitHub/public/Markdown/Get-GitHubMarkdown.ps1 +++ b/src/GitHub/public/Markdown/Get-GitHubMarkdown.ps1 @@ -1,7 +1,7 @@ filter Get-GitHubMarkdown { <# .NOTES - https://docs.github.com/en/rest/reference/meta#github-api-root + https://docs.github.com/rest/reference/meta#github-api-root #> [CmdletBinding()] param ( diff --git a/src/GitHub/public/Markdown/Get-GitHubMarkdownRaw.ps1 b/src/GitHub/public/Markdown/Get-GitHubMarkdownRaw.ps1 index d4033d9af..053764516 100644 --- a/src/GitHub/public/Markdown/Get-GitHubMarkdownRaw.ps1 +++ b/src/GitHub/public/Markdown/Get-GitHubMarkdownRaw.ps1 @@ -1,7 +1,7 @@ filter Get-GitHubMarkdownRaw { <# .NOTES - https://docs.github.com/en/rest/reference/meta#github-api-root + https://docs.github.com/rest/reference/meta#github-api-root #> [CmdletBinding()] param ( diff --git a/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 b/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 index e50fb8c67..054242e3e 100644 --- a/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 +++ b/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 @@ -30,7 +30,7 @@ Get the organization 'PSModule'. .NOTES - https://docs.github.com/rest/orgs/orgs#list-organizations-for-the-authenticated-user + https://docs.github.com/rest/orgs/orgs #> [OutputType([pscustomobject])] [CmdletBinding(DefaultParameterSetName = '__DefaultSet')] diff --git a/src/GitHub/public/Teams/Get-GitHubRepoTeam.ps1 b/src/GitHub/public/Teams/Get-GitHubRepoTeam.ps1 index f2695ca0b..c07dd89f1 100644 --- a/src/GitHub/public/Teams/Get-GitHubRepoTeam.ps1 +++ b/src/GitHub/public/Teams/Get-GitHubRepoTeam.ps1 @@ -1,7 +1,7 @@ filter Get-GitHubRepoTeam { <# .NOTES - https://docs.github.com/en/rest/reference/repos#get-a-repository + https://docs.github.com/rest/reference/repos#get-a-repository #> [CmdletBinding()] param ( diff --git a/src/GitHub/public/Users/Get-GitHubUser.ps1 b/src/GitHub/public/Users/Get-GitHubUser.ps1 index 6e8ef9dc6..8efa351fa 100644 --- a/src/GitHub/public/Users/Get-GitHubUser.ps1 +++ b/src/GitHub/public/Users/Get-GitHubUser.ps1 @@ -24,7 +24,7 @@ Get a list of users, starting with the user 'MariusStorhaug'. .NOTES - https://docs.github.com/en/rest/users/users + https://docs.github.com/rest/users/users #> [OutputType([pscustomobject])] [CmdletBinding(DefaultParameterSetName = '__DefaultSet')] diff --git a/tools/utilities/GitHubAPI.ps1 b/tools/utilities/GitHubAPI.ps1 index f8840a4a8..037d40d7a 100644 --- a/tools/utilities/GitHubAPI.ps1 +++ b/tools/utilities/GitHubAPI.ps1 @@ -21,7 +21,7 @@ $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 = '/orgs/{org}/blocks/{username}' +$path = '/users/{username}' $method = 'get' $response.paths.$path.$method $response.paths.$path.$method.tags | clip # -> Namespace/foldername From 60a7f15c9df7386d5f1190b195c069f9aedda81e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 1 Oct 2023 18:15:30 +0200 Subject: [PATCH 59/61] Use errorhandling to get correct errorcode from assert --- src/GitHub/public/API/Invoke-GitHubAPI.ps1 | 30 ++++++------------- .../Assert-GitHubOrganizationBlockedUser.ps1 | 2 +- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 index 36855c337..6945c056e 100644 --- a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 +++ b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 @@ -127,26 +127,14 @@ } } - # try { - # (Invoke-RestMethod @APICall) | ForEach-Object { - (Invoke-RestMethod @APICall -ErrorAction SilentlyContinue) | ForEach-Object { - $statusCode = $APICallStatusCode | ConvertTo-Json -Depth 100 | ConvertFrom-Json - $responseHeaders = $APICallResponseHeaders | ConvertTo-Json -Depth 100 | ConvertFrom-Json - [pscustomobject]@{ - Request = $APICall - Response = $_ - StatusCode = $statusCode - ResponseHeaders = $responseHeaders - } + Invoke-RestMethod @APICall | ForEach-Object { + $statusCode = $APICallStatusCode | ConvertTo-Json -Depth 100 | ConvertFrom-Json + $responseHeaders = $APICallResponseHeaders | ConvertTo-Json -Depth 100 | ConvertFrom-Json + [pscustomobject]@{ + Request = $APICall + Response = $_ + StatusCode = $statusCode + ResponseHeaders = $responseHeaders } - # } catch { - # Write-Error "[$functionName] - Status code - [$APICallStatusCode]" - # $err = $_ | ConvertFrom-Json -Depth 10 - # Write-Error "[$functionName] - $($err.Message)" - # Write-Error "[$functionName] - For more info please see: [$($err.documentation_url)]" - # $APICallResponseHeaders.PSObject.Properties | ForEach-Object { - # Write-Error "[$functionName] - $($_.Key): $($_.Value)" - # } - # return 1 - # } + } } diff --git a/src/GitHub/public/Organization/Blocking/Assert-GitHubOrganizationBlockedUser.ps1 b/src/GitHub/public/Organization/Blocking/Assert-GitHubOrganizationBlockedUser.ps1 index 4c542f1ae..67219e3e8 100644 --- a/src/GitHub/public/Organization/Blocking/Assert-GitHubOrganizationBlockedUser.ps1 +++ b/src/GitHub/public/Organization/Blocking/Assert-GitHubOrganizationBlockedUser.ps1 @@ -43,7 +43,7 @@ Method = 'GET' } - $statusCode = (Invoke-GitHubAPI @inputObject).SatusCode + $statusCode = (Invoke-GitHubAPI @inputObject -ErrorAction SilentlyContinue).StatusCode if ($statusCode -eq 204) { return $true From 5d8b50eaca5172ee920b28c85d5895a65e065ca0 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 1 Oct 2023 18:59:13 +0200 Subject: [PATCH 60/61] Add some user commands --- .../Blocking/Get-GitHubBlockedUser copy.ps1 | 32 +++++++++++++++++++ .../Users/Blocking/Get-GitHubBlockedUser.ps1 | 32 +++++++++++++++++++ tools/utilities/GitHubAPI.ps1 | 4 ++- 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 src/GitHub/public/Users/Blocking/Get-GitHubBlockedUser copy.ps1 create mode 100644 src/GitHub/public/Users/Blocking/Get-GitHubBlockedUser.ps1 diff --git a/src/GitHub/public/Users/Blocking/Get-GitHubBlockedUser copy.ps1 b/src/GitHub/public/Users/Blocking/Get-GitHubBlockedUser copy.ps1 new file mode 100644 index 000000000..2b55d0370 --- /dev/null +++ b/src/GitHub/public/Users/Blocking/Get-GitHubBlockedUser copy.ps1 @@ -0,0 +1,32 @@ +filter Assert-GitHubBlockedUser { + <# + .SYNOPSIS + Check if a user is blocked by the authenticated user + + .DESCRIPTION + 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 + + .NOTES + https://docs.github.com/rest/users/blocking#check-if-a-user-is-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/Get-GitHubBlockedUser.ps1 b/src/GitHub/public/Users/Blocking/Get-GitHubBlockedUser.ps1 new file mode 100644 index 000000000..3f5187976 --- /dev/null +++ b/src/GitHub/public/Users/Blocking/Get-GitHubBlockedUser.ps1 @@ -0,0 +1,32 @@ +filter Get-GitHubBlockedUser { + <# + .SYNOPSIS + List users blocked by the authenticated user + + .DESCRIPTION + List the users you've blocked on your personal account. + + .EXAMPLE + + .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/tools/utilities/GitHubAPI.ps1 b/tools/utilities/GitHubAPI.ps1 index 037d40d7a..530c90274 100644 --- a/tools/utilities/GitHubAPI.ps1 +++ b/tools/utilities/GitHubAPI.ps1 @@ -21,7 +21,7 @@ $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 = '/users/{username}' +$path = '/user/blocks/{username}' $method = 'get' $response.paths.$path.$method $response.paths.$path.$method.tags | clip # -> Namespace/foldername @@ -35,5 +35,7 @@ $response.paths.$path.$method.'x-github'.enabledForGitHubApps | clip # -> Note $response.paths.$path.$method.'x-github'.githubCloudOnly | clip # -> Note $response.paths.$path.$method.parameters # -> Parameter list $response.paths.$path.$method.parameters.'$ref' # -> Parameter list +$response.components.parameters.username # -> Parameter list ? +$response.paths.$path.$method.responses # -> Could be used to decide error handling within the function $response.paths.$path.$method.responses.'200'.content.'application/json'.schema # -> OutputType qualifyer $response.paths.$path.$method.responses.'200'.content.'application/json'.schema.items # -> OutputType From 3a4d93a56a78327d5f1cb71fa628f05688d04c96 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 1 Oct 2023 18:59:44 +0200 Subject: [PATCH 61/61] version bump --- src/GitHub/GitHub.psd1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GitHub/GitHub.psd1 b/src/GitHub/GitHub.psd1 index 14bc32924..bea4814b7 100644 --- a/src/GitHub/GitHub.psd1 +++ b/src/GitHub/GitHub.psd1 @@ -3,7 +3,7 @@ Author = 'Marius Storhaug' # Version number of this module - ModuleVersion = '0.1.1' + ModuleVersion = '0.2.0' # Description of the functionality provided by this module Description = 'GitHub PowerShell Module'