From b9c6fcb9e94397cc123ef22d3d74e715c35def59 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 8 Oct 2023 11:35:06 +0200 Subject: [PATCH 001/193] Add GetRepo functions --- .../Repositories/Get-GitHubMyRepositories.ps1 | 115 ++++++++++++++++++ .../Get-GitHubReleaseByTagName.ps1 | 43 +++++++ .../Get-GitHubRepositoryByName.ps1 | 41 +++++++ .../Get-GitHubRepositoryListByOrg.ps1 | 69 +++++++++++ .../Get-GitHubRepositoryListByUser.ps1 | 72 +++++++++++ tools/utilities/GitHubAPI.ps1 | 4 +- 6 files changed, 342 insertions(+), 2 deletions(-) create mode 100644 src/GitHub/public/Repositories/Get-GitHubMyRepositories.ps1 create mode 100644 src/GitHub/public/Repositories/Get-GitHubReleaseByTagName.ps1 create mode 100644 src/GitHub/public/Repositories/Get-GitHubRepositoryByName.ps1 create mode 100644 src/GitHub/public/Repositories/Get-GitHubRepositoryListByOrg.ps1 create mode 100644 src/GitHub/public/Repositories/Get-GitHubRepositoryListByUser.ps1 diff --git a/src/GitHub/public/Repositories/Get-GitHubMyRepositories.ps1 b/src/GitHub/public/Repositories/Get-GitHubMyRepositories.ps1 new file mode 100644 index 000000000..b0caf9a1e --- /dev/null +++ b/src/GitHub/public/Repositories/Get-GitHubMyRepositories.ps1 @@ -0,0 +1,115 @@ +filter Get-GitHubMyRepositories { + <# + .SYNOPSIS + List repositories for the authenticated user + + .DESCRIPTION + Lists repositories that the authenticated user has explicit permission (`:read`, `:write`, or `:admin`) to access. + The authenticated user has explicit permission to access repositories they own, repositories where they are a collaborator, + and repositories that they can access through an organization membership. + + .EXAMPLE + Get-GitHubMyRepositories + + Gets the repositories for the authenticated user. + + .EXAMPLE + Get-GitHubMyRepositories -Visibility 'private' + + Gets the private repositories for the authenticated user. + + .EXAMPLE + Get-GitHubMyRepositories -Visibility 'public' -Affiliation 'owner','collaborator' -Sort 'created' -Direction 'asc' -PerPage 100 -Since (Get-Date).AddYears(-5) -Before (Get-Date).AddDays(-1) + + Gets the public repositories for the authenticated user that are owned by the authenticated user or that the authenticated user has been added to as a collaborator. + The results are sorted by creation date in ascending order and the results are limited to 100 repositories. + The results are limited to repositories created between 5 years ago and 1 day ago. + + .EXAMPLE + Get-GitHubMyRepositories -Type 'forks' + + Gets the forked repositories for the authenticated user. + + .EXAMPLE + Get-GitHubMyRepositories -Type 'sources' + + Gets the non-forked repositories for the authenticated user. + + .EXAMPLE + Get-GitHubMyRepositories -Type 'member' + + Gets the repositories for the authenticated user that are owned by an organization. + + .NOTES + https://docs.github.com/rest/repos/repos#list-repositories-for-the-authenticated-user + + #> + [CmdletBinding()] + param ( + + #Limit results to repositories with the specified visibility. + [Parameter( + ParameterSetName = 'Aff-Vis' + )] + [validateSet('all', 'public', 'private')] + [string] $Visibility = 'all', + + # Comma-separated list of values. Can include: + # - owner: Repositories that are owned by the authenticated user. + # - collaborator: Repositories that the user has been added to as a collaborator. + # - organization_member: Repositories that the user has access to through being a member of an organization. This includes every repository on every team that the user is on. + # Default: owner, collaborator, organization_member + [Parameter( + ParameterSetName = 'Aff-Vis' + )] + [validateset('owner', 'collaborator', 'organization_member')] + [string[]] $Affiliation = @('owner', 'collaborator', 'organization_member'), + + # Specifies the types of repositories you want returned. + [Parameter( + ParameterSetName = 'Type' + )] + [validateSet('all', 'public', 'private', 'forks', 'sources', 'member')] + [string] $Type = 'all', + + # The property to sort the results by. + [Parameter()] + [validateSet('created', 'updated', 'pushed', 'full_name')] + [string] $Sort = 'created', + + # The order to sort by. + # Default: asc when using full_name, otherwise desc. + [Parameter()] + [validateSet('asc', 'desc')] + [string] $Direction, + + # The number of results per page (max 100). + [Parameter()] + [int] $PerPage = 30, + + # Only show repositories updated after the given time. + [Parameter()] + [datetime] $Since, + + # Only show repositories updated before the given time. + [Parameter()] + [datetime] $Before + ) + + $Affiliation = $Affiliation -join ',' + + # This is a timestamp in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ. + $Since = $Since.ToString('yyyy-MM-ddTHH:mm:ssZ') + $Before = $Before.ToString('yyyy-MM-ddTHH:mm:ssZ') + + $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case + Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner' + + $inputObject = @{ + APIEndpoint = "/user/repos" + Method = 'GET' + } + + (Invoke-GitHubAPI @inputObject).Response + +} diff --git a/src/GitHub/public/Repositories/Get-GitHubReleaseByTagName.ps1 b/src/GitHub/public/Repositories/Get-GitHubReleaseByTagName.ps1 new file mode 100644 index 000000000..57c4b0dca --- /dev/null +++ b/src/GitHub/public/Repositories/Get-GitHubReleaseByTagName.ps1 @@ -0,0 +1,43 @@ +filter Get-GitHubReleaseByTagName { + <# + .SYNOPSIS + Get a release by tag name + + .DESCRIPTION + Get a published release with the specified tag. + + .EXAMPLE + Get-GitHubReleaseByTagName -Owner 'octocat' -Repo 'hello-world' -Tag 'v1.0.0' + + Gets the release with the tag 'v1.0.0' for the repository 'hello-world' owned by 'octocat'. + + .NOTES + https://docs.github.com/rest/releases/releases#get-a-release-by-tag-name + + #> + [CmdletBinding()] + param ( + # The account owner of the repository. The name is not case sensitive. + [Parameter()] + [string] $Owner = (Get-GitHubConfig -Name Owner), + + # The name of the repository without the .git extension. The name is not case sensitive. + [Parameter()] + [string] $Repo = (Get-GitHubConfig -Name Repo), + + # The name of the tag to get a release from. + [Parameter( + Mandatory + )] + [Alias('tag_name')] + [string] $Tag + ) + + $inputObject = @{ + APIEndpoint = "/repos/$Owner/$Repo/releases/tags/$Tag" + Method = 'GET' + } + + (Invoke-GitHubAPI @inputObject).Response + +} diff --git a/src/GitHub/public/Repositories/Get-GitHubRepositoryByName.ps1 b/src/GitHub/public/Repositories/Get-GitHubRepositoryByName.ps1 new file mode 100644 index 000000000..7f201d83a --- /dev/null +++ b/src/GitHub/public/Repositories/Get-GitHubRepositoryByName.ps1 @@ -0,0 +1,41 @@ +filter Get-GitHubRepositoryByName { + <# + .SYNOPSIS + Get a repository + + .DESCRIPTION + The `parent` and `source` objects are present when the repository is a fork. + `parent` is the repository this repository was forked from, `source` is the ultimate source for the network. + **Note:** In order to see the `security_and_analysis` block for a repository 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](https://docs.github.com/organizations/managing-peoples-access-to-your-organization-with-roles/managing-security-managers-in-your-organization)." + + .EXAMPLE + Get-GitHubRepositoryByName -Owner 'octocat' -Repo 'Hello-World' + + Gets the repository 'Hello-World' for the organization 'octocat'. + + .NOTES + https://docs.github.com/rest/repos/repos#get-a-repository + + #> + [CmdletBinding()] + param ( + # The account owner of the repository. The name is not case sensitive. + [Parameter()] + [string] $Owner = (Get-GitHubConfig -Name Owner), + + # The name of the repository without the .git extension. The name is not case sensitive. + [Parameter()] + [string] $Repo = (Get-GitHubConfig -Name Repo) + + ) + + $inputObject = @{ + APIEndpoint = "/repos/$Owner/$Repo" + Method = 'GET' + } + + (Invoke-GitHubAPI @inputObject).Response + +} diff --git a/src/GitHub/public/Repositories/Get-GitHubRepositoryListByOrg.ps1 b/src/GitHub/public/Repositories/Get-GitHubRepositoryListByOrg.ps1 new file mode 100644 index 000000000..746c4dbe0 --- /dev/null +++ b/src/GitHub/public/Repositories/Get-GitHubRepositoryListByOrg.ps1 @@ -0,0 +1,69 @@ +filter Get-GitHubRepositoryListByOrg { + <# + .SYNOPSIS + List organization repositories + + .DESCRIPTION + Lists repositories for the specified organization. + **Note:** In order to see the `security_and_analysis` block for a repository 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](https://docs.github.com/organizations/managing-peoples-access-to-your-organization-with-roles/managing-security-managers-in-your-organization)." + + .EXAMPLE + Get-GitHubRepositoryListByOrg -Owner 'octocat' + + Gets the repositories for the organization 'octocat'. + + .EXAMPLE + Get-GitHubRepositoryListByOrg -Owner 'octocat' -Type 'public' + + Gets the public repositories for the organization 'octocat'. + + .EXAMPLE + Get-GitHubRepositoryListByOrg -Owner 'octocat' -Sort 'created' -Direction 'asc' + + Gets the repositories for the organization 'octocat' sorted by creation date in ascending order. + + .NOTES + https://docs.github.com/rest/repos/repos#list-organization-repositories + + #> + [CmdletBinding()] + param ( + # The account owner of the repository. The name is not case sensitive. + [Parameter()] + [string] $Owner = (Get-GitHubConfig -Name Owner), + + # Specifies the types of repositories you want returned. + [Parameter()] + [validateSet('all', 'public', 'private', 'forks', 'sources', 'member')] + [string] $type = 'all', + + # The property to sort the results by. + [Parameter()] + [validateSet('created', 'updated', 'pushed', 'full_name')] + [string] $Sort = 'created', + + # The order to sort by. + # Default: asc when using full_name, otherwise desc. + [Parameter()] + [validateSet('asc', 'desc')] + [string] $Direction, + + # The number of results per page (max 100). + [Parameter()] + [int] $PerPage = 30 + ) + + $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case + Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner' + + $inputObject = @{ + APIEndpoint = "/repos/$Owner/repos" + Method = 'GET' + Body = $body + } + + (Invoke-GitHubAPI @inputObject).Response + +} diff --git a/src/GitHub/public/Repositories/Get-GitHubRepositoryListByUser.ps1 b/src/GitHub/public/Repositories/Get-GitHubRepositoryListByUser.ps1 new file mode 100644 index 000000000..9b33579c6 --- /dev/null +++ b/src/GitHub/public/Repositories/Get-GitHubRepositoryListByUser.ps1 @@ -0,0 +1,72 @@ +filter Get-GitHubRepositoryListByUser { + <# + .SYNOPSIS + List repositories for a user + + .DESCRIPTION + Lists public repositories for the specified user. + Note: For GitHub AE, this endpoint will list internal repositories for the specified user. + + .EXAMPLE + Get-GitHubRepositoryListByUser -Username 'octocat' + + Gets the repositories for the user 'octocat'. + + .EXAMPLE + Get-GitHubRepositoryListByUser -Username 'octocat' -Type 'member' + + Gets the repositories of organizations where the user 'octocat' is a member. + + .EXAMPLE + Get-GitHubRepositoryListByUser -Username 'octocat' -Sort 'created' -Direction 'asc' + + Gets the repositories for the user 'octocat' sorted by creation date in ascending order. + + .NOTES + https://docs.github.com/rest/repos/repos#list-repositories-for-a-user + + #> + [CmdletBinding()] + param ( + # The handle for the GitHub user account. + [Parameter( + Mandatory, + ValueFromPipeline, + ValueFromPipelineByPropertyName + )] + [Alias('login')] + [string] $Username, + + # Specifies the types of repositories you want returned. + [Parameter()] + [validateSet('all', 'public', 'private', 'forks', 'sources', 'member')] + [string] $type = 'all', + + # The property to sort the results by. + [Parameter()] + [validateSet('created', 'updated', 'pushed', 'full_name')] + [string] $Sort = 'created', + + # The order to sort by. + # Default: asc when using full_name, otherwise desc. + [Parameter()] + [validateSet('asc', 'desc')] + [string] $Direction, + + # The number of results per page (max 100). + [Parameter()] + [int] $PerPage = 30 + ) + + $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case + Remove-HashtableEntries -Hashtable $body -RemoveNames 'Username' + + $inputObject = @{ + APIEndpoint = "/users/$Username/repos" + Method = 'GET' + Body = $body + } + + (Invoke-GitHubAPI @inputObject).Response + +} diff --git a/tools/utilities/GitHubAPI.ps1 b/tools/utilities/GitHubAPI.ps1 index 64aeedf58..4205452dc 100644 --- a/tools/utilities/GitHubAPI.ps1 +++ b/tools/utilities/GitHubAPI.ps1 @@ -21,8 +21,8 @@ $response = Invoke-RestMethod -Uri $APIDocURI -Method Get # @{n = 'PUT'; e = { (($_.value.psobject.Properties.Name) -contains 'PUT') } }, ` # @{n = 'PATCH'; e = { (($_.value.psobject.Properties.Name) -contains 'PATCH') } } | Format-Table -$path = '/repos/{owner}/{repo}/releases/{release_id}/assets' -$method = 'post' +$path = '/users/{username}/repos' +$method = 'get' $response.paths.$path.$method $response.paths.$path.$method.tags | clip # -> Namespace/foldername $response.paths.$path.$method.operationId | clip # -> FunctionName From 52dfb6142f103f3017e0334540bc12972dfa9e09 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 8 Oct 2023 11:44:14 +0200 Subject: [PATCH 002/193] Fix for repoByOrg --- .../Get-GitHubReleaseByTagName.ps1 | 43 ------------------- .../Get-GitHubRepositoryListByOrg.ps1 | 2 +- tools/utilities/Local-Testing.ps1 | 14 ++++++ 3 files changed, 15 insertions(+), 44 deletions(-) delete mode 100644 src/GitHub/public/Repositories/Get-GitHubReleaseByTagName.ps1 diff --git a/src/GitHub/public/Repositories/Get-GitHubReleaseByTagName.ps1 b/src/GitHub/public/Repositories/Get-GitHubReleaseByTagName.ps1 deleted file mode 100644 index 57c4b0dca..000000000 --- a/src/GitHub/public/Repositories/Get-GitHubReleaseByTagName.ps1 +++ /dev/null @@ -1,43 +0,0 @@ -filter Get-GitHubReleaseByTagName { - <# - .SYNOPSIS - Get a release by tag name - - .DESCRIPTION - Get a published release with the specified tag. - - .EXAMPLE - Get-GitHubReleaseByTagName -Owner 'octocat' -Repo 'hello-world' -Tag 'v1.0.0' - - Gets the release with the tag 'v1.0.0' for the repository 'hello-world' owned by 'octocat'. - - .NOTES - https://docs.github.com/rest/releases/releases#get-a-release-by-tag-name - - #> - [CmdletBinding()] - param ( - # The account owner of the repository. The name is not case sensitive. - [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), - - # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), - - # The name of the tag to get a release from. - [Parameter( - Mandatory - )] - [Alias('tag_name')] - [string] $Tag - ) - - $inputObject = @{ - APIEndpoint = "/repos/$Owner/$Repo/releases/tags/$Tag" - Method = 'GET' - } - - (Invoke-GitHubAPI @inputObject).Response - -} diff --git a/src/GitHub/public/Repositories/Get-GitHubRepositoryListByOrg.ps1 b/src/GitHub/public/Repositories/Get-GitHubRepositoryListByOrg.ps1 index 746c4dbe0..ffa1d18b1 100644 --- a/src/GitHub/public/Repositories/Get-GitHubRepositoryListByOrg.ps1 +++ b/src/GitHub/public/Repositories/Get-GitHubRepositoryListByOrg.ps1 @@ -59,7 +59,7 @@ Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner' $inputObject = @{ - APIEndpoint = "/repos/$Owner/repos" + APIEndpoint = "/orgs/$Owner/repos" Method = 'GET' Body = $body } diff --git a/tools/utilities/Local-Testing.ps1 b/tools/utilities/Local-Testing.ps1 index 0cf21d57c..733d27903 100644 --- a/tools/utilities/Local-Testing.ps1 +++ b/tools/utilities/Local-Testing.ps1 @@ -80,3 +80,17 @@ $Release = Get-GitHubRelease -Owner PSModule -Repo Demo -Latest Add-GitHubReleaseAsset -Owner PSModule -Repo Demo -ID $Release.id -FilePath 'C:\Repos\GitHub\PSModule\Modules\GitHub\tools\utilities\Local-Testing.ps1' Get-GitHubReleaseAsset -Owner PSModule -Repo Demo -ReleaseID $Release.id + + +Get-GitHubRepositoryListByUser -Username 'octocat' | Select full_name, id, visibility, forks + +Get-GitHubRepositoryListByUser -Username 'octocat' -Type 'member' | Select full_name, id, visibility, forks + +Get-GitHubRepositoryListByUser -Username 'octocat' -Sort 'created' -Direction 'asc' | Select full_name, id, visibility, created_at + +Get-GitHubRepositoryListByOrg -Owner 'PSModule' | Select full_name, id, visibility, created_at + +Get-GitHubRepositoryListByOrg -Owner 'PSModule' -Type 'public' | Select full_name, id, visibility, created_at + +Get-GitHubRepositoryListByOrg -Owner 'PSModule' -Sort 'created' -Direction 'asc' | Select full_name, id, visibility, created_at + From 1672151d6cf9b5cc6c2e2b385835b7b1f08b99bd Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 8 Oct 2023 12:37:13 +0200 Subject: [PATCH 003/193] Add a unified Get-Repo function --- .../Repositories/Get-GitHubRepository.ps1 | 159 ++++++++++++++++++ .../Get-GitHubRepositoryListByID.ps1 | 38 +++++ tools/utilities/GitHubAPI.ps1 | 2 +- 3 files changed, 198 insertions(+), 1 deletion(-) create mode 100644 src/GitHub/public/Repositories/Get-GitHubRepository.ps1 create mode 100644 src/GitHub/public/Repositories/Get-GitHubRepositoryListByID.ps1 diff --git a/src/GitHub/public/Repositories/Get-GitHubRepository.ps1 b/src/GitHub/public/Repositories/Get-GitHubRepository.ps1 new file mode 100644 index 000000000..a629ff272 --- /dev/null +++ b/src/GitHub/public/Repositories/Get-GitHubRepository.ps1 @@ -0,0 +1,159 @@ +filter Get-GitHubRepository { + <# + .SYNOPSIS + Gets a specific repository or list of repositories. + + .DESCRIPTION + Gets a specific repository or list of repositories based on parameter sets. + If no parameters are specified, the authenticated user's repositories are returned. + If a Username parameter is specified, the specified user's public repositories are returned. + If the SinceId parameter is specified, the repositories with an ID greater than the specified ID are returned. + If an Owner and Repo parameters are specified, the specified repository is returned. + If the Owner and Repo parameters are specified, the specified repository is returned. + + .EXAMPLE + An example + + .NOTES + General notes + #> + [CmdletBinding(DefaultParameterSetName = 'MyRepos_Type')] + param ( + #Limit results to repositories with the specified visibility. + [Parameter(ParameterSetName = 'MyRepos_Aff-Vis')] + [validateSet('all', 'public', 'private')] + [string] $Visibility = 'all', + + # Comma-separated list of values. Can include: + # - owner: Repositories that are owned by the authenticated user. + # - collaborator: Repositories that the user has been added to as a collaborator. + # - organization_member: Repositories that the user has access to through being a member of an organization. This includes every repository on every team that the user is on. + # Default: owner, collaborator, organization_member + [Parameter(ParameterSetName = 'MyRepos_Aff-Vis')] + [validateset('owner', 'collaborator', 'organization_member')] + [string[]] $Affiliation = @('owner', 'collaborator', 'organization_member'), + + # A repository ID. Only return repositories with an ID greater than this ID. + [Parameter(ParameterSetName = 'ListByID')] + [int] $SinceID = 0, + + # Only show repositories updated after the given time. + [Parameter(ParameterSetName = 'MyRepos_Type')] + [Parameter(ParameterSetName = 'MyRepos_Aff-Vis')] + [datetime] $Since, + + # Only show repositories updated before the given time. + [Parameter(ParameterSetName = 'MyRepos_Type')] + [Parameter(ParameterSetName = 'MyRepos_Aff-Vis')] + [datetime] $Before, + + # The account owner of the repository. The name is not case sensitive. + [Parameter(ParameterSetName = 'ByName')] + [Parameter(ParameterSetName = 'ListByOrg')] + [string] $Owner = (Get-GitHubConfig -Name Owner), + + # The name of the repository without the .git extension. The name is not case sensitive. + [Parameter()] + [string] $Repo = (Get-GitHubConfig -Name Repo), + + # The handle for the GitHub user account. + [Parameter( + Mandatory, + ValueFromPipeline, + ValueFromPipelineByPropertyName, + ParameterSetName = 'ListByUser' + )] + [Alias('login')] + [string] $Username, + + # Specifies the types of repositories you want returned. + [Parameter(ParameterSetName = 'MyRepos_Type')] + [Parameter(ParameterSetName = 'ListByOrg')] + [Parameter(ParameterSetName = 'ListByUser')] + [validateSet('all', 'public', 'private', 'forks', 'sources', 'member')] + [string] $Type = 'all', + + # The property to sort the results by. + [Parameter(ParameterSetName = 'MyRepos_Type')] + [Parameter(ParameterSetName = 'MyRepos_Aff-Vis')] + [Parameter(ParameterSetName = 'ListByOrg')] + [Parameter(ParameterSetName = 'ListByUser')] + [validateSet('created', 'updated', 'pushed', 'full_name')] + [string] $Sort = 'created', + + # The order to sort by. + # Default: asc when using full_name, otherwise desc. + [Parameter(ParameterSetName = 'MyRepos')] + [Parameter(ParameterSetName = 'ListByOrg')] + [Parameter(ParameterSetName = 'ListByUser')] + [validateSet('asc', 'desc')] + [string] $Direction, + + # The number of results per page (max 100). + [Parameter(ParameterSetName = 'MyRepos')] + [Parameter(ParameterSetName = 'ListByOrg')] + [Parameter(ParameterSetName = 'ListByUser')] + [int] $PerPage = 30 + + ) + + switch ($PSCmdlet.ParameterSetName) { + 'MyRepos_Type' { + $params = @{ + Type = $Type + Sort = $Sort + Direction = $Direction + PerPage = $PerPage + Since = $Since + Before = $Before + } + Get-GitHubMyRepositories @params + } + 'MyRepos_Aff-Vis' { + $params = @{ + Visibility = $Visibility + Affiliation = $Affiliation + Sort = $Sort + Direction = $Direction + PerPage = $PerPage + Since = $Since + Before = $Before + } + Get-GitHubMyRepositories @params + } + 'ByName' { + $params = @{ + Owner = $Owner + Repo = $Repo + } + Get-GitHubRepositoryByName @params + } + 'ListByID' { + $params = @{ + Since = $SinceID + } + Get-GitHubRepositoryListByID @params + } + 'ListByOrg' { + $params = @{ + Owner = $Owner + Type = $Type + Sort = $Sort + Direction = $Direction + PerPage = $PerPage + } + Get-GitHubRepositoryListByOrg @params + } + 'ListByUser' { + $params = @{ + Username = $Username + Type = $Type + Sort = $Sort + Direction = $Direction + PerPage = $PerPage + } + Get-GitHubRepositoryListByUser @params + } + } + +} diff --git a/src/GitHub/public/Repositories/Get-GitHubRepositoryListByID.ps1 b/src/GitHub/public/Repositories/Get-GitHubRepositoryListByID.ps1 new file mode 100644 index 000000000..d363f2447 --- /dev/null +++ b/src/GitHub/public/Repositories/Get-GitHubRepositoryListByID.ps1 @@ -0,0 +1,38 @@ +filter Get-GitHubRepositoryListByID { + <# + .SYNOPSIS + List public repositories + + .DESCRIPTION + Lists all public repositories in the order that they were created. + + Note: + - For GitHub Enterprise Server, this endpoint will only list repositories available to all users on the enterprise. + - 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 repositories. + + .EXAMPLE + Get-GitHubRepositoryListByID -Since '123456789 + + Gets the repositories with an ID equals and greater than 123456789. + + .NOTES + https://docs.github.com/rest/repos/repos#list-public-repositories + + #> + [CmdletBinding()] + param ( + # A repository ID. Only return repositories with an ID greater than this ID. + [Parameter()] + [int] $Since = 0 + ) + + $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case + + $inputObject = @{ + APIEndpoint = '/repositories' + Method = 'GET' + } + + (Invoke-GitHubAPI @inputObject).Response + +} diff --git a/tools/utilities/GitHubAPI.ps1 b/tools/utilities/GitHubAPI.ps1 index 4205452dc..b9a21409d 100644 --- a/tools/utilities/GitHubAPI.ps1 +++ b/tools/utilities/GitHubAPI.ps1 @@ -21,7 +21,7 @@ $response = Invoke-RestMethod -Uri $APIDocURI -Method Get # @{n = 'PUT'; e = { (($_.value.psobject.Properties.Name) -contains 'PUT') } }, ` # @{n = 'PATCH'; e = { (($_.value.psobject.Properties.Name) -contains 'PATCH') } } | Format-Table -$path = '/users/{username}/repos' +$path = '/repositories' $method = 'get' $response.paths.$path.$method $response.paths.$path.$method.tags | clip # -> Namespace/foldername From efc599f78d990662569f9d44862b5aef0c65194a Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 8 Oct 2023 12:41:04 +0200 Subject: [PATCH 004/193] Fix for GetGitHubRepos --- src/GitHub/public/Repositories/Get-GitHubRepository.ps1 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/GitHub/public/Repositories/Get-GitHubRepository.ps1 b/src/GitHub/public/Repositories/Get-GitHubRepository.ps1 index a629ff272..a606505a4 100644 --- a/src/GitHub/public/Repositories/Get-GitHubRepository.ps1 +++ b/src/GitHub/public/Repositories/Get-GitHubRepository.ps1 @@ -107,6 +107,7 @@ Since = $Since Before = $Before } + Remove-HashTableEntries -Hashtable $params -NullOrEmptyValues Get-GitHubMyRepositories @params } 'MyRepos_Aff-Vis' { @@ -119,6 +120,7 @@ Since = $Since Before = $Before } + Remove-HashTableEntries -Hashtable $params -NullOrEmptyValues Get-GitHubMyRepositories @params } 'ByName' { @@ -126,12 +128,14 @@ Owner = $Owner Repo = $Repo } + Remove-HashTableEntries -Hashtable $params -NullOrEmptyValues Get-GitHubRepositoryByName @params } 'ListByID' { $params = @{ Since = $SinceID } + Remove-HashTableEntries -Hashtable $params -NullOrEmptyValues Get-GitHubRepositoryListByID @params } 'ListByOrg' { @@ -142,6 +146,7 @@ Direction = $Direction PerPage = $PerPage } + Remove-HashTableEntries -Hashtable $params -NullOrEmptyValues Get-GitHubRepositoryListByOrg @params } 'ListByUser' { @@ -152,6 +157,7 @@ Direction = $Direction PerPage = $PerPage } + Remove-HashTableEntries -Hashtable $params -NullOrEmptyValues Get-GitHubRepositoryListByUser @params } } From ea41c8fc8119b62fef941e87cbe5183723e09a95 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 8 Oct 2023 13:10:10 +0200 Subject: [PATCH 005/193] Fix streaming output for GitHubRepoListById --- .../Repositories/Get-GitHubMyRepositories.ps1 | 2 +- .../Get-GitHubRepositoryListByID.ps1 | 7 ++++++- tools/utilities/Local-Testing.ps1 | 16 ++++++++++------ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/GitHub/public/Repositories/Get-GitHubMyRepositories.ps1 b/src/GitHub/public/Repositories/Get-GitHubMyRepositories.ps1 index b0caf9a1e..b4e67945f 100644 --- a/src/GitHub/public/Repositories/Get-GitHubMyRepositories.ps1 +++ b/src/GitHub/public/Repositories/Get-GitHubMyRepositories.ps1 @@ -44,7 +44,7 @@ https://docs.github.com/rest/repos/repos#list-repositories-for-the-authenticated-user #> - [CmdletBinding()] + [CmdletBinding(DefaultParameterSetName = 'type')] param ( #Limit results to repositories with the specified visibility. diff --git a/src/GitHub/public/Repositories/Get-GitHubRepositoryListByID.ps1 b/src/GitHub/public/Repositories/Get-GitHubRepositoryListByID.ps1 index d363f2447..d8020386d 100644 --- a/src/GitHub/public/Repositories/Get-GitHubRepositoryListByID.ps1 +++ b/src/GitHub/public/Repositories/Get-GitHubRepositoryListByID.ps1 @@ -33,6 +33,11 @@ Method = 'GET' } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Verbose $_.Request + Write-Output $_.Response + Write-Verbose $_.StatusCode + Write-Verbose $_.ResponseHeaders + } } diff --git a/tools/utilities/Local-Testing.ps1 b/tools/utilities/Local-Testing.ps1 index 733d27903..4b8d57fab 100644 --- a/tools/utilities/Local-Testing.ps1 +++ b/tools/utilities/Local-Testing.ps1 @@ -81,16 +81,20 @@ Add-GitHubReleaseAsset -Owner PSModule -Repo Demo -ID $Release.id -FilePath 'C:\ Get-GitHubReleaseAsset -Owner PSModule -Repo Demo -ReleaseID $Release.id +Get-GitHubMyRepositories | Select-Object full_name, id, visibility, forks -Get-GitHubRepositoryListByUser -Username 'octocat' | Select full_name, id, visibility, forks +Get-GitHubRepositoryByName -Owner 'PSModule' -Repo 'Demo' | Select-Object full_name, id, visibility, forks +Get-GitHubRepositoryByName -Owner 'Azure' -Repo 'ResourceModules' | Select-Object full_name, id, visibility, forks -Get-GitHubRepositoryListByUser -Username 'octocat' -Type 'member' | Select full_name, id, visibility, forks +Get-GitHubRepositoryListByID | Select-Object full_name, id, visibility, forks -Get-GitHubRepositoryListByUser -Username 'octocat' -Sort 'created' -Direction 'asc' | Select full_name, id, visibility, created_at +Get-GitHubRepositoryListByUser -Username 'octocat' | Select-Object full_name, id, visibility, forks +Get-GitHubRepositoryListByUser -Username 'octocat' -type 'member' | Select-Object full_name, id, visibility, forks +Get-GitHubRepositoryListByUser -Username 'octocat' -Sort 'created' -Direction 'asc' | Select-Object full_name, id, visibility, created_at -Get-GitHubRepositoryListByOrg -Owner 'PSModule' | Select full_name, id, visibility, created_at +Get-GitHubRepositoryListByOrg -Owner 'PSModule' | Select-Object full_name, id, visibility, created_at +Get-GitHubRepositoryListByOrg -Owner 'PSModule' -type 'public' | Select-Object full_name, id, visibility, created_at +Get-GitHubRepositoryListByOrg -Owner 'PSModule' -Sort 'created' -Direction 'asc' | Select-Object full_name, id, visibility, created_at -Get-GitHubRepositoryListByOrg -Owner 'PSModule' -Type 'public' | Select full_name, id, visibility, created_at -Get-GitHubRepositoryListByOrg -Owner 'PSModule' -Sort 'created' -Direction 'asc' | Select full_name, id, visibility, created_at From 4e2796236f15729d8bf17a457b076fa16595ffac Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 8 Oct 2023 13:32:28 +0200 Subject: [PATCH 006/193] Fix some issues + streaming --- .../Repositories/Get-GitHubMyRepositories.ps1 | 27 ++++++++++++------- .../Get-GitHubRepositoryByName.ps1 | 7 ++++- .../Get-GitHubRepositoryListByID.ps1 | 6 ++--- .../Get-GitHubRepositoryListByOrg.ps1 | 7 ++++- .../Get-GitHubRepositoryListByUser.ps1 | 8 ++++-- 5 files changed, 39 insertions(+), 16 deletions(-) diff --git a/src/GitHub/public/Repositories/Get-GitHubMyRepositories.ps1 b/src/GitHub/public/Repositories/Get-GitHubMyRepositories.ps1 index b4e67945f..5a2550421 100644 --- a/src/GitHub/public/Repositories/Get-GitHubMyRepositories.ps1 +++ b/src/GitHub/public/Repositories/Get-GitHubMyRepositories.ps1 @@ -44,7 +44,7 @@ https://docs.github.com/rest/repos/repos#list-repositories-for-the-authenticated-user #> - [CmdletBinding(DefaultParameterSetName = 'type')] + [CmdletBinding(DefaultParameterSetName = 'Type')] param ( #Limit results to repositories with the specified visibility. @@ -52,7 +52,7 @@ ParameterSetName = 'Aff-Vis' )] [validateSet('all', 'public', 'private')] - [string] $Visibility = 'all', + [string] $Visibility, # Comma-separated list of values. Can include: # - owner: Repositories that are owned by the authenticated user. @@ -96,20 +96,29 @@ [datetime] $Before ) - $Affiliation = $Affiliation -join ',' - - # This is a timestamp in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ. - $Since = $Since.ToString('yyyy-MM-ddTHH:mm:ssZ') - $Before = $Before.ToString('yyyy-MM-ddTHH:mm:ssZ') + if ($Affiliation) { + $Affiliation = $Affiliation -join ',' + } + if ($Since) { + $Since = $Since.ToString('yyyy-MM-ddTHH:mm:ssZ') + } + if ($Before) { + $Before = $Before.ToString('yyyy-MM-ddTHH:mm:ssZ') + } $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner' $inputObject = @{ - APIEndpoint = "/user/repos" + APIEndpoint = '/user/repos' Method = 'GET' } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + Write-Verbose "Request: $($_.Request | ConvertFrom-Json | Out-String)" + Write-Verbose "StatusCode: $($_.StatusCode)" + Write-Verbose "ResponseHeaders: $($_.ResponseHeaders | ConvertFrom-Json | Out-String)" + } } diff --git a/src/GitHub/public/Repositories/Get-GitHubRepositoryByName.ps1 b/src/GitHub/public/Repositories/Get-GitHubRepositoryByName.ps1 index 7f201d83a..c005bbe15 100644 --- a/src/GitHub/public/Repositories/Get-GitHubRepositoryByName.ps1 +++ b/src/GitHub/public/Repositories/Get-GitHubRepositoryByName.ps1 @@ -36,6 +36,11 @@ Method = 'GET' } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + Write-Verbose "Request: $($_.Request | ConvertFrom-Json | Out-String)" + Write-Verbose "StatusCode: $($_.StatusCode)" + Write-Verbose "ResponseHeaders: $($_.ResponseHeaders | ConvertFrom-Json | Out-String)" + } } diff --git a/src/GitHub/public/Repositories/Get-GitHubRepositoryListByID.ps1 b/src/GitHub/public/Repositories/Get-GitHubRepositoryListByID.ps1 index d8020386d..6edf2cd08 100644 --- a/src/GitHub/public/Repositories/Get-GitHubRepositoryListByID.ps1 +++ b/src/GitHub/public/Repositories/Get-GitHubRepositoryListByID.ps1 @@ -34,10 +34,10 @@ } Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Verbose $_.Request Write-Output $_.Response - Write-Verbose $_.StatusCode - Write-Verbose $_.ResponseHeaders + Write-Verbose "Request: $($_.Request | ConvertFrom-Json | Out-String)" + Write-Verbose "StatusCode: $($_.StatusCode)" + Write-Verbose "ResponseHeaders: $($_.ResponseHeaders | ConvertFrom-Json | Out-String)" } } diff --git a/src/GitHub/public/Repositories/Get-GitHubRepositoryListByOrg.ps1 b/src/GitHub/public/Repositories/Get-GitHubRepositoryListByOrg.ps1 index ffa1d18b1..d19404624 100644 --- a/src/GitHub/public/Repositories/Get-GitHubRepositoryListByOrg.ps1 +++ b/src/GitHub/public/Repositories/Get-GitHubRepositoryListByOrg.ps1 @@ -64,6 +64,11 @@ Body = $body } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + Write-Verbose "Request: $($_.Request | ConvertFrom-Json | Out-String)" + Write-Verbose "StatusCode: $($_.StatusCode)" + Write-Verbose "ResponseHeaders: $($_.ResponseHeaders | ConvertFrom-Json | Out-String)" + } } diff --git a/src/GitHub/public/Repositories/Get-GitHubRepositoryListByUser.ps1 b/src/GitHub/public/Repositories/Get-GitHubRepositoryListByUser.ps1 index 9b33579c6..a422cc050 100644 --- a/src/GitHub/public/Repositories/Get-GitHubRepositoryListByUser.ps1 +++ b/src/GitHub/public/Repositories/Get-GitHubRepositoryListByUser.ps1 @@ -67,6 +67,10 @@ Body = $body } - (Invoke-GitHubAPI @inputObject).Response - + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + Write-Verbose "Request: $($_.Request | ConvertFrom-Json | Out-String)" + Write-Verbose "StatusCode: $($_.StatusCode)" + Write-Verbose "ResponseHeaders: $($_.ResponseHeaders | ConvertFrom-Json | Out-String)" + } } From 310d0963d11415ac7e086f69b40e3e74ec423aa8 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 8 Oct 2023 13:40:07 +0200 Subject: [PATCH 007/193] Move verbose API output to API function --- src/GitHub/public/API/Invoke-GitHubAPI.ps1 | 5 +++++ src/GitHub/public/Repositories/Get-GitHubMyRepositories.ps1 | 3 --- .../public/Repositories/Get-GitHubRepositoryByName.ps1 | 3 --- .../public/Repositories/Get-GitHubRepositoryListByID.ps1 | 3 --- .../public/Repositories/Get-GitHubRepositoryListByOrg.ps1 | 3 --- .../public/Repositories/Get-GitHubRepositoryListByUser.ps1 | 3 --- 6 files changed, 5 insertions(+), 15 deletions(-) diff --git a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 index c37c5edf4..1b9f60a75 100644 --- a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 +++ b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 @@ -152,6 +152,11 @@ Invoke-RestMethod @APICall | ForEach-Object { $statusCode = $APICallStatusCode | ConvertTo-Json -Depth 100 | ConvertFrom-Json $responseHeaders = $APICallResponseHeaders | ConvertTo-Json -Depth 100 | ConvertFrom-Json + + Write-Verbose "Request: $($APICall | Out-String)" + Write-Verbose "StatusCode: $($statusCode | Out-String)" + Write-Verbose "ResponseHeaders: $($responseHeaders | Out-String)" + [pscustomobject]@{ Request = $APICall Response = $_ diff --git a/src/GitHub/public/Repositories/Get-GitHubMyRepositories.ps1 b/src/GitHub/public/Repositories/Get-GitHubMyRepositories.ps1 index 5a2550421..a04823f1d 100644 --- a/src/GitHub/public/Repositories/Get-GitHubMyRepositories.ps1 +++ b/src/GitHub/public/Repositories/Get-GitHubMyRepositories.ps1 @@ -116,9 +116,6 @@ Invoke-GitHubAPI @inputObject | ForEach-Object { Write-Output $_.Response - Write-Verbose "Request: $($_.Request | ConvertFrom-Json | Out-String)" - Write-Verbose "StatusCode: $($_.StatusCode)" - Write-Verbose "ResponseHeaders: $($_.ResponseHeaders | ConvertFrom-Json | Out-String)" } } diff --git a/src/GitHub/public/Repositories/Get-GitHubRepositoryByName.ps1 b/src/GitHub/public/Repositories/Get-GitHubRepositoryByName.ps1 index c005bbe15..73799dd76 100644 --- a/src/GitHub/public/Repositories/Get-GitHubRepositoryByName.ps1 +++ b/src/GitHub/public/Repositories/Get-GitHubRepositoryByName.ps1 @@ -38,9 +38,6 @@ Invoke-GitHubAPI @inputObject | ForEach-Object { Write-Output $_.Response - Write-Verbose "Request: $($_.Request | ConvertFrom-Json | Out-String)" - Write-Verbose "StatusCode: $($_.StatusCode)" - Write-Verbose "ResponseHeaders: $($_.ResponseHeaders | ConvertFrom-Json | Out-String)" } } diff --git a/src/GitHub/public/Repositories/Get-GitHubRepositoryListByID.ps1 b/src/GitHub/public/Repositories/Get-GitHubRepositoryListByID.ps1 index 6edf2cd08..c82c7bb0a 100644 --- a/src/GitHub/public/Repositories/Get-GitHubRepositoryListByID.ps1 +++ b/src/GitHub/public/Repositories/Get-GitHubRepositoryListByID.ps1 @@ -35,9 +35,6 @@ Invoke-GitHubAPI @inputObject | ForEach-Object { Write-Output $_.Response - Write-Verbose "Request: $($_.Request | ConvertFrom-Json | Out-String)" - Write-Verbose "StatusCode: $($_.StatusCode)" - Write-Verbose "ResponseHeaders: $($_.ResponseHeaders | ConvertFrom-Json | Out-String)" } } diff --git a/src/GitHub/public/Repositories/Get-GitHubRepositoryListByOrg.ps1 b/src/GitHub/public/Repositories/Get-GitHubRepositoryListByOrg.ps1 index d19404624..ca4e2c242 100644 --- a/src/GitHub/public/Repositories/Get-GitHubRepositoryListByOrg.ps1 +++ b/src/GitHub/public/Repositories/Get-GitHubRepositoryListByOrg.ps1 @@ -66,9 +66,6 @@ Invoke-GitHubAPI @inputObject | ForEach-Object { Write-Output $_.Response - Write-Verbose "Request: $($_.Request | ConvertFrom-Json | Out-String)" - Write-Verbose "StatusCode: $($_.StatusCode)" - Write-Verbose "ResponseHeaders: $($_.ResponseHeaders | ConvertFrom-Json | Out-String)" } } diff --git a/src/GitHub/public/Repositories/Get-GitHubRepositoryListByUser.ps1 b/src/GitHub/public/Repositories/Get-GitHubRepositoryListByUser.ps1 index a422cc050..d18ccbcd6 100644 --- a/src/GitHub/public/Repositories/Get-GitHubRepositoryListByUser.ps1 +++ b/src/GitHub/public/Repositories/Get-GitHubRepositoryListByUser.ps1 @@ -69,8 +69,5 @@ Invoke-GitHubAPI @inputObject | ForEach-Object { Write-Output $_.Response - Write-Verbose "Request: $($_.Request | ConvertFrom-Json | Out-String)" - Write-Verbose "StatusCode: $($_.StatusCode)" - Write-Verbose "ResponseHeaders: $($_.ResponseHeaders | ConvertFrom-Json | Out-String)" } } From 9332806b8a79787daceb1b7c549d70ed25ad71be Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 8 Oct 2023 14:13:36 +0200 Subject: [PATCH 008/193] Fix API call --- src/GitHub/public/API/Invoke-GitHubAPI.ps1 | 13 +++++++++---- tools/utilities/Local-Testing.ps1 | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 index 1b9f60a75..d889418a3 100644 --- a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 +++ b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 @@ -142,7 +142,8 @@ if ($Method -eq 'GET') { $queryString = $Body | ConvertTo-QueryString $APICall.Uri = $APICall.Uri + $queryString - } elseif ($Body -is [string]) { # Use body to create the form data + } elseif ($Body -is [string]) { + # Use body to create the form data $APICall.Body = $Body } else { $APICall.Body = $Body | ConvertTo-Json -Depth 100 @@ -153,9 +154,13 @@ $statusCode = $APICallStatusCode | ConvertTo-Json -Depth 100 | ConvertFrom-Json $responseHeaders = $APICallResponseHeaders | ConvertTo-Json -Depth 100 | ConvertFrom-Json - Write-Verbose "Request: $($APICall | Out-String)" - Write-Verbose "StatusCode: $($statusCode | Out-String)" - Write-Verbose "ResponseHeaders: $($responseHeaders | Out-String)" + Write-Verbose '----------------------------------' + Write-Verbose "StatusCode: $statusCode" + Write-Verbose '----------------------------------' + Write-Verbose "Request: $($APICall | ConvertFrom-HashTable | Format-List | Out-String)" + Write-Verbose '----------------------------------' + Write-Verbose "ResponseHeaders: $($responseHeaders | Format-List | Out-String)" + Write-Verbose '----------------------------------' [pscustomobject]@{ Request = $APICall diff --git a/tools/utilities/Local-Testing.ps1 b/tools/utilities/Local-Testing.ps1 index 4b8d57fab..f29869df3 100644 --- a/tools/utilities/Local-Testing.ps1 +++ b/tools/utilities/Local-Testing.ps1 @@ -86,7 +86,7 @@ Get-GitHubMyRepositories | Select-Object full_name, id, visibility, forks Get-GitHubRepositoryByName -Owner 'PSModule' -Repo 'Demo' | Select-Object full_name, id, visibility, forks Get-GitHubRepositoryByName -Owner 'Azure' -Repo 'ResourceModules' | Select-Object full_name, id, visibility, forks -Get-GitHubRepositoryListByID | Select-Object full_name, id, visibility, forks +Get-GitHubRepositoryListByID -Verbose | Select-Object full_name, id, visibility, forks Get-GitHubRepositoryListByUser -Username 'octocat' | Select-Object full_name, id, visibility, forks Get-GitHubRepositoryListByUser -Username 'octocat' -type 'member' | Select-Object full_name, id, visibility, forks From d4a4c59060743233348c02bcfbfd7eaa4e4dede7 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 8 Oct 2023 15:32:57 +0200 Subject: [PATCH 009/193] Fix Get-MyRepos --- .../Repositories/Get-GitHubMyRepositories.ps1 | 28 ++++++++++--------- tools/utilities/Local-Testing.ps1 | 5 +--- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/GitHub/public/Repositories/Get-GitHubMyRepositories.ps1 b/src/GitHub/public/Repositories/Get-GitHubMyRepositories.ps1 index a04823f1d..7a3cba7d1 100644 --- a/src/GitHub/public/Repositories/Get-GitHubMyRepositories.ps1 +++ b/src/GitHub/public/Repositories/Get-GitHubMyRepositories.ps1 @@ -47,12 +47,12 @@ [CmdletBinding(DefaultParameterSetName = 'Type')] param ( - #Limit results to repositories with the specified visibility. + # Limit results to repositories with the specified visibility. [Parameter( ParameterSetName = 'Aff-Vis' )] - [validateSet('all', 'public', 'private')] - [string] $Visibility, + [ValidateSet('all', 'public', 'private')] + [string] $Visibility = 'all', # Comma-separated list of values. Can include: # - owner: Repositories that are owned by the authenticated user. @@ -62,25 +62,25 @@ [Parameter( ParameterSetName = 'Aff-Vis' )] - [validateset('owner', 'collaborator', 'organization_member')] + [ValidateSet('owner', 'collaborator', 'organization_member')] [string[]] $Affiliation = @('owner', 'collaborator', 'organization_member'), # Specifies the types of repositories you want returned. [Parameter( ParameterSetName = 'Type' )] - [validateSet('all', 'public', 'private', 'forks', 'sources', 'member')] + [ValidateSet('all', 'public', 'private', 'forks', 'sources', 'member')] [string] $Type = 'all', # The property to sort the results by. [Parameter()] - [validateSet('created', 'updated', 'pushed', 'full_name')] + [ValidateSet('created', 'updated', 'pushed', 'full_name')] [string] $Sort = 'created', # The order to sort by. # Default: asc when using full_name, otherwise desc. [Parameter()] - [validateSet('asc', 'desc')] + [ValidateSet('asc', 'desc')] [string] $Direction, # The number of results per page (max 100). @@ -96,22 +96,24 @@ [datetime] $Before ) + + $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case + Remove-HashtableEntries -Hashtable $body -RemoveNames 'Affiliation', 'Since', 'Before' -RemoveTypes 'SwitchParameters' + if ($Affiliation) { - $Affiliation = $Affiliation -join ',' + $body['affiliation'] = $Affiliation -join ',' } if ($Since) { - $Since = $Since.ToString('yyyy-MM-ddTHH:mm:ssZ') + $body['since'] = $Since.ToString('yyyy-MM-ddTHH:mm:ssZ') } if ($Before) { - $Before = $Before.ToString('yyyy-MM-ddTHH:mm:ssZ') + $body['before'] = $Before.ToString('yyyy-MM-ddTHH:mm:ssZ') } - $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner' - $inputObject = @{ APIEndpoint = '/user/repos' Method = 'GET' + body = $body } Invoke-GitHubAPI @inputObject | ForEach-Object { diff --git a/tools/utilities/Local-Testing.ps1 b/tools/utilities/Local-Testing.ps1 index f29869df3..cfb96723a 100644 --- a/tools/utilities/Local-Testing.ps1 +++ b/tools/utilities/Local-Testing.ps1 @@ -81,7 +81,7 @@ Add-GitHubReleaseAsset -Owner PSModule -Repo Demo -ID $Release.id -FilePath 'C:\ Get-GitHubReleaseAsset -Owner PSModule -Repo Demo -ReleaseID $Release.id -Get-GitHubMyRepositories | Select-Object full_name, id, visibility, forks +Get-GitHubMyRepositories -Affiliation owner, collaborator -Verbose | Select-Object full_name, id, visibility, forks Get-GitHubRepositoryByName -Owner 'PSModule' -Repo 'Demo' | Select-Object full_name, id, visibility, forks Get-GitHubRepositoryByName -Owner 'Azure' -Repo 'ResourceModules' | Select-Object full_name, id, visibility, forks @@ -95,6 +95,3 @@ Get-GitHubRepositoryListByUser -Username 'octocat' -Sort 'created' -Direction 'a Get-GitHubRepositoryListByOrg -Owner 'PSModule' | Select-Object full_name, id, visibility, created_at Get-GitHubRepositoryListByOrg -Owner 'PSModule' -type 'public' | Select-Object full_name, id, visibility, created_at Get-GitHubRepositoryListByOrg -Owner 'PSModule' -Sort 'created' -Direction 'asc' | Select-Object full_name, id, visibility, created_at - - - From e345c56bba5d052cb3d667ba56beede09a7b26e7 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 8 Oct 2023 16:02:13 +0200 Subject: [PATCH 010/193] Fix parameterset type --- .../public/Repositories/Get-GitHubMyRepositories.ps1 | 10 +++++----- tools/utilities/Local-Testing.ps1 | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/GitHub/public/Repositories/Get-GitHubMyRepositories.ps1 b/src/GitHub/public/Repositories/Get-GitHubMyRepositories.ps1 index 7a3cba7d1..e23ea30fd 100644 --- a/src/GitHub/public/Repositories/Get-GitHubMyRepositories.ps1 +++ b/src/GitHub/public/Repositories/Get-GitHubMyRepositories.ps1 @@ -69,7 +69,7 @@ [Parameter( ParameterSetName = 'Type' )] - [ValidateSet('all', 'public', 'private', 'forks', 'sources', 'member')] + [ValidateSet('all', 'owner', 'public', 'private', 'member')] [string] $Type = 'all', # The property to sort the results by. @@ -98,15 +98,15 @@ $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntries -Hashtable $body -RemoveNames 'Affiliation', 'Since', 'Before' -RemoveTypes 'SwitchParameters' + Remove-HashtableEntries -Hashtable $body -RemoveNames 'Affiliation', 'Since', 'Before' - if ($Affiliation) { + if ($PSBoundParameters.ContainsKey('Affiliation')) { $body['affiliation'] = $Affiliation -join ',' } - if ($Since) { + if ($PSBoundParameters.ContainsKey('Since')) { $body['since'] = $Since.ToString('yyyy-MM-ddTHH:mm:ssZ') } - if ($Before) { + if ($PSBoundParameters.ContainsKey('Before')) { $body['before'] = $Before.ToString('yyyy-MM-ddTHH:mm:ssZ') } diff --git a/tools/utilities/Local-Testing.ps1 b/tools/utilities/Local-Testing.ps1 index cfb96723a..c365fa468 100644 --- a/tools/utilities/Local-Testing.ps1 +++ b/tools/utilities/Local-Testing.ps1 @@ -81,7 +81,7 @@ Add-GitHubReleaseAsset -Owner PSModule -Repo Demo -ID $Release.id -FilePath 'C:\ Get-GitHubReleaseAsset -Owner PSModule -Repo Demo -ReleaseID $Release.id -Get-GitHubMyRepositories -Affiliation owner, collaborator -Verbose | Select-Object full_name, id, visibility, forks +Get-GitHubMyRepositories -Type owner | Select-Object full_name, id, visibility, forks Get-GitHubRepositoryByName -Owner 'PSModule' -Repo 'Demo' | Select-Object full_name, id, visibility, forks Get-GitHubRepositoryByName -Owner 'Azure' -Repo 'ResourceModules' | Select-Object full_name, id, visibility, forks From 4e98ee26282d3b752fa31a441bed274d2884f5a7 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 8 Oct 2023 16:45:15 +0200 Subject: [PATCH 011/193] Fixed dynamic param for type --- .../Repositories/Get-GitHubRepository.ps1 | 169 +++++++++++------- tools/utilities/Local-Testing.ps1 | 17 ++ 2 files changed, 120 insertions(+), 66 deletions(-) diff --git a/src/GitHub/public/Repositories/Get-GitHubRepository.ps1 b/src/GitHub/public/Repositories/Get-GitHubRepository.ps1 index a606505a4..9ee743e11 100644 --- a/src/GitHub/public/Repositories/Get-GitHubRepository.ps1 +++ b/src/GitHub/public/Repositories/Get-GitHubRepository.ps1 @@ -11,6 +11,9 @@ If an Owner and Repo parameters are specified, the specified repository is returned. If the Owner and Repo parameters are specified, the specified repository is returned. + .PARAMETER Type + Specifies the types of repositories you want returned. + .EXAMPLE An example @@ -21,7 +24,7 @@ param ( #Limit results to repositories with the specified visibility. [Parameter(ParameterSetName = 'MyRepos_Aff-Vis')] - [validateSet('all', 'public', 'private')] + [ValidateSet('all', 'public', 'private')] [string] $Visibility = 'all', # Comma-separated list of values. Can include: @@ -30,7 +33,7 @@ # - organization_member: Repositories that the user has access to through being a member of an organization. This includes every repository on every team that the user is on. # Default: owner, collaborator, organization_member [Parameter(ParameterSetName = 'MyRepos_Aff-Vis')] - [validateset('owner', 'collaborator', 'organization_member')] + [ValidateSet('owner', 'collaborator', 'organization_member')] [string[]] $Affiliation = @('owner', 'collaborator', 'organization_member'), # A repository ID. Only return repositories with an ID greater than this ID. @@ -66,19 +69,12 @@ [Alias('login')] [string] $Username, - # Specifies the types of repositories you want returned. - [Parameter(ParameterSetName = 'MyRepos_Type')] - [Parameter(ParameterSetName = 'ListByOrg')] - [Parameter(ParameterSetName = 'ListByUser')] - [validateSet('all', 'public', 'private', 'forks', 'sources', 'member')] - [string] $Type = 'all', - # The property to sort the results by. [Parameter(ParameterSetName = 'MyRepos_Type')] [Parameter(ParameterSetName = 'MyRepos_Aff-Vis')] [Parameter(ParameterSetName = 'ListByOrg')] [Parameter(ParameterSetName = 'ListByUser')] - [validateSet('created', 'updated', 'pushed', 'full_name')] + [ValidateSet('created', 'updated', 'pushed', 'full_name')] [string] $Sort = 'created', # The order to sort by. @@ -86,7 +82,7 @@ [Parameter(ParameterSetName = 'MyRepos')] [Parameter(ParameterSetName = 'ListByOrg')] [Parameter(ParameterSetName = 'ListByUser')] - [validateSet('asc', 'desc')] + [ValidateSet('asc', 'desc')] [string] $Direction, # The number of results per page (max 100). @@ -97,69 +93,110 @@ ) - switch ($PSCmdlet.ParameterSetName) { - 'MyRepos_Type' { - $params = @{ - Type = $Type - Sort = $Sort - Direction = $Direction - PerPage = $PerPage - Since = $Since - Before = $Before + DynamicParam { + $runtimeDefinedParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary + $attributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute] + + $parameterName = 'Type' + $parameterAttribute = New-Object System.Management.Automation.ParameterAttribute + $parameterAttribute.Mandatory = $false + + switch ($PSCmdlet.ParameterSetName) { + 'MyRepos_Type' { + $parameterAttribute.ParameterSetName = 'MyRepos_Type' } - Remove-HashTableEntries -Hashtable $params -NullOrEmptyValues - Get-GitHubMyRepositories @params - } - 'MyRepos_Aff-Vis' { - $params = @{ - Visibility = $Visibility - Affiliation = $Affiliation - Sort = $Sort - Direction = $Direction - PerPage = $PerPage - Since = $Since - Before = $Before + 'ListByOrg' { + $parameterAttribute.ParameterSetName = 'ListByOrg' } - Remove-HashTableEntries -Hashtable $params -NullOrEmptyValues - Get-GitHubMyRepositories @params - } - 'ByName' { - $params = @{ - Owner = $Owner - Repo = $Repo + 'ListByUser' { + $parameterAttribute.ParameterSetName = 'ListByUser' } - Remove-HashTableEntries -Hashtable $params -NullOrEmptyValues - Get-GitHubRepositoryByName @params } - 'ListByID' { - $params = @{ - Since = $SinceID + $attributeCollection.Add($parameterAttribute) + + switch ($PSCmdlet.ParameterSetName) { + 'MyRepos_Type' { + $parameterValidateSet = 'all', 'owner', 'public', 'private', 'member' } - Remove-HashTableEntries -Hashtable $params -NullOrEmptyValues - Get-GitHubRepositoryListByID @params - } - 'ListByOrg' { - $params = @{ - Owner = $Owner - Type = $Type - Sort = $Sort - Direction = $Direction - PerPage = $PerPage + 'ListByOrg' { + $parameterValidateSet = 'all', 'public', 'private', 'forks', 'sources', 'member' } - Remove-HashTableEntries -Hashtable $params -NullOrEmptyValues - Get-GitHubRepositoryListByOrg @params - } - 'ListByUser' { - $params = @{ - Username = $Username - Type = $Type - Sort = $Sort - Direction = $Direction - PerPage = $PerPage + 'ListByUser' { + $parameterValidateSet = 'all', 'owner', 'member' } - Remove-HashTableEntries -Hashtable $params -NullOrEmptyValues - Get-GitHubRepositoryListByUser @params } + $validateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($parameterValidateSet) + $attributeCollection.Add($validateSetAttribute) + + $runtimeDefinedParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($parameterName, [string], $attributeCollection) + $runtimeDefinedParameterDictionary.Add($parameterName, $runtimeDefinedParameter) + return $runtimeDefinedParameterDictionary } + Process { + switch ($PSCmdlet.ParameterSetName) { + 'MyRepos_Type' { + $params = @{ + Type = $Type + Sort = $Sort + Direction = $Direction + PerPage = $PerPage + Since = $Since + Before = $Before + } + Remove-HashTableEntries -Hashtable $params -NullOrEmptyValues + Get-GitHubMyRepositories @params + } + 'MyRepos_Aff-Vis' { + $params = @{ + Visibility = $Visibility + Affiliation = $Affiliation + Sort = $Sort + Direction = $Direction + PerPage = $PerPage + Since = $Since + Before = $Before + } + Remove-HashTableEntries -Hashtable $params -NullOrEmptyValues + Get-GitHubMyRepositories @params + } + 'ByName' { + $params = @{ + Owner = $Owner + Repo = $Repo + } + Remove-HashTableEntries -Hashtable $params -NullOrEmptyValues + Get-GitHubRepositoryByName @params + } + 'ListByID' { + $params = @{ + Since = $SinceID + } + Remove-HashTableEntries -Hashtable $params -NullOrEmptyValues + Get-GitHubRepositoryListByID @params + } + 'ListByOrg' { + $params = @{ + Owner = $Owner + Type = $Type + Sort = $Sort + Direction = $Direction + PerPage = $PerPage + } + Remove-HashTableEntries -Hashtable $params -NullOrEmptyValues + Get-GitHubRepositoryListByOrg @params + } + 'ListByUser' { + $params = @{ + Username = $Username + Type = $Type + Sort = $Sort + Direction = $Direction + PerPage = $PerPage + } + Remove-HashTableEntries -Hashtable $params -NullOrEmptyValues + Get-GitHubRepositoryListByUser @params + } + } + } } diff --git a/tools/utilities/Local-Testing.ps1 b/tools/utilities/Local-Testing.ps1 index c365fa468..6f2b71dd0 100644 --- a/tools/utilities/Local-Testing.ps1 +++ b/tools/utilities/Local-Testing.ps1 @@ -95,3 +95,20 @@ Get-GitHubRepositoryListByUser -Username 'octocat' -Sort 'created' -Direction 'a Get-GitHubRepositoryListByOrg -Owner 'PSModule' | Select-Object full_name, id, visibility, created_at Get-GitHubRepositoryListByOrg -Owner 'PSModule' -type 'public' | Select-Object full_name, id, visibility, created_at Get-GitHubRepositoryListByOrg -Owner 'PSModule' -Sort 'created' -Direction 'asc' | Select-Object full_name, id, visibility, created_at + + +Get-GitHubRepository +Get-GitHubRepository -Type owner | Select-Object full_name, id, visibility, forks + +Get-GitHubRepository -Owner 'PSModule' -Repo 'Demo' | Select-Object full_name, id, visibility, forks +Get-GitHubRepository -Owner 'Azure' -Repo 'ResourceModules' | Select-Object full_name, id, visibility, forks + +Get-GitHubRepository -Verbose | Select-Object full_name, id, visibility, forks + +Get-GitHubRepository -Username 'octocat' | Select-Object full_name, id, visibility, forks +Get-GitHubRepository -Username 'octocat' -Type 'member' | Select-Object full_name, id, visibility, forks +Get-GitHubRepository -Username 'octocat' -Sort 'created' -Direction 'asc' | Select-Object full_name, id, visibility, created_at + +Get-GitHubRepository -Owner 'PSModule' | Select-Object full_name, id, visibility, created_at +Get-GitHubRepository -Owner 'PSModule' -type 'public' | Select-Object full_name, id, visibility, created_at +Get-GitHubRepository -Owner 'PSModule' -Sort 'created' -Direction 'asc' | Select-Object full_name, id, visibility, created_at From ab9f1252959808d8738ac297e160a36322020e80 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 8 Oct 2023 17:19:05 +0200 Subject: [PATCH 012/193] Integration to Get-GitHubRepository --- .../Repositories/Get-GitHubMyRepositories.ps1 | 6 ++ .../Repositories/Get-GitHubRepository.ps1 | 67 +++++++++++-------- .../Get-GitHubRepositoryListByID.ps1 | 8 +++ .../Get-GitHubRepositoryListByOrg.ps1 | 7 ++ .../Get-GitHubRepositoryListByUser.ps1 | 11 ++- tools/utilities/Local-Testing.ps1 | 27 ++++---- 6 files changed, 82 insertions(+), 44 deletions(-) diff --git a/src/GitHub/public/Repositories/Get-GitHubMyRepositories.ps1 b/src/GitHub/public/Repositories/Get-GitHubMyRepositories.ps1 index e23ea30fd..5b7a70cb5 100644 --- a/src/GitHub/public/Repositories/Get-GitHubMyRepositories.ps1 +++ b/src/GitHub/public/Repositories/Get-GitHubMyRepositories.ps1 @@ -96,6 +96,12 @@ [datetime] $Before ) + $PSCmdlet.MyInvocation.MyCommand.Parameters.GetEnumerator() | ForEach-Object { + $paramDefaultValue = Get-Variable -Name $_.Key -ValueOnly -ErrorAction SilentlyContinue + if (-not $PSBoundParameters.ContainsKey($_.Key) -and ($null -ne $paramDefaultValue)) { + $PSBoundParameters[$_.Key] = $paramDefaultValue + } + } $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case Remove-HashtableEntries -Hashtable $body -RemoveNames 'Affiliation', 'Since', 'Before' diff --git a/src/GitHub/public/Repositories/Get-GitHubRepository.ps1 b/src/GitHub/public/Repositories/Get-GitHubRepository.ps1 index 9ee743e11..749c8d006 100644 --- a/src/GitHub/public/Repositories/Get-GitHubRepository.ps1 +++ b/src/GitHub/public/Repositories/Get-GitHubRepository.ps1 @@ -56,7 +56,10 @@ [string] $Owner = (Get-GitHubConfig -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter()] + [Parameter( + Mandatory, + ParameterSetName = 'ByName' + )] [string] $Repo = (Get-GitHubConfig -Name Repo), # The handle for the GitHub user account. @@ -97,43 +100,49 @@ $runtimeDefinedParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary $attributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute] - $parameterName = 'Type' - $parameterAttribute = New-Object System.Management.Automation.ParameterAttribute - $parameterAttribute.Mandatory = $false + if ($PSCmdlet.ParameterSetName -in 'MyRepos_Type', 'ListByOrg', 'ListByUser') { + $parameterName = 'Type' + $parameterAttribute = New-Object System.Management.Automation.ParameterAttribute - switch ($PSCmdlet.ParameterSetName) { - 'MyRepos_Type' { - $parameterAttribute.ParameterSetName = 'MyRepos_Type' - } - 'ListByOrg' { - $parameterAttribute.ParameterSetName = 'ListByOrg' - } - 'ListByUser' { - $parameterAttribute.ParameterSetName = 'ListByUser' + switch ($PSCmdlet.ParameterSetName) { + 'MyRepos_Type' { + $parameterAttribute.Mandatory = $false + $parameterAttribute.ParameterSetName = 'MyRepos_Type' + } + 'ListByOrg' { + $parameterAttribute.Mandatory = $false + $parameterAttribute.ParameterSetName = 'ListByOrg' + } + 'ListByUser' { + $parameterAttribute.Mandatory = $false + $parameterAttribute.ParameterSetName = 'ListByUser' + } } - } - $attributeCollection.Add($parameterAttribute) + $attributeCollection.Add($parameterAttribute) - switch ($PSCmdlet.ParameterSetName) { - 'MyRepos_Type' { - $parameterValidateSet = 'all', 'owner', 'public', 'private', 'member' - } - 'ListByOrg' { - $parameterValidateSet = 'all', 'public', 'private', 'forks', 'sources', 'member' - } - 'ListByUser' { - $parameterValidateSet = 'all', 'owner', 'member' + switch ($PSCmdlet.ParameterSetName) { + 'MyRepos_Type' { + $parameterValidateSet = 'all', 'owner', 'public', 'private', 'member' + } + 'ListByOrg' { + $parameterValidateSet = 'all', 'public', 'private', 'forks', 'sources', 'member' + } + 'ListByUser' { + $parameterValidateSet = 'all', 'owner', 'member' + } } - } - $validateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($parameterValidateSet) - $attributeCollection.Add($validateSetAttribute) + $validateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($parameterValidateSet) + $attributeCollection.Add($validateSetAttribute) - $runtimeDefinedParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($parameterName, [string], $attributeCollection) - $runtimeDefinedParameterDictionary.Add($parameterName, $runtimeDefinedParameter) + $runtimeDefinedParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($parameterName, [string], $attributeCollection) + $runtimeDefinedParameterDictionary.Add($parameterName, $runtimeDefinedParameter) + } return $runtimeDefinedParameterDictionary } Process { + $Type = $PSBoundParameters['Type'] + switch ($PSCmdlet.ParameterSetName) { 'MyRepos_Type' { $params = @{ diff --git a/src/GitHub/public/Repositories/Get-GitHubRepositoryListByID.ps1 b/src/GitHub/public/Repositories/Get-GitHubRepositoryListByID.ps1 index c82c7bb0a..14788b4e1 100644 --- a/src/GitHub/public/Repositories/Get-GitHubRepositoryListByID.ps1 +++ b/src/GitHub/public/Repositories/Get-GitHubRepositoryListByID.ps1 @@ -26,11 +26,19 @@ [int] $Since = 0 ) + $PSCmdlet.MyInvocation.MyCommand.Parameters.GetEnumerator() | ForEach-Object { + $paramDefaultValue = Get-Variable -Name $_.Key -ValueOnly -ErrorAction SilentlyContinue + if (-not $PSBoundParameters.ContainsKey($_.Key) -and ($null -ne $paramDefaultValue)) { + $PSBoundParameters[$_.Key] = $paramDefaultValue + } + } + $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case $inputObject = @{ APIEndpoint = '/repositories' Method = 'GET' + Body = $body } Invoke-GitHubAPI @inputObject | ForEach-Object { diff --git a/src/GitHub/public/Repositories/Get-GitHubRepositoryListByOrg.ps1 b/src/GitHub/public/Repositories/Get-GitHubRepositoryListByOrg.ps1 index ca4e2c242..429fa1daf 100644 --- a/src/GitHub/public/Repositories/Get-GitHubRepositoryListByOrg.ps1 +++ b/src/GitHub/public/Repositories/Get-GitHubRepositoryListByOrg.ps1 @@ -55,6 +55,13 @@ [int] $PerPage = 30 ) + $PSCmdlet.MyInvocation.MyCommand.Parameters.GetEnumerator() | ForEach-Object { + $paramDefaultValue = Get-Variable -Name $_.Key -ValueOnly -ErrorAction SilentlyContinue + if (-not $PSBoundParameters.ContainsKey($_.Key) -and ($null -ne $paramDefaultValue)) { + $PSBoundParameters[$_.Key] = $paramDefaultValue + } + } + $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner' diff --git a/src/GitHub/public/Repositories/Get-GitHubRepositoryListByUser.ps1 b/src/GitHub/public/Repositories/Get-GitHubRepositoryListByUser.ps1 index d18ccbcd6..0f90f2083 100644 --- a/src/GitHub/public/Repositories/Get-GitHubRepositoryListByUser.ps1 +++ b/src/GitHub/public/Repositories/Get-GitHubRepositoryListByUser.ps1 @@ -39,8 +39,8 @@ # Specifies the types of repositories you want returned. [Parameter()] - [validateSet('all', 'public', 'private', 'forks', 'sources', 'member')] - [string] $type = 'all', + [validateSet('all', 'owner', 'member')] + [string] $Type = 'all', # The property to sort the results by. [Parameter()] @@ -58,6 +58,13 @@ [int] $PerPage = 30 ) + $PSCmdlet.MyInvocation.MyCommand.Parameters.GetEnumerator() | ForEach-Object { + $paramDefaultValue = Get-Variable -Name $_.Key -ValueOnly -ErrorAction SilentlyContinue + if (-not $PSBoundParameters.ContainsKey($_.Key) -and ($null -ne $paramDefaultValue)) { + $PSBoundParameters[$_.Key] = $paramDefaultValue + } + } + $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case Remove-HashtableEntries -Hashtable $body -RemoveNames 'Username' diff --git a/tools/utilities/Local-Testing.ps1 b/tools/utilities/Local-Testing.ps1 index 6f2b71dd0..239bb058e 100644 --- a/tools/utilities/Local-Testing.ps1 +++ b/tools/utilities/Local-Testing.ps1 @@ -81,15 +81,15 @@ Add-GitHubReleaseAsset -Owner PSModule -Repo Demo -ID $Release.id -FilePath 'C:\ Get-GitHubReleaseAsset -Owner PSModule -Repo Demo -ReleaseID $Release.id -Get-GitHubMyRepositories -Type owner | Select-Object full_name, id, visibility, forks +Get-GitHubMyRepositories -Type owner | Select-Object full_name, id, visibility, created_at -Get-GitHubRepositoryByName -Owner 'PSModule' -Repo 'Demo' | Select-Object full_name, id, visibility, forks -Get-GitHubRepositoryByName -Owner 'Azure' -Repo 'ResourceModules' | Select-Object full_name, id, visibility, forks +Get-GitHubRepositoryByName -Owner 'PSModule' -Repo 'Demo' | Select-Object full_name, id, visibility, created_at +Get-GitHubRepositoryByName -Owner 'Azure' -Repo 'ResourceModules' | Select-Object full_name, id, visibility, created_at -Get-GitHubRepositoryListByID -Verbose | Select-Object full_name, id, visibility, forks +Get-GitHubRepositoryListByID -Verbose | Select-Object full_name, id, visibility, created_at -Get-GitHubRepositoryListByUser -Username 'octocat' | Select-Object full_name, id, visibility, forks -Get-GitHubRepositoryListByUser -Username 'octocat' -type 'member' | Select-Object full_name, id, visibility, forks +Get-GitHubRepositoryListByUser -Username 'octocat' | Select-Object full_name, id, visibility, created_at +Get-GitHubRepositoryListByUser -Username 'octocat' -type 'member' | Select-Object full_name, id, visibility, created_at Get-GitHubRepositoryListByUser -Username 'octocat' -Sort 'created' -Direction 'asc' | Select-Object full_name, id, visibility, created_at Get-GitHubRepositoryListByOrg -Owner 'PSModule' | Select-Object full_name, id, visibility, created_at @@ -97,16 +97,17 @@ Get-GitHubRepositoryListByOrg -Owner 'PSModule' -type 'public' | Select-Object f Get-GitHubRepositoryListByOrg -Owner 'PSModule' -Sort 'created' -Direction 'asc' | Select-Object full_name, id, visibility, created_at -Get-GitHubRepository -Get-GitHubRepository -Type owner | Select-Object full_name, id, visibility, forks +Get-GitHubRepository | Select-Object full_name, id, visibility, created_at +Get-GitHubRepository -Type owner | Select-Object full_name, id, visibility, created_at +Get-GitHubRepository -Type private -Sort pushed | Select-Object full_name, id, visibility, created_at -Get-GitHubRepository -Owner 'PSModule' -Repo 'Demo' | Select-Object full_name, id, visibility, forks -Get-GitHubRepository -Owner 'Azure' -Repo 'ResourceModules' | Select-Object full_name, id, visibility, forks +Get-GitHubRepository -Owner 'PSModule' -Repo 'Demo' | Select-Object full_name, id, visibility, created_at +Get-GitHubRepository -Owner 'Azure' -Repo 'ResourceModules' | Select-Object full_name, id, visibility, created_at -Get-GitHubRepository -Verbose | Select-Object full_name, id, visibility, forks +Get-GitHubRepository -SinceID 702104693 -Verbose | Select-Object full_name, id, visibility, created_at -Get-GitHubRepository -Username 'octocat' | Select-Object full_name, id, visibility, forks -Get-GitHubRepository -Username 'octocat' -Type 'member' | Select-Object full_name, id, visibility, forks +Get-GitHubRepository -Username 'octocat' -Type all | Select-Object full_name, id, visibility, created_at +Get-GitHubRepository -Username 'octocat' -Type 'member' | Select-Object full_name, id, visibility, created_at Get-GitHubRepository -Username 'octocat' -Sort 'created' -Direction 'asc' | Select-Object full_name, id, visibility, created_at Get-GitHubRepository -Owner 'PSModule' | Select-Object full_name, id, visibility, created_at From 04dfe85adfb4d5ad0ad4b179267d6ea397d3af05 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 8 Oct 2023 17:25:51 +0200 Subject: [PATCH 013/193] Add logging --- .../public/Repositories/Get-GitHubRepositoryListByID.ps1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/GitHub/public/Repositories/Get-GitHubRepositoryListByID.ps1 b/src/GitHub/public/Repositories/Get-GitHubRepositoryListByID.ps1 index 14788b4e1..0251d90ad 100644 --- a/src/GitHub/public/Repositories/Get-GitHubRepositoryListByID.ps1 +++ b/src/GitHub/public/Repositories/Get-GitHubRepositoryListByID.ps1 @@ -27,10 +27,13 @@ ) $PSCmdlet.MyInvocation.MyCommand.Parameters.GetEnumerator() | ForEach-Object { + Write-Verbose "Parameter: [$($_.Key)] = [$($_.Value)]" $paramDefaultValue = Get-Variable -Name $_.Key -ValueOnly -ErrorAction SilentlyContinue if (-not $PSBoundParameters.ContainsKey($_.Key) -and ($null -ne $paramDefaultValue)) { + Write-Verbose "Parameter: [$($_.Key)] = [$($_.Value)] - Adding default value" $PSBoundParameters[$_.Key] = $paramDefaultValue } + Write-Verbose " - $($PSBoundParameters[$_.Key])" } $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case From 5282534dfaeb02c99651a0fbd317af9460c7c917 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 8 Oct 2023 19:00:05 +0200 Subject: [PATCH 014/193] Reorg and fix Get-GitHubRepository --- .../Repositories/Get-GitHubMyRepositories.ps1 | 0 .../Get-GitHubRepositoryByName.ps1 | 0 .../Get-GitHubRepositoryListByID.ps1 | 0 .../Get-GitHubRepositoryListByOrg.ps1 | 0 .../Get-GitHubRepositoryListByUser.ps1 | 0 .../Get-GitHubRepository.ps1 | 59 ++++++++++++++----- 6 files changed, 43 insertions(+), 16 deletions(-) rename src/GitHub/{public => private/Repositories}/Repositories/Get-GitHubMyRepositories.ps1 (100%) rename src/GitHub/{public => private/Repositories}/Repositories/Get-GitHubRepositoryByName.ps1 (100%) rename src/GitHub/{public => private/Repositories}/Repositories/Get-GitHubRepositoryListByID.ps1 (100%) rename src/GitHub/{public => private/Repositories}/Repositories/Get-GitHubRepositoryListByOrg.ps1 (100%) rename src/GitHub/{public => private/Repositories}/Repositories/Get-GitHubRepositoryListByUser.ps1 (100%) rename src/GitHub/public/Repositories/{ => Repositories}/Get-GitHubRepository.ps1 (81%) diff --git a/src/GitHub/public/Repositories/Get-GitHubMyRepositories.ps1 b/src/GitHub/private/Repositories/Repositories/Get-GitHubMyRepositories.ps1 similarity index 100% rename from src/GitHub/public/Repositories/Get-GitHubMyRepositories.ps1 rename to src/GitHub/private/Repositories/Repositories/Get-GitHubMyRepositories.ps1 diff --git a/src/GitHub/public/Repositories/Get-GitHubRepositoryByName.ps1 b/src/GitHub/private/Repositories/Repositories/Get-GitHubRepositoryByName.ps1 similarity index 100% rename from src/GitHub/public/Repositories/Get-GitHubRepositoryByName.ps1 rename to src/GitHub/private/Repositories/Repositories/Get-GitHubRepositoryByName.ps1 diff --git a/src/GitHub/public/Repositories/Get-GitHubRepositoryListByID.ps1 b/src/GitHub/private/Repositories/Repositories/Get-GitHubRepositoryListByID.ps1 similarity index 100% rename from src/GitHub/public/Repositories/Get-GitHubRepositoryListByID.ps1 rename to src/GitHub/private/Repositories/Repositories/Get-GitHubRepositoryListByID.ps1 diff --git a/src/GitHub/public/Repositories/Get-GitHubRepositoryListByOrg.ps1 b/src/GitHub/private/Repositories/Repositories/Get-GitHubRepositoryListByOrg.ps1 similarity index 100% rename from src/GitHub/public/Repositories/Get-GitHubRepositoryListByOrg.ps1 rename to src/GitHub/private/Repositories/Repositories/Get-GitHubRepositoryListByOrg.ps1 diff --git a/src/GitHub/public/Repositories/Get-GitHubRepositoryListByUser.ps1 b/src/GitHub/private/Repositories/Repositories/Get-GitHubRepositoryListByUser.ps1 similarity index 100% rename from src/GitHub/public/Repositories/Get-GitHubRepositoryListByUser.ps1 rename to src/GitHub/private/Repositories/Repositories/Get-GitHubRepositoryListByUser.ps1 diff --git a/src/GitHub/public/Repositories/Get-GitHubRepository.ps1 b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepository.ps1 similarity index 81% rename from src/GitHub/public/Repositories/Get-GitHubRepository.ps1 rename to src/GitHub/public/Repositories/Repositories/Get-GitHubRepository.ps1 index 749c8d006..f63d86803 100644 --- a/src/GitHub/public/Repositories/Get-GitHubRepository.ps1 +++ b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepository.ps1 @@ -1,24 +1,51 @@ filter Get-GitHubRepository { <# - .SYNOPSIS - Gets a specific repository or list of repositories. + .SYNOPSIS + Gets a specific repository or list of repositories. - .DESCRIPTION - Gets a specific repository or list of repositories based on parameter sets. - If no parameters are specified, the authenticated user's repositories are returned. - If a Username parameter is specified, the specified user's public repositories are returned. - If the SinceId parameter is specified, the repositories with an ID greater than the specified ID are returned. - If an Owner and Repo parameters are specified, the specified repository is returned. - If the Owner and Repo parameters are specified, the specified repository is returned. + .DESCRIPTION + Gets a specific repository or list of repositories based on parameter sets. + If no parameters are specified, the authenticated user's repositories are returned. + If a Username parameter is specified, the specified user's public repositories are returned. + If the SinceId parameter is specified, the repositories with an ID greater than the specified ID are returned. + If an Owner and Repo parameters are specified, the specified repository is returned. + If the Owner and Repo parameters are specified, the specified repository is returned. - .PARAMETER Type - Specifies the types of repositories you want returned. + .PARAMETER Type + Specifies the types of repositories you want returned. - .EXAMPLE - An example + .EXAMPLE + Get-GitHubRepository + + Gets the repositories for the authenticated user. + + .EXAMPLE + Get-GitHubRepository -Type 'owner' + + Gets the repositories owned by the authenticated user. + + .EXAMPLE + Get-GitHubRepository -Username 'octocat' + + Gets the repositories for the specified user. + + .EXAMPLE + Get-GitHubRepository -SinceID 123456789 + + Gets the repositories with an ID equals and greater than 123456789. + + .EXAMPLE + Get-GitHubRepository -Owner 'github' -Repo 'octocat' + + Gets the specified repository. + + .NOTES + https://docs.github.com/rest/repos/repos#list-repositories-for-the-authenticated-user + https://docs.github.com/rest/repos/repos#get-a-repository + https://docs.github.com/rest/repos/repos#list-public-repositories + https://docs.github.com/rest/repos/repos#list-organization-repositories + https://docs.github.com/rest/repos/repos#list-repositories-for-a-user - .NOTES - General notes #> [CmdletBinding(DefaultParameterSetName = 'MyRepos_Type')] param ( @@ -142,7 +169,7 @@ Process { $Type = $PSBoundParameters['Type'] - + switch ($PSCmdlet.ParameterSetName) { 'MyRepos_Type' { $params = @{ From 0ab5cac2a42b524ede1d993076773006b33954aa Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 8 Oct 2023 19:00:27 +0200 Subject: [PATCH 015/193] remove stale samples --- tools/utilities/Local-Testing.ps1 | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/tools/utilities/Local-Testing.ps1 b/tools/utilities/Local-Testing.ps1 index 239bb058e..f0a986518 100644 --- a/tools/utilities/Local-Testing.ps1 +++ b/tools/utilities/Local-Testing.ps1 @@ -81,22 +81,6 @@ Add-GitHubReleaseAsset -Owner PSModule -Repo Demo -ID $Release.id -FilePath 'C:\ Get-GitHubReleaseAsset -Owner PSModule -Repo Demo -ReleaseID $Release.id -Get-GitHubMyRepositories -Type owner | Select-Object full_name, id, visibility, created_at - -Get-GitHubRepositoryByName -Owner 'PSModule' -Repo 'Demo' | Select-Object full_name, id, visibility, created_at -Get-GitHubRepositoryByName -Owner 'Azure' -Repo 'ResourceModules' | Select-Object full_name, id, visibility, created_at - -Get-GitHubRepositoryListByID -Verbose | Select-Object full_name, id, visibility, created_at - -Get-GitHubRepositoryListByUser -Username 'octocat' | Select-Object full_name, id, visibility, created_at -Get-GitHubRepositoryListByUser -Username 'octocat' -type 'member' | Select-Object full_name, id, visibility, created_at -Get-GitHubRepositoryListByUser -Username 'octocat' -Sort 'created' -Direction 'asc' | Select-Object full_name, id, visibility, created_at - -Get-GitHubRepositoryListByOrg -Owner 'PSModule' | Select-Object full_name, id, visibility, created_at -Get-GitHubRepositoryListByOrg -Owner 'PSModule' -type 'public' | Select-Object full_name, id, visibility, created_at -Get-GitHubRepositoryListByOrg -Owner 'PSModule' -Sort 'created' -Direction 'asc' | Select-Object full_name, id, visibility, created_at - - Get-GitHubRepository | Select-Object full_name, id, visibility, created_at Get-GitHubRepository -Type owner | Select-Object full_name, id, visibility, created_at Get-GitHubRepository -Type private -Sort pushed | Select-Object full_name, id, visibility, created_at @@ -113,3 +97,4 @@ Get-GitHubRepository -Username 'octocat' -Sort 'created' -Direction 'asc' | Sele Get-GitHubRepository -Owner 'PSModule' | Select-Object full_name, id, visibility, created_at Get-GitHubRepository -Owner 'PSModule' -type 'public' | Select-Object full_name, id, visibility, created_at Get-GitHubRepository -Owner 'PSModule' -Sort 'created' -Direction 'asc' | Select-Object full_name, id, visibility, created_at + From d73b95544bbad351f6273438772ee2b81405d8b4 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 8 Oct 2023 20:01:50 +0200 Subject: [PATCH 016/193] Add command to create org repo --- .../Repositories/New-GitHubRepositoryOrg.ps1 | 195 ++++++++++++++++++ tools/utilities/GitHubAPI.ps1 | 4 +- 2 files changed, 197 insertions(+), 2 deletions(-) create mode 100644 src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 diff --git a/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 b/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 new file mode 100644 index 000000000..f757a31d9 --- /dev/null +++ b/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 @@ -0,0 +1,195 @@ +filter New-GitHubRepositoryOrg { + <# + .SYNOPSIS + Create an organization repository + + .DESCRIPTION + Creates a new repository in the specified organization. The authenticated user must be a member of the organization. + + **OAuth scope requirements** + + When using [OAuth](https://docs.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/), authorizations must include: + + * `public_repo` scope or `repo` scope to create a public repository. Note: For GitHub AE, use `repo` scope to create an internal repository. + * `repo` scope to create a private repository + + .EXAMPLE + $params = @{ + Owner = 'PSModule' + Name = 'Hello-World' + Description = 'This is your first repository' + Homepage = 'https://github.com' + HasIssues = $true + HasProjects = $true + HasWiki = $true + HasDownloads = $true + IsTemplate = $true + AutoInit = $true + AllowSquashMerge = $true + AllowAutoMerge = $true + DeleteBranchOnMerge = $true + SquashMergeCommitTitle = 'PR_TITLE' + SquashMergeCommitMessage = 'PR_BODY' + } + New-GitHubRepositoryOrg @params + + .NOTES + https://docs.github.com/rest/repos/repos#create-an-organization-repository + + #> + [CmdletBinding()] + param ( + # The account owner of the repository. The name is not case sensitive. + [Parameter()] + [Alias('org')] + [string] $Owner = (Get-GitHubConfig -Name Owner), + + # The name of the repository. + [Parameter(Mandatory)] + [string] $Name, + + # A short description of the repository. + [Parameter()] + [string] $Description, + + # A URL with more information about the repository. + [Parameter()] + [ValidateNotNullOrEmpty()] + [uri] $Homepage, + + # Whether the repository is private. + [Parameter()] + [switch] $Private, + + #The visibility of the repository. + [Parameter()] + [ValidateSet('public', 'private')] + [string] $Visibility, + + # Either true to enable issues for this repository or false to disable them. + [Parameter()] + [Alias('has_issues')] + [switch] $HasIssues, + + # Either true to enable projects for this repository or false to disable them. + # Note: If you're creating a repository in an organization that has disabled repository projects, the default is false, and if you pass true, the API returns an error. + [Parameter()] + [Alias('has_projects')] + [switch] $HasProjects, + + # Either true to enable the wiki for this repository or false to disable it. + [Parameter()] + [Alias('has_wiki')] + [switch] $HasWiki, + + # Whether downloads are enabled. + [Parameter()] + [Alias('has_downloads')] + [switch] $HasDownloads, + + # Either true to make this repo available as a template repository or false to prevent it. + [Parameter()] + [Alias('is_template')] + [switch] $IsTemplate, + + # The id of the team that will be granted access to this repository. This is only valid when creating a repository in an organization. + [Parameter()] + [Alias('team_id')] + [int] $TeamID, + + # Pass true to create an initial commit with empty README. + [Parameter()] + [Alias('auto_init')] + [switch] $AutoInit, + + # Desired language or platform .gitignore template to apply. Use the name of the template without the extension. For example, "Haskell". + [Parameter()] + [Alias('gitignore_template')] + [string] $GitignoreTemplate, + + # Choose an open source license template that best suits your needs, and then use the license keyword as the license_template string. For example, "mit" or "mpl-2.0". + [Parameter()] + [Alias('license_template')] + [string] $LicenseTemplate, + + # Either true to allow squash-merging pull requests, or false to prevent squash-merging. + [Parameter()] + [Alias('allow_squash_merge')] + [switch] $AllowSquashMerge, + + # Either true to allow merging pull requests with a merge commit, or false to prevent merging pull requests with merge commits. + [Parameter()] + [Alias('allow_merge_commit')] + [switch] $AllowMergeCommit, + + # Either true to allow rebase-merging pull requests, or false to prevent rebase-merging. + [Parameter()] + [Alias('allow_rebase_merge')] + [switch] $AllowRebaseMerge, + + # Either true to allow auto-merge on pull requests, or false to disallow auto-merge. + [Parameter()] + [Alias('allow_auto_merge')] + [switch] $AllowAutoMerge, + + # Either true to allow automatically deleting head branches when pull requests are merged, or false to prevent automatic deletion. The authenticated user must be an organization owner to set this property to true. + [Parameter()] + [Alias('delete_branch_on_merge')] + [switch] $DeleteBranchOnMerge, + + # The default value for a squash merge commit title: + # - PR_TITLE - default to the pull request's title. + # - COMMIT_OR_PR_TITLE - default to the commit's title (if only one commit) or the pull request's title (when more than one commit). + [Parameter()] + [ValidateSet('PR_TITLE', 'COMMIT_OR_PR_TITLE')] + [Alias('squash_merge_commit_title')] + [string] $SquashMergeCommitTitle, + + # The default value for a squash merge commit message: + # - PR_BODY - default to the pull request's body. + # - COMMIT_MESSAGES - default to the branch's commit messages. + # - BLANK - default to a blank commit message. + [Parameter()] + [ValidateSet('PR_BODY', 'COMMIT_MESSAGES', 'BLANK')] + [Alias('squash_merge_commit_message')] + [string] $SquashMergeCommitMessage, + + # The default value for a merge commit title. + # - PR_TITLE - default to the pull request's title. + # - MERGE_MESSAGE - default to the classic title for a merge message (e.g.,Merge pull request #123 from branch-name). + [Parameter()] + [ValidateSet('PR_TITLE', 'MERGE_MESSAGE')] + [Alias('merge_commit_title')] + [string] $MergeCommitTitle, + + # The default value for a merge commit message. + # - PR_BODY - default to the pull request's body. + # - PR_TITLE - default to the pull request's title. + # - BLANK - default to a blank commit message. + [Parameter()] + [ValidateSet('PR_BODY', 'PR_TITLE', 'BLANK')] + [Alias('merge_commit_message')] + [string] $MergeCommitMessage + ) + + $PSCmdlet.MyInvocation.MyCommand.Parameters.GetEnumerator() | ForEach-Object { + $paramDefaultValue = Get-Variable -Name $_.Key -ValueOnly -ErrorAction SilentlyContinue + if (-not $PSBoundParameters.ContainsKey($_.Key) -and ($null -ne $paramDefaultValue)) { + $PSBoundParameters[$_.Key] = $paramDefaultValue + } + } + + $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case + Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner' + + $inputObject = @{ + APIEndpoint = "/orgs/$Owner/repos" + Method = 'POST' + Body = $body + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + +} diff --git a/tools/utilities/GitHubAPI.ps1 b/tools/utilities/GitHubAPI.ps1 index b9a21409d..6a388163a 100644 --- a/tools/utilities/GitHubAPI.ps1 +++ b/tools/utilities/GitHubAPI.ps1 @@ -21,8 +21,8 @@ $response = Invoke-RestMethod -Uri $APIDocURI -Method Get # @{n = 'PUT'; e = { (($_.value.psobject.Properties.Name) -contains 'PUT') } }, ` # @{n = 'PATCH'; e = { (($_.value.psobject.Properties.Name) -contains 'PATCH') } } | Format-Table -$path = '/repositories' -$method = 'get' +$path = '/orgs/{org}/repos' +$method = 'post' $response.paths.$path.$method $response.paths.$path.$method.tags | clip # -> Namespace/foldername $response.paths.$path.$method.operationId | clip # -> FunctionName From 2b631412053dbbd389d3b49137462c6298c3d062 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 8 Oct 2023 20:57:41 +0200 Subject: [PATCH 017/193] Added verbosity for logging --- .../Repositories/Repositories/Get-GitHubMyRepositories.ps1 | 3 +++ .../Repositories/Get-GitHubRepositoryListByOrg.ps1 | 3 +++ .../Repositories/Get-GitHubRepositoryListByUser.ps1 | 3 +++ 3 files changed, 9 insertions(+) diff --git a/src/GitHub/private/Repositories/Repositories/Get-GitHubMyRepositories.ps1 b/src/GitHub/private/Repositories/Repositories/Get-GitHubMyRepositories.ps1 index 5b7a70cb5..0ed183ae1 100644 --- a/src/GitHub/private/Repositories/Repositories/Get-GitHubMyRepositories.ps1 +++ b/src/GitHub/private/Repositories/Repositories/Get-GitHubMyRepositories.ps1 @@ -97,10 +97,13 @@ ) $PSCmdlet.MyInvocation.MyCommand.Parameters.GetEnumerator() | ForEach-Object { + Write-Verbose "Parameter: [$($_.Key)] = [$($_.Value)]" $paramDefaultValue = Get-Variable -Name $_.Key -ValueOnly -ErrorAction SilentlyContinue if (-not $PSBoundParameters.ContainsKey($_.Key) -and ($null -ne $paramDefaultValue)) { + Write-Verbose "Parameter: [$($_.Key)] = [$($_.Value)] - Adding default value" $PSBoundParameters[$_.Key] = $paramDefaultValue } + Write-Verbose " - $($PSBoundParameters[$_.Key])" } $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case diff --git a/src/GitHub/private/Repositories/Repositories/Get-GitHubRepositoryListByOrg.ps1 b/src/GitHub/private/Repositories/Repositories/Get-GitHubRepositoryListByOrg.ps1 index 429fa1daf..edb9253c5 100644 --- a/src/GitHub/private/Repositories/Repositories/Get-GitHubRepositoryListByOrg.ps1 +++ b/src/GitHub/private/Repositories/Repositories/Get-GitHubRepositoryListByOrg.ps1 @@ -56,10 +56,13 @@ ) $PSCmdlet.MyInvocation.MyCommand.Parameters.GetEnumerator() | ForEach-Object { + Write-Verbose "Parameter: [$($_.Key)] = [$($_.Value)]" $paramDefaultValue = Get-Variable -Name $_.Key -ValueOnly -ErrorAction SilentlyContinue if (-not $PSBoundParameters.ContainsKey($_.Key) -and ($null -ne $paramDefaultValue)) { + Write-Verbose "Parameter: [$($_.Key)] = [$($_.Value)] - Adding default value" $PSBoundParameters[$_.Key] = $paramDefaultValue } + Write-Verbose " - $($PSBoundParameters[$_.Key])" } $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case diff --git a/src/GitHub/private/Repositories/Repositories/Get-GitHubRepositoryListByUser.ps1 b/src/GitHub/private/Repositories/Repositories/Get-GitHubRepositoryListByUser.ps1 index 0f90f2083..2a0b1758e 100644 --- a/src/GitHub/private/Repositories/Repositories/Get-GitHubRepositoryListByUser.ps1 +++ b/src/GitHub/private/Repositories/Repositories/Get-GitHubRepositoryListByUser.ps1 @@ -59,10 +59,13 @@ ) $PSCmdlet.MyInvocation.MyCommand.Parameters.GetEnumerator() | ForEach-Object { + Write-Verbose "Parameter: [$($_.Key)] = [$($_.Value)]" $paramDefaultValue = Get-Variable -Name $_.Key -ValueOnly -ErrorAction SilentlyContinue if (-not $PSBoundParameters.ContainsKey($_.Key) -and ($null -ne $paramDefaultValue)) { + Write-Verbose "Parameter: [$($_.Key)] = [$($_.Value)] - Adding default value" $PSBoundParameters[$_.Key] = $paramDefaultValue } + Write-Verbose " - $($PSBoundParameters[$_.Key])" } $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case From e739cefd76d66af3c9a94d4d126f176c2a99c63d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 8 Oct 2023 20:57:51 +0200 Subject: [PATCH 018/193] added remove repo function --- .../Repositories/Remove-GitHubRepository.ps1 | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/GitHub/public/Repositories/Repositories/Remove-GitHubRepository.ps1 diff --git a/src/GitHub/public/Repositories/Repositories/Remove-GitHubRepository.ps1 b/src/GitHub/public/Repositories/Repositories/Remove-GitHubRepository.ps1 new file mode 100644 index 000000000..099180627 --- /dev/null +++ b/src/GitHub/public/Repositories/Repositories/Remove-GitHubRepository.ps1 @@ -0,0 +1,43 @@ +filter Remove-GitHubRepository { + <# + .SYNOPSIS + Delete a repository + + .DESCRIPTION + Deleting a repository requires admin access. If OAuth is used, the `delete_repo` scope is required. + + If an organization owner has configured the organization to prevent members from deleting organization-owned + repositories, you will get a `403 Forbidden` response. + + .EXAMPLE + Remove-GitHubRepository -Owner 'PSModule' -Repo 'Hello-World' + + Deletes the repository `Hello-World` in the `PSModule` organization. + + .NOTES + https://docs.github.com/rest/repos/repos#delete-a-repository + + #> + [CmdletBinding()] + param ( + # The account owner of the repository. The name is not case sensitive. + [Parameter(Mandatory)] + [Alias('org')] + [Alias('login')] + [string] $Owner, + + # The name of the repository without the .git extension. The name is not case sensitive. + [Parameter(Mandatory)] + [string] $Repo + ) + + $inputObject = @{ + APIEndpoint = "/repos/$Owner/$Repo" + Method = 'DELETE' + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + +} From 1b3da5cd89530db393c2f9e6e0a2f5f7d5aa5427 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 8 Oct 2023 22:13:16 +0200 Subject: [PATCH 019/193] Add a try catch on invoke --- src/GitHub/public/API/Invoke-GitHubAPI.ps1 | 48 ++++++++++++++-------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 index d889418a3..49d2d5213 100644 --- a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 +++ b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 @@ -150,23 +150,37 @@ } } - Invoke-RestMethod @APICall | ForEach-Object { - $statusCode = $APICallStatusCode | ConvertTo-Json -Depth 100 | ConvertFrom-Json - $responseHeaders = $APICallResponseHeaders | ConvertTo-Json -Depth 100 | ConvertFrom-Json - - Write-Verbose '----------------------------------' - Write-Verbose "StatusCode: $statusCode" - Write-Verbose '----------------------------------' - Write-Verbose "Request: $($APICall | ConvertFrom-HashTable | Format-List | Out-String)" - Write-Verbose '----------------------------------' - Write-Verbose "ResponseHeaders: $($responseHeaders | Format-List | Out-String)" - Write-Verbose '----------------------------------' - - [pscustomobject]@{ - Request = $APICall - Response = $_ - StatusCode = $statusCode - ResponseHeaders = $responseHeaders + try { + Invoke-RestMethod @APICall | ForEach-Object { + $statusCode = $APICallStatusCode | ConvertTo-Json -Depth 100 | ConvertFrom-Json + $responseHeaders = $APICallResponseHeaders | ConvertTo-Json -Depth 100 | ConvertFrom-Json + + Write-Verbose '----------------------------------' + Write-Verbose "StatusCode: $statusCode" + Write-Verbose '----------------------------------' + Write-Verbose "Request:" + $APICall | ConvertFrom-HashTable | Format-List | Out-String -Stream | Write-Verbose + Write-Verbose '----------------------------------' + Write-Verbose "ResponseHeaders:" + $responseHeaders | Format-List | Out-String -Stream | Write-Verbose + Write-Verbose '----------------------------------' + + [pscustomobject]@{ + Request = $APICall + Response = $_ + StatusCode = $statusCode + ResponseHeaders = $responseHeaders + } } + } catch { + Write-Error "Request:" + $APICall | ConvertFrom-HashTable | Format-List | Out-String -Stream | Write-Error + + Write-Error "Message:" + $_.Exception.Message | ConvertFrom-HashTable | Format-List | Out-String -Stream | Write-Error + + Write-Error "Response:" + $_.Exception.Response | ConvertFrom-HashTable | Format-List | Out-String -Stream | Write-Error + throw $errorMessage } } From d31549045a20df9d689dc3bc81d2936a7214e2b1 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 8 Oct 2023 22:13:48 +0200 Subject: [PATCH 020/193] Add more param handling on new repo --- .../Repositories/New-GitHubRepositoryOrg.ps1 | 39 ++++++++++++++----- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 b/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 index f757a31d9..ab3dec865 100644 --- a/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 +++ b/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 @@ -57,14 +57,10 @@ [ValidateNotNullOrEmpty()] [uri] $Homepage, - # Whether the repository is private. - [Parameter()] - [switch] $Private, - #The visibility of the repository. [Parameter()] [ValidateSet('public', 'private')] - [string] $Visibility, + [string] $Visibility = 'public', # Either true to enable issues for this repository or false to disable them. [Parameter()] @@ -95,7 +91,7 @@ # The id of the team that will be granted access to this repository. This is only valid when creating a repository in an organization. [Parameter()] [Alias('team_id')] - [int] $TeamID, + [int] $TeamId, # Pass true to create an initial commit with empty README. [Parameter()] @@ -173,14 +169,37 @@ ) $PSCmdlet.MyInvocation.MyCommand.Parameters.GetEnumerator() | ForEach-Object { - $paramDefaultValue = Get-Variable -Name $_.Key -ValueOnly -ErrorAction SilentlyContinue - if (-not $PSBoundParameters.ContainsKey($_.Key) -and ($null -ne $paramDefaultValue)) { - $PSBoundParameters[$_.Key] = $paramDefaultValue + $paramName = $_.Key + $paramDefaultValue = Get-Variable -Name $paramName -ValueOnly -ErrorAction SilentlyContinue + $providedValue = $PSBoundParameters[$paramName] + Write-Verbose "[$paramName]" + Write-Verbose " - Default: [$paramDefaultValue]" + Write-Verbose " - Provided: [$providedValue]" + if (-not $PSBoundParameters.ContainsKey($paramName) -and ($null -ne $paramDefaultValue)) { + Write-Verbose " - Using default value" + $PSBoundParameters[$paramName] = $paramDefaultValue + } else { + Write-Verbose " - Using provided value" } } $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner' + Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner' -RemoveTypes 'SwitchParameter' + + $body['private'] = $Visibility -eq 'private' + $body['has_issues'] = $HasIssues.IsPresent ? $HasIssues : $false + $body['has_wiki'] = $HasWiki.IsPresent ? $HasWiki : $false + $body['has_projects'] = $HasProjects.IsPresent ? $HasProjects : $false + $body['has_downloads'] = $HasDownloads.IsPresent ? $HasDownloads : $false + $body['is_template'] = $IsTemplate.IsPresent ? $IsTemplate : $false + $body['auto_init'] = $AutoInit.IsPresent ? $AutoInit : $false + $body['allow_squash_merge'] = $AllowSquashMerge.IsPresent ? $AllowSquashMerge : $false + $body['allow_merge_commit'] = $AllowMergeCommit.IsPresent ? $AllowMergeCommit : $false + $body['allow_rebase_merge'] = $AllowRebaseMerge.IsPresent ? $AllowRebaseMerge : $false + $body['allow_auto_merge'] = $AllowAutoMerge.IsPresent ? $AllowAutoMerge : $false + $body['delete_branch_on_merge'] = $DeleteBranchOnMerge.IsPresent ? $DeleteBranchOnMerge : $false + + Remove-HashtableEntries -Hashtable $body -NullOrEmptyValues $inputObject = @{ APIEndpoint = "/orgs/$Owner/repos" From 1e453bf1a89f20958e282518ff7f92b99302c5ea Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 8 Oct 2023 22:14:00 +0200 Subject: [PATCH 021/193] Add testing stuff --- tools/utilities/GitHubAPI.ps1 | 4 ++-- tools/utilities/Local-Testing.ps1 | 31 ++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/tools/utilities/GitHubAPI.ps1 b/tools/utilities/GitHubAPI.ps1 index 6a388163a..533d6edb9 100644 --- a/tools/utilities/GitHubAPI.ps1 +++ b/tools/utilities/GitHubAPI.ps1 @@ -21,8 +21,8 @@ $response = Invoke-RestMethod -Uri $APIDocURI -Method Get # @{n = 'PUT'; e = { (($_.value.psobject.Properties.Name) -contains 'PUT') } }, ` # @{n = 'PATCH'; e = { (($_.value.psobject.Properties.Name) -contains 'PATCH') } } | Format-Table -$path = '/orgs/{org}/repos' -$method = 'post' +$path = '/repos/{owner}/{repo}' +$method = 'DELETE' $response.paths.$path.$method $response.paths.$path.$method.tags | clip # -> Namespace/foldername $response.paths.$path.$method.operationId | clip # -> FunctionName diff --git a/tools/utilities/Local-Testing.ps1 b/tools/utilities/Local-Testing.ps1 index f0a986518..94443ad7a 100644 --- a/tools/utilities/Local-Testing.ps1 +++ b/tools/utilities/Local-Testing.ps1 @@ -95,6 +95,35 @@ Get-GitHubRepository -Username 'octocat' -Type 'member' | Select-Object full_nam Get-GitHubRepository -Username 'octocat' -Sort 'created' -Direction 'asc' | Select-Object full_name, id, visibility, created_at Get-GitHubRepository -Owner 'PSModule' | Select-Object full_name, id, visibility, created_at -Get-GitHubRepository -Owner 'PSModule' -type 'public' | Select-Object full_name, id, visibility, created_at +Get-GitHubRepository -Owner 'PSModule' -Type 'public' | Select-Object full_name, id, visibility, created_at Get-GitHubRepository -Owner 'PSModule' -Sort 'created' -Direction 'asc' | Select-Object full_name, id, visibility, created_at +$params = @{ + Verbose = $true + Owner = 'PSModule' + Name = 'Hello-world' + # Description = 'This is a test repo.' + # Homepage = 'https://github.com' + # Visibility = 'public' + # HasIssues = $true + # HasProjects = $true + # HasWiki = $true + # HasDownloads = $true + # IsTemplate = $true + # TeamID = 12345679 + # AutoInit = $true + # GitignoreTemplate = 'VisualStudio' + # LicenseTemplate = 'mit' + # AllowSquashMerge = $true + # SquashMergeCommitTitle = 'PR_TITLE' + # SquashMergeCommitMessage = 'PR_BODY' + # AllowMergeCommit = $true + # MergeCommitTitle = 'PR_TITLE' + # MergeCommitMessage = 'PR_BODY' + # AllowRebaseMerge = $true + # AllowAutoMerge = $true + # DeleteBranchOnMerge = $true +} +New-GitHubRepositoryOrg @params + +Remove-GitHubRepository -Owner PSModule -Repo 'Hello-world' -Verbose From 2b0a903b183da90af2b62fb26185634e0323d742 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 9 Oct 2023 01:26:56 +0200 Subject: [PATCH 022/193] Add helpers for dynamic param --- .../DynamicParam/Initialize-DynamicParam.ps1 | 3 + .../DynamicParam/New-DynamicParam.ps1 | 206 ++++++++++++++++++ 2 files changed, 209 insertions(+) create mode 100644 src/GitHub/private/Utilities/DynamicParam/Initialize-DynamicParam.ps1 create mode 100644 src/GitHub/private/Utilities/DynamicParam/New-DynamicParam.ps1 diff --git a/src/GitHub/private/Utilities/DynamicParam/Initialize-DynamicParam.ps1 b/src/GitHub/private/Utilities/DynamicParam/Initialize-DynamicParam.ps1 new file mode 100644 index 000000000..9547f3806 --- /dev/null +++ b/src/GitHub/private/Utilities/DynamicParam/Initialize-DynamicParam.ps1 @@ -0,0 +1,3 @@ +function Initialize-DynamicParam { + return [System.Management.Automation.RuntimeDefinedParameterDictionary]::new() +} diff --git a/src/GitHub/private/Utilities/DynamicParam/New-DynamicParam.ps1 b/src/GitHub/private/Utilities/DynamicParam/New-DynamicParam.ps1 new file mode 100644 index 000000000..33f0c945f --- /dev/null +++ b/src/GitHub/private/Utilities/DynamicParam/New-DynamicParam.ps1 @@ -0,0 +1,206 @@ +function New-DynamicParam { + <# + .SYNOPSIS + Creates a new dynamic parameter for a function. + + .DESCRIPTION + Creates a new dynamic parameter for a function. + + .EXAMPLE + An example + + .NOTES + https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_functions_advanced_parameters?view=powershell-7.3#psdefaultvalue-attribute-arguments + + #Default Value + # https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_functions_advanced_parameters?view=powershell-7.3#psdefaultvalue-attribute-arguments + # https://learn.microsoft.com/en-us/dotnet/api/system.management.automation.runtimedefinedparameter.value?view=powershellsdk-7.3.0 + #> + [CmdletBinding()] + param( + # Specifies the name of the parameter. + [Parameter(Mandatory)] + [string] $Name, + + # Specifies the aliases of the parameter. + [Parameter()] + [string[]] $Alias, + + # Specifies the default value of the parameter. + [Parameter()] + $DefaultValue = $null, + + # Specifies the data type of the parameter. + [Parameter()] + [type] $Type, + + # Specifies the parameter set name. + [Parameter()] + [string] $ParameterSetName = '__AllParameterSets', + + # Specifies if the parameter is mandatory. + # Parameter Set specific + [Parameter()] + [switch] $Mandatory, + + # Specifies the parameters positional binding. + # Parameter Set specific + [Parameter()] + [int] $Position, + + # Specifies if the parameter accepts values from the pipeline. + # Parameter Set specific + [Parameter()] + [switch] $ValueFromPipeline, + + # Specifies if the parameter accepts values from the pipeline by property name. + # Parameter Set specific + [Parameter()] + [switch] $ValueFromPipelineByPropertyName, + + # Specifies if the parameter accepts values from the remaining command line arguments that are not associated with another parameter. + # Parameter Set specific + [Parameter()] + [switch] $ValueFromRemainingArguments, + + # Specifies the help message of the parameter. + # Parameter Set specific + [Parameter()] + [string] $HelpMessage, + + # Specifies the comments of the parameter. + [Parameter()] + [string] $Comment, + + # Specifies the validate script of the parameter. + [Parameter()] + [scriptblock] $ValidateScript, + + # Specifies the validate regex pattern of the parameter. + [Parameter()] + [regex] $ValidatePattern, + + # Specifies the validate number of items for the parameter. + [Parameter()] + [ValidateCount(2, 2)] + [int[]] $ValidateCount, + + # Specifies the validate range of the parameter. + [Parameter()] + [object] $ValidateRange, + + # Specifies the validate set of the parameter. + [Parameter()] + [object] $ValidateSet, + + # Specifies the validate length of the parameter. + [Parameter()] + [ValidateCount(2, 2)] + [int[]] $ValidateLength, + + # Specifies if the parameter accepts null or empty values. + [Parameter()] + [switch] $ValidateNotNullOrEmpty, + + # Specifies if the parameter accepts wildcards. + [Parameter()] + [switch] $SupportsWildcards, + + # Specifies if the parameter accepts empty strings. + [Parameter()] + [switch] $AllowEmptyString, + + # Specifies if the parameter accepts null values. + [Parameter()] + [switch] $AllowNull, + + # Specifies if the parameter accepts empty collections. + [Parameter()] + [switch] $AllowEmptyCollection, + + # Specifies the dynamic parameter dictionary. + [Parameter()] + [System.Management.Automation.RuntimeDefinedParameterDictionary] $dynamicParamDictionary + ) + + $attributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute] + + # foreach ParameterSet in ParameterSets , Key = name, Value = Hashtable + $parameterAttribute = [System.Management.Automation.ParameterAttribute]::new() + + $parameterAttribute.ParameterSetName = $ParameterSetName + if ($PSBoundParameters.ContainsKey('HelpMessage')) { + $parameterAttribute.HelpMessage = $HelpMessage + } + if ($PSBoundParameters.ContainsKey('Position')) { + $parameterAttribute.Position = $Position + } + $parameterAttribute.Mandatory = $Mandatory + $parameterAttribute.ValueFromPipeline = $ValueFromPipeline + $parameterAttribute.ValueFromPipelineByPropertyName = $ValueFromPipelineByPropertyName + $parameterAttribute.ValueFromRemainingArguments = $ValueFromRemainingArguments + $attributeCollection.Add($parameterAttribute) + + if ($PSBoundParameters.ContainsKey('Alias')) { + $Alias | ForEach-Object { + $aliasAttribute = New-Object System.Management.Automation.AliasAttribute($_) + $attributeCollection.Add($aliasAttribute) + } + } + + if ($PSBoundParameters.ContainsKey('DefaultValue')) { + $commentAttribute = New-Object System.Management.Automation.PSDefaultValueAttribute($DefaultValue) + $attributeCollection.Add($commentAttribute) + } + + # $Comment + + if ($PSBoundParameters.ContainsKey('ValidateSet')) { + $validateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($ValidateSet) + $attributeCollection.Add($validateSetAttribute) + } + if ($PSBoundParameters.ContainsKey('ValidateNotNullOrEmpty')) { + $validateSetAttribute = New-Object System.Management.Automation.ValidateNotNullOrEmptyAttribute + $attributeCollection.Add($validateSetAttribute) + } + if ($PSBoundParameters.ContainsKey('ValidateLength')) { + $validateLengthAttribute = New-Object System.Management.Automation.ValidateLengthAttribute($ValidateLength[0], $ValidateLength[1]) + $attributeCollection.Add($validateLengthAttribute) + } + if ($PSBoundParameters.ContainsKey('ValidateCount')) { + $validateCountAttribute = New-Object System.Management.Automation.ValidateCountAttribute($ValidateCount[0], $ValidateCount[1]) + $attributeCollection.Add($validateCountAttribute) + } + if ($PSBoundParameters.ContainsKey('ValidateScript')) { + $validateScriptAttribute = New-Object System.Management.Automation.ValidateScriptAttribute($ValidateScript) + $attributeCollection.Add($validateScriptAttribute) + } + if ($PSBoundParameters.ContainsKey('ValidatePattern')) { + $validatePatternAttribute = New-Object System.Management.Automation.ValidatePatternAttribute($ValidatePattern) + $attributeCollection.Add($validatePatternAttribute) + } + if ($PSBoundParameters.ContainsKey('ValidateRange')) { + $validateRangeAttribute = New-Object System.Management.Automation.ValidateRangeAttribute($ValidateRange) + $attributeCollection.Add($validateRangeAttribute) + } + if ($PSBoundParameters.ContainsKey('SupportsWildcards')) { + $supportsWildcardsAttribute = New-Object System.Management.Automation.SupportsWildcardsAttribute + $attributeCollection.Add($supportsWildcardsAttribute) + } + if ($PSBoundParameters.ContainsKey('AllowEmptyString')) { + $allowEmptyStringAttribute = New-Object System.Management.Automation.AllowEmptyStringAttribute + $attributeCollection.Add($allowEmptyStringAttribute) + } + if ($PSBoundParameters.ContainsKey('AllowNull')) { + $allowNullAttribute = New-Object System.Management.Automation.AllowNullAttribute + $attributeCollection.Add($allowNullAttribute) + } + if ($PSBoundParameters.ContainsKey('AllowEmptyCollection')) { + $allowEmptyCollectionAttribute = New-Object System.Management.Automation.AllowEmptyCollectionAttribute + $attributeCollection.Add($allowEmptyCollectionAttribute) + } + + $runtimeDefinedParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($Name, $Type, $attributeCollection) + $dynamicParamDictionary.Add($Name, $runtimeDefinedParameter) + +} From 87dc3786b1705855185072c92437858746b2495c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 9 Oct 2023 01:44:10 +0200 Subject: [PATCH 023/193] Added GitIgnore function --- .../Gitignore/Get-GitHubGitignoreByName.ps1 | 38 ++++++++++++ .../Gitignore/Get-GitHubGitignoreList.ps1 | 31 ++++++++++ .../public/Gitignore/Get-GitHubGitignore.ps1 | 60 +++++++++++++++++++ 3 files changed, 129 insertions(+) create mode 100644 src/GitHub/private/Gitignore/Get-GitHubGitignoreByName.ps1 create mode 100644 src/GitHub/private/Gitignore/Get-GitHubGitignoreList.ps1 create mode 100644 src/GitHub/public/Gitignore/Get-GitHubGitignore.ps1 diff --git a/src/GitHub/private/Gitignore/Get-GitHubGitignoreByName.ps1 b/src/GitHub/private/Gitignore/Get-GitHubGitignoreByName.ps1 new file mode 100644 index 000000000..f4259c994 --- /dev/null +++ b/src/GitHub/private/Gitignore/Get-GitHubGitignoreByName.ps1 @@ -0,0 +1,38 @@ +filter Get-GitHubGitignoreByName { + <# + .SYNOPSIS + Get a gitignore template + + .DESCRIPTION + The API also allows fetching the source of a single template. + Use the raw [media type](https://docs.github.com/rest/overview/media-types/) to get the raw contents. + + .EXAMPLE + Get-GitHubGitignoreList + + Get all gitignore templates + + .NOTES + https://docs.github.com/rest/gitignore/gitignore#get-a-gitignore-template + + #> + [CmdletBinding()] + param ( + [Parameter()] + [ValidateNotNullOrEmpty()] + [string] $Name + ) + + Process { + $inputObject = @{ + APIEndpoint = "/gitignore/templates/$Name" + Accept = 'application/vnd.github.raw+json' + Method = 'GET' + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + + } +} diff --git a/src/GitHub/private/Gitignore/Get-GitHubGitignoreList.ps1 b/src/GitHub/private/Gitignore/Get-GitHubGitignoreList.ps1 new file mode 100644 index 000000000..a00a29a2f --- /dev/null +++ b/src/GitHub/private/Gitignore/Get-GitHubGitignoreList.ps1 @@ -0,0 +1,31 @@ +filter Get-GitHubGitignoreList { + <# + .SYNOPSIS + Get all gitignore templates + + .DESCRIPTION + List all templates available to pass as an option when [creating a repository](https://docs.github.com/rest/repos/repos#create-a-repository-for-the-authenticated-user). + + .EXAMPLE + Get-GitHubGitignoreList + + Get all gitignore templates + + .NOTES + https://docs.github.com/rest/gitignore/gitignore#get-all-gitignore-templates + + #> + [OutputType([string[]])] + [CmdletBinding()] + param () + + $inputObject = @{ + APIEndpoint = '/gitignore/templates' + Method = 'GET' + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + +} diff --git a/src/GitHub/public/Gitignore/Get-GitHubGitignore.ps1 b/src/GitHub/public/Gitignore/Get-GitHubGitignore.ps1 new file mode 100644 index 000000000..c8ace9a0e --- /dev/null +++ b/src/GitHub/public/Gitignore/Get-GitHubGitignore.ps1 @@ -0,0 +1,60 @@ +filter Get-GitHubGitignore { + <# + .SYNOPSIS + Get a gitignore template or list of all gitignore templates names + + .DESCRIPTION + If no parameters are specified, the function will return a list of all gitignore templates names. + If the Name parameter is specified, the function will return the gitignore template for the specified name. + + .EXAMPLE + Get-GitHubGitignoreList + + Get all gitignore templates + + .EXAMPLE + Get-GitHubGitignore -Name 'VisualStudio' + + Get a gitignore template for VisualStudio + + .NOTES + https://docs.github.com/rest/gitignore/gitignore#get-a-gitignore-template + https://docs.github.com/rest/gitignore/gitignore#get-all-gitignore-templates + + #> + [CmdletBinding(DefaultParameterSetName = 'List')] + param () + + DynamicParam { + $runtimeDefinedParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary + $attributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute] + + $parameterName = 'Name' + $parameterType = [string] + $parameterAttribute = New-Object System.Management.Automation.ParameterAttribute + $parameterAttribute.ParameterSetName = 'Name' + $parameterAttribute.Mandatory = $true + $attributeCollection.Add($parameterAttribute) + + $parameterValidateSet = Get-GitHubGitignoreList + $validateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($parameterValidateSet) + $attributeCollection.Add($validateSetAttribute) + + $runtimeDefinedParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($parameterName, $parameterType, $attributeCollection) + $runtimeDefinedParameterDictionary.Add($parameterName, $runtimeDefinedParameter) + + return $runtimeDefinedParameterDictionary + } + + Process { + $Name = $PSBoundParameters['Name'] + switch ($PSCmdlet.ParameterSetName) { + 'List' { + Get-GitHubGitignoreList + } + 'Name' { + Get-GitHubGitignoreByName -Name $Name + } + } + } +} From db6a5d07f7b316226431ffa0c6daa1903363639a Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 9 Oct 2023 01:44:23 +0200 Subject: [PATCH 024/193] Added dynamic param functions --- .../DynamicParam/New-DynamicParam.ps1 | 4 +- ...namicParam.ps1 => New-ParamDictionary.ps1} | 2 +- .../Repositories/New-GitHubRepositoryOrg.ps1 | 117 +++++++++++------- tests/DynamicParam.ps1 | 38 ++++++ tools/utilities/GitHubAPI.ps1 | 4 +- tools/utilities/Local-Testing.ps1 | 40 +++--- 6 files changed, 132 insertions(+), 73 deletions(-) rename src/GitHub/private/Utilities/DynamicParam/{Initialize-DynamicParam.ps1 => New-ParamDictionary.ps1} (69%) create mode 100644 tests/DynamicParam.ps1 diff --git a/src/GitHub/private/Utilities/DynamicParam/New-DynamicParam.ps1 b/src/GitHub/private/Utilities/DynamicParam/New-DynamicParam.ps1 index 33f0c945f..8b1f17f24 100644 --- a/src/GitHub/private/Utilities/DynamicParam/New-DynamicParam.ps1 +++ b/src/GitHub/private/Utilities/DynamicParam/New-DynamicParam.ps1 @@ -120,7 +120,7 @@ # Specifies the dynamic parameter dictionary. [Parameter()] - [System.Management.Automation.RuntimeDefinedParameterDictionary] $dynamicParamDictionary + [System.Management.Automation.RuntimeDefinedParameterDictionary] $ParamDictionary ) $attributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute] @@ -201,6 +201,6 @@ } $runtimeDefinedParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($Name, $Type, $attributeCollection) - $dynamicParamDictionary.Add($Name, $runtimeDefinedParameter) + $ParamDictionary.Add($Name, $runtimeDefinedParameter) } diff --git a/src/GitHub/private/Utilities/DynamicParam/Initialize-DynamicParam.ps1 b/src/GitHub/private/Utilities/DynamicParam/New-ParamDictionary.ps1 similarity index 69% rename from src/GitHub/private/Utilities/DynamicParam/Initialize-DynamicParam.ps1 rename to src/GitHub/private/Utilities/DynamicParam/New-ParamDictionary.ps1 index 9547f3806..e5ba112ae 100644 --- a/src/GitHub/private/Utilities/DynamicParam/Initialize-DynamicParam.ps1 +++ b/src/GitHub/private/Utilities/DynamicParam/New-ParamDictionary.ps1 @@ -1,3 +1,3 @@ -function Initialize-DynamicParam { +function New-ParamDictionary { return [System.Management.Automation.RuntimeDefinedParameterDictionary]::new() } diff --git a/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 b/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 index ab3dec865..4aef53438 100644 --- a/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 +++ b/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 @@ -33,6 +33,12 @@ } New-GitHubRepositoryOrg @params + .PARAMETER GitignoreTemplate + Desired language or platform .gitignore template to apply. Use the name of the template without the extension. For example, "Haskell". + + .PARAMETER LicenseTemplate + Choose an open source license template that best suits your needs, and then use the license keyword as the license_template string. For example, "mit" or "mpl-2.0". + .NOTES https://docs.github.com/rest/repos/repos#create-an-organization-repository @@ -98,16 +104,6 @@ [Alias('auto_init')] [switch] $AutoInit, - # Desired language or platform .gitignore template to apply. Use the name of the template without the extension. For example, "Haskell". - [Parameter()] - [Alias('gitignore_template')] - [string] $GitignoreTemplate, - - # Choose an open source license template that best suits your needs, and then use the license keyword as the license_template string. For example, "mit" or "mpl-2.0". - [Parameter()] - [Alias('license_template')] - [string] $LicenseTemplate, - # Either true to allow squash-merging pull requests, or false to prevent squash-merging. [Parameter()] [Alias('allow_squash_merge')] @@ -168,47 +164,72 @@ [string] $MergeCommitMessage ) - $PSCmdlet.MyInvocation.MyCommand.Parameters.GetEnumerator() | ForEach-Object { - $paramName = $_.Key - $paramDefaultValue = Get-Variable -Name $paramName -ValueOnly -ErrorAction SilentlyContinue - $providedValue = $PSBoundParameters[$paramName] - Write-Verbose "[$paramName]" - Write-Verbose " - Default: [$paramDefaultValue]" - Write-Verbose " - Provided: [$providedValue]" - if (-not $PSBoundParameters.ContainsKey($paramName) -and ($null -ne $paramDefaultValue)) { - Write-Verbose " - Using default value" - $PSBoundParameters[$paramName] = $paramDefaultValue - } else { - Write-Verbose " - Using provided value" + DynamicParam { + $ParamDictionary = New-ParamDictionary + + $dynParam = @{ + Name = 'Gitignore' + Alias = 'gitignore_template' + Type = [string] + ValidateSet = Get-GitHubGitignoreList + ParamDictionary = $ParamDictionary } - } + New-DynamicParam @dynParam + + $dynParam2 = @{ + Name = 'License' + Alias = 'license_template' + Type = [string] + ValidateSet = Get-GitHubLicenseList + ParamDictionary = $ParamDictionary + } + New-DynamicParam @dynParam2 - $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner' -RemoveTypes 'SwitchParameter' - - $body['private'] = $Visibility -eq 'private' - $body['has_issues'] = $HasIssues.IsPresent ? $HasIssues : $false - $body['has_wiki'] = $HasWiki.IsPresent ? $HasWiki : $false - $body['has_projects'] = $HasProjects.IsPresent ? $HasProjects : $false - $body['has_downloads'] = $HasDownloads.IsPresent ? $HasDownloads : $false - $body['is_template'] = $IsTemplate.IsPresent ? $IsTemplate : $false - $body['auto_init'] = $AutoInit.IsPresent ? $AutoInit : $false - $body['allow_squash_merge'] = $AllowSquashMerge.IsPresent ? $AllowSquashMerge : $false - $body['allow_merge_commit'] = $AllowMergeCommit.IsPresent ? $AllowMergeCommit : $false - $body['allow_rebase_merge'] = $AllowRebaseMerge.IsPresent ? $AllowRebaseMerge : $false - $body['allow_auto_merge'] = $AllowAutoMerge.IsPresent ? $AllowAutoMerge : $false - $body['delete_branch_on_merge'] = $DeleteBranchOnMerge.IsPresent ? $DeleteBranchOnMerge : $false - - Remove-HashtableEntries -Hashtable $body -NullOrEmptyValues - - $inputObject = @{ - APIEndpoint = "/orgs/$Owner/repos" - Method = 'POST' - Body = $body + return $ParamDictionary } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + Process { + $PSCmdlet.MyInvocation.MyCommand.Parameters.GetEnumerator() | ForEach-Object { + $paramName = $_.Key + $paramDefaultValue = Get-Variable -Name $paramName -ValueOnly -ErrorAction SilentlyContinue + $providedValue = $PSBoundParameters[$paramName] + Write-Verbose "[$paramName]" + Write-Verbose " - Default: [$paramDefaultValue]" + Write-Verbose " - Provided: [$providedValue]" + if (-not $PSBoundParameters.ContainsKey($paramName) -and ($null -ne $paramDefaultValue)) { + Write-Verbose ' - Using default value' + $PSBoundParameters[$paramName] = $paramDefaultValue + } else { + Write-Verbose ' - Using provided value' + } + } + $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case + Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner' -RemoveTypes 'SwitchParameter' + + $body['private'] = $Visibility -eq 'private' + $body['has_issues'] = $HasIssues.IsPresent ? $HasIssues : $false + $body['has_wiki'] = $HasWiki.IsPresent ? $HasWiki : $false + $body['has_projects'] = $HasProjects.IsPresent ? $HasProjects : $false + $body['has_downloads'] = $HasDownloads.IsPresent ? $HasDownloads : $false + $body['is_template'] = $IsTemplate.IsPresent ? $IsTemplate : $false + $body['auto_init'] = $AutoInit.IsPresent ? $AutoInit : $false + $body['allow_squash_merge'] = $AllowSquashMerge.IsPresent ? $AllowSquashMerge : $false + $body['allow_merge_commit'] = $AllowMergeCommit.IsPresent ? $AllowMergeCommit : $false + $body['allow_rebase_merge'] = $AllowRebaseMerge.IsPresent ? $AllowRebaseMerge : $false + $body['allow_auto_merge'] = $AllowAutoMerge.IsPresent ? $AllowAutoMerge : $false + $body['delete_branch_on_merge'] = $DeleteBranchOnMerge.IsPresent ? $DeleteBranchOnMerge : $false + + Remove-HashtableEntries -Hashtable $body -NullOrEmptyValues + + $inputObject = @{ + APIEndpoint = "/orgs/$Owner/repos" + Method = 'POST' + Body = $body + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } } diff --git a/tests/DynamicParam.ps1 b/tests/DynamicParam.ps1 new file mode 100644 index 000000000..65fa5237f --- /dev/null +++ b/tests/DynamicParam.ps1 @@ -0,0 +1,38 @@ +function Test-DynParam { + [CmdletBinding()] + param ( + [Parameter()] + [ValidateSet('A', 'B', 'C')] + [string]$Param1 + ) + + DynamicParam { + $ParamDictionary = New-ParamDictionary + + $dynParam2 = @{ + Name = 'Param2' + Type = [string] + ValidateSet = Get-Process | Select-Object -ExpandProperty Name + ParamDictionary = $ParamDictionary + } + New-DynamicParam @dynParam2 + + $dynParam3 = @{ + Name = 'Param3' + Type = [string] + ValidateSet = Get-ChildItem -Path C:\ | Select-Object -ExpandProperty Name + ParamDictionary = $ParamDictionary + } + New-DynamicParam @dynParam3 + + return $ParamDictionary + } + + process { + Write-Host "Param1: $Param1" + Write-Host "Param2: $Param2" + Write-Host "Param3: $Param3" + } +} + +Test-DynParam -Param1 A -Param2 cmd -Param3 PerfLogs diff --git a/tools/utilities/GitHubAPI.ps1 b/tools/utilities/GitHubAPI.ps1 index 533d6edb9..c02af3e82 100644 --- a/tools/utilities/GitHubAPI.ps1 +++ b/tools/utilities/GitHubAPI.ps1 @@ -21,8 +21,8 @@ $response = Invoke-RestMethod -Uri $APIDocURI -Method Get # @{n = 'PUT'; e = { (($_.value.psobject.Properties.Name) -contains 'PUT') } }, ` # @{n = 'PATCH'; e = { (($_.value.psobject.Properties.Name) -contains 'PATCH') } } | Format-Table -$path = '/repos/{owner}/{repo}' -$method = 'DELETE' +$path = '/gitignore/templates/{name}' +$method = 'get' $response.paths.$path.$method $response.paths.$path.$method.tags | clip # -> Namespace/foldername $response.paths.$path.$method.operationId | clip # -> FunctionName diff --git a/tools/utilities/Local-Testing.ps1 b/tools/utilities/Local-Testing.ps1 index 94443ad7a..78a62cb7f 100644 --- a/tools/utilities/Local-Testing.ps1 +++ b/tools/utilities/Local-Testing.ps1 @@ -102,27 +102,27 @@ $params = @{ Verbose = $true Owner = 'PSModule' Name = 'Hello-world' - # Description = 'This is a test repo.' - # Homepage = 'https://github.com' - # Visibility = 'public' - # HasIssues = $true - # HasProjects = $true - # HasWiki = $true - # HasDownloads = $true - # IsTemplate = $true + Description = 'This is a test repo.' + Homepage = 'https://github.com' + Visibility = 'public' + HasIssues = $true + HasProjects = $true + HasWiki = $true + HasDownloads = $true + IsTemplate = $true # TeamID = 12345679 - # AutoInit = $true - # GitignoreTemplate = 'VisualStudio' - # LicenseTemplate = 'mit' - # AllowSquashMerge = $true - # SquashMergeCommitTitle = 'PR_TITLE' - # SquashMergeCommitMessage = 'PR_BODY' - # AllowMergeCommit = $true - # MergeCommitTitle = 'PR_TITLE' - # MergeCommitMessage = 'PR_BODY' - # AllowRebaseMerge = $true - # AllowAutoMerge = $true - # DeleteBranchOnMerge = $true + AutoInit = $true + GitignoreTemplate = 'VisualStudio' + LicenseTemplate = 'MIT' + AllowSquashMerge = $true + SquashMergeCommitTitle = 'PR_TITLE' + SquashMergeCommitMessage = 'PR_BODY' + AllowMergeCommit = $true + MergeCommitTitle = 'PR_TITLE' + MergeCommitMessage = 'PR_BODY' + AllowRebaseMerge = $true + AllowAutoMerge = $true + DeleteBranchOnMerge = $true } New-GitHubRepositoryOrg @params From 1b0b26e0882b8437ba3d4ffb5bdb6ab70169d634 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 9 Oct 2023 02:04:50 +0200 Subject: [PATCH 025/193] Added license --- .../License/Get-GitHubLicenseByName.ps1 | 40 ++++++++++ .../private/License/Get-GitHubLicenseList.ps1 | 32 ++++++++ .../License/Get-GitHubRepositoryLicense.ps1 | 44 +++++++++++ .../public/License/Get-GitHubLicense.ps1 | 76 +++++++++++++++++++ 4 files changed, 192 insertions(+) create mode 100644 src/GitHub/private/License/Get-GitHubLicenseByName.ps1 create mode 100644 src/GitHub/private/License/Get-GitHubLicenseList.ps1 create mode 100644 src/GitHub/private/License/Get-GitHubRepositoryLicense.ps1 create mode 100644 src/GitHub/public/License/Get-GitHubLicense.ps1 diff --git a/src/GitHub/private/License/Get-GitHubLicenseByName.ps1 b/src/GitHub/private/License/Get-GitHubLicenseByName.ps1 new file mode 100644 index 000000000..1b04d4087 --- /dev/null +++ b/src/GitHub/private/License/Get-GitHubLicenseByName.ps1 @@ -0,0 +1,40 @@ +filter Get-GitHubLicenseByName { + <# + .SYNOPSIS + Get a license + + .DESCRIPTION + Gets information about a specific license. + For more information, see "[Licensing a repository ](https://docs.github.com/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/licensing-a-repository)." + + .EXAMPLE + Get-GitHubGitignoreList + + Get all gitignore templates + + .NOTES + https://docs.github.com/rest/licenses/licenses#get-a-license + + #> + [CmdletBinding()] + param ( + # The license keyword, license name, or license SPDX ID. For example, mit or mpl-2.0. + [Parameter()] + [ValidateNotNullOrEmpty()] + [Alias('license')] + [string] $Name + ) + + Process { + $inputObject = @{ + APIEndpoint = "/licenses/$Name" + Accept = 'application/vnd.github.raw+json' + Method = 'GET' + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + + } +} diff --git a/src/GitHub/private/License/Get-GitHubLicenseList.ps1 b/src/GitHub/private/License/Get-GitHubLicenseList.ps1 new file mode 100644 index 000000000..8086c12e7 --- /dev/null +++ b/src/GitHub/private/License/Get-GitHubLicenseList.ps1 @@ -0,0 +1,32 @@ +filter Get-GitHubLicenseList { + <# + .SYNOPSIS + Get all commonly used licenses + + .DESCRIPTION + Lists the most commonly used licenses on GitHub. + For more information, see "[Licensing a repository ](https://docs.github.com/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/licensing-a-repository)." + + .EXAMPLE + Get-GitHubLicenseList + + Get all commonly used licenses. + + .NOTES + https://docs.github.com/rest/licenses/licenses#get-all-commonly-used-licenses + + #> + [OutputType([string[]])] + [CmdletBinding()] + param () + + $inputObject = @{ + APIEndpoint = '/licenses' + Method = 'GET' + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + +} diff --git a/src/GitHub/private/License/Get-GitHubRepositoryLicense.ps1 b/src/GitHub/private/License/Get-GitHubRepositoryLicense.ps1 new file mode 100644 index 000000000..2364f5cc6 --- /dev/null +++ b/src/GitHub/private/License/Get-GitHubRepositoryLicense.ps1 @@ -0,0 +1,44 @@ +filter Get-GitHubRepositoryLicense { + <# + .SYNOPSIS + Get the license for a repository + + .DESCRIPTION + This method returns the contents of the repository's license file, if one is detected. + + Similar to [Get repository content](https://docs.github.com/rest/repos/contents#get-repository-content), this method also supports + [custom media types](https://docs.github.com/rest/overview/media-types) for retrieving the raw license content or rendered license HTML. + + .EXAMPLE + Get-GitHubRepositoryLicense -Owner 'octocat' -Repo 'Hello-World' + + Get the license for the Hello-World repository from the octocat account. + + .NOTES + https://docs.github.com/rest/licenses/licenses#get-the-license-for-a-repository + + #> + [CmdletBinding()] + param ( + # The account owner of the repository. The name is not case sensitive. + [Parameter()] + [string] $Owner = (Get-GitHubConfig -Name Owner), + + # The name of the repository without the .git extension. The name is not case sensitive. + [Parameter()] + [string] $Repo = (Get-GitHubConfig -Name Repo) + ) + + Process { + $inputObject = @{ + APIEndpoint = "/repos/$Owner/$Repo/license" + Accept = 'application/vnd.github.raw+json' + Method = 'GET' + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + + } +} diff --git a/src/GitHub/public/License/Get-GitHubLicense.ps1 b/src/GitHub/public/License/Get-GitHubLicense.ps1 new file mode 100644 index 000000000..8082fad09 --- /dev/null +++ b/src/GitHub/public/License/Get-GitHubLicense.ps1 @@ -0,0 +1,76 @@ +filter Get-GitHubLicense { + <# + .SYNOPSIS + Get a license template, list of all popular license templates or a license for a repository + + .DESCRIPTION + If no parameters are specified, the function will return a list of all license templates. + If the Name parameter is specified, the function will return the license template for the specified name. + If the Owner and Repo parameters are specified, the function will return the license for the specified repository. + + .EXAMPLE + Get-GitHubLicense + + Get all license templates + + .EXAMPLE + Get-GitHubLicense -Name mit + + Get the mit license template + + .EXAMPLE + Get-GitHubLicense -Owner 'octocat' -Repo 'Hello-World' + + Get the license for the Hello-World repository from the octocat account. + + .PARAMETER Name + The license keyword, license name, or license SPDX ID. For example, mit or mpl-2.0. + + .NOTES + https://docs.github.com/rest/licenses/licenses#get-a-license + https://docs.github.com/rest/licenses/licenses#get-all-commonly-used-licenses + https://docs.github.com/rest/licenses/licenses#get-the-license-for-a-repository + + #> + [CmdletBinding(DefaultParameterSetName = 'List')] + param ( + # The account owner of the repository. The name is not case sensitive. + [Parameter(ParameterSetName = 'Repository')] + [string] $Owner = (Get-GitHubConfig -Name Owner), + + # The name of the repository without the .git extension. The name is not case sensitive. + [Parameter(ParameterSetName = 'Repository')] + [string] $Repo = (Get-GitHubConfig -Name Repo) + ) + + DynamicParam { + $ParamDictionary = New-ParamDictionary + + $dynParam = @{ + Name = 'Name' + ParameterSetName = 'Name' + Type = [string] + Mandatory = $true + ValidateSet = Get-GitHubLicenseList | Select-Object -ExpandProperty Name + ParamDictionary = $ParamDictionary + } + New-DynamicParam @dynParam + + return $ParamDictionary + } + + Process { + $Name = $PSBoundParameters['Name'] + switch ($PSCmdlet.ParameterSetName) { + 'List' { + Get-GitHubLicenseList + } + 'Name' { + Get-GitHubLicenseByName -Name $Name + } + 'Repository' { + Get-GitHubRepositoryLicense -Owner $Owner -Repo $Repo + } + } + } +} From 56dd59fed7940fe2f4f0634b9770e5702db56fb7 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 9 Oct 2023 02:05:06 +0200 Subject: [PATCH 026/193] fix dynamic param for gitignore --- .../public/Gitignore/Get-GitHubGitignore.ps1 | 29 ++++++++----------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/src/GitHub/public/Gitignore/Get-GitHubGitignore.ps1 b/src/GitHub/public/Gitignore/Get-GitHubGitignore.ps1 index c8ace9a0e..59d6ad7f3 100644 --- a/src/GitHub/public/Gitignore/Get-GitHubGitignore.ps1 +++ b/src/GitHub/public/Gitignore/Get-GitHubGitignore.ps1 @@ -26,24 +26,19 @@ filter Get-GitHubGitignore { param () DynamicParam { - $runtimeDefinedParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary - $attributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute] - - $parameterName = 'Name' - $parameterType = [string] - $parameterAttribute = New-Object System.Management.Automation.ParameterAttribute - $parameterAttribute.ParameterSetName = 'Name' - $parameterAttribute.Mandatory = $true - $attributeCollection.Add($parameterAttribute) - - $parameterValidateSet = Get-GitHubGitignoreList - $validateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($parameterValidateSet) - $attributeCollection.Add($validateSetAttribute) - - $runtimeDefinedParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($parameterName, $parameterType, $attributeCollection) - $runtimeDefinedParameterDictionary.Add($parameterName, $runtimeDefinedParameter) + $ParamDictionary = New-ParamDictionary + + $dynParam = @{ + Name = 'Name' + ParameterSetName = 'Name' + Type = [string] + Mandatory = $true + ValidateSet = Get-GitHubGitignoreList + ParamDictionary = $ParamDictionary + } + New-DynamicParam @dynParam - return $runtimeDefinedParameterDictionary + return $ParamDictionary } Process { From 27bafed98e891a15312a5037fe9596c29e526d31 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 9 Oct 2023 02:05:24 +0200 Subject: [PATCH 027/193] Fix dynamic param for repo --- .../Repositories/New-GitHubRepositoryOrg.ps1 | 14 ++++++++++---- tools/utilities/GitHubAPI.ps1 | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 b/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 index 4aef53438..17693d3c3 100644 --- a/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 +++ b/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 @@ -166,9 +166,9 @@ DynamicParam { $ParamDictionary = New-ParamDictionary - + $dynParam = @{ - Name = 'Gitignore' + Name = 'GitignoreTemplate' Alias = 'gitignore_template' Type = [string] ValidateSet = Get-GitHubGitignoreList @@ -177,10 +177,10 @@ New-DynamicParam @dynParam $dynParam2 = @{ - Name = 'License' + Name = 'LicenseTemplate' Alias = 'license_template' Type = [string] - ValidateSet = Get-GitHubLicenseList + ValidateSet = Get-GitHubLicenseList | Select-Object -ExpandProperty Name ParamDictionary = $ParamDictionary } New-DynamicParam @dynParam2 @@ -188,7 +188,13 @@ return $ParamDictionary } + begin { + $GitignoreTemplate = $PSBoundParameters['GitignoreTemplate'] + $LicenseTemplate = $PSBoundParameters['LicenseTemplate'] + } + Process { + $PSCmdlet.MyInvocation.MyCommand.Parameters.GetEnumerator() | ForEach-Object { $paramName = $_.Key $paramDefaultValue = Get-Variable -Name $paramName -ValueOnly -ErrorAction SilentlyContinue diff --git a/tools/utilities/GitHubAPI.ps1 b/tools/utilities/GitHubAPI.ps1 index c02af3e82..d04600723 100644 --- a/tools/utilities/GitHubAPI.ps1 +++ b/tools/utilities/GitHubAPI.ps1 @@ -21,7 +21,7 @@ $response = Invoke-RestMethod -Uri $APIDocURI -Method Get # @{n = 'PUT'; e = { (($_.value.psobject.Properties.Name) -contains 'PUT') } }, ` # @{n = 'PATCH'; e = { (($_.value.psobject.Properties.Name) -contains 'PATCH') } } | Format-Table -$path = '/gitignore/templates/{name}' +$path = '/repos/{owner}/{repo}/license' $method = 'get' $response.paths.$path.$method $response.paths.$path.$method.tags | clip # -> Namespace/foldername From c3d487db907c7d41231848b6106ede64133545a9 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 9 Oct 2023 21:10:50 +0200 Subject: [PATCH 028/193] Align dynamic param for get repo --- .../Repositories/Get-GitHubRepository.ps1 | 41 +++++++------------ 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepository.ps1 b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepository.ps1 index f63d86803..18572f078 100644 --- a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepository.ps1 +++ b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepository.ps1 @@ -124,47 +124,34 @@ ) DynamicParam { - $runtimeDefinedParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary - $attributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute] + $ParamDictionary = New-ParamDictionary if ($PSCmdlet.ParameterSetName -in 'MyRepos_Type', 'ListByOrg', 'ListByUser') { - $parameterName = 'Type' - $parameterAttribute = New-Object System.Management.Automation.ParameterAttribute switch ($PSCmdlet.ParameterSetName) { 'MyRepos_Type' { - $parameterAttribute.Mandatory = $false - $parameterAttribute.ParameterSetName = 'MyRepos_Type' + $ValidateSet = 'all', 'owner', 'public', 'private', 'member' } 'ListByOrg' { - $parameterAttribute.Mandatory = $false - $parameterAttribute.ParameterSetName = 'ListByOrg' + $ValidateSet = 'all', 'public', 'private', 'forks', 'sources', 'member' } 'ListByUser' { - $parameterAttribute.Mandatory = $false - $parameterAttribute.ParameterSetName = 'ListByUser' + $ValidateSet = 'all', 'owner', 'member' } } - $attributeCollection.Add($parameterAttribute) - switch ($PSCmdlet.ParameterSetName) { - 'MyRepos_Type' { - $parameterValidateSet = 'all', 'owner', 'public', 'private', 'member' - } - 'ListByOrg' { - $parameterValidateSet = 'all', 'public', 'private', 'forks', 'sources', 'member' - } - 'ListByUser' { - $parameterValidateSet = 'all', 'owner', 'member' - } + $dynParam = @{ + Name = 'Type' + ParameterSetName = $PSCmdlet.ParameterSetName + Type = [string] + Mandatory = $false + ValidateSet = $ValidateSet + ParamDictionary = $ParamDictionary } - $validateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($parameterValidateSet) - $attributeCollection.Add($validateSetAttribute) - - $runtimeDefinedParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($parameterName, [string], $attributeCollection) - $runtimeDefinedParameterDictionary.Add($parameterName, $runtimeDefinedParameter) + New-DynamicParam @dynParam } - return $runtimeDefinedParameterDictionary + + return $ParamDictionary } Process { From f6164d3de9dced09b4d94e7556c8e473131d8748 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 9 Oct 2023 21:26:56 +0200 Subject: [PATCH 029/193] Fix dynamicParam new repo --- .../Repositories/Repositories/New-GitHubRepositoryOrg.ps1 | 2 +- tools/utilities/Local-Testing.ps1 | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 b/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 index 17693d3c3..6f944cf8b 100644 --- a/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 +++ b/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 @@ -180,7 +180,7 @@ Name = 'LicenseTemplate' Alias = 'license_template' Type = [string] - ValidateSet = Get-GitHubLicenseList | Select-Object -ExpandProperty Name + ValidateSet = Get-GitHubLicenseList | Select-Object -ExpandProperty key ParamDictionary = $ParamDictionary } New-DynamicParam @dynParam2 diff --git a/tools/utilities/Local-Testing.ps1 b/tools/utilities/Local-Testing.ps1 index 78a62cb7f..6ff8dc36e 100644 --- a/tools/utilities/Local-Testing.ps1 +++ b/tools/utilities/Local-Testing.ps1 @@ -112,8 +112,8 @@ $params = @{ IsTemplate = $true # TeamID = 12345679 AutoInit = $true - GitignoreTemplate = 'VisualStudio' - LicenseTemplate = 'MIT' + # GitignoreTemplate = 'VisualStudio' + # LicenseTemplate = 'MIT' AllowSquashMerge = $true SquashMergeCommitTitle = 'PR_TITLE' SquashMergeCommitMessage = 'PR_BODY' @@ -124,6 +124,6 @@ $params = @{ AllowAutoMerge = $true DeleteBranchOnMerge = $true } -New-GitHubRepositoryOrg @params +New-GitHubRepositoryOrg @params -GitignoreTemplate Fortran -LicenseTemplate 'MIT License' Remove-GitHubRepository -Owner PSModule -Repo 'Hello-world' -Verbose From d5926c6463ad2f1f4589118a924c190a184132b3 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 9 Oct 2023 21:47:07 +0200 Subject: [PATCH 030/193] fix params for licensing --- src/GitHub/private/License/Get-GitHubLicenseByName.ps1 | 2 +- .../private/License/Get-GitHubRepositoryLicense.ps1 | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/GitHub/private/License/Get-GitHubLicenseByName.ps1 b/src/GitHub/private/License/Get-GitHubLicenseByName.ps1 index 1b04d4087..f8534d8b4 100644 --- a/src/GitHub/private/License/Get-GitHubLicenseByName.ps1 +++ b/src/GitHub/private/License/Get-GitHubLicenseByName.ps1 @@ -28,7 +28,7 @@ filter Get-GitHubLicenseByName { Process { $inputObject = @{ APIEndpoint = "/licenses/$Name" - Accept = 'application/vnd.github.raw+json' + Accept = 'application/vnd.github+json' Method = 'GET' } diff --git a/src/GitHub/private/License/Get-GitHubRepositoryLicense.ps1 b/src/GitHub/private/License/Get-GitHubRepositoryLicense.ps1 index 2364f5cc6..aea2bc04e 100644 --- a/src/GitHub/private/License/Get-GitHubRepositoryLicense.ps1 +++ b/src/GitHub/private/License/Get-GitHubRepositoryLicense.ps1 @@ -32,13 +32,15 @@ filter Get-GitHubRepositoryLicense { Process { $inputObject = @{ APIEndpoint = "/repos/$Owner/$Repo/license" - Accept = 'application/vnd.github.raw+json' + Accept = 'application/vnd.github+json' Method = 'GET' } Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + $Response = $_.Response + $rawContent = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($Response.content)) + $Response | Add-Member -NotePropertyName 'raw_content' -NotePropertyValue $rawContent -Force + $Response } - } } From 00c00cf3d49a6f40d18ade4e31f30886c97e10d0 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 9 Oct 2023 22:15:05 +0200 Subject: [PATCH 031/193] Add function to create new personal repo --- .../Repositories/New-GitHubRepositoryOrg.ps1 | 4 +- .../Repositories/New-GitHubRepositoryUser.ps1 | 241 ++++++++++++++++++ tools/utilities/GitHubAPI.ps1 | 4 +- tools/utilities/Local-Testing.ps1 | 4 +- 4 files changed, 248 insertions(+), 5 deletions(-) create mode 100644 src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryUser.ps1 diff --git a/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 b/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 index 6f944cf8b..70b03689d 100644 --- a/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 +++ b/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 @@ -33,6 +33,8 @@ } New-GitHubRepositoryOrg @params + Creates a new public repository named "Hello-World" owned by the organization "PSModule". + .PARAMETER GitignoreTemplate Desired language or platform .gitignore template to apply. Use the name of the template without the extension. For example, "Haskell". @@ -63,7 +65,7 @@ [ValidateNotNullOrEmpty()] [uri] $Homepage, - #The visibility of the repository. + # The visibility of the repository. [Parameter()] [ValidateSet('public', 'private')] [string] $Visibility = 'public', diff --git a/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryUser.ps1 b/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryUser.ps1 new file mode 100644 index 000000000..4d0178702 --- /dev/null +++ b/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryUser.ps1 @@ -0,0 +1,241 @@ +filter New-GitHubRepositoryUser { + <# + .SYNOPSIS + Create a repository for the authenticated user + + .DESCRIPTION + Creates a new repository for the authenticated user. + + **OAuth scope requirements** + + When using [OAuth](https://docs.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/), authorizations must include: + + * `public_repo` scope or `repo` scope to create a public repository. Note: For GitHub AE, use `repo` scope to create an internal repository. + * `repo` scope to create a private repository. + + .EXAMPLE + $params = @{ + Name = 'Hello-World' + Description = 'This is your first repository' + Homepage = 'https://github.com' + HasIssues = $true + HasProjects = $true + HasWiki = $true + HasDownloads = $true + IsTemplate = $true + AutoInit = $true + AllowSquashMerge = $true + AllowAutoMerge = $true + DeleteBranchOnMerge = $true + SquashMergeCommitTitle = 'PR_TITLE' + SquashMergeCommitMessage = 'PR_BODY' + } + New-GitHubRepositoryUser @params + + Creates a new public repository named "Hello-World" owned by the authenticated user. + + .PARAMETER GitignoreTemplate + The desired language or platform to apply to the .gitignore. + + .PARAMETER LicenseTemplate + The license keyword of the open source license for this repository. + + .NOTES + https://docs.github.com/rest/repos/repos#create-a-repository-for-the-authenticated-user + + #> + [CmdletBinding()] + param ( + # The name of the repository. + [Parameter(Mandatory)] + [string] $Name, + + # A short description of the repository. + [Parameter()] + [string] $Description, + + # A URL with more information about the repository. + [Parameter()] + [ValidateNotNullOrEmpty()] + [uri] $Homepage, + + # The visibility of the repository. + [Parameter()] + [ValidateSet('public', 'private')] + [string] $Visibility = 'public', + + # Whether issues are enabled. + [Parameter()] + [Alias('has_issues')] + [switch] $HasIssues, + + # Whether projects are enabled. + [Parameter()] + [Alias('has_projects')] + [switch] $HasProjects, + + # Whether the wiki is enabled. + [Parameter()] + [Alias('has_wiki')] + [switch] $HasWiki, + + # Whether discussions are enabled. + [Parameter()] + [Alias('has_discussions')] + [switch] $HasDiscussions, + + # Whether downloads are enabled. + [Parameter()] + [Alias('has_downloads')] + [switch] $HasDownloads, + + # Whether this repository acts as a template that can be used to generate new repositories. + [Parameter()] + [Alias('is_template')] + [switch] $IsTemplate, + + # The id of the team that will be granted access to this repository. This is only valid when creating a repository in an organization. + [Parameter()] + [Alias('team_id')] + [int] $TeamId, + + # Pass true to create an initial commit with empty README. + [Parameter()] + [Alias('auto_init')] + [switch] $AutoInit, + + # Whether to allow squash merges for pull requests. + [Parameter()] + [Alias('allow_squash_merge')] + [switch] $AllowSquashMerge, + + # Whether to allow merge commits for pull requests. + [Parameter()] + [Alias('allow_merge_commit')] + [switch] $AllowMergeCommit, + + # Whether to allow rebase merges for pull requests. + [Parameter()] + [Alias('allow_rebase_merge')] + [switch] $AllowRebaseMerge, + + # Whether to allow Auto-merge to be used on pull requests. + [Parameter()] + [Alias('allow_auto_merge')] + [switch] $AllowAutoMerge, + + # Whether to delete head branches when pull requests are merged + [Parameter()] + [Alias('delete_branch_on_merge')] + [switch] $DeleteBranchOnMerge, + + # The default value for a squash merge commit title: + # - PR_TITLE - default to the pull request's title. + # - COMMIT_OR_PR_TITLE - default to the commit's title (if only one commit) or the pull request's title (when more than one commit). + [Parameter()] + [ValidateSet('PR_TITLE', 'COMMIT_OR_PR_TITLE')] + [Alias('squash_merge_commit_title')] + [string] $SquashMergeCommitTitle, + + # The default value for a squash merge commit message: + # - PR_BODY - default to the pull request's body. + # - COMMIT_MESSAGES - default to the branch's commit messages. + # - BLANK - default to a blank commit message. + [Parameter()] + [ValidateSet('PR_BODY', 'COMMIT_MESSAGES', 'BLANK')] + [Alias('squash_merge_commit_message')] + [string] $SquashMergeCommitMessage, + + # The default value for a merge commit title. + # - PR_TITLE - default to the pull request's title. + # - MERGE_MESSAGE - default to the classic title for a merge message (e.g.,Merge pull request #123 from branch-name). + [Parameter()] + [ValidateSet('PR_TITLE', 'MERGE_MESSAGE')] + [Alias('merge_commit_title')] + [string] $MergeCommitTitle, + + # The default value for a merge commit message. + # - PR_BODY - default to the pull request's body. + # - PR_TITLE - default to the pull request's title. + # - BLANK - default to a blank commit message. + [Parameter()] + [ValidateSet('PR_BODY', 'PR_TITLE', 'BLANK')] + [Alias('merge_commit_message')] + [string] $MergeCommitMessage + ) + + DynamicParam { + $ParamDictionary = New-ParamDictionary + + $dynParam = @{ + Name = 'GitignoreTemplate' + Alias = 'gitignore_template' + Type = [string] + ValidateSet = Get-GitHubGitignoreList + ParamDictionary = $ParamDictionary + } + New-DynamicParam @dynParam + + $dynParam2 = @{ + Name = 'LicenseTemplate' + Alias = 'license_template' + Type = [string] + ValidateSet = Get-GitHubLicenseList | Select-Object -ExpandProperty key + ParamDictionary = $ParamDictionary + } + New-DynamicParam @dynParam2 + + return $ParamDictionary + } + + begin { + $GitignoreTemplate = $PSBoundParameters['GitignoreTemplate'] + $LicenseTemplate = $PSBoundParameters['LicenseTemplate'] + } + + Process { + + $PSCmdlet.MyInvocation.MyCommand.Parameters.GetEnumerator() | ForEach-Object { + $paramName = $_.Key + $paramDefaultValue = Get-Variable -Name $paramName -ValueOnly -ErrorAction SilentlyContinue + $providedValue = $PSBoundParameters[$paramName] + Write-Verbose "[$paramName]" + Write-Verbose " - Default: [$paramDefaultValue]" + Write-Verbose " - Provided: [$providedValue]" + if (-not $PSBoundParameters.ContainsKey($paramName) -and ($null -ne $paramDefaultValue)) { + Write-Verbose ' - Using default value' + $PSBoundParameters[$paramName] = $paramDefaultValue + } else { + Write-Verbose ' - Using provided value' + } + } + + $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case + Remove-HashtableEntries -Hashtable $body -RemoveNames 'visibility' -RemoveTypes 'SwitchParameter' + + $body['private'] = $Visibility -eq 'private' + $body['has_issues'] = $HasIssues.IsPresent ? $HasIssues : $false + $body['has_wiki'] = $HasWiki.IsPresent ? $HasWiki : $false + $body['has_projects'] = $HasProjects.IsPresent ? $HasProjects : $false + $body['has_downloads'] = $HasDownloads.IsPresent ? $HasDownloads : $false + $body['is_template'] = $IsTemplate.IsPresent ? $IsTemplate : $false + $body['auto_init'] = $AutoInit.IsPresent ? $AutoInit : $false + $body['allow_squash_merge'] = $AllowSquashMerge.IsPresent ? $AllowSquashMerge : $false + $body['allow_merge_commit'] = $AllowMergeCommit.IsPresent ? $AllowMergeCommit : $false + $body['allow_rebase_merge'] = $AllowRebaseMerge.IsPresent ? $AllowRebaseMerge : $false + $body['allow_auto_merge'] = $AllowAutoMerge.IsPresent ? $AllowAutoMerge : $false + $body['delete_branch_on_merge'] = $DeleteBranchOnMerge.IsPresent ? $DeleteBranchOnMerge : $false + + Remove-HashtableEntries -Hashtable $body -NullOrEmptyValues + + $inputObject = @{ + APIEndpoint = "/user/repos" + Method = 'POST' + Body = $body + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } +} diff --git a/tools/utilities/GitHubAPI.ps1 b/tools/utilities/GitHubAPI.ps1 index d04600723..27349bb60 100644 --- a/tools/utilities/GitHubAPI.ps1 +++ b/tools/utilities/GitHubAPI.ps1 @@ -21,8 +21,8 @@ $response = Invoke-RestMethod -Uri $APIDocURI -Method Get # @{n = 'PUT'; e = { (($_.value.psobject.Properties.Name) -contains 'PUT') } }, ` # @{n = 'PATCH'; e = { (($_.value.psobject.Properties.Name) -contains 'PATCH') } } | Format-Table -$path = '/repos/{owner}/{repo}/license' -$method = 'get' +$path = '/user/repos' +$method = 'post' $response.paths.$path.$method $response.paths.$path.$method.tags | clip # -> Namespace/foldername $response.paths.$path.$method.operationId | clip # -> FunctionName diff --git a/tools/utilities/Local-Testing.ps1 b/tools/utilities/Local-Testing.ps1 index 6ff8dc36e..de114f604 100644 --- a/tools/utilities/Local-Testing.ps1 +++ b/tools/utilities/Local-Testing.ps1 @@ -110,7 +110,7 @@ $params = @{ HasWiki = $true HasDownloads = $true IsTemplate = $true - # TeamID = 12345679 + # TeamID = 12345679 AutoInit = $true # GitignoreTemplate = 'VisualStudio' # LicenseTemplate = 'MIT' @@ -124,6 +124,6 @@ $params = @{ AllowAutoMerge = $true DeleteBranchOnMerge = $true } -New-GitHubRepositoryOrg @params -GitignoreTemplate Fortran -LicenseTemplate 'MIT License' +New-GitHubRepositoryOrg @params -GitignoreTemplate VisualStudio -LicenseTemplate mit Remove-GitHubRepository -Owner PSModule -Repo 'Hello-world' -Verbose From 156e3c68b047972fe6a5bdfa12bcbe1a2ee43bfc Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 9 Oct 2023 22:53:04 +0200 Subject: [PATCH 032/193] Align PerPage --- .../Get-GitHubBlockedUserByOrganization.ps1 | 1 + .../Get-GitHubAllOrganization.ps1 | 1 + .../Organization/Get-GitHubMyOrganization.ps1 | 1 + .../Get-GitHubUserOrganization.ps1 | 1 + .../Get-GitHubReleaseAssetByReleaseID.ps1 | 1 + .../Releases/Get-GitHubReleaseAll.ps1 | 1 + .../Repositories/Get-GitHubMyRepositories.ps1 | 1 + .../Get-GitHubRepositoryListByOrg.ps1 | 1 + .../Get-GitHubRepositoryListByUser.ps1 | 1 + .../Blocking/Get-GitHubBlockedUserByUser.ps1 | 1 + .../Blocking/Test-GitHubBlockedUserByUser.ps1 | 1 + .../Users/Emails/Get-GitHubUserAllEmail.ps1 | 1 + .../Emails/Get-GitHubUserPublicEmail.ps1 | 1 + .../Get-GitHubUserFollowersOfUser.ps1 | 1 + .../Followers/Get-GitHubUserFollowingMe.ps1 | 1 + .../Followers/Get-GitHubUserFollowingUser.ps1 | 1 + .../Followers/Get-GitHubUserMyFollowers.ps1 | 1 + .../GPG-Keys/Get-GitHubUserGpgKeyForUser.ps1 | 1 + .../Users/GPG-Keys/Get-GitHubUserMyGpgKey.ps1 | 1 + .../private/Users/Get-GitHubAllUser.ps1 | 1 + .../Users/Keys/Get-GitHubUserKeyForUser.ps1 | 1 + .../Users/Keys/Get-GitHubUserMyKey.ps1 | 1 + .../Get-GitHubUserMySigningKey.ps1 | 1 + .../Get-GitHubUserSigningKeyForUser.ps1 | 1 + .../Get-GitHubMyUserSocials.ps1 | 1 + .../DynamicParam/New-DynamicParam.ps1 | 9 ------ .../public/Actions/Get-GitHubWorkflow.ps1 | 2 ++ .../public/Actions/Get-GitHubWorkflowRun.ps1 | 2 ++ .../Organization/Get-GitHubOrganization.ps1 | 1 + .../Get-GitHubOrganizationAppInstallation.ps1 | 1 + .../Releases/Releases/Get-GitHubRelease.ps1 | 1 + .../Repositories/Get-GitHubRepository.ps1 | 3 +- .../Users/Blocking/Get-GitHubBlockedUser.ps1 | 1 + .../Users/Blocking/Test-GitHubBlockedUser.ps1 | 1 + .../Users/Emails/Get-GitHubUserEmail.ps1 | 1 + .../Followers/Get-GitHubUserFollowers.ps1 | 1 + .../Followers/Get-GitHubUserFollowing.ps1 | 1 + .../Users/GPG-Keys/Get-GitHubUserGpgKey.ps1 | 1 + src/GitHub/public/Users/Get-GitHubUser.ps1 | 1 + .../public/Users/Keys/Get-GitHubUserKey.ps1 | 1 + .../Get-GitHubUserSigningKey.ps1 | 1 + tests/DynamicParam.ps1 | 6 +++- tools/utilities/Local-Testing.ps1 | 29 +++++++++++++++++++ 43 files changed, 77 insertions(+), 11 deletions(-) diff --git a/src/GitHub/private/Organization/Blocking/Get-GitHubBlockedUserByOrganization.ps1 b/src/GitHub/private/Organization/Blocking/Get-GitHubBlockedUserByOrganization.ps1 index 96d690692..42f317ac7 100644 --- a/src/GitHub/private/Organization/Blocking/Get-GitHubBlockedUserByOrganization.ps1 +++ b/src/GitHub/private/Organization/Blocking/Get-GitHubBlockedUserByOrganization.ps1 @@ -26,6 +26,7 @@ # The number of results per page (max 100). [Parameter()] + [ValidateRange(1, 100)] [int] $PerPage = 30 ) diff --git a/src/GitHub/private/Organization/Get-GitHubAllOrganization.ps1 b/src/GitHub/private/Organization/Get-GitHubAllOrganization.ps1 index 9448116a1..8461eac52 100644 --- a/src/GitHub/private/Organization/Get-GitHubAllOrganization.ps1 +++ b/src/GitHub/private/Organization/Get-GitHubAllOrganization.ps1 @@ -26,6 +26,7 @@ # The number of results per page (max 100). [Parameter()] + [ValidateRange(1, 100)] [int] $PerPage = 30 ) diff --git a/src/GitHub/private/Organization/Get-GitHubMyOrganization.ps1 b/src/GitHub/private/Organization/Get-GitHubMyOrganization.ps1 index d90f84142..885031b14 100644 --- a/src/GitHub/private/Organization/Get-GitHubMyOrganization.ps1 +++ b/src/GitHub/private/Organization/Get-GitHubMyOrganization.ps1 @@ -23,6 +23,7 @@ param ( # The number of results per page (max 100). [Parameter()] + [ValidateRange(1, 100)] [int] $PerPage = 30 ) diff --git a/src/GitHub/private/Organization/Get-GitHubUserOrganization.ps1 b/src/GitHub/private/Organization/Get-GitHubUserOrganization.ps1 index 1e815c218..196605a7d 100644 --- a/src/GitHub/private/Organization/Get-GitHubUserOrganization.ps1 +++ b/src/GitHub/private/Organization/Get-GitHubUserOrganization.ps1 @@ -25,6 +25,7 @@ # The number of results per page (max 100). [Parameter()] + [ValidateRange(1, 100)] [int] $PerPage = 30 ) diff --git a/src/GitHub/private/Releases/Assets/Get-GitHubReleaseAssetByReleaseID.ps1 b/src/GitHub/private/Releases/Assets/Get-GitHubReleaseAssetByReleaseID.ps1 index 022f54b7d..6adf119a9 100644 --- a/src/GitHub/private/Releases/Assets/Get-GitHubReleaseAssetByReleaseID.ps1 +++ b/src/GitHub/private/Releases/Assets/Get-GitHubReleaseAssetByReleaseID.ps1 @@ -35,6 +35,7 @@ # The number of results per page (max 100). [Parameter()] + [ValidateRange(1, 100)] [int] $PerPage = 30 ) diff --git a/src/GitHub/private/Releases/Releases/Get-GitHubReleaseAll.ps1 b/src/GitHub/private/Releases/Releases/Get-GitHubReleaseAll.ps1 index a29ed01ef..0c9615146 100644 --- a/src/GitHub/private/Releases/Releases/Get-GitHubReleaseAll.ps1 +++ b/src/GitHub/private/Releases/Releases/Get-GitHubReleaseAll.ps1 @@ -29,6 +29,7 @@ # The number of results per page (max 100). [Parameter(ParameterSetName = 'AllUsers')] + [ValidateRange(1, 100)] [int] $PerPage = 30 ) diff --git a/src/GitHub/private/Repositories/Repositories/Get-GitHubMyRepositories.ps1 b/src/GitHub/private/Repositories/Repositories/Get-GitHubMyRepositories.ps1 index 0ed183ae1..1ad2c106d 100644 --- a/src/GitHub/private/Repositories/Repositories/Get-GitHubMyRepositories.ps1 +++ b/src/GitHub/private/Repositories/Repositories/Get-GitHubMyRepositories.ps1 @@ -85,6 +85,7 @@ # The number of results per page (max 100). [Parameter()] + [ValidateRange(1, 100)] [int] $PerPage = 30, # Only show repositories updated after the given time. diff --git a/src/GitHub/private/Repositories/Repositories/Get-GitHubRepositoryListByOrg.ps1 b/src/GitHub/private/Repositories/Repositories/Get-GitHubRepositoryListByOrg.ps1 index edb9253c5..7ec25bf2b 100644 --- a/src/GitHub/private/Repositories/Repositories/Get-GitHubRepositoryListByOrg.ps1 +++ b/src/GitHub/private/Repositories/Repositories/Get-GitHubRepositoryListByOrg.ps1 @@ -52,6 +52,7 @@ # The number of results per page (max 100). [Parameter()] + [ValidateRange(1, 100)] [int] $PerPage = 30 ) diff --git a/src/GitHub/private/Repositories/Repositories/Get-GitHubRepositoryListByUser.ps1 b/src/GitHub/private/Repositories/Repositories/Get-GitHubRepositoryListByUser.ps1 index 2a0b1758e..dc31410dd 100644 --- a/src/GitHub/private/Repositories/Repositories/Get-GitHubRepositoryListByUser.ps1 +++ b/src/GitHub/private/Repositories/Repositories/Get-GitHubRepositoryListByUser.ps1 @@ -55,6 +55,7 @@ # The number of results per page (max 100). [Parameter()] + [ValidateRange(1, 100)] [int] $PerPage = 30 ) diff --git a/src/GitHub/private/Users/Blocking/Get-GitHubBlockedUserByUser.ps1 b/src/GitHub/private/Users/Blocking/Get-GitHubBlockedUserByUser.ps1 index e11fb208e..6fbad3725 100644 --- a/src/GitHub/private/Users/Blocking/Get-GitHubBlockedUserByUser.ps1 +++ b/src/GitHub/private/Users/Blocking/Get-GitHubBlockedUserByUser.ps1 @@ -19,6 +19,7 @@ param ( # The number of results per page (max 100). [Parameter()] + [ValidateRange(1, 100)] [int] $PerPage = 30 ) diff --git a/src/GitHub/private/Users/Blocking/Test-GitHubBlockedUserByUser.ps1 b/src/GitHub/private/Users/Blocking/Test-GitHubBlockedUserByUser.ps1 index 843905aab..5807f28ce 100644 --- a/src/GitHub/private/Users/Blocking/Test-GitHubBlockedUserByUser.ps1 +++ b/src/GitHub/private/Users/Blocking/Test-GitHubBlockedUserByUser.ps1 @@ -29,6 +29,7 @@ # The number of results per page (max 100). [Parameter()] + [ValidateRange(1, 100)] [int] $PerPage = 30 ) diff --git a/src/GitHub/private/Users/Emails/Get-GitHubUserAllEmail.ps1 b/src/GitHub/private/Users/Emails/Get-GitHubUserAllEmail.ps1 index 5ef211eba..732f5c38f 100644 --- a/src/GitHub/private/Users/Emails/Get-GitHubUserAllEmail.ps1 +++ b/src/GitHub/private/Users/Emails/Get-GitHubUserAllEmail.ps1 @@ -20,6 +20,7 @@ param ( # The number of results per page (max 100). [Parameter()] + [ValidateRange(1, 100)] [int] $PerPage = 30 ) diff --git a/src/GitHub/private/Users/Emails/Get-GitHubUserPublicEmail.ps1 b/src/GitHub/private/Users/Emails/Get-GitHubUserPublicEmail.ps1 index c264d5d83..b81229bec 100644 --- a/src/GitHub/private/Users/Emails/Get-GitHubUserPublicEmail.ps1 +++ b/src/GitHub/private/Users/Emails/Get-GitHubUserPublicEmail.ps1 @@ -20,6 +20,7 @@ param ( # The number of results per page (max 100). [Parameter()] + [ValidateRange(1, 100)] [int] $PerPage = 30 ) diff --git a/src/GitHub/private/Users/Followers/Get-GitHubUserFollowersOfUser.ps1 b/src/GitHub/private/Users/Followers/Get-GitHubUserFollowersOfUser.ps1 index 7d6f50800..651148238 100644 --- a/src/GitHub/private/Users/Followers/Get-GitHubUserFollowersOfUser.ps1 +++ b/src/GitHub/private/Users/Followers/Get-GitHubUserFollowersOfUser.ps1 @@ -29,6 +29,7 @@ # The number of results per page (max 100). [Parameter()] + [ValidateRange(1, 100)] [int] $PerPage = 30 ) diff --git a/src/GitHub/private/Users/Followers/Get-GitHubUserFollowingMe.ps1 b/src/GitHub/private/Users/Followers/Get-GitHubUserFollowingMe.ps1 index 0e250bfbf..bf73f7d48 100644 --- a/src/GitHub/private/Users/Followers/Get-GitHubUserFollowingMe.ps1 +++ b/src/GitHub/private/Users/Followers/Get-GitHubUserFollowingMe.ps1 @@ -20,6 +20,7 @@ param ( # The number of results per page (max 100). [Parameter()] + [ValidateRange(1, 100)] [int] $PerPage = 30 ) diff --git a/src/GitHub/private/Users/Followers/Get-GitHubUserFollowingUser.ps1 b/src/GitHub/private/Users/Followers/Get-GitHubUserFollowingUser.ps1 index e73873a1a..503eae2ba 100644 --- a/src/GitHub/private/Users/Followers/Get-GitHubUserFollowingUser.ps1 +++ b/src/GitHub/private/Users/Followers/Get-GitHubUserFollowingUser.ps1 @@ -29,6 +29,7 @@ # The number of results per page (max 100). [Parameter()] + [ValidateRange(1, 100)] [int] $PerPage = 30 ) diff --git a/src/GitHub/private/Users/Followers/Get-GitHubUserMyFollowers.ps1 b/src/GitHub/private/Users/Followers/Get-GitHubUserMyFollowers.ps1 index 0d100888c..ec0668974 100644 --- a/src/GitHub/private/Users/Followers/Get-GitHubUserMyFollowers.ps1 +++ b/src/GitHub/private/Users/Followers/Get-GitHubUserMyFollowers.ps1 @@ -20,6 +20,7 @@ param ( # The number of results per page (max 100). [Parameter()] + [ValidateRange(1, 100)] [int] $PerPage = 30 ) diff --git a/src/GitHub/private/Users/GPG-Keys/Get-GitHubUserGpgKeyForUser.ps1 b/src/GitHub/private/Users/GPG-Keys/Get-GitHubUserGpgKeyForUser.ps1 index 035b0f7c4..547c82e28 100644 --- a/src/GitHub/private/Users/GPG-Keys/Get-GitHubUserGpgKeyForUser.ps1 +++ b/src/GitHub/private/Users/GPG-Keys/Get-GitHubUserGpgKeyForUser.ps1 @@ -27,6 +27,7 @@ # The number of results per page (max 100). [Parameter()] + [ValidateRange(1, 100)] [int] $PerPage = 30 ) diff --git a/src/GitHub/private/Users/GPG-Keys/Get-GitHubUserMyGpgKey.ps1 b/src/GitHub/private/Users/GPG-Keys/Get-GitHubUserMyGpgKey.ps1 index bacfe48ff..ba53b2422 100644 --- a/src/GitHub/private/Users/GPG-Keys/Get-GitHubUserMyGpgKey.ps1 +++ b/src/GitHub/private/Users/GPG-Keys/Get-GitHubUserMyGpgKey.ps1 @@ -21,6 +21,7 @@ param ( # The number of results per page (max 100). [Parameter()] + [ValidateRange(1, 100)] [int] $PerPage = 30 ) diff --git a/src/GitHub/private/Users/Get-GitHubAllUser.ps1 b/src/GitHub/private/Users/Get-GitHubAllUser.ps1 index a996a830e..eff4bafa6 100644 --- a/src/GitHub/private/Users/Get-GitHubAllUser.ps1 +++ b/src/GitHub/private/Users/Get-GitHubAllUser.ps1 @@ -25,6 +25,7 @@ # The number of results per page (max 100). [Parameter()] + [ValidateRange(1, 100)] [int] $PerPage = 30 ) diff --git a/src/GitHub/private/Users/Keys/Get-GitHubUserKeyForUser.ps1 b/src/GitHub/private/Users/Keys/Get-GitHubUserKeyForUser.ps1 index feb8a8e31..5d8def2aa 100644 --- a/src/GitHub/private/Users/Keys/Get-GitHubUserKeyForUser.ps1 +++ b/src/GitHub/private/Users/Keys/Get-GitHubUserKeyForUser.ps1 @@ -27,6 +27,7 @@ # The number of results per page (max 100). [Parameter()] + [ValidateRange(1, 100)] [int] $PerPage = 30 ) diff --git a/src/GitHub/private/Users/Keys/Get-GitHubUserMyKey.ps1 b/src/GitHub/private/Users/Keys/Get-GitHubUserMyKey.ps1 index cef244f18..f1a79153e 100644 --- a/src/GitHub/private/Users/Keys/Get-GitHubUserMyKey.ps1 +++ b/src/GitHub/private/Users/Keys/Get-GitHubUserMyKey.ps1 @@ -21,6 +21,7 @@ param ( # The number of results per page (max 100). [Parameter()] + [ValidateRange(1, 100)] [int] $PerPage = 30 ) diff --git a/src/GitHub/private/Users/SSH-Signing-Keys/Get-GitHubUserMySigningKey.ps1 b/src/GitHub/private/Users/SSH-Signing-Keys/Get-GitHubUserMySigningKey.ps1 index ad6f7f7bf..a406934d5 100644 --- a/src/GitHub/private/Users/SSH-Signing-Keys/Get-GitHubUserMySigningKey.ps1 +++ b/src/GitHub/private/Users/SSH-Signing-Keys/Get-GitHubUserMySigningKey.ps1 @@ -21,6 +21,7 @@ param ( # The number of results per page (max 100). [Parameter()] + [ValidateRange(1, 100)] [int] $PerPage = 30 ) diff --git a/src/GitHub/private/Users/SSH-Signing-Keys/Get-GitHubUserSigningKeyForUser.ps1 b/src/GitHub/private/Users/SSH-Signing-Keys/Get-GitHubUserSigningKeyForUser.ps1 index 78aa25598..8e88966f2 100644 --- a/src/GitHub/private/Users/SSH-Signing-Keys/Get-GitHubUserSigningKeyForUser.ps1 +++ b/src/GitHub/private/Users/SSH-Signing-Keys/Get-GitHubUserSigningKeyForUser.ps1 @@ -27,6 +27,7 @@ # The number of results per page (max 100). [Parameter()] + [ValidateRange(1, 100)] [int] $PerPage = 30 ) diff --git a/src/GitHub/private/Users/Social-Accounts/Get-GitHubMyUserSocials.ps1 b/src/GitHub/private/Users/Social-Accounts/Get-GitHubMyUserSocials.ps1 index fde1e83c2..0d229fc3b 100644 --- a/src/GitHub/private/Users/Social-Accounts/Get-GitHubMyUserSocials.ps1 +++ b/src/GitHub/private/Users/Social-Accounts/Get-GitHubMyUserSocials.ps1 @@ -19,6 +19,7 @@ param ( # The number of results per page (max 100). [Parameter()] + [ValidateRange(1, 100)] [int] $PerPage = 30 ) diff --git a/src/GitHub/private/Utilities/DynamicParam/New-DynamicParam.ps1 b/src/GitHub/private/Utilities/DynamicParam/New-DynamicParam.ps1 index 8b1f17f24..f2df28a86 100644 --- a/src/GitHub/private/Utilities/DynamicParam/New-DynamicParam.ps1 +++ b/src/GitHub/private/Utilities/DynamicParam/New-DynamicParam.ps1 @@ -26,10 +26,6 @@ [Parameter()] [string[]] $Alias, - # Specifies the default value of the parameter. - [Parameter()] - $DefaultValue = $null, - # Specifies the data type of the parameter. [Parameter()] [type] $Type, @@ -148,11 +144,6 @@ } } - if ($PSBoundParameters.ContainsKey('DefaultValue')) { - $commentAttribute = New-Object System.Management.Automation.PSDefaultValueAttribute($DefaultValue) - $attributeCollection.Add($commentAttribute) - } - # $Comment if ($PSBoundParameters.ContainsKey('ValidateSet')) { diff --git a/src/GitHub/public/Actions/Get-GitHubWorkflow.ps1 b/src/GitHub/public/Actions/Get-GitHubWorkflow.ps1 index 0be3d2b40..8666aad4f 100644 --- a/src/GitHub/public/Actions/Get-GitHubWorkflow.ps1 +++ b/src/GitHub/public/Actions/Get-GitHubWorkflow.ps1 @@ -35,7 +35,9 @@ [Parameter(ParameterSetName = 'ByID')] [string] $ID, + # The number of results per page (max 100). [Parameter()] + [ValidateRange(1, 100)] [int] $PerPage = 30 ) diff --git a/src/GitHub/public/Actions/Get-GitHubWorkflowRun.ps1 b/src/GitHub/public/Actions/Get-GitHubWorkflowRun.ps1 index eaecf3997..2616124ad 100644 --- a/src/GitHub/public/Actions/Get-GitHubWorkflowRun.ps1 +++ b/src/GitHub/public/Actions/Get-GitHubWorkflowRun.ps1 @@ -18,7 +18,9 @@ [Parameter(ParameterSetName = 'ByID')] [string] $ID, + # The number of results per page (max 100). [Parameter()] + [ValidateRange(1, 100)] [int] $PerPage = 30 ) diff --git a/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 b/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 index 054242e3e..f296340cd 100644 --- a/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 +++ b/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 @@ -69,6 +69,7 @@ [Parameter(ParameterSetName = 'AllOrg')] [Parameter(ParameterSetName = 'UserOrg')] [Parameter(ParameterSetName = '__DefaultSet')] + [ValidateRange(1, 100)] [int] $PerPage = 30 ) diff --git a/src/GitHub/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 b/src/GitHub/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 index 48557d266..e6e5bcea2 100644 --- a/src/GitHub/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 +++ b/src/GitHub/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 @@ -31,6 +31,7 @@ # The number of results per page (max 100). [Parameter()] + [ValidateRange(1, 100)] [int] $PerPage = 30 ) diff --git a/src/GitHub/public/Releases/Releases/Get-GitHubRelease.ps1 b/src/GitHub/public/Releases/Releases/Get-GitHubRelease.ps1 index 177f93ede..203f50649 100644 --- a/src/GitHub/public/Releases/Releases/Get-GitHubRelease.ps1 +++ b/src/GitHub/public/Releases/Releases/Get-GitHubRelease.ps1 @@ -45,6 +45,7 @@ # The number of results per page (max 100). [Parameter(ParameterSetName = 'All')] + [ValidateRange(1, 100)] [int] $PerPage = 30, # Get the latest release only diff --git a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepository.ps1 b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepository.ps1 index 18572f078..955f1c963 100644 --- a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepository.ps1 +++ b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepository.ps1 @@ -119,6 +119,7 @@ [Parameter(ParameterSetName = 'MyRepos')] [Parameter(ParameterSetName = 'ListByOrg')] [Parameter(ParameterSetName = 'ListByUser')] + [ValidateRange(1, 100)] [int] $PerPage = 30 ) @@ -150,7 +151,7 @@ } New-DynamicParam @dynParam } - + return $ParamDictionary } diff --git a/src/GitHub/public/Users/Blocking/Get-GitHubBlockedUser.ps1 b/src/GitHub/public/Users/Blocking/Get-GitHubBlockedUser.ps1 index 664fea731..59f0d3345 100644 --- a/src/GitHub/public/Users/Blocking/Get-GitHubBlockedUser.ps1 +++ b/src/GitHub/public/Users/Blocking/Get-GitHubBlockedUser.ps1 @@ -35,6 +35,7 @@ # The number of results per page (max 100). [Parameter()] + [ValidateRange(1, 100)] [int] $PerPage = 30 ) diff --git a/src/GitHub/public/Users/Blocking/Test-GitHubBlockedUser.ps1 b/src/GitHub/public/Users/Blocking/Test-GitHubBlockedUser.ps1 index 7484d2be2..154c4aad7 100644 --- a/src/GitHub/public/Users/Blocking/Test-GitHubBlockedUser.ps1 +++ b/src/GitHub/public/Users/Blocking/Test-GitHubBlockedUser.ps1 @@ -47,6 +47,7 @@ # The number of results per page (max 100). [Parameter()] + [ValidateRange(1, 100)] [int] $PerPage = 30 ) diff --git a/src/GitHub/public/Users/Emails/Get-GitHubUserEmail.ps1 b/src/GitHub/public/Users/Emails/Get-GitHubUserEmail.ps1 index ae97b91c4..31f92a9d5 100644 --- a/src/GitHub/public/Users/Emails/Get-GitHubUserEmail.ps1 +++ b/src/GitHub/public/Users/Emails/Get-GitHubUserEmail.ps1 @@ -27,6 +27,7 @@ param ( # The number of results per page (max 100). [Parameter()] + [ValidateRange(1, 100)] [int] $PerPage = 30, [Parameter()] diff --git a/src/GitHub/public/Users/Followers/Get-GitHubUserFollowers.ps1 b/src/GitHub/public/Users/Followers/Get-GitHubUserFollowers.ps1 index b59ed7afd..95ef3229b 100644 --- a/src/GitHub/public/Users/Followers/Get-GitHubUserFollowers.ps1 +++ b/src/GitHub/public/Users/Followers/Get-GitHubUserFollowers.ps1 @@ -33,6 +33,7 @@ # The number of results per page (max 100). [Parameter()] + [ValidateRange(1, 100)] [int] $PerPage = 30 ) diff --git a/src/GitHub/public/Users/Followers/Get-GitHubUserFollowing.ps1 b/src/GitHub/public/Users/Followers/Get-GitHubUserFollowing.ps1 index cdf12c54c..611b411aa 100644 --- a/src/GitHub/public/Users/Followers/Get-GitHubUserFollowing.ps1 +++ b/src/GitHub/public/Users/Followers/Get-GitHubUserFollowing.ps1 @@ -34,6 +34,7 @@ # The number of results per page (max 100). [Parameter()] + [ValidateRange(1, 100)] [int] $PerPage = 30 ) diff --git a/src/GitHub/public/Users/GPG-Keys/Get-GitHubUserGpgKey.ps1 b/src/GitHub/public/Users/GPG-Keys/Get-GitHubUserGpgKey.ps1 index 0ccb50c2b..8cb551333 100644 --- a/src/GitHub/public/Users/GPG-Keys/Get-GitHubUserGpgKey.ps1 +++ b/src/GitHub/public/Users/GPG-Keys/Get-GitHubUserGpgKey.ps1 @@ -46,6 +46,7 @@ # The number of results per page (max 100). [Parameter()] + [ValidateRange(1, 100)] [int] $PerPage = 30 ) diff --git a/src/GitHub/public/Users/Get-GitHubUser.ps1 b/src/GitHub/public/Users/Get-GitHubUser.ps1 index d505df4c1..9b4d6fb1d 100644 --- a/src/GitHub/public/Users/Get-GitHubUser.ps1 +++ b/src/GitHub/public/Users/Get-GitHubUser.ps1 @@ -50,6 +50,7 @@ # The number of results per page (max 100). [Parameter(ParameterSetName = 'AllUsers')] + [ValidateRange(1, 100)] [int] $PerPage = 30 ) diff --git a/src/GitHub/public/Users/Keys/Get-GitHubUserKey.ps1 b/src/GitHub/public/Users/Keys/Get-GitHubUserKey.ps1 index cdbfca733..bec99e8b4 100644 --- a/src/GitHub/public/Users/Keys/Get-GitHubUserKey.ps1 +++ b/src/GitHub/public/Users/Keys/Get-GitHubUserKey.ps1 @@ -48,6 +48,7 @@ # The number of results per page (max 100). [Parameter()] + [ValidateRange(1, 100)] [int] $PerPage = 30 ) diff --git a/src/GitHub/public/Users/SSH-Signing-Keys/Get-GitHubUserSigningKey.ps1 b/src/GitHub/public/Users/SSH-Signing-Keys/Get-GitHubUserSigningKey.ps1 index e7c60b53e..645dfb8da 100644 --- a/src/GitHub/public/Users/SSH-Signing-Keys/Get-GitHubUserSigningKey.ps1 +++ b/src/GitHub/public/Users/SSH-Signing-Keys/Get-GitHubUserSigningKey.ps1 @@ -48,6 +48,7 @@ # The number of results per page (max 100). [Parameter()] + [ValidateRange(1, 100)] [int] $PerPage = 30 ) diff --git a/tests/DynamicParam.ps1 b/tests/DynamicParam.ps1 index 65fa5237f..7be4f9ea5 100644 --- a/tests/DynamicParam.ps1 +++ b/tests/DynamicParam.ps1 @@ -29,10 +29,14 @@ } process { + $Param1 = $PSBoundParameters['Param1'] + $Param2 = $PSBoundParameters['Param2'] + $Param3 = $PSBoundParameters['Param3'] + Write-Host "Param1: $Param1" Write-Host "Param2: $Param2" Write-Host "Param3: $Param3" } } -Test-DynParam -Param1 A -Param2 cmd -Param3 PerfLogs +Test-DynParam -Param1 A -Param3 PerfLogs diff --git a/tools/utilities/Local-Testing.ps1 b/tools/utilities/Local-Testing.ps1 index de114f604..f5d6e373f 100644 --- a/tools/utilities/Local-Testing.ps1 +++ b/tools/utilities/Local-Testing.ps1 @@ -127,3 +127,32 @@ $params = @{ New-GitHubRepositoryOrg @params -GitignoreTemplate VisualStudio -LicenseTemplate mit Remove-GitHubRepository -Owner PSModule -Repo 'Hello-world' -Verbose + +$params = @{ + Verbose = $true + Name = 'Hello-world' + Description = 'This is a test repo.' + Homepage = 'https://github.com' + Visibility = 'public' + HasIssues = $true + HasProjects = $true + HasWiki = $true + HasDownloads = $true + IsTemplate = $true + # TeamID = 12345679 + AutoInit = $true + # GitignoreTemplate = 'VisualStudio' + # LicenseTemplate = 'MIT' + AllowSquashMerge = $true + SquashMergeCommitTitle = 'PR_TITLE' + SquashMergeCommitMessage = 'PR_BODY' + AllowMergeCommit = $true + MergeCommitTitle = 'PR_TITLE' + MergeCommitMessage = 'PR_BODY' + AllowRebaseMerge = $true + AllowAutoMerge = $true + DeleteBranchOnMerge = $true +} +New-GitHubRepositoryUser @params -GitignoreTemplate VisualStudio -LicenseTemplate gpl-3.0 + +Remove-GitHubRepository -Owner MariusStorhaug -Repo 'Hello-world' -Verbose From 4b2634daf170be00d4da8a12331cf5c9c97be8b9 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 9 Oct 2023 23:11:32 +0200 Subject: [PATCH 033/193] Add function to set and get topics --- .../Get-GitHubRepositoryTopic.ps1 | 44 +++++++++++++++++++ .../Set-GitHubRepositoryTopic.ps1 | 44 +++++++++++++++++++ tools/utilities/GitHubAPI.ps1 | 4 +- 3 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryTopic.ps1 create mode 100644 src/GitHub/public/Repositories/Repositories/Set-GitHubRepositoryTopic.ps1 diff --git a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryTopic.ps1 b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryTopic.ps1 new file mode 100644 index 000000000..8948d42ce --- /dev/null +++ b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryTopic.ps1 @@ -0,0 +1,44 @@ +filter Get-GitHubRepositoryTopic { + <# + .SYNOPSIS + Get all repository topics + + .DESCRIPTION + Get all repository topics + + .EXAMPLE + + .NOTES + https://docs.github.com/rest/repos/repos#get-all-repository-topics + + #> + [CmdletBinding()] + param ( + # The account owner of the repository. The name is not case sensitive. + [Parameter()] + [Alias('org')] + [string] $Owner = (Get-GitHubConfig -Name Owner), + + # The name of the repository without the .git extension. The name is not case sensitive. + [Parameter()] + [string] $Repo = (Get-GitHubConfig -Name Repo), + + # The number of results per page (max 100). + [Parameter()] + [ValidateRange(1, 100)] + [int] $PerPage = 30 + ) + + $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case + Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner','Repo' -RemoveTypes 'SwitchParameter' + + $inputObject = @{ + APIEndpoint = "/repos/$Owner/$Repo/topics" + Method = 'GET' + Body = $body + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } +} diff --git a/src/GitHub/public/Repositories/Repositories/Set-GitHubRepositoryTopic.ps1 b/src/GitHub/public/Repositories/Repositories/Set-GitHubRepositoryTopic.ps1 new file mode 100644 index 000000000..0bdc37258 --- /dev/null +++ b/src/GitHub/public/Repositories/Repositories/Set-GitHubRepositoryTopic.ps1 @@ -0,0 +1,44 @@ +filter Set-GitHubRepositoryTopic { + <# + .SYNOPSIS + Replace all repository topics + + .DESCRIPTION + Replace all repository topics + + .EXAMPLE + + .NOTES + https://docs.github.com/rest/repos/repos#replace-all-repository-topics + + #> + [CmdletBinding()] + param ( + # The account owner of the repository. The name is not case sensitive. + [Parameter()] + [Alias('org')] + [string] $Owner = (Get-GitHubConfig -Name Owner), + + # The name of the repository without the .git extension. The name is not case sensitive. + [Parameter()] + [string] $Repo = (Get-GitHubConfig -Name Repo), + + # The number of results per page (max 100). + [Parameter()] + [Alias('names')] + [string[]] $Topics = @() + ) + + $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case + Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner','Repo' -RemoveTypes 'SwitchParameter' + + $inputObject = @{ + APIEndpoint = "/repos/$Owner/$Repo/topics" + Method = 'PUT' + Body = $body + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } +} diff --git a/tools/utilities/GitHubAPI.ps1 b/tools/utilities/GitHubAPI.ps1 index 27349bb60..b0a4b36bb 100644 --- a/tools/utilities/GitHubAPI.ps1 +++ b/tools/utilities/GitHubAPI.ps1 @@ -21,8 +21,8 @@ $response = Invoke-RestMethod -Uri $APIDocURI -Method Get # @{n = 'PUT'; e = { (($_.value.psobject.Properties.Name) -contains 'PUT') } }, ` # @{n = 'PATCH'; e = { (($_.value.psobject.Properties.Name) -contains 'PATCH') } } | Format-Table -$path = '/user/repos' -$method = 'post' +$path = '/repos/{owner}/{repo}/topics' +$method = 'Put' $response.paths.$path.$method $response.paths.$path.$method.tags | clip # -> Namespace/foldername $response.paths.$path.$method.operationId | clip # -> FunctionName From 61fa38b50977a07abf25bf900387bb152d9ea0a2 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 9 Oct 2023 23:20:17 +0200 Subject: [PATCH 034/193] Fix topic commands --- .../Repositories/Get-GitHubRepositoryTopic.ps1 | 2 +- .../Repositories/Set-GitHubRepositoryTopic.ps1 | 10 ++++++---- tools/utilities/Local-Testing.ps1 | 3 +++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryTopic.ps1 b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryTopic.ps1 index 8948d42ce..70b54088a 100644 --- a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryTopic.ps1 +++ b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryTopic.ps1 @@ -39,6 +39,6 @@ } Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + Write-Output $_.Response.names } } diff --git a/src/GitHub/public/Repositories/Repositories/Set-GitHubRepositoryTopic.ps1 b/src/GitHub/public/Repositories/Repositories/Set-GitHubRepositoryTopic.ps1 index 0bdc37258..a194bab50 100644 --- a/src/GitHub/public/Repositories/Repositories/Set-GitHubRepositoryTopic.ps1 +++ b/src/GitHub/public/Repositories/Repositories/Set-GitHubRepositoryTopic.ps1 @@ -25,12 +25,14 @@ # The number of results per page (max 100). [Parameter()] - [Alias('names')] - [string[]] $Topics = @() + [Alias('Topics')] + [string[]] $Names = @() ) $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner','Repo' -RemoveTypes 'SwitchParameter' + Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner', 'Repo' -RemoveTypes 'SwitchParameter' + + $body.names = $body.names | ForEach-Object { $_.ToLower() } $inputObject = @{ APIEndpoint = "/repos/$Owner/$Repo/topics" @@ -39,6 +41,6 @@ } Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + Write-Output $_.Response.names } } diff --git a/tools/utilities/Local-Testing.ps1 b/tools/utilities/Local-Testing.ps1 index f5d6e373f..d985cec1a 100644 --- a/tools/utilities/Local-Testing.ps1 +++ b/tools/utilities/Local-Testing.ps1 @@ -156,3 +156,6 @@ $params = @{ New-GitHubRepositoryUser @params -GitignoreTemplate VisualStudio -LicenseTemplate gpl-3.0 Remove-GitHubRepository -Owner MariusStorhaug -Repo 'Hello-world' -Verbose + + +Get-GitHubRepositoryTopic -Owner 'PSModule' -Repo 'GitHub' From 55e74767ff8924848deae0f17c7b683783b5350a Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 9 Oct 2023 23:34:03 +0200 Subject: [PATCH 035/193] Added Get-contributors --- .../Get-GitHubRepositoryContributor.ps1 | 53 +++++++++++++++++++ tools/utilities/GitHubAPI.ps1 | 4 +- 2 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryContributor.ps1 diff --git a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryContributor.ps1 b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryContributor.ps1 new file mode 100644 index 000000000..59e512786 --- /dev/null +++ b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryContributor.ps1 @@ -0,0 +1,53 @@ +filter Get-GitHubRepositoryContributor { + <# + .SYNOPSIS + List repository contributors + + .DESCRIPTION + Lists contributors to the specified repository and sorts them by the number of commits per contributor in descending order. This endpoint may return information that is a few hours old because the GitHub REST API caches contributor data to improve performance. + + GitHub identifies contributors by author email address. This endpoint groups contribution counts by GitHub user, which includes all associated email addresses. To improve performance, only the first 500 author email addresses in the repository link to GitHub users. The rest will appear as anonymous contributors without associated GitHub user information. + + .EXAMPLE + Get-GitHubRepositoryContributor -Owner 'PSModule' -Repo 'GitHub' + + Gets all contributors to the GitHub repository. + + .NOTES + https://docs.github.com/rest/repos/repos#list-repository-contributors + + #> + [CmdletBinding()] + param ( + # The account owner of the repository. The name is not case sensitive. + [Parameter()] + [Alias('org')] + [string] $Owner = (Get-GitHubConfig -Name Owner), + + # The name of the repository without the .git extension. The name is not case sensitive. + [Parameter()] + [string] $Repo = (Get-GitHubConfig -Name Repo), + + # Wether to include anonymous contributors in results. + [Parameter()] + [switch] $Anon, + + # The number of results per page (max 100). + [Parameter()] + [ValidateRange(1, 100)] + [int] $PerPage = 30 + ) + + $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case + Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner','Repo' -RemoveTypes 'SwitchParameter' + + $inputObject = @{ + APIEndpoint = "/repos/$Owner/$Repo/contributors" + Method = 'GET' + Body = $body + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } +} diff --git a/tools/utilities/GitHubAPI.ps1 b/tools/utilities/GitHubAPI.ps1 index b0a4b36bb..e4be8041e 100644 --- a/tools/utilities/GitHubAPI.ps1 +++ b/tools/utilities/GitHubAPI.ps1 @@ -21,8 +21,8 @@ $response = Invoke-RestMethod -Uri $APIDocURI -Method Get # @{n = 'PUT'; e = { (($_.value.psobject.Properties.Name) -contains 'PUT') } }, ` # @{n = 'PATCH'; e = { (($_.value.psobject.Properties.Name) -contains 'PATCH') } } | Format-Table -$path = '/repos/{owner}/{repo}/topics' -$method = 'Put' +$path = '/repos/{owner}/{repo}/contributors' +$method = 'get' $response.paths.$path.$method $response.paths.$path.$method.tags | clip # -> Namespace/foldername $response.paths.$path.$method.operationId | clip # -> FunctionName From fd49a9fcf7f0520e9665ddd56580c73183b53133 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 9 Oct 2023 23:41:50 +0200 Subject: [PATCH 036/193] Added Get-repoteams --- .../Get-GitHubRepositoryTeams.ps1 | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryTeams.ps1 diff --git a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryTeams.ps1 b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryTeams.ps1 new file mode 100644 index 000000000..be17dfc6b --- /dev/null +++ b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryTeams.ps1 @@ -0,0 +1,55 @@ +filter Get-GitHubRepositoryTeams { + <# + .SYNOPSIS + List repository teams + + .DESCRIPTION + Lists the teams that have access to the specified repository and that are also visible to the authenticated user. + + For a public repository, a team is listed only if that team added the public repository explicitly. + + Personal access tokens require the following scopes: + * `public_repo` to call this endpoint on a public repository + * `repo` to call this endpoint on a private repository (this scope also includes public repositories) + + This endpoint is not compatible with fine-grained personal access tokens. + + .EXAMPLE + Get-GitHubRepositoryTeams -Owner 'PSModule' -Repo 'GitHub' + + Lists the teams that have access to the specified repository and that are also visible to the authenticated user. + + .NOTES + https://docs.github.com/rest/repos/repos#list-repository-teams + + #> + [CmdletBinding()] + param ( + # The account owner of the repository. The name is not case sensitive. + [Parameter()] + [Alias('org')] + [string] $Owner = (Get-GitHubConfig -Name Owner), + + # The name of the repository without the .git extension. The name is not case sensitive. + [Parameter()] + [string] $Repo = (Get-GitHubConfig -Name Repo), + + # The number of results per page (max 100). + [Parameter()] + [ValidateRange(1, 100)] + [int] $PerPage = 30 + ) + + $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case + Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner', 'Repo' -RemoveTypes 'SwitchParameter' + + $inputObject = @{ + APIEndpoint = "/repos/$Owner/$Repo/teams" + Method = 'GET' + Body = $body + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } +} From ac30a8197245d4085e1490c906cad69a91f23f36 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 9 Oct 2023 23:41:56 +0200 Subject: [PATCH 037/193] Added get repotags --- .../Repositories/Get-GitHubRepositoryTags.ps1 | 47 +++++++++++++++++++ tools/utilities/GitHubAPI.ps1 | 2 +- 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryTags.ps1 diff --git a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryTags.ps1 b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryTags.ps1 new file mode 100644 index 000000000..24580724c --- /dev/null +++ b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryTags.ps1 @@ -0,0 +1,47 @@ +filter Get-GitHubRepositoryTags { + <# + .SYNOPSIS + List repository tags + + .DESCRIPTION + List repository tags + + .EXAMPLE + Get-GitHubRepositoryTags -Owner 'PSModule' -Repo 'GitHub' + + Gets all tags of the GitHub repository. + + .NOTES + https://docs.github.com/rest/repos/repos#list-repository-tags + + #> + [CmdletBinding()] + param ( + # The account owner of the repository. The name is not case sensitive. + [Parameter()] + [Alias('org')] + [string] $Owner = (Get-GitHubConfig -Name Owner), + + # The name of the repository without the .git extension. The name is not case sensitive. + [Parameter()] + [string] $Repo = (Get-GitHubConfig -Name Repo), + + # The number of results per page (max 100). + [Parameter()] + [ValidateRange(1, 100)] + [int] $PerPage = 30 + ) + + $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case + Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner', 'Repo' -RemoveTypes 'SwitchParameter' + + $inputObject = @{ + APIEndpoint = "/repos/$Owner/$Repo/tags" + Method = 'GET' + Body = $body + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } +} diff --git a/tools/utilities/GitHubAPI.ps1 b/tools/utilities/GitHubAPI.ps1 index e4be8041e..6516f778f 100644 --- a/tools/utilities/GitHubAPI.ps1 +++ b/tools/utilities/GitHubAPI.ps1 @@ -21,7 +21,7 @@ $response = Invoke-RestMethod -Uri $APIDocURI -Method Get # @{n = 'PUT'; e = { (($_.value.psobject.Properties.Name) -contains 'PUT') } }, ` # @{n = 'PATCH'; e = { (($_.value.psobject.Properties.Name) -contains 'PATCH') } } | Format-Table -$path = '/repos/{owner}/{repo}/contributors' +$path = '/repos/{owner}/{repo}/teams' $method = 'get' $response.paths.$path.$method $response.paths.$path.$method.tags | clip # -> Namespace/foldername From 1ec6f359e638df96139a33e7b1c349cdeae35c0c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 12 Oct 2023 07:14:56 +0200 Subject: [PATCH 038/193] Add Get-Secfixes --- .../Get-GitHubRepositorySecurityFixes.ps1 | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/GitHub/public/Repositories/Repositories/Get-GitHubRepositorySecurityFixes.ps1 diff --git a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositorySecurityFixes.ps1 b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositorySecurityFixes.ps1 new file mode 100644 index 000000000..396e8c487 --- /dev/null +++ b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositorySecurityFixes.ps1 @@ -0,0 +1,42 @@ +filter Get-GitHubRepositorySecurityFixes { + <# + .SYNOPSIS + Check if automated security fixes are enabled for a repository + + .DESCRIPTION + Shows whether automated security fixes are enabled, disabled or paused for a repository. The authenticated user must have admin read access to the repository. For more information, see "[Configuring automated security fixes](https://docs.github.com/articles/configuring-automated-security-fixes)". + + .EXAMPLE + Get-GitHubRepositorySecurityFixes -Owner 'PSModule' -Repo 'GitHub' + + Gets the automated security fixes status for the GitHub repository. + + .NOTES + https://docs.github.com/rest/repos/repos#check-if-automated-security-fixes-are-enabled-for-a-repository + + #> + [CmdletBinding()] + param ( + # The account owner of the repository. The name is not case sensitive. + [Parameter()] + [Alias('org')] + [string] $Owner = (Get-GitHubConfig -Name Owner), + + # The name of the repository without the .git extension. The name is not case sensitive. + [Parameter()] + [string] $Repo = (Get-GitHubConfig -Name Repo) + ) + + $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case + Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner','Repo' -RemoveTypes 'SwitchParameter' + + $inputObject = @{ + APIEndpoint = "/repos/$Owner/$Repo/automated-security-fixes" + Method = 'GET' + Body = $body + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } +} From 220f8dc1652044ddfba59674bcd1441d9f9faec6 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 12 Oct 2023 07:15:38 +0200 Subject: [PATCH 039/193] Add Move-Repo --- .../Repositories/Move-GitHubRepository.ps1 | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/GitHub/public/Repositories/Repositories/Move-GitHubRepository.ps1 diff --git a/src/GitHub/public/Repositories/Repositories/Move-GitHubRepository.ps1 b/src/GitHub/public/Repositories/Repositories/Move-GitHubRepository.ps1 new file mode 100644 index 000000000..7e803c7f5 --- /dev/null +++ b/src/GitHub/public/Repositories/Repositories/Move-GitHubRepository.ps1 @@ -0,0 +1,73 @@ +filter Move-GitHubRepository { + <# + .SYNOPSIS + Transfer a repository + + .DESCRIPTION + A transfer request will need to be accepted by the new owner when transferring a personal repository to another user. The response will contain the original `owner`, and the transfer will continue asynchronously. For more details on the requirements to transfer personal and organization-owned repositories, see [about repository transfers](https://docs.github.com/articles/about-repository-transfers/). + You must use a personal access token (classic) or an OAuth token for this endpoint. An installation access token or a fine-grained personal access token cannot be used because they are only granted access to a single account. + + .EXAMPLE + Move-GitHubRepository -Owner 'PSModule' -Repo 'GitHub' -NewOwner 'GitHub' -NewName 'PowerShell' + + Moves the GitHub repository to the PSModule organization and renames it to GitHub. + + .NOTES + https://docs.github.com/rest/repos/repos#transfer-a-repository + + #> + [CmdletBinding()] + param ( + # The account owner of the repository. The name is not case sensitive. + [Parameter()] + [Alias('org')] + [string] $Owner = (Get-GitHubConfig -Name Owner), + + # The name of the repository without the .git extension. The name is not case sensitive. + [Parameter()] + [string] $Repo = (Get-GitHubConfig -Name Repo), + + # The username or organization name the repository will be transferred to. + [Parameter(Mandatory)] + [Alias('new_owner')] + [string] $NewOwner, + + # The new name to be given to the repository. + [Parameter()] + [Alias('new_name')] + [string] $NewName, + + # ID of the team or teams to add to the repository. Teams can only be added to organization-owned repositories. + [Parameter()] + [Alias('team_ids')] + [int[]] $TeamIds + ) + + $PSCmdlet.MyInvocation.MyCommand.Parameters.GetEnumerator() | ForEach-Object { + $paramName = $_.Key + $paramDefaultValue = Get-Variable -Name $paramName -ValueOnly -ErrorAction SilentlyContinue + $providedValue = $PSBoundParameters[$paramName] + Write-Verbose "[$paramName]" + Write-Verbose " - Default: [$paramDefaultValue]" + Write-Verbose " - Provided: [$providedValue]" + if (-not $PSBoundParameters.ContainsKey($paramName) -and ($null -ne $paramDefaultValue)) { + Write-Verbose ' - Using default value' + $PSBoundParameters[$paramName] = $paramDefaultValue + } else { + Write-Verbose ' - Using provided value' + } + } + + $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case + Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner','Repo' -RemoveTypes 'SwitchParameter' + + $inputObject = @{ + APIEndpoint = "/repos/$Owner/$Repo/transfer" + Method = 'POST' + Body = $body + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } +} From 46e7bd6fe799d97fa1671f357682fa78030b7e4e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 12 Oct 2023 07:48:23 +0200 Subject: [PATCH 040/193] Added Security fix enable disable function --- .../Disable-GitHubRepositorySecurityFixes.ps1 | 57 +++++++++++++++++++ .../Enable-GitHubRepositorySecurityFixes.ps1 | 57 +++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 src/GitHub/public/Repositories/Repositories/Disable-GitHubRepositorySecurityFixes.ps1 create mode 100644 src/GitHub/public/Repositories/Repositories/Enable-GitHubRepositorySecurityFixes.ps1 diff --git a/src/GitHub/public/Repositories/Repositories/Disable-GitHubRepositorySecurityFixes.ps1 b/src/GitHub/public/Repositories/Repositories/Disable-GitHubRepositorySecurityFixes.ps1 new file mode 100644 index 000000000..0301b88ab --- /dev/null +++ b/src/GitHub/public/Repositories/Repositories/Disable-GitHubRepositorySecurityFixes.ps1 @@ -0,0 +1,57 @@ +filter Disable-GitHubRepositorySecurityFixes { + <# + .SYNOPSIS + Disable automated security fixes + + .DESCRIPTION + Disables automated security fixes for a repository. The authenticated user must have admin access to the repository. For more information, see "[Configuring automated security fixes](https://docs.github.com/articles/configuring-automated-security-fixes)". + + .EXAMPLE + Disable-GitHubRepositorySecurityFixes -Owner 'PSModule' -Repo 'GitHub' + + Disables automated security fixes for the repository. + + .NOTES + https://docs.github.com/rest/repos/repos#disable-automated-security-fixes + + #> + [CmdletBinding()] + param ( + # The account owner of the repository. The name is not case sensitive. + [Parameter()] + [Alias('org')] + [string] $Owner = (Get-GitHubConfig -Name Owner), + + # The name of the repository without the .git extension. The name is not case sensitive. + [Parameter()] + [string] $Repo = (Get-GitHubConfig -Name Repo) + ) + + $PSCmdlet.MyInvocation.MyCommand.Parameters.GetEnumerator() | ForEach-Object { + $paramName = $_.Key + $paramDefaultValue = Get-Variable -Name $paramName -ValueOnly -ErrorAction SilentlyContinue + $providedValue = $PSBoundParameters[$paramName] + Write-Verbose "[$paramName]" + Write-Verbose " - Default: [$paramDefaultValue]" + Write-Verbose " - Provided: [$providedValue]" + if (-not $PSBoundParameters.ContainsKey($paramName) -and ($null -ne $paramDefaultValue)) { + Write-Verbose ' - Using default value' + $PSBoundParameters[$paramName] = $paramDefaultValue + } else { + Write-Verbose ' - Using provided value' + } + } + + $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case + Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner', 'Repo' -RemoveTypes 'SwitchParameter' + + $inputObject = @{ + APIEndpoint = "/repos/$Owner/$Repo/automated-security-fixes" + Method = 'DELETE' + Body = $body + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response.names + } +} diff --git a/src/GitHub/public/Repositories/Repositories/Enable-GitHubRepositorySecurityFixes.ps1 b/src/GitHub/public/Repositories/Repositories/Enable-GitHubRepositorySecurityFixes.ps1 new file mode 100644 index 000000000..b5cc0d3b0 --- /dev/null +++ b/src/GitHub/public/Repositories/Repositories/Enable-GitHubRepositorySecurityFixes.ps1 @@ -0,0 +1,57 @@ +filter Enable-GitHubRepositorySecurityFixes { + <# + .SYNOPSIS + Enable automated security fixes + + .DESCRIPTION + Enables automated security fixes for a repository. The authenticated user must have admin access to the repository. For more information, see "[Configuring automated security fixes](https://docs.github.com/articles/configuring-automated-security-fixes)". + + .EXAMPLE + Enable-GitHubRepositorySecurityFixes -Owner 'PSModule' -Repo 'GitHub' + + Enables automated security fixes for the repository. + + .NOTES + https://docs.github.com/rest/repos/repos#enable-automated-security-fixes + + #> + [CmdletBinding()] + param ( + # The account owner of the repository. The name is not case sensitive. + [Parameter()] + [Alias('org')] + [string] $Owner = (Get-GitHubConfig -Name Owner), + + # The name of the repository without the .git extension. The name is not case sensitive. + [Parameter()] + [string] $Repo = (Get-GitHubConfig -Name Repo) + ) + + $PSCmdlet.MyInvocation.MyCommand.Parameters.GetEnumerator() | ForEach-Object { + $paramName = $_.Key + $paramDefaultValue = Get-Variable -Name $paramName -ValueOnly -ErrorAction SilentlyContinue + $providedValue = $PSBoundParameters[$paramName] + Write-Verbose "[$paramName]" + Write-Verbose " - Default: [$paramDefaultValue]" + Write-Verbose " - Provided: [$providedValue]" + if (-not $PSBoundParameters.ContainsKey($paramName) -and ($null -ne $paramDefaultValue)) { + Write-Verbose ' - Using default value' + $PSBoundParameters[$paramName] = $paramDefaultValue + } else { + Write-Verbose ' - Using provided value' + } + } + + $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case + Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner', 'Repo' -RemoveTypes 'SwitchParameter' + + $inputObject = @{ + APIEndpoint = "/repos/$Owner/$Repo/automated-security-fixes" + Method = 'PUT' + Body = $body + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response.names + } +} From 23dd302ce62099bf2c5337c0ae496c8bc413a1e8 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 12 Oct 2023 07:48:33 +0200 Subject: [PATCH 041/193] Added Get-RepoActivity --- .../Get-GitHubRepositoryActivity.ps1 | 127 ++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryActivity.ps1 diff --git a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryActivity.ps1 b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryActivity.ps1 new file mode 100644 index 000000000..baf0d69a5 --- /dev/null +++ b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryActivity.ps1 @@ -0,0 +1,127 @@ +filter Get-GitHubRepositoryActivity { + <# + .SYNOPSIS + List repository activities + + .DESCRIPTION + Lists a detailed history of changes to a repository, such as pushes, merges, force pushes, and branch changes, and associates these changes with commits and users. + + For more information about viewing repository activity, + see "[Viewing activity and data for your repository](https://docs.github.com/repositories/viewing-activity-and-data-for-your-repository)." + + .EXAMPLE + Get-GitHubRepositoryActivity -Owner 'PSModule' -Repo 'GitHub' + + .EXAMPLE + Get-GitHubRepositoryActivity -Owner 'PSModule' -Repo 'GitHub' -Direction 'asc' + + .EXAMPLE + Get-GitHubRepositoryActivity -Owner 'PSModule' -Repo 'GitHub' -PerPage 100 + + .EXAMPLE + Get-GitHubRepositoryActivity -Owner 'PSModule' -Repo 'GitHub' -Before '2021-01-01T00:00:00Z' + + .EXAMPLE + Get-GitHubRepositoryActivity -Owner 'PSModule' -Repo 'GitHub' -After '2021-01-01T00:00:00Z' + + .EXAMPLE + Get-GitHubRepositoryActivity -Owner 'PSModule' -Repo 'GitHub' -Ref 'refs/heads/main' + + .EXAMPLE + Get-GitHubRepositoryActivity -Owner 'PSModule' -Repo 'GitHub' -Actor 'octocat' + + .EXAMPLE + Get-GitHubRepositoryActivity -Owner 'PSModule' -Repo 'GitHub' -TimePeriod 'day' | Select-Object -Property @{n='actor';e={$_.actor.login}},activity_type,ref,timestamp + + Gets the activity for the past 24 hours and selects the actor, activity type, ref, and timestamp. + + .EXAMPLE + Get-GitHubRepositoryActivity -Owner 'PSModule' -Repo 'GitHub' -ActivityType 'push','force_push' + + .NOTES + https://docs.github.com/rest/repos/repos#list-repository-activities + + #> + [CmdletBinding()] + param ( + # The account owner of the repository. The name is not case sensitive. + [Parameter()] + [Alias('org')] + [string] $Owner = (Get-GitHubConfig -Name Owner), + + # The name of the repository without the .git extension. The name is not case sensitive. + [Parameter()] + [string] $Repo = (Get-GitHubConfig -Name Repo), + + # The direction to sort the results by. + [Parameter()] + [ValidateSet('asc', 'desc')] + [string] $Direction = 'desc', + + # The number of results per page (max 100). + # Default: 30 + [Parameter()] + [ValidateRange(1, 100)] + [Alias('per_page')] + [int] $PerPage = 30, + + # A cursor, as given in the Link header. If specified, the query only searches for results before this cursor. + [Parameter(ParameterSetName = 'BeforeAfter')] + [string] $Before, + + # A cursor, as given in the Link header. If specified, the query only searches for results after this cursor. + [Parameter(ParameterSetName = 'BeforeAfter')] + [string] $After, + + # The Git reference for the activities you want to list. + # The ref for a branch can be formatted either as refs/heads/BRANCH_NAME or BRANCH_NAME, where BRANCH_NAME is the name of your branch. + [Parameter()] + [string] $Ref, + + # The GitHub username to use to filter by the actor who performed the activity. + [Parameter()] + [string] $Actor, + + # The time period to filter by. + # For example,day will filter for activity that occurred in the past 24 hours, and week will filter for activity that occurred in the past 7 days (168 hours). + [Parameter()] + [ValidateSet('day', 'week', 'month', 'quarter', 'year')] + [Alias('time_period')] + [string] $TimePeriod, + + # The activity type to filter by. + # For example,you can choose to filter by 'force_push', to see all force pushes to the repository. + [Parameter()] + [ValidateSet('push', 'force_push', 'branch_creation', 'branch_deletion', 'pr_merge', 'merge_queue_merge')] + [Alias('activity_type')] + [string] $ActivityType + ) + + $PSCmdlet.MyInvocation.MyCommand.Parameters.GetEnumerator() | ForEach-Object { + $paramName = $_.Key + $paramDefaultValue = Get-Variable -Name $paramName -ValueOnly -ErrorAction SilentlyContinue + $providedValue = $PSBoundParameters[$paramName] + Write-Verbose "[$paramName]" + Write-Verbose " - Default: [$paramDefaultValue]" + Write-Verbose " - Provided: [$providedValue]" + if (-not $PSBoundParameters.ContainsKey($paramName) -and ($null -ne $paramDefaultValue)) { + Write-Verbose ' - Using default value' + $PSBoundParameters[$paramName] = $paramDefaultValue + } else { + Write-Verbose ' - Using provided value' + } + } + + $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case + Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner', 'Repo' -RemoveTypes 'SwitchParameter' + + $inputObject = @{ + APIEndpoint = "/repos/$Owner/$Repo/activity" + Method = 'GET' + Body = $body + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } +} From 6564da85be4ad43f46132475ba1b108d7a19c440 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 12 Oct 2023 07:48:45 +0200 Subject: [PATCH 042/193] Added get repo CODEOWNERS errors --- .../Get-GitHubRepositoryCodeownersError.ps1 | 65 +++++++++++++++++++ tools/utilities/GitHubAPI.ps1 | 2 +- tools/utilities/Local-Testing.ps1 | 4 +- 3 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryCodeownersError.ps1 diff --git a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryCodeownersError.ps1 b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryCodeownersError.ps1 new file mode 100644 index 000000000..33b800c7d --- /dev/null +++ b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryCodeownersError.ps1 @@ -0,0 +1,65 @@ +filter Get-GitHubRepositoryCodeownersError { + <# + .SYNOPSIS + List CODEOWNERS errors + + .DESCRIPTION + List any syntax errors that are detected in the CODEOWNERS file. + + For more information about the correct CODEOWNERS syntax, + see "[About code owners](https://docs.github.com/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners)." + + .EXAMPLE + Get-GitHubRepositoryCodeownersError -Owner 'PSModule' -Repo 'GitHub' + + Gets the CODEOWNERS errors for the repository. + + .NOTES + https://docs.github.com/rest/repos/repos#list-codeowners-errors + + #> + [CmdletBinding()] + param ( + # The account owner of the repository. The name is not case sensitive. + [Parameter()] + [Alias('org')] + [string] $Owner = (Get-GitHubConfig -Name Owner), + + # The name of the repository without the .git extension. The name is not case sensitive. + [Parameter()] + [string] $Repo = (Get-GitHubConfig -Name Repo), + + # A branch, tag or commit name used to determine which version of the CODEOWNERS file to use. + # Default: the repository's default branch (e.g. main) + [Parameter()] + [string] $Ref + ) + + $PSCmdlet.MyInvocation.MyCommand.Parameters.GetEnumerator() | ForEach-Object { + $paramName = $_.Key + $paramDefaultValue = Get-Variable -Name $paramName -ValueOnly -ErrorAction SilentlyContinue + $providedValue = $PSBoundParameters[$paramName] + Write-Verbose "[$paramName]" + Write-Verbose " - Default: [$paramDefaultValue]" + Write-Verbose " - Provided: [$providedValue]" + if (-not $PSBoundParameters.ContainsKey($paramName) -and ($null -ne $paramDefaultValue)) { + Write-Verbose ' - Using default value' + $PSBoundParameters[$paramName] = $paramDefaultValue + } else { + Write-Verbose ' - Using provided value' + } + } + + $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case + Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner','Repo' -RemoveTypes 'SwitchParameter' + + $inputObject = @{ + APIEndpoint = "/repos/$Owner/$Repo/codeowners/errors" + Method = 'GET' + Body = $body + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } +} diff --git a/tools/utilities/GitHubAPI.ps1 b/tools/utilities/GitHubAPI.ps1 index 6516f778f..3c4bad088 100644 --- a/tools/utilities/GitHubAPI.ps1 +++ b/tools/utilities/GitHubAPI.ps1 @@ -21,7 +21,7 @@ $response = Invoke-RestMethod -Uri $APIDocURI -Method Get # @{n = 'PUT'; e = { (($_.value.psobject.Properties.Name) -contains 'PUT') } }, ` # @{n = 'PATCH'; e = { (($_.value.psobject.Properties.Name) -contains 'PATCH') } } | Format-Table -$path = '/repos/{owner}/{repo}/teams' +$path = '/repos/{owner}/{repo}/codeowners/errors' $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 d985cec1a..9ede69b36 100644 --- a/tools/utilities/Local-Testing.ps1 +++ b/tools/utilities/Local-Testing.ps1 @@ -11,6 +11,7 @@ Get-SecretInfo Get-Module -Name GitHub -ListAvailable $VerbosePreference = 'Continue' +Find-Module -Name GitHub Install-Module -Name GitHub -Force -Verbose -AllowPrerelease Get-Module -Name GitHub -ListAvailable # $env:PSModulePath += ';C:\Repos\GitHub\PSModule\Modules\GitHub\outputs' @@ -125,9 +126,9 @@ $params = @{ DeleteBranchOnMerge = $true } New-GitHubRepositoryOrg @params -GitignoreTemplate VisualStudio -LicenseTemplate mit - Remove-GitHubRepository -Owner PSModule -Repo 'Hello-world' -Verbose + $params = @{ Verbose = $true Name = 'Hello-world' @@ -154,7 +155,6 @@ $params = @{ DeleteBranchOnMerge = $true } New-GitHubRepositoryUser @params -GitignoreTemplate VisualStudio -LicenseTemplate gpl-3.0 - Remove-GitHubRepository -Owner MariusStorhaug -Repo 'Hello-world' -Verbose From 296c74a16d1d0e58ed72021a9aaa8982ff664268 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 14 Oct 2023 12:57:33 +0200 Subject: [PATCH 043/193] Test new version of pipeline --- .github/workflows/Module.GitHub.yml | 36 ------------------------ .github/workflows/Process-PSModule.yml | 38 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 36 deletions(-) delete mode 100644 .github/workflows/Module.GitHub.yml create mode 100644 .github/workflows/Process-PSModule.yml diff --git a/.github/workflows/Module.GitHub.yml b/.github/workflows/Module.GitHub.yml deleted file mode 100644 index 9a67150b8..000000000 --- a/.github/workflows/Module.GitHub.yml +++ /dev/null @@ -1,36 +0,0 @@ -name: Module [GitHub] - -on: - push: - branches: - - '*' - paths: - - .github/workflows/Module.GitHub.yml - - src/GitHub/** - workflow_dispatch: - -jobs: - BuildModule: - name: Build Module - runs-on: ubuntu-latest - env: - GH_TOKEN: ${{ github.token }} # Used for GitHub CLI authentication - steps: - - name: Checkout Code - uses: actions/checkout@v4 - - - name: Build Module - uses: PSModule/Build-Module@main - with: - Verbose: true - - - name: Test Module - uses: PSModule/Test-Module@main - with: - Verbose: true - - - name: Release Module - uses: PSModule/Release-Module@main - with: - APIKey: ${{ secrets.APIKEY }} - Verbose: true diff --git a/.github/workflows/Process-PSModule.yml b/.github/workflows/Process-PSModule.yml new file mode 100644 index 000000000..7c3926475 --- /dev/null +++ b/.github/workflows/Process-PSModule.yml @@ -0,0 +1,38 @@ +name: Process-PSModule + +on: + push: + branches: + - '*' + workflow_dispatch: + +jobs: + Process-PSModule: + name: Process-PSModule + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Initialize-PSModule + uses: PSModule/Initialize-PSModule@main + with: + Verbose: true + + - name: Build-PSModule + uses: PSModule/Build-PSModule@main + with: + Verbose: true + + - name: Test-PSModule + uses: PSModule/Test-PSModule@main + with: + Verbose: true + + - name: Release-PSModule + uses: PSModule/Release-PSModule@main + with: + APIKey: ${{ secrets.APIKEY }} + Verbose: true + env: + GH_TOKEN: ${{ github.token }} # Used for GitHub CLI authentication From 8b4125373697c44ace438591be916f8cbc1fdb69 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 22 Oct 2023 10:13:52 +0200 Subject: [PATCH 044/193] Added vscode files --- .vscode/settings.json | 1 + 1 file changed, 1 insertion(+) diff --git a/.vscode/settings.json b/.vscode/settings.json index d48c3e7ee..e732ea127 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -29,6 +29,7 @@ "editor.insertSpaces": true, "editor.tabSize": 2 }, + "editor.rulers": [0, 150], "powershell.codeFormatting.autoCorrectAliases": true, "powershell.codeFormatting.newLineAfterCloseBrace": false, "powershell.codeFormatting.pipelineIndentationStyle": "IncreaseIndentationForFirstPipeline", From 297a09ff3857ebe7e2e82a937fc6060d59b8ff2a Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 23 Oct 2023 22:03:40 +0200 Subject: [PATCH 045/193] Fix output type --- .../Auth/DeviceFlow/Test-GitHubAccessTokenRefreshRequired.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/GitHub/private/Auth/DeviceFlow/Test-GitHubAccessTokenRefreshRequired.ps1 b/src/GitHub/private/Auth/DeviceFlow/Test-GitHubAccessTokenRefreshRequired.ps1 index 1606c6630..f9aa14138 100644 --- a/src/GitHub/private/Auth/DeviceFlow/Test-GitHubAccessTokenRefreshRequired.ps1 +++ b/src/GitHub/private/Auth/DeviceFlow/Test-GitHubAccessTokenRefreshRequired.ps1 @@ -11,12 +11,13 @@ This will test if the GitHub access token should be refreshed. #> + [OutputType([bool])] [CmdletBinding()] param() $tokenType = Get-GitHubConfig -Name 'AccessTokenType' -ErrorAction SilentlyContinue if ($tokenType -ne 'ghu_*') { - Write-Verbose "The access token is not a user token. No need to refresh." + Write-Verbose 'The access token is not a user token. No need to refresh.' return $false } From 47bfd011f8b91fc899e6023a070da75347135967 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 24 Oct 2023 21:22:22 +0200 Subject: [PATCH 046/193] Fix docs for Get-GitHubRepoBranch --- .../public/Branches/Get-GitHubRepoBranch.ps1 | 17 +++++++++++++++++ tools/utilities/GitHubAPI.ps1 | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/GitHub/public/Branches/Get-GitHubRepoBranch.ps1 b/src/GitHub/public/Branches/Get-GitHubRepoBranch.ps1 index 7150c6dad..62869ec21 100644 --- a/src/GitHub/public/Branches/Get-GitHubRepoBranch.ps1 +++ b/src/GitHub/public/Branches/Get-GitHubRepoBranch.ps1 @@ -1,9 +1,26 @@ filter Get-GitHubRepoBranch { + <# + .SYNOPSIS + List branches + + .DESCRIPTION + Lists all branches from a repository + + .EXAMPLE + Get-GitHubRepoBranch -Owner 'octocat' -Repo 'Hello-World' + + Gets all the branches from the 'Hello-World' repository owned by 'octocat' + + .NOTES + https://docs.github.com/rest/branches/branches#list-branches + #> [CmdletBinding()] param ( + # The account owner of the repository. The name is not case sensitive. [Parameter()] [string] $Owner = (Get-GitHubConfig -Name Owner), + # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] [string] $Repo = (Get-GitHubConfig -Name Repo) ) diff --git a/tools/utilities/GitHubAPI.ps1 b/tools/utilities/GitHubAPI.ps1 index 3c4bad088..ef32de4e2 100644 --- a/tools/utilities/GitHubAPI.ps1 +++ b/tools/utilities/GitHubAPI.ps1 @@ -21,7 +21,7 @@ $response = Invoke-RestMethod -Uri $APIDocURI -Method Get # @{n = 'PUT'; e = { (($_.value.psobject.Properties.Name) -contains 'PUT') } }, ` # @{n = 'PATCH'; e = { (($_.value.psobject.Properties.Name) -contains 'PATCH') } } | Format-Table -$path = '/repos/{owner}/{repo}/codeowners/errors' +$path = '/repos/{owner}/{repo}/branches' $method = 'get' $response.paths.$path.$method $response.paths.$path.$method.tags | clip # -> Namespace/foldername From 2ffbec38703b4a564ef62294b57b376af79326f6 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 24 Oct 2023 21:28:59 +0200 Subject: [PATCH 047/193] fix docs for Remove-GitHubWorkflowRun --- .../Actions/Remove-GitHubWorkflowRun.ps1 | 23 ++++++++++++++++++- tools/utilities/GitHubAPI.ps1 | 4 ++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/GitHub/public/Actions/Remove-GitHubWorkflowRun.ps1 b/src/GitHub/public/Actions/Remove-GitHubWorkflowRun.ps1 index 88fd9d921..af9340f50 100644 --- a/src/GitHub/public/Actions/Remove-GitHubWorkflowRun.ps1 +++ b/src/GitHub/public/Actions/Remove-GitHubWorkflowRun.ps1 @@ -1,17 +1,38 @@ filter Remove-GitHubWorkflowRun { + <# + .SYNOPSIS + Delete a workflow run + + .DESCRIPTION + Delete a specific workflow run. Anyone with write access to the repository can use this endpoint. If the repository is + private you must use an access token with the `repo` scope. GitHub Apps must have the `actions:write` permission to use + this endpoint. + + .EXAMPLE + Remove-GitHubWorkflowRun -Owner 'octocat' -Repo 'Hello-World' -ID 123456789 + + Deletes the workflow run with the ID 123456789 from the 'Hello-World' repository owned by 'octocat' + + .NOTES + https://docs.github.com/rest/actions/workflow-runs#delete-a-workflow-run + #> [CmdletBinding()] param ( + # The account owner of the repository. The name is not case sensitive. [Parameter()] [string] $Owner = (Get-GitHubConfig -Name Owner), + # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] [string] $Repo = (Get-GitHubConfig -Name Repo), + # The unique identifier of the workflow run. [Parameter( Mandatory, ValueFromPipelineByPropertyName )] - [string] $ID + [Alias('ID', 'run_id')] + [string] $RunID ) $inputObject = @{ diff --git a/tools/utilities/GitHubAPI.ps1 b/tools/utilities/GitHubAPI.ps1 index ef32de4e2..e5c20db2c 100644 --- a/tools/utilities/GitHubAPI.ps1 +++ b/tools/utilities/GitHubAPI.ps1 @@ -21,8 +21,8 @@ $response = Invoke-RestMethod -Uri $APIDocURI -Method Get # @{n = 'PUT'; e = { (($_.value.psobject.Properties.Name) -contains 'PUT') } }, ` # @{n = 'PATCH'; e = { (($_.value.psobject.Properties.Name) -contains 'PATCH') } } | Format-Table -$path = '/repos/{owner}/{repo}/branches' -$method = 'get' +$path = '/repos/{owner}/{repo}/actions/runs/{run_id}' +$method = 'delete' $response.paths.$path.$method $response.paths.$path.$method.tags | clip # -> Namespace/foldername $response.paths.$path.$method.operationId | clip # -> FunctionName From 34000758da1138888749e84290b893c2b459cdfc Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 24 Oct 2023 22:09:17 +0200 Subject: [PATCH 048/193] Clean docs for Remove-HashtableEntries --- .../Hashtable/Remove-HashTableEntries.ps1 | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/GitHub/private/Utilities/Hashtable/Remove-HashTableEntries.ps1 b/src/GitHub/private/Utilities/Hashtable/Remove-HashTableEntries.ps1 index 110bb3ed0..c5d09452d 100644 --- a/src/GitHub/private/Utilities/Hashtable/Remove-HashTableEntries.ps1 +++ b/src/GitHub/private/Utilities/Hashtable/Remove-HashTableEntries.ps1 @@ -1,29 +1,54 @@ filter Remove-HashtableEntries { + <# + .SYNOPSIS + Remove entries from a hashtable. + + .DESCRIPTION + Remove different types of entries from a hashtable. + + .EXAMPLE + $Hashtable = @{ + 'Key1' = 'Value1' + 'Key2' = 'Value2' + 'Key3' = $null + 'Key4' = 'Value4' + 'Key5' = '' + } + $Hashtable | Remove-HashtableEntries -NullOrEmptyValues + + Remove keys with null or empty values + #> [OutputType([void])] [CmdletBinding()] param ( + # The hashtable to remove entries from. [Parameter( Mandatory, ValueFromPipeline )] [hashtable] $Hashtable, + # Remove keys with null or empty values. [Parameter()] [switch] $NullOrEmptyValues, + # Remove keys of type. [Parameter()] [string[]] $RemoveTypes, + # Remove keys with a given name. [Parameter()] [string[]] $RemoveNames, + # Remove keys NOT of type. [Parameter()] [string[]] $KeepTypes, + # Remove keys NOT with a given name. [Parameter()] [string[]] $KeepNames - ) + if ($NullOrEmptyValues) { Write-Verbose 'Remove keys with null or empty values' ($Hashtable.GetEnumerator() | Where-Object { -not $_.Value }) | ForEach-Object { From cd1844f5220497b3412d860da7eb73c1c7c3c470 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 24 Oct 2023 22:11:52 +0200 Subject: [PATCH 049/193] fix --- .../private/Utilities/Hashtable/Remove-HashTableEntries.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GitHub/private/Utilities/Hashtable/Remove-HashTableEntries.ps1 b/src/GitHub/private/Utilities/Hashtable/Remove-HashTableEntries.ps1 index c5d09452d..30a24a763 100644 --- a/src/GitHub/private/Utilities/Hashtable/Remove-HashTableEntries.ps1 +++ b/src/GitHub/private/Utilities/Hashtable/Remove-HashTableEntries.ps1 @@ -48,7 +48,7 @@ [Parameter()] [string[]] $KeepNames ) - + if ($NullOrEmptyValues) { Write-Verbose 'Remove keys with null or empty values' ($Hashtable.GetEnumerator() | Where-Object { -not $_.Value }) | ForEach-Object { From 3b86b99813cfbd3f11b6d4a565190e2ea05bbe4d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 26 Oct 2023 07:10:46 +0200 Subject: [PATCH 050/193] removed menu as its currently not used --- src/GitHub/private/Menu/Invoke-DrawMenu.ps1 | 29 --------------------- src/GitHub/private/Menu/Invoke-Menu.ps1 | 29 --------------------- 2 files changed, 58 deletions(-) delete mode 100644 src/GitHub/private/Menu/Invoke-DrawMenu.ps1 delete mode 100644 src/GitHub/private/Menu/Invoke-Menu.ps1 diff --git a/src/GitHub/private/Menu/Invoke-DrawMenu.ps1 b/src/GitHub/private/Menu/Invoke-DrawMenu.ps1 deleted file mode 100644 index 4ca69a42e..000000000 --- a/src/GitHub/private/Menu/Invoke-DrawMenu.ps1 +++ /dev/null @@ -1,29 +0,0 @@ -function Invoke-DrawMenu { - ## supportfunction to the Menu function below - param ( - $menuItems, - $menuPosition, - $menuTitel - ) - $fcolor = $host.UI.RawUI.ForegroundColor - $bcolor = $host.UI.RawUI.BackgroundColor - $l = $menuItems.length + 1 - Clear-Host - $menuwidth = $menuTitel.length + 4 - Write-Host "`t" -NoNewline - Write-Host ('*' * $menuwidth) -fore $fcolor -back $bcolor - Write-Host "`t" -NoNewline - Write-Host "* $menuTitel *" -fore $fcolor -back $bcolor - Write-Host "`t" -NoNewline - Write-Host ('*' * $menuwidth) -fore $fcolor -back $bcolor - Write-Host '' - Write-Debug "L: $l MenuItems: $menuItems MenuPosition: $menuposition" - for ($i = 0; $i -le $l; $i++) { - Write-Host "`t" -NoNewline - if ($i -eq $menuPosition) { - Write-Host "$($menuItems[$i])" -fore $bcolor -back $fcolor - } else { - Write-Host "$($menuItems[$i])" -fore $fcolor -back $bcolor - } - } -} diff --git a/src/GitHub/private/Menu/Invoke-Menu.ps1 b/src/GitHub/private/Menu/Invoke-Menu.ps1 deleted file mode 100644 index 7059a10fd..000000000 --- a/src/GitHub/private/Menu/Invoke-Menu.ps1 +++ /dev/null @@ -1,29 +0,0 @@ -function Invoke-Menu { - ## Generate a small "DOS-like" menu. - ## Choose a menuitem using up and down arrows, select by pressing ENTER - param ( - [array]$menuItems, - $menuTitel = 'MENU' - ) - $vkeycode = 0 - $pos = 0 - Invoke-DrawMenu $menuItems $pos $menuTitel - while ($vkeycode -ne 13) { - $press = $host.ui.rawui.readkey('NoEcho,IncludeKeyDown') - $vkeycode = $press.virtualkeycode - Write-Host "$($press.character)" -NoNewline - if ($vkeycode -eq 38) { $pos-- } - if ($vkeycode -eq 40) { $pos++ } - if ($pos -lt 0) { $pos = 0 } - if ($pos -ge $menuItems.length) { $pos = $menuItems.length - 1 } - Invoke-DrawMenu $menuItems $pos $menuTitel - } - $($menuItems[$pos]) -} - - -<# -? What account do you want to log into? [Use arrows to move, type to filter] -> GitHub.com - GitHub Enterprise Server -#> From 5f2815dfbccea08304e043d58e332460e64f1315 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 26 Oct 2023 07:16:06 +0200 Subject: [PATCH 051/193] Fix DynamicParam --- .../DynamicParam/New-DynamicParam.ps1 | 4 +-- .../New-DynamicParamDictionary.ps1 | 18 +++++++++++++ .../DynamicParam/New-ParamDictionary.ps1 | 3 --- .../public/Gitignore/Get-GitHubGitignore.ps1 | 16 ++++++------ .../public/License/Get-GitHubLicense.ps1 | 16 ++++++------ .../Repositories/Get-GitHubRepository.ps1 | 16 ++++++------ .../Repositories/New-GitHubRepositoryOrg.ps1 | 24 ++++++++--------- .../Repositories/New-GitHubRepositoryUser.ps1 | 26 +++++++++---------- 8 files changed, 69 insertions(+), 54 deletions(-) create mode 100644 src/GitHub/private/Utilities/DynamicParam/New-DynamicParamDictionary.ps1 delete mode 100644 src/GitHub/private/Utilities/DynamicParam/New-ParamDictionary.ps1 diff --git a/src/GitHub/private/Utilities/DynamicParam/New-DynamicParam.ps1 b/src/GitHub/private/Utilities/DynamicParam/New-DynamicParam.ps1 index f2df28a86..28cab29e1 100644 --- a/src/GitHub/private/Utilities/DynamicParam/New-DynamicParam.ps1 +++ b/src/GitHub/private/Utilities/DynamicParam/New-DynamicParam.ps1 @@ -116,7 +116,7 @@ # Specifies the dynamic parameter dictionary. [Parameter()] - [System.Management.Automation.RuntimeDefinedParameterDictionary] $ParamDictionary + [System.Management.Automation.RuntimeDefinedParameterDictionary] $DynamicParamDictionary ) $attributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute] @@ -192,6 +192,6 @@ } $runtimeDefinedParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($Name, $Type, $attributeCollection) - $ParamDictionary.Add($Name, $runtimeDefinedParameter) + $DynamicParamDictionary.Add($Name, $runtimeDefinedParameter) } diff --git a/src/GitHub/private/Utilities/DynamicParam/New-DynamicParamDictionary.ps1 b/src/GitHub/private/Utilities/DynamicParam/New-DynamicParamDictionary.ps1 new file mode 100644 index 000000000..5636ce4f0 --- /dev/null +++ b/src/GitHub/private/Utilities/DynamicParam/New-DynamicParamDictionary.ps1 @@ -0,0 +1,18 @@ +function New-DynamicParamDictionary { + <# + .SYNOPSIS + Creates a new RuntimeDefinedParameterDictionary + + .DESCRIPTION + Creates a new RuntimeDefinedParameterDictionary + + .EXAMPLE + New-DynamicParamDictionary + + Returns a new RuntimeDefinedParameterDictionary + #> + [CmdletBinding()] + param() + + return [System.Management.Automation.RuntimeDefinedParameterDictionary]::new() +} diff --git a/src/GitHub/private/Utilities/DynamicParam/New-ParamDictionary.ps1 b/src/GitHub/private/Utilities/DynamicParam/New-ParamDictionary.ps1 deleted file mode 100644 index e5ba112ae..000000000 --- a/src/GitHub/private/Utilities/DynamicParam/New-ParamDictionary.ps1 +++ /dev/null @@ -1,3 +0,0 @@ -function New-ParamDictionary { - return [System.Management.Automation.RuntimeDefinedParameterDictionary]::new() -} diff --git a/src/GitHub/public/Gitignore/Get-GitHubGitignore.ps1 b/src/GitHub/public/Gitignore/Get-GitHubGitignore.ps1 index 59d6ad7f3..6fc19a794 100644 --- a/src/GitHub/public/Gitignore/Get-GitHubGitignore.ps1 +++ b/src/GitHub/public/Gitignore/Get-GitHubGitignore.ps1 @@ -26,19 +26,19 @@ filter Get-GitHubGitignore { param () DynamicParam { - $ParamDictionary = New-ParamDictionary + $DynamicParamDictionary = New-DynamicParamDictionary $dynParam = @{ - Name = 'Name' - ParameterSetName = 'Name' - Type = [string] - Mandatory = $true - ValidateSet = Get-GitHubGitignoreList - ParamDictionary = $ParamDictionary + Name = 'Name' + ParameterSetName = 'Name' + Type = [string] + Mandatory = $true + ValidateSet = Get-GitHubGitignoreList + DynamicParamDictionary = $DynamicParamDictionary } New-DynamicParam @dynParam - return $ParamDictionary + return $DynamicParamDictionary } Process { diff --git a/src/GitHub/public/License/Get-GitHubLicense.ps1 b/src/GitHub/public/License/Get-GitHubLicense.ps1 index 8082fad09..de1f90986 100644 --- a/src/GitHub/public/License/Get-GitHubLicense.ps1 +++ b/src/GitHub/public/License/Get-GitHubLicense.ps1 @@ -44,19 +44,19 @@ filter Get-GitHubLicense { ) DynamicParam { - $ParamDictionary = New-ParamDictionary + $DynamicParamDictionary = New-DynamicParamDictionary $dynParam = @{ - Name = 'Name' - ParameterSetName = 'Name' - Type = [string] - Mandatory = $true - ValidateSet = Get-GitHubLicenseList | Select-Object -ExpandProperty Name - ParamDictionary = $ParamDictionary + Name = 'Name' + ParameterSetName = 'Name' + Type = [string] + Mandatory = $true + ValidateSet = Get-GitHubLicenseList | Select-Object -ExpandProperty Name + DynamicParamDictionary = $DynamicParamDictionary } New-DynamicParam @dynParam - return $ParamDictionary + return $DynamicParamDictionary } Process { diff --git a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepository.ps1 b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepository.ps1 index 955f1c963..e8b8c86c1 100644 --- a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepository.ps1 +++ b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepository.ps1 @@ -125,7 +125,7 @@ ) DynamicParam { - $ParamDictionary = New-ParamDictionary + $DynamicParamDictionary = New-DynamicParamDictionary if ($PSCmdlet.ParameterSetName -in 'MyRepos_Type', 'ListByOrg', 'ListByUser') { @@ -142,17 +142,17 @@ } $dynParam = @{ - Name = 'Type' - ParameterSetName = $PSCmdlet.ParameterSetName - Type = [string] - Mandatory = $false - ValidateSet = $ValidateSet - ParamDictionary = $ParamDictionary + Name = 'Type' + ParameterSetName = $PSCmdlet.ParameterSetName + Type = [string] + Mandatory = $false + ValidateSet = $ValidateSet + DynamicParamDictionary = $DynamicParamDictionary } New-DynamicParam @dynParam } - return $ParamDictionary + return $DynamicParamDictionary } Process { diff --git a/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 b/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 index 70b03689d..698902e99 100644 --- a/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 +++ b/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 @@ -167,27 +167,27 @@ ) DynamicParam { - $ParamDictionary = New-ParamDictionary + $DynamicParamDictionary = New-DynamicParamDictionary $dynParam = @{ - Name = 'GitignoreTemplate' - Alias = 'gitignore_template' - Type = [string] - ValidateSet = Get-GitHubGitignoreList - ParamDictionary = $ParamDictionary + Name = 'GitignoreTemplate' + Alias = 'gitignore_template' + Type = [string] + ValidateSet = Get-GitHubGitignoreList + DynamicParamDictionary = $DynamicParamDictionary } New-DynamicParam @dynParam $dynParam2 = @{ - Name = 'LicenseTemplate' - Alias = 'license_template' - Type = [string] - ValidateSet = Get-GitHubLicenseList | Select-Object -ExpandProperty key - ParamDictionary = $ParamDictionary + Name = 'LicenseTemplate' + Alias = 'license_template' + Type = [string] + ValidateSet = Get-GitHubLicenseList | Select-Object -ExpandProperty key + DynamicParamDictionary = $DynamicParamDictionary } New-DynamicParam @dynParam2 - return $ParamDictionary + return $DynamicParamDictionary } begin { diff --git a/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryUser.ps1 b/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryUser.ps1 index 4d0178702..c8e90f3aa 100644 --- a/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryUser.ps1 +++ b/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryUser.ps1 @@ -165,27 +165,27 @@ ) DynamicParam { - $ParamDictionary = New-ParamDictionary + $DynamicParamDictionary = New-DynamicParamDictionary $dynParam = @{ - Name = 'GitignoreTemplate' - Alias = 'gitignore_template' - Type = [string] - ValidateSet = Get-GitHubGitignoreList - ParamDictionary = $ParamDictionary + Name = 'GitignoreTemplate' + Alias = 'gitignore_template' + Type = [string] + ValidateSet = Get-GitHubGitignoreList + DynamicParamDictionary = $DynamicParamDictionary } New-DynamicParam @dynParam $dynParam2 = @{ - Name = 'LicenseTemplate' - Alias = 'license_template' - Type = [string] - ValidateSet = Get-GitHubLicenseList | Select-Object -ExpandProperty key - ParamDictionary = $ParamDictionary + Name = 'LicenseTemplate' + Alias = 'license_template' + Type = [string] + ValidateSet = Get-GitHubLicenseList | Select-Object -ExpandProperty key + DynamicParamDictionary = $DynamicParamDictionary } New-DynamicParam @dynParam2 - return $ParamDictionary + return $DynamicParamDictionary } begin { @@ -229,7 +229,7 @@ Remove-HashtableEntries -Hashtable $body -NullOrEmptyValues $inputObject = @{ - APIEndpoint = "/user/repos" + APIEndpoint = '/user/repos' Method = 'POST' Body = $body } From 228433636923df8998217b4b0503ad13594e7663 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 26 Oct 2023 07:20:28 +0200 Subject: [PATCH 052/193] Fix for dynamicParam --- src/GitHub/private/Utilities/DynamicParam/New-DynamicParam.ps1 | 1 + .../Utilities/DynamicParam/New-DynamicParamDictionary.ps1 | 1 + 2 files changed, 2 insertions(+) diff --git a/src/GitHub/private/Utilities/DynamicParam/New-DynamicParam.ps1 b/src/GitHub/private/Utilities/DynamicParam/New-DynamicParam.ps1 index 28cab29e1..139332e2b 100644 --- a/src/GitHub/private/Utilities/DynamicParam/New-DynamicParam.ps1 +++ b/src/GitHub/private/Utilities/DynamicParam/New-DynamicParam.ps1 @@ -16,6 +16,7 @@ # https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_functions_advanced_parameters?view=powershell-7.3#psdefaultvalue-attribute-arguments # https://learn.microsoft.com/en-us/dotnet/api/system.management.automation.runtimedefinedparameter.value?view=powershellsdk-7.3.0 #> + [OutputType([void])] [CmdletBinding()] param( # Specifies the name of the parameter. diff --git a/src/GitHub/private/Utilities/DynamicParam/New-DynamicParamDictionary.ps1 b/src/GitHub/private/Utilities/DynamicParam/New-DynamicParamDictionary.ps1 index 5636ce4f0..302a26345 100644 --- a/src/GitHub/private/Utilities/DynamicParam/New-DynamicParamDictionary.ps1 +++ b/src/GitHub/private/Utilities/DynamicParam/New-DynamicParamDictionary.ps1 @@ -11,6 +11,7 @@ Returns a new RuntimeDefinedParameterDictionary #> + [OutputType([System.Management.Automation.RuntimeDefinedParameterDictionary])] [CmdletBinding()] param() From 9ee130e71dc9eeca7df7eb5dafe8da5cffaf6b5a Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 26 Oct 2023 07:30:40 +0200 Subject: [PATCH 053/193] remove deployments --- .../Deployments/Get-GitHubEnvironment.ps1 | 37 -------------- .../Get-GitHubEnvironmentSecrets.ps1 | 49 ------------------- .../Deployments/Update-GitHubEnvironment.ps1 | 36 -------------- tools/utilities/GitHubAPI.ps1 | 4 +- 4 files changed, 2 insertions(+), 124 deletions(-) delete mode 100644 src/GitHub/public/Deployments/Get-GitHubEnvironment.ps1 delete mode 100644 src/GitHub/public/Deployments/Get-GitHubEnvironmentSecrets.ps1 delete mode 100644 src/GitHub/public/Deployments/Update-GitHubEnvironment.ps1 diff --git a/src/GitHub/public/Deployments/Get-GitHubEnvironment.ps1 b/src/GitHub/public/Deployments/Get-GitHubEnvironment.ps1 deleted file mode 100644 index 0cb07872f..000000000 --- a/src/GitHub/public/Deployments/Get-GitHubEnvironment.ps1 +++ /dev/null @@ -1,37 +0,0 @@ -filter Get-GitHubEnvironment { - <# - .SYNOPSIS - Get GitHub environment - - .DESCRIPTION - Long description - - .PARAMETER Owner - Parameter description - - .PARAMETER Repo - Parameter description - - .EXAMPLE - An example - - .NOTES - https://docs.github.com/rest/reference/repos#get-all-environments - #> - [CmdletBinding()] - param ( - [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), - - [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo) - ) - - $inputObject = @{ - APIEndpoint = "/repos/$Owner/$Repo/environments" - Method = 'GET' - } - - (Invoke-GitHubAPI @inputObject).Response - -} diff --git a/src/GitHub/public/Deployments/Get-GitHubEnvironmentSecrets.ps1 b/src/GitHub/public/Deployments/Get-GitHubEnvironmentSecrets.ps1 deleted file mode 100644 index 643eb7167..000000000 --- a/src/GitHub/public/Deployments/Get-GitHubEnvironmentSecrets.ps1 +++ /dev/null @@ -1,49 +0,0 @@ -filter Get-GitHubEnvironmentSecrets { - <# - .SYNOPSIS - Get GitHub environment secrets - - .DESCRIPTION - Long description - - .PARAMETER Owner - Parameter description - - .PARAMETER Repo - Parameter description - - .PARAMETER EnvironmentName - Parameter description - - .EXAMPLE - An example - - .NOTES - https://docs.github.com/rest/reference/repos#get-all-environments - #> - [CmdletBinding()] - param ( - [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), - - [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), - - [Parameter( - Mandatory, - ValueFromPipelineByPropertyName - )] - [Alias('name')] - [string] $EnvironmentName - ) - - $RepoID = (Get-GitHubRepo).id - - $inputObject = @{ - APIEndpoint = "/repositories/$RepoID/environments/$EnvironmentName/secrets" - Method = 'GET' - } - - (Invoke-GitHubAPI @inputObject).Response - -} diff --git a/src/GitHub/public/Deployments/Update-GitHubEnvironment.ps1 b/src/GitHub/public/Deployments/Update-GitHubEnvironment.ps1 deleted file mode 100644 index c03cc78f2..000000000 --- a/src/GitHub/public/Deployments/Update-GitHubEnvironment.ps1 +++ /dev/null @@ -1,36 +0,0 @@ -filter Update-GitHubEnvironment { - <# - .NOTES - https://docs.github.com/rest/reference/repos#create-or-update-an-environment - #> - [CmdletBinding()] - param ( - [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), - - [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), - - [Alias('environment_name')] - [Parameter( - Mandatory, - ValueFromPipelineByPropertyName - )] - [string] $Name - ) - - $body = @{ - owner = $Owner - repo = $Repo - environment_name = $Name - } - - $inputObject = @{ - APIEndpoint = "/repos/$Owner/$Repo/environments/$Name" - Method = 'PUT' - Body = $body - } - - (Invoke-GitHubAPI @inputObject).Response - -} diff --git a/tools/utilities/GitHubAPI.ps1 b/tools/utilities/GitHubAPI.ps1 index e5c20db2c..272bfa514 100644 --- a/tools/utilities/GitHubAPI.ps1 +++ b/tools/utilities/GitHubAPI.ps1 @@ -21,8 +21,8 @@ $response = Invoke-RestMethod -Uri $APIDocURI -Method Get # @{n = 'PUT'; e = { (($_.value.psobject.Properties.Name) -contains 'PUT') } }, ` # @{n = 'PATCH'; e = { (($_.value.psobject.Properties.Name) -contains 'PATCH') } } | Format-Table -$path = '/repos/{owner}/{repo}/actions/runs/{run_id}' -$method = 'delete' +$path = '/repositories/{repository_id}/environments/{environment_name}/secrets/{secret_name}' +$method = 'get' $response.paths.$path.$method $response.paths.$path.$method.tags | clip # -> Namespace/foldername $response.paths.$path.$method.operationId | clip # -> FunctionName From 84ab255b514f9a312512f333e47fc9cb82379d72 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 26 Oct 2023 07:40:10 +0200 Subject: [PATCH 054/193] exempt the all switch --- src/GitHub/public/Organization/Get-GitHubOrganization.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 b/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 index f296340cd..cc2c2183d 100644 --- a/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 +++ b/src/GitHub/public/Organization/Get-GitHubOrganization.ps1 @@ -34,6 +34,7 @@ #> [OutputType([pscustomobject])] [CmdletBinding(DefaultParameterSetName = '__DefaultSet')] + [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', 'All', Justification = 'Required for parameter set')] param ( # The organization name. The name is not case sensitive. [Parameter( From 610a81925f7bdc6ae83293e84d81ec6ecb883c0e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 26 Oct 2023 07:50:06 +0200 Subject: [PATCH 055/193] fix URL of unblock user from organization --- .../Organization/Blocking/Unblock-GitHubUserByOrganization.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GitHub/private/Organization/Blocking/Unblock-GitHubUserByOrganization.ps1 b/src/GitHub/private/Organization/Blocking/Unblock-GitHubUserByOrganization.ps1 index 3e8d208cd..14637373a 100644 --- a/src/GitHub/private/Organization/Blocking/Unblock-GitHubUserByOrganization.ps1 +++ b/src/GitHub/private/Organization/Blocking/Unblock-GitHubUserByOrganization.ps1 @@ -40,7 +40,7 @@ ) $inputObject = @{ - APIEndpoint = "/user/blocks/$Username" + APIEndpoint = "/orgs/$OrganizationName/blocks/$Username" Method = 'DELETE' } From 30cf03dde7cf71cf1c92e49872a204c68f3a9c3c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 26 Oct 2023 08:10:43 +0200 Subject: [PATCH 056/193] Fixes --- src/GitHub/data/Auth.psd1 | 4 +-- .../Invoke-GitHubDeviceFlowLogin.ps1 | 1 + .../private/Config/Initialize-SecretVault.ps1 | 20 +++++++------- .../private/Config/Reset-GitHubConfig.ps1 | 6 +++-- .../Gitignore/Get-GitHubGitignoreList.ps1 | 3 ++- .../License/Get-GitHubLicenseByName.ps1 | 1 + .../private/License/Get-GitHubLicenseList.ps1 | 1 + .../License/Get-GitHubRepositoryLicense.ps1 | 2 +- .../Block-GitHubUserByOrganization.ps1 | 3 ++- .../Test-GitHubBlockedUserByOrganization.ps1 | 3 ++- .../Get-GitHubAllOrganization.ps1 | 4 ++- .../Organization/Get-GitHubMyOrganization.ps1 | 6 ++++- .../Get-GitHubOrganizationByName.ps1 | 12 ++++++--- .../Get-GitHubUserOrganization.ps1 | 8 ++++-- .../Assets/Get-GitHubReleaseAssetByID.ps1 | 6 +++-- .../Repositories/Get-GitHubMyRepositories.ps1 | 27 +++++++++++++------ .../Blocking/Get-GitHubBlockedUserByUser.ps1 | 2 +- .../Blocking/Test-GitHubBlockedUserByUser.ps1 | 4 ++- .../Users/Emails/Get-GitHubUserAllEmail.ps1 | 5 ++-- .../Emails/Get-GitHubUserPublicEmail.ps1 | 7 +++-- .../Followers/Get-GitHubUserMyFollowers.ps1 | 1 + .../Users/GPG-Keys/Get-GitHubUserMyGpgKey.ps1 | 3 ++- .../GPG-Keys/Get-GitHubUserMyGpgKeyById.ps1 | 3 ++- .../Users/Keys/Get-GitHubUserMyKey.ps1 | 3 ++- .../Users/Keys/Get-GitHubUserMyKeyById.ps1 | 3 ++- .../Get-GitHubUserMySigningKey.ps1 | 5 ++-- .../Get-GitHubMyUserSocials.ps1 | 1 + src/GitHub/public/API/Invoke-GitHubAPI.ps1 | 12 ++++----- tools/utilities/GitHubAPI.ps1 | 8 +++--- 29 files changed, 106 insertions(+), 58 deletions(-) diff --git a/src/GitHub/data/Auth.psd1 b/src/GitHub/data/Auth.psd1 index 9a306d5c6..98d42943a 100644 --- a/src/GitHub/data/Auth.psd1 +++ b/src/GitHub/data/Auth.psd1 @@ -1,8 +1,8 @@ @{ - GitHubApp = @{ + GitHubApp = @{ ClientID = 'Iv1.f26b61bc99e69405' # $script:Auth.GitHubApp.ClientID } - OAuthApp = @{ + OAuthApp = @{ ClientID = '7204ae9b0580f2cb8288' # $script:Auth.OAuthApp.ClientID } AccessTokenGracePeriodInHours = 4 diff --git a/src/GitHub/private/Auth/DeviceFlow/Invoke-GitHubDeviceFlowLogin.ps1 b/src/GitHub/private/Auth/DeviceFlow/Invoke-GitHubDeviceFlowLogin.ps1 index 6bc64b2d6..1fc237268 100644 --- a/src/GitHub/private/Auth/DeviceFlow/Invoke-GitHubDeviceFlowLogin.ps1 +++ b/src/GitHub/private/Auth/DeviceFlow/Invoke-GitHubDeviceFlowLogin.ps1 @@ -18,6 +18,7 @@ https://docs.github.com/apps/oauth-apps/building-oauth-apps/authorizing-oauth-apps#device-flow #> [OutputType([void])] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Justification = 'Is the CLI part of the module.')] [CmdletBinding()] param( # The Client ID of the GitHub App. diff --git a/src/GitHub/private/Config/Initialize-SecretVault.ps1 b/src/GitHub/private/Config/Initialize-SecretVault.ps1 index b17dee6f6..e39dd3d90 100644 --- a/src/GitHub/private/Config/Initialize-SecretVault.ps1 +++ b/src/GitHub/private/Config/Initialize-SecretVault.ps1 @@ -4,21 +4,21 @@ function Initialize-SecretVault { <# - .SYNOPSIS - Initialize a secret vault. + .SYNOPSIS + Initialize a secret vault. - .DESCRIPTION - Initialize a secret vault. If the vault does not exist, it will be created. + .DESCRIPTION + Initialize a secret vault. If the vault does not exist, it will be created. - .EXAMPLE - Initialize-SecretVault -Name 'SecretStore' -Type 'Microsoft.PowerShell.SecretStore' + .EXAMPLE + Initialize-SecretVault -Name 'SecretStore' -Type 'Microsoft.PowerShell.SecretStore' - Initializes a secret vault named 'SecretStore' using the 'Microsoft.PowerShell.SecretStore' module. + Initializes a secret vault named 'SecretStore' using the 'Microsoft.PowerShell.SecretStore' module. - .NOTES - For more information about secret vaults, see https://learn.microsoft.com/en-us/powershell/utility-modules/secretmanagement/overview?view=ps-modules + .NOTES + For more information about secret vaults, see + https://learn.microsoft.com/en-us/powershell/utility-modules/secretmanagement/overview?view=ps-modules #> - [OutputType([void])] [CmdletBinding()] param ( diff --git a/src/GitHub/private/Config/Reset-GitHubConfig.ps1 b/src/GitHub/private/Config/Reset-GitHubConfig.ps1 index 54f0933bc..5bba90f60 100644 --- a/src/GitHub/private/Config/Reset-GitHubConfig.ps1 +++ b/src/GitHub/private/Config/Reset-GitHubConfig.ps1 @@ -18,7 +18,7 @@ #> [Alias('Reset-GHConfig')] [OutputType([void])] - [CmdletBinding()] + [CmdletBinding(SupportsShouldProcess)] param( # Reset the GitHub configuration for a specific scope. [Parameter()] @@ -58,5 +58,7 @@ } } } - Set-GitHubConfig @Settings + if ($PSCmdlet.ShouldProcess("Module config", "Reset")) { + Set-GitHubConfig @Settings + } } diff --git a/src/GitHub/private/Gitignore/Get-GitHubGitignoreList.ps1 b/src/GitHub/private/Gitignore/Get-GitHubGitignoreList.ps1 index a00a29a2f..d4a7e3ab5 100644 --- a/src/GitHub/private/Gitignore/Get-GitHubGitignoreList.ps1 +++ b/src/GitHub/private/Gitignore/Get-GitHubGitignoreList.ps1 @@ -4,7 +4,8 @@ filter Get-GitHubGitignoreList { Get all gitignore templates .DESCRIPTION - List all templates available to pass as an option when [creating a repository](https://docs.github.com/rest/repos/repos#create-a-repository-for-the-authenticated-user). + List all templates available to pass as an option when + [creating a repository](https://docs.github.com/rest/repos/repos#create-a-repository-for-the-authenticated-user). .EXAMPLE Get-GitHubGitignoreList diff --git a/src/GitHub/private/License/Get-GitHubLicenseByName.ps1 b/src/GitHub/private/License/Get-GitHubLicenseByName.ps1 index f8534d8b4..77afc3d7a 100644 --- a/src/GitHub/private/License/Get-GitHubLicenseByName.ps1 +++ b/src/GitHub/private/License/Get-GitHubLicenseByName.ps1 @@ -16,6 +16,7 @@ filter Get-GitHubLicenseByName { https://docs.github.com/rest/licenses/licenses#get-a-license #> + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Contains a long link.')] [CmdletBinding()] param ( # The license keyword, license name, or license SPDX ID. For example, mit or mpl-2.0. diff --git a/src/GitHub/private/License/Get-GitHubLicenseList.ps1 b/src/GitHub/private/License/Get-GitHubLicenseList.ps1 index 8086c12e7..9caba4260 100644 --- a/src/GitHub/private/License/Get-GitHubLicenseList.ps1 +++ b/src/GitHub/private/License/Get-GitHubLicenseList.ps1 @@ -16,6 +16,7 @@ filter Get-GitHubLicenseList { https://docs.github.com/rest/licenses/licenses#get-all-commonly-used-licenses #> + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Contains a long link.')] [OutputType([string[]])] [CmdletBinding()] param () diff --git a/src/GitHub/private/License/Get-GitHubRepositoryLicense.ps1 b/src/GitHub/private/License/Get-GitHubRepositoryLicense.ps1 index aea2bc04e..403c62a8f 100644 --- a/src/GitHub/private/License/Get-GitHubRepositoryLicense.ps1 +++ b/src/GitHub/private/License/Get-GitHubRepositoryLicense.ps1 @@ -38,7 +38,7 @@ filter Get-GitHubRepositoryLicense { Invoke-GitHubAPI @inputObject | ForEach-Object { $Response = $_.Response - $rawContent = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($Response.content)) + $rawContent = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($Response.content)) $Response | Add-Member -NotePropertyName 'raw_content' -NotePropertyValue $rawContent -Force $Response } diff --git a/src/GitHub/private/Organization/Blocking/Block-GitHubUserByOrganization.ps1 b/src/GitHub/private/Organization/Blocking/Block-GitHubUserByOrganization.ps1 index 14ffea29f..4097f4bf1 100644 --- a/src/GitHub/private/Organization/Blocking/Block-GitHubUserByOrganization.ps1 +++ b/src/GitHub/private/Organization/Blocking/Block-GitHubUserByOrganization.ps1 @@ -4,7 +4,8 @@ Block a user from an organization .DESCRIPTION - Blocks the given user on behalf of the specified organization and returns a 204. If the organization cannot block the given user a 422 is returned. + Blocks the given user on behalf of the specified organization and returns a 204. + If the organization cannot block the given user a 422 is returned. .EXAMPLE Block-GitHubUserByOrganization -OrganizationName 'github' -Username 'octocat' diff --git a/src/GitHub/private/Organization/Blocking/Test-GitHubBlockedUserByOrganization.ps1 b/src/GitHub/private/Organization/Blocking/Test-GitHubBlockedUserByOrganization.ps1 index 231a29ea3..7f44bdc38 100644 --- a/src/GitHub/private/Organization/Blocking/Test-GitHubBlockedUserByOrganization.ps1 +++ b/src/GitHub/private/Organization/Blocking/Test-GitHubBlockedUserByOrganization.ps1 @@ -4,7 +4,8 @@ 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. + 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 Test-GitHubBlockedUserByOrganization -OrganizationName 'PSModule' -Username 'octocat' diff --git a/src/GitHub/private/Organization/Get-GitHubAllOrganization.ps1 b/src/GitHub/private/Organization/Get-GitHubAllOrganization.ps1 index 8461eac52..924b7f4b1 100644 --- a/src/GitHub/private/Organization/Get-GitHubAllOrganization.ps1 +++ b/src/GitHub/private/Organization/Get-GitHubAllOrganization.ps1 @@ -6,7 +6,8 @@ .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. + **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-GitHubAllOrganization -Since 142951047 @@ -18,6 +19,7 @@ #> [OutputType([pscustomobject])] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Contains a long link.')] [CmdletBinding()] param ( # A organization ID. Only return organizations with an ID greater than this ID. diff --git a/src/GitHub/private/Organization/Get-GitHubMyOrganization.ps1 b/src/GitHub/private/Organization/Get-GitHubMyOrganization.ps1 index 885031b14..353aadda9 100644 --- a/src/GitHub/private/Organization/Get-GitHubMyOrganization.ps1 +++ b/src/GitHub/private/Organization/Get-GitHubMyOrganization.ps1 @@ -8,7 +8,11 @@ **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. + 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 diff --git a/src/GitHub/private/Organization/Get-GitHubOrganizationByName.ps1 b/src/GitHub/private/Organization/Get-GitHubOrganizationByName.ps1 index 1e7c140fd..9e5517b04 100644 --- a/src/GitHub/private/Organization/Get-GitHubOrganizationByName.ps1 +++ b/src/GitHub/private/Organization/Get-GitHubOrganizationByName.ps1 @@ -4,9 +4,15 @@ 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." + 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' diff --git a/src/GitHub/private/Organization/Get-GitHubUserOrganization.ps1 b/src/GitHub/private/Organization/Get-GitHubUserOrganization.ps1 index 196605a7d..068a72ae0 100644 --- a/src/GitHub/private/Organization/Get-GitHubUserOrganization.ps1 +++ b/src/GitHub/private/Organization/Get-GitHubUserOrganization.ps1 @@ -4,9 +4,13 @@ List organizations for a user .DESCRIPTION - List [public organization memberships](https://docs.github.com/articles/publicizing-or-concealing-organization-membership) for the specified user. + 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. + 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-GitHubUserOrganization -Username 'octocat' diff --git a/src/GitHub/private/Releases/Assets/Get-GitHubReleaseAssetByID.ps1 b/src/GitHub/private/Releases/Assets/Get-GitHubReleaseAssetByID.ps1 index 98a405a4e..8eae21487 100644 --- a/src/GitHub/private/Releases/Assets/Get-GitHubReleaseAssetByID.ps1 +++ b/src/GitHub/private/Releases/Assets/Get-GitHubReleaseAssetByID.ps1 @@ -4,8 +4,10 @@ Get a release asset .DESCRIPTION - To download the asset's binary content, set the `Accept` header of the request to [`application/octet-stream`](https://docs.github.com/rest/overview/media-types). - The API will either redirect the client to the location, or stream it directly if possible. API clients should handle both a `200` or `302` response. + To download the asset's binary content, set the `Accept` header of the request to + [`application/octet-stream`](https://docs.github.com/rest/overview/media-types). + The API will either redirect the client to the location, or stream it directly if + possible. API clients should handle both a `200` or `302` response. .EXAMPLE Get-GitHubReleaseAssetByID -Owner 'octocat' -Repo 'hello-world' -ID '1234567' diff --git a/src/GitHub/private/Repositories/Repositories/Get-GitHubMyRepositories.ps1 b/src/GitHub/private/Repositories/Repositories/Get-GitHubMyRepositories.ps1 index 1ad2c106d..257b71993 100644 --- a/src/GitHub/private/Repositories/Repositories/Get-GitHubMyRepositories.ps1 +++ b/src/GitHub/private/Repositories/Repositories/Get-GitHubMyRepositories.ps1 @@ -5,8 +5,8 @@ .DESCRIPTION Lists repositories that the authenticated user has explicit permission (`:read`, `:write`, or `:admin`) to access. - The authenticated user has explicit permission to access repositories they own, repositories where they are a collaborator, - and repositories that they can access through an organization membership. + The authenticated user has explicit permission to access repositories they own, repositories where + they are a collaborator, and repositories that they can access through an organization membership. .EXAMPLE Get-GitHubMyRepositories @@ -19,11 +19,21 @@ Gets the private repositories for the authenticated user. .EXAMPLE - Get-GitHubMyRepositories -Visibility 'public' -Affiliation 'owner','collaborator' -Sort 'created' -Direction 'asc' -PerPage 100 -Since (Get-Date).AddYears(-5) -Before (Get-Date).AddDays(-1) + $param = @{ + Visibility = 'public' + Affiliation = 'owner','collaborator' + Sort = 'created' + Direction = 'asc' + PerPage = 100 + Since = (Get-Date).AddYears(-5) + Before = (Get-Date).AddDays(-1) + } + Get-GitHubMyRepositories @param - Gets the public repositories for the authenticated user that are owned by the authenticated user or that the authenticated user has been added to as a collaborator. - The results are sorted by creation date in ascending order and the results are limited to 100 repositories. - The results are limited to repositories created between 5 years ago and 1 day ago. + Gets the public repositories for the authenticated user that are owned by the authenticated user + or that the authenticated user has been added to as a collaborator. The results are sorted by + creation date in ascending order and the results are limited to 100 repositories. The results + are limited to repositories created between 5 years ago and 1 day ago. .EXAMPLE Get-GitHubMyRepositories -Type 'forks' @@ -45,8 +55,8 @@ #> [CmdletBinding(DefaultParameterSetName = 'Type')] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', Justification = 'Private function, not exposed to user.')] param ( - # Limit results to repositories with the specified visibility. [Parameter( ParameterSetName = 'Aff-Vis' @@ -57,7 +67,8 @@ # Comma-separated list of values. Can include: # - owner: Repositories that are owned by the authenticated user. # - collaborator: Repositories that the user has been added to as a collaborator. - # - organization_member: Repositories that the user has access to through being a member of an organization. This includes every repository on every team that the user is on. + # - organization_member: Repositories that the user has access to through being a member of an organization. + # This includes every repository on every team that the user is on. # Default: owner, collaborator, organization_member [Parameter( ParameterSetName = 'Aff-Vis' diff --git a/src/GitHub/private/Users/Blocking/Get-GitHubBlockedUserByUser.ps1 b/src/GitHub/private/Users/Blocking/Get-GitHubBlockedUserByUser.ps1 index 6fbad3725..35d8a55fd 100644 --- a/src/GitHub/private/Users/Blocking/Get-GitHubBlockedUserByUser.ps1 +++ b/src/GitHub/private/Users/Blocking/Get-GitHubBlockedUserByUser.ps1 @@ -26,7 +26,7 @@ $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case $inputObject = @{ - APIEndpoint = "/user/blocks" + APIEndpoint = '/user/blocks' Method = 'GET' Body = $body } diff --git a/src/GitHub/private/Users/Blocking/Test-GitHubBlockedUserByUser.ps1 b/src/GitHub/private/Users/Blocking/Test-GitHubBlockedUserByUser.ps1 index 5807f28ce..5b7525e35 100644 --- a/src/GitHub/private/Users/Blocking/Test-GitHubBlockedUserByUser.ps1 +++ b/src/GitHub/private/Users/Blocking/Test-GitHubBlockedUserByUser.ps1 @@ -4,7 +4,9 @@ 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. + Returns a 204 if the given user is blocked by the authenticated user. + Returns a 404 if the given user is not blocked by the authenticated user, + or if the given user account has been identified as spam by GitHub. .EXAMPLE Test-GitHubBlockedUserByUser -Username 'octocat' diff --git a/src/GitHub/private/Users/Emails/Get-GitHubUserAllEmail.ps1 b/src/GitHub/private/Users/Emails/Get-GitHubUserAllEmail.ps1 index 732f5c38f..02709351d 100644 --- a/src/GitHub/private/Users/Emails/Get-GitHubUserAllEmail.ps1 +++ b/src/GitHub/private/Users/Emails/Get-GitHubUserAllEmail.ps1 @@ -4,7 +4,8 @@ List email addresses for the authenticated user .DESCRIPTION - Lists all of your email addresses, and specifies which one is visible to the public. This endpoint is accessible with the `user:email` scope. + Lists all of your email addresses, and specifies which one is visible to the public. + This endpoint is accessible with the `user:email` scope. .EXAMPLE Get-GitHubUserAllEmail @@ -27,7 +28,7 @@ $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case $inputObject = @{ - APIEndpoint = "/user/emails" + APIEndpoint = '/user/emails' Method = 'GET' Body = $body } diff --git a/src/GitHub/private/Users/Emails/Get-GitHubUserPublicEmail.ps1 b/src/GitHub/private/Users/Emails/Get-GitHubUserPublicEmail.ps1 index b81229bec..26fa21c20 100644 --- a/src/GitHub/private/Users/Emails/Get-GitHubUserPublicEmail.ps1 +++ b/src/GitHub/private/Users/Emails/Get-GitHubUserPublicEmail.ps1 @@ -4,7 +4,9 @@ List public email addresses for the authenticated user .DESCRIPTION - Lists your publicly visible email address, which you can set with the [Set primary email visibility for the authenticated user](https://docs.github.com/rest/users/emails#set-primary-email-visibility-for-the-authenticated-user) endpoint. This endpoint is accessible with the `user:email` scope. + Lists your publicly visible email address, which you can set with the + [Set primary email visibility for the authenticated user](https://docs.github.com/rest/users/emails#set-primary-email-visibility-for-the-authenticated-user) + endpoint. This endpoint is accessible with the `user:email` scope. .EXAMPLE Get-GitHubUserPublicEmail @@ -16,6 +18,7 @@ #> [OutputType([pscustomobject])] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Link to documentation.')] [CmdletBinding()] param ( # The number of results per page (max 100). @@ -27,7 +30,7 @@ $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case $inputObject = @{ - APIEndpoint = "/user/public_emails" + APIEndpoint = '/user/public_emails' Method = 'GET' Body = $body } diff --git a/src/GitHub/private/Users/Followers/Get-GitHubUserMyFollowers.ps1 b/src/GitHub/private/Users/Followers/Get-GitHubUserMyFollowers.ps1 index ec0668974..9edf72d65 100644 --- a/src/GitHub/private/Users/Followers/Get-GitHubUserMyFollowers.ps1 +++ b/src/GitHub/private/Users/Followers/Get-GitHubUserMyFollowers.ps1 @@ -16,6 +16,7 @@ #> [OutputType([pscustomobject])] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', Justification = 'Private function, not exposed to user.')] [CmdletBinding()] param ( # The number of results per page (max 100). diff --git a/src/GitHub/private/Users/GPG-Keys/Get-GitHubUserMyGpgKey.ps1 b/src/GitHub/private/Users/GPG-Keys/Get-GitHubUserMyGpgKey.ps1 index ba53b2422..1d41bec40 100644 --- a/src/GitHub/private/Users/GPG-Keys/Get-GitHubUserMyGpgKey.ps1 +++ b/src/GitHub/private/Users/GPG-Keys/Get-GitHubUserMyGpgKey.ps1 @@ -5,7 +5,8 @@ .DESCRIPTION Lists the current user's GPG keys. - Requires that you are authenticated via Basic Auth or via OAuth with at least `read:gpg_key` [scope](https://docs.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/). + Requires that you are authenticated via Basic Auth or via OAuth with at least `read:gpg_key` + [scope](https://docs.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/). .EXAMPLE Get-GitHubUserMyGpgKey diff --git a/src/GitHub/private/Users/GPG-Keys/Get-GitHubUserMyGpgKeyById.ps1 b/src/GitHub/private/Users/GPG-Keys/Get-GitHubUserMyGpgKeyById.ps1 index 37970f68c..1e6b5f872 100644 --- a/src/GitHub/private/Users/GPG-Keys/Get-GitHubUserMyGpgKeyById.ps1 +++ b/src/GitHub/private/Users/GPG-Keys/Get-GitHubUserMyGpgKeyById.ps1 @@ -5,7 +5,8 @@ .DESCRIPTION View extended details for a single GPG key. - Requires that you are authenticated via Basic Auth or via OAuth with at least `read:gpg_key` [scope](https://docs.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/). + Requires that you are authenticated via Basic Auth or via OAuth with at least `read:gpg_key` + [scope](https://docs.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/). .EXAMPLE Get-GitHubUserMyGpgKeyById -ID '1234567' diff --git a/src/GitHub/private/Users/Keys/Get-GitHubUserMyKey.ps1 b/src/GitHub/private/Users/Keys/Get-GitHubUserMyKey.ps1 index f1a79153e..711d125c5 100644 --- a/src/GitHub/private/Users/Keys/Get-GitHubUserMyKey.ps1 +++ b/src/GitHub/private/Users/Keys/Get-GitHubUserMyKey.ps1 @@ -5,7 +5,8 @@ .DESCRIPTION Lists the public SSH keys for the authenticated user's GitHub account. - Requires that you are authenticated via Basic Auth or via OAuth with at least `read:public_key` [scope](https://docs.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/). + Requires that you are authenticated via Basic Auth or via OAuth with at least `read:public_key` + [scope](https://docs.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/). .EXAMPLE Get-GitHubUserMyKey diff --git a/src/GitHub/private/Users/Keys/Get-GitHubUserMyKeyById.ps1 b/src/GitHub/private/Users/Keys/Get-GitHubUserMyKeyById.ps1 index a3728756f..793098551 100644 --- a/src/GitHub/private/Users/Keys/Get-GitHubUserMyKeyById.ps1 +++ b/src/GitHub/private/Users/Keys/Get-GitHubUserMyKeyById.ps1 @@ -5,7 +5,8 @@ .DESCRIPTION View extended details for a single public SSH key. - Requires that you are authenticated via Basic Auth or via OAuth with at least `read:public_key` [scope](https://docs.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/). + Requires that you are authenticated via Basic Auth or via OAuth with at least `read:public_key` + [scope](https://docs.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/). .EXAMPLE Get-GitHubUserMyKeyById -ID '1234567' diff --git a/src/GitHub/private/Users/SSH-Signing-Keys/Get-GitHubUserMySigningKey.ps1 b/src/GitHub/private/Users/SSH-Signing-Keys/Get-GitHubUserMySigningKey.ps1 index a406934d5..df562ad1b 100644 --- a/src/GitHub/private/Users/SSH-Signing-Keys/Get-GitHubUserMySigningKey.ps1 +++ b/src/GitHub/private/Users/SSH-Signing-Keys/Get-GitHubUserMySigningKey.ps1 @@ -4,8 +4,9 @@ List SSH signing keys for the authenticated user .DESCRIPTION - Lists the SSH signing keys for the authenticated user's GitHub account. - You must authenticate with Basic Authentication, or you must authenticate with OAuth with at least `read:ssh_signing_key` scope. For more information, see "[Understanding scopes for OAuth apps](https://docs.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/)." + Lists the SSH signing keys for the authenticated user's GitHub account. You must authenticate with + Basic Authentication, or you must authenticate with OAuth with at least `read:ssh_signing_key` scope. For more information, see + "[Understanding scopes for OAuth apps](https://docs.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/)." .EXAMPLE Get-GitHubUserMySigningKey diff --git a/src/GitHub/private/Users/Social-Accounts/Get-GitHubMyUserSocials.ps1 b/src/GitHub/private/Users/Social-Accounts/Get-GitHubMyUserSocials.ps1 index 0d229fc3b..717ec15fb 100644 --- a/src/GitHub/private/Users/Social-Accounts/Get-GitHubMyUserSocials.ps1 +++ b/src/GitHub/private/Users/Social-Accounts/Get-GitHubMyUserSocials.ps1 @@ -15,6 +15,7 @@ https://docs.github.com/rest/users/social-accounts#list-social-accounts-for-the-authenticated-user #> [OutputType([pscustomobject])] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', Justification = 'Private function, not exposed to user.')] [CmdletBinding()] param ( # The number of results per page (max 100). diff --git a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 index 49d2d5213..35f0c8167 100644 --- a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 +++ b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 @@ -90,8 +90,6 @@ $AccessToken = (Get-GitHubConfig -Name AccessToken) } - $functionName = $MyInvocation.MyCommand.Name - $headers = @{ Accept = $Accept 'X-GitHub-Api-Version' = $Version @@ -158,10 +156,10 @@ Write-Verbose '----------------------------------' Write-Verbose "StatusCode: $statusCode" Write-Verbose '----------------------------------' - Write-Verbose "Request:" + Write-Verbose 'Request:' $APICall | ConvertFrom-HashTable | Format-List | Out-String -Stream | Write-Verbose Write-Verbose '----------------------------------' - Write-Verbose "ResponseHeaders:" + Write-Verbose 'ResponseHeaders:' $responseHeaders | Format-List | Out-String -Stream | Write-Verbose Write-Verbose '----------------------------------' @@ -173,13 +171,13 @@ } } } catch { - Write-Error "Request:" + Write-Error 'Request:' $APICall | ConvertFrom-HashTable | Format-List | Out-String -Stream | Write-Error - Write-Error "Message:" + Write-Error 'Message:' $_.Exception.Message | ConvertFrom-HashTable | Format-List | Out-String -Stream | Write-Error - Write-Error "Response:" + Write-Error 'Response:' $_.Exception.Response | ConvertFrom-HashTable | Format-List | Out-String -Stream | Write-Error throw $errorMessage } diff --git a/tools/utilities/GitHubAPI.ps1 b/tools/utilities/GitHubAPI.ps1 index 272bfa514..70f95bc42 100644 --- a/tools/utilities/GitHubAPI.ps1 +++ b/tools/utilities/GitHubAPI.ps1 @@ -42,11 +42,11 @@ $response.paths.$path.$method.responses.'200'.content.'application/json'.schema. $response.components.schemas.PSobject.Properties | ForEach-Object { [pscustomobject]@{ - Name = $_.Name - Title = $_.Value.title - Type = $_.Value.type + Name = $_.Name + Title = $_.Value.title + Type = $_.Value.type Properties = $_.Value.properties - Required = $_.Value.required + Required = $_.Value.required } } From acd6b2f0b6b13545ca006df3e0b8b7e6089ef07d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 26 Oct 2023 22:09:06 +0200 Subject: [PATCH 057/193] fix issue --- src/GitHub/public/Releases/Releases/Get-GitHubRelease.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/src/GitHub/public/Releases/Releases/Get-GitHubRelease.ps1 b/src/GitHub/public/Releases/Releases/Get-GitHubRelease.ps1 index 203f50649..978b1a2d6 100644 --- a/src/GitHub/public/Releases/Releases/Get-GitHubRelease.ps1 +++ b/src/GitHub/public/Releases/Releases/Get-GitHubRelease.ps1 @@ -34,6 +34,7 @@ #> [CmdletBinding(DefaultParameterSetName = 'All')] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', 'Latest', Justification = 'Required for parameter set')] param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] From bf8ca06f94521729ac46bbbc0d0028f5def6241a Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 26 Oct 2023 22:15:20 +0200 Subject: [PATCH 058/193] fix Get-GitHubWorkflow --- src/GitHub/public/Actions/Get-GitHubWorkflow.ps1 | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/GitHub/public/Actions/Get-GitHubWorkflow.ps1 b/src/GitHub/public/Actions/Get-GitHubWorkflow.ps1 index 8666aad4f..15f0b5692 100644 --- a/src/GitHub/public/Actions/Get-GitHubWorkflow.ps1 +++ b/src/GitHub/public/Actions/Get-GitHubWorkflow.ps1 @@ -29,12 +29,6 @@ [Parameter()] [string] $Repo = (Get-GitHubConfig -Name Repo), - [Parameter(ParameterSetName = 'ByName')] - [string] $Name, - - [Parameter(ParameterSetName = 'ByID')] - [string] $ID, - # The number of results per page (max 100). [Parameter()] [ValidateRange(1, 100)] From 64b8b84ab13634470b468f262f4ce93c70f65d3f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 26 Oct 2023 22:16:17 +0200 Subject: [PATCH 059/193] 2fix $RunID --- src/GitHub/public/Actions/Remove-GitHubWorkflowRun.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GitHub/public/Actions/Remove-GitHubWorkflowRun.ps1 b/src/GitHub/public/Actions/Remove-GitHubWorkflowRun.ps1 index af9340f50..b24047ab9 100644 --- a/src/GitHub/public/Actions/Remove-GitHubWorkflowRun.ps1 +++ b/src/GitHub/public/Actions/Remove-GitHubWorkflowRun.ps1 @@ -36,7 +36,7 @@ ) $inputObject = @{ - APIEndpoint = "repos/$Owner/$Repo/actions/runs/$ID" + APIEndpoint = "repos/$Owner/$Repo/actions/runs/$RunID" Method = 'DELETE' } From c23457274ee8267da4804b50864fa7b02ff0bd48 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 26 Oct 2023 22:21:39 +0200 Subject: [PATCH 060/193] fix --- src/GitHub/public/Auth/Connect-GitHubAccount.ps1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/GitHub/public/Auth/Connect-GitHubAccount.ps1 b/src/GitHub/public/Auth/Connect-GitHubAccount.ps1 index 64b771674..9b0b5eda0 100644 --- a/src/GitHub/public/Auth/Connect-GitHubAccount.ps1 +++ b/src/GitHub/public/Auth/Connect-GitHubAccount.ps1 @@ -41,6 +41,9 @@ [Alias('Login-GitHub')] [Alias('Login-GH')] [OutputType([void])] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', 'AccessToken', Justification = 'Required for parameter set')] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Justification = 'Is the CLI part of the module.')] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Justification = 'Is the CLI part of the module.')] [CmdletBinding(DefaultParameterSetName = 'DeviceFlow')] param ( # Choose between authentication methods, either OAuthApp or GitHubApp. From 0790b4ee3682f1a946024215aae8e824e03176a7 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 26 Oct 2023 22:27:01 +0200 Subject: [PATCH 061/193] fix PSReviewUnusedParameter --- src/GitHub/public/Users/Get-GitHubUser.ps1 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/GitHub/public/Users/Get-GitHubUser.ps1 b/src/GitHub/public/Users/Get-GitHubUser.ps1 index 9b4d6fb1d..34fd51c58 100644 --- a/src/GitHub/public/Users/Get-GitHubUser.ps1 +++ b/src/GitHub/public/Users/Get-GitHubUser.ps1 @@ -27,6 +27,11 @@ https://docs.github.com/rest/users/users #> [OutputType([pscustomobject])] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSReviewUnusedParameter', + 'All', + Justification = 'Parameter is used in dynamic parameter validation.' + )] [CmdletBinding(DefaultParameterSetName = '__DefaultSet')] param ( # The handle for the GitHub user account. From b32ce7354b92fdae90ccae256a8ebae48aa63039 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 26 Oct 2023 22:37:04 +0200 Subject: [PATCH 062/193] cleanup --- .../Repositories/New-GitHubRepositoryOrg.ps1 | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 b/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 index 698902e99..97a1dee2d 100644 --- a/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 +++ b/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 @@ -39,13 +39,25 @@ Desired language or platform .gitignore template to apply. Use the name of the template without the extension. For example, "Haskell". .PARAMETER LicenseTemplate - Choose an open source license template that best suits your needs, and then use the license keyword as the license_template string. For example, "mit" or "mpl-2.0". + Choose an open source license template that best suits your needs, and then use the license keyword as the license_template string. + For example, "mit" or "mpl-2.0". .NOTES https://docs.github.com/rest/repos/repos#create-an-organization-repository #> - [CmdletBinding()] + [OutputType([pscustomobject])] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSUseDeclaredVarsMoreThanAssignments', + 'GitignoreTemplate', + Justification = 'Parameter is used in dynamic parameter validation.' + )] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSUseDeclaredVarsMoreThanAssignments', + 'LicenseTemplate', + Justification = 'Parameter is used in dynamic parameter validation.' + )] + [CmdletBinding(SupportsShouldProcess)] param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] @@ -76,7 +88,8 @@ [switch] $HasIssues, # Either true to enable projects for this repository or false to disable them. - # Note: If you're creating a repository in an organization that has disabled repository projects, the default is false, and if you pass true, the API returns an error. + # Note: If you're creating a repository in an organization that has disabled repository projects, the default is false, + # and if you pass true, the API returns an error. [Parameter()] [Alias('has_projects')] [switch] $HasProjects, @@ -126,7 +139,8 @@ [Alias('allow_auto_merge')] [switch] $AllowAutoMerge, - # Either true to allow automatically deleting head branches when pull requests are merged, or false to prevent automatic deletion. The authenticated user must be an organization owner to set this property to true. + # Either true to allow automatically deleting head branches when pull requests are merged, or false to prevent automatic deletion. + # The authenticated user must be an organization owner to set this property to true. [Parameter()] [Alias('delete_branch_on_merge')] [switch] $DeleteBranchOnMerge, @@ -196,7 +210,6 @@ } Process { - $PSCmdlet.MyInvocation.MyCommand.Parameters.GetEnumerator() | ForEach-Object { $paramName = $_.Key $paramDefaultValue = Get-Variable -Name $paramName -ValueOnly -ErrorAction SilentlyContinue @@ -236,8 +249,10 @@ Body = $body } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + if ($PSCmdlet.ShouldProcess("Repository in organization $Owner", "Create")) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } } } From 7dc9efb78e72ad030ba131c006f9ec90c2aaf470 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 26 Oct 2023 22:43:24 +0200 Subject: [PATCH 063/193] fixes --- .../Repositories/New-GitHubRepositoryUser.ps1 | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryUser.ps1 b/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryUser.ps1 index c8e90f3aa..5e87c1056 100644 --- a/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryUser.ps1 +++ b/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryUser.ps1 @@ -44,7 +44,17 @@ https://docs.github.com/rest/repos/repos#create-a-repository-for-the-authenticated-user #> - [CmdletBinding()] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSUseDeclaredVarsMoreThanAssignments', + 'GitignoreTemplate', + Justification = 'Parameter is used in dynamic parameter validation.' + )] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSUseDeclaredVarsMoreThanAssignments', + 'LicenseTemplate', + Justification = 'Parameter is used in dynamic parameter validation.' + )] + [CmdletBinding(SupportsShouldProcess)] param ( # The name of the repository. [Parameter(Mandatory)] @@ -234,8 +244,10 @@ Body = $body } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + if ($PSCmdlet.ShouldProcess("Repository for user", 'Create')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } } } From 056948b437fdc99bf98afe2e3e530f31b460e010 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 26 Oct 2023 22:56:42 +0200 Subject: [PATCH 064/193] fix issues --- .../Repositories/Get-GitHubRepositoryByName.ps1 | 1 + .../Repositories/Get-GitHubRepositoryListByID.ps1 | 4 +++- .../Repositories/Get-GitHubRepositoryListByOrg.ps1 | 1 + .../Releases/Assets/Set-GitHubReleaseAsset.ps1 | 5 +++-- .../public/Releases/Releases/New-GitHubRelease.ps1 | 3 ++- .../public/Releases/Releases/Set-GitHubRelease.ps1 | 6 +++--- .../Repositories/Get-GitHubRepository.ps1 | 3 ++- .../Repositories/Get-GitHubRepositoryActivity.ps1 | 14 +++++++++++--- .../Get-GitHubRepositoryCodeownersError.ps1 | 1 + .../Get-GitHubRepositoryContributor.ps1 | 9 ++++++--- .../Get-GitHubRepositorySecurityFixes.ps1 | 6 ++++-- 11 files changed, 37 insertions(+), 16 deletions(-) diff --git a/src/GitHub/private/Repositories/Repositories/Get-GitHubRepositoryByName.ps1 b/src/GitHub/private/Repositories/Repositories/Get-GitHubRepositoryByName.ps1 index 73799dd76..a37e81f12 100644 --- a/src/GitHub/private/Repositories/Repositories/Get-GitHubRepositoryByName.ps1 +++ b/src/GitHub/private/Repositories/Repositories/Get-GitHubRepositoryByName.ps1 @@ -20,6 +20,7 @@ #> [CmdletBinding()] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Contains a long link.')] param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] diff --git a/src/GitHub/private/Repositories/Repositories/Get-GitHubRepositoryListByID.ps1 b/src/GitHub/private/Repositories/Repositories/Get-GitHubRepositoryListByID.ps1 index 0251d90ad..ab2695799 100644 --- a/src/GitHub/private/Repositories/Repositories/Get-GitHubRepositoryListByID.ps1 +++ b/src/GitHub/private/Repositories/Repositories/Get-GitHubRepositoryListByID.ps1 @@ -8,7 +8,9 @@ Note: - For GitHub Enterprise Server, this endpoint will only list repositories available to all users on the enterprise. - - 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 repositories. + - 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 repositories. .EXAMPLE Get-GitHubRepositoryListByID -Since '123456789 diff --git a/src/GitHub/private/Repositories/Repositories/Get-GitHubRepositoryListByOrg.ps1 b/src/GitHub/private/Repositories/Repositories/Get-GitHubRepositoryListByOrg.ps1 index 7ec25bf2b..f9cafc59e 100644 --- a/src/GitHub/private/Repositories/Repositories/Get-GitHubRepositoryListByOrg.ps1 +++ b/src/GitHub/private/Repositories/Repositories/Get-GitHubRepositoryListByOrg.ps1 @@ -29,6 +29,7 @@ #> [CmdletBinding()] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Contains a long link.')] param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] diff --git a/src/GitHub/public/Releases/Assets/Set-GitHubReleaseAsset.ps1 b/src/GitHub/public/Releases/Assets/Set-GitHubReleaseAsset.ps1 index 48ac2ec3a..5834d5574 100644 --- a/src/GitHub/public/Releases/Assets/Set-GitHubReleaseAsset.ps1 +++ b/src/GitHub/public/Releases/Assets/Set-GitHubReleaseAsset.ps1 @@ -9,7 +9,8 @@ .EXAMPLE Set-GitHubReleaseAsset -Owner 'octocat' -Repo 'hello-world' -ID '1234567' -Name 'new_asset_name' -Label 'new_asset_label' - Updates the release asset with the ID '1234567' for the repository 'octocat/hello-world' with the new name 'new_asset_name' and label 'new_asset_label'. + Updates the release asset with the ID '1234567' for the repository 'octocat/hello-world' with the new name 'new_asset_name' and + label 'new_asset_label'. .NOTES https://docs.github.com/rest/releases/assets#update-a-release-asset @@ -46,7 +47,7 @@ ) $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner', 'Repo','ID' + Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner', 'Repo', 'ID' $inputObject = @{ APIEndpoint = "/repos/$Owner/$Repo/releases/assets/$ID" diff --git a/src/GitHub/public/Releases/Releases/New-GitHubRelease.ps1 b/src/GitHub/public/Releases/Releases/New-GitHubRelease.ps1 index bcc92f02e..c31cdcef2 100644 --- a/src/GitHub/public/Releases/Releases/New-GitHubRelease.ps1 +++ b/src/GitHub/public/Releases/Releases/New-GitHubRelease.ps1 @@ -20,6 +20,7 @@ #> [OutputType([pscustomobject])] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Contains a long link.')] [CmdletBinding()] param ( # The account owner of the repository. The name is not case sensitive. @@ -79,7 +80,7 @@ $requestBody = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case Remove-HashtableEntries -Hashtable $requestBody -RemoveNames 'Owner', 'Repo', 'GenerateReleaseNotes', 'Draft', 'Prerelease' - $requestBody = Join-Object -AsHashtable -Main $requestBody -Overrides @{ + $requestBody = Join-Object -AsHashtable -Main $requestBody -Overrides @{ generate_release_notes = $GenerateReleaseNotes.IsPresent draft = $Draft.IsPresent prerelease = $Prerelease.IsPresent diff --git a/src/GitHub/public/Releases/Releases/Set-GitHubRelease.ps1 b/src/GitHub/public/Releases/Releases/Set-GitHubRelease.ps1 index e11478bc0..730570dd1 100644 --- a/src/GitHub/public/Releases/Releases/Set-GitHubRelease.ps1 +++ b/src/GitHub/public/Releases/Releases/Set-GitHubRelease.ps1 @@ -75,9 +75,9 @@ $requestBody = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case Remove-HashtableEntries -Hashtable $requestBody -RemoveNames 'Owner', 'Repo', 'Draft', 'Prerelease' - $requestBody = Join-Object -AsHashtable -Main $requestBody -Overrides @{ - draft = $Draft.IsPresent ? $Draft : $false - prerelease = $Prerelease.IsPresent ? $Prerelease : $false + $requestBody = Join-Object -AsHashtable -Main $requestBody -Overrides @{ + draft = $Draft.IsPresent ? $Draft : $false + prerelease = $Prerelease.IsPresent ? $Prerelease : $false } $inputObject = @{ diff --git a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepository.ps1 b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepository.ps1 index e8b8c86c1..9d178daa0 100644 --- a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepository.ps1 +++ b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepository.ps1 @@ -57,7 +57,8 @@ # Comma-separated list of values. Can include: # - owner: Repositories that are owned by the authenticated user. # - collaborator: Repositories that the user has been added to as a collaborator. - # - organization_member: Repositories that the user has access to through being a member of an organization. This includes every repository on every team that the user is on. + # - organization_member: Repositories that the user has access to through being a member of an organization. + # This includes every repository on every team that the user is on. # Default: owner, collaborator, organization_member [Parameter(ParameterSetName = 'MyRepos_Aff-Vis')] [ValidateSet('owner', 'collaborator', 'organization_member')] diff --git a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryActivity.ps1 b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryActivity.ps1 index baf0d69a5..d6875bdbc 100644 --- a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryActivity.ps1 +++ b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryActivity.ps1 @@ -4,7 +4,8 @@ List repository activities .DESCRIPTION - Lists a detailed history of changes to a repository, such as pushes, merges, force pushes, and branch changes, and associates these changes with commits and users. + Lists a detailed history of changes to a repository, such as pushes, merges, force pushes, and branch changes, + and associates these changes with commits and users. For more information about viewing repository activity, see "[Viewing activity and data for your repository](https://docs.github.com/repositories/viewing-activity-and-data-for-your-repository)." @@ -31,7 +32,13 @@ Get-GitHubRepositoryActivity -Owner 'PSModule' -Repo 'GitHub' -Actor 'octocat' .EXAMPLE - Get-GitHubRepositoryActivity -Owner 'PSModule' -Repo 'GitHub' -TimePeriod 'day' | Select-Object -Property @{n='actor';e={$_.actor.login}},activity_type,ref,timestamp + $params = @{ + Owner = 'PSModule' + Repo = 'GitHub' + TimePeriod = 'day' + } + Get-GitHubRepositoryActivity @params | + Select-Object -Property @{n='actor';e={$_.actor.login}},activity_type,ref,timestamp Gets the activity for the past 24 hours and selects the actor, activity type, ref, and timestamp. @@ -83,7 +90,8 @@ [string] $Actor, # The time period to filter by. - # For example,day will filter for activity that occurred in the past 24 hours, and week will filter for activity that occurred in the past 7 days (168 hours). + # For example,day will filter for activity that occurred in the past 24 hours, + # and week will filter for activity that occurred in the past 7 days (168 hours). [Parameter()] [ValidateSet('day', 'week', 'month', 'quarter', 'year')] [Alias('time_period')] diff --git a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryCodeownersError.ps1 b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryCodeownersError.ps1 index 33b800c7d..a9504bfd5 100644 --- a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryCodeownersError.ps1 +++ b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryCodeownersError.ps1 @@ -19,6 +19,7 @@ #> [CmdletBinding()] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Contains a long link.')] param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] diff --git a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryContributor.ps1 b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryContributor.ps1 index 59e512786..b87a7be75 100644 --- a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryContributor.ps1 +++ b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryContributor.ps1 @@ -4,9 +4,12 @@ List repository contributors .DESCRIPTION - Lists contributors to the specified repository and sorts them by the number of commits per contributor in descending order. This endpoint may return information that is a few hours old because the GitHub REST API caches contributor data to improve performance. + Lists contributors to the specified repository and sorts them by the number of commits per contributor in descending order. + This endpoint may return information that is a few hours old because the GitHub REST API caches contributor data to improve performance. - GitHub identifies contributors by author email address. This endpoint groups contribution counts by GitHub user, which includes all associated email addresses. To improve performance, only the first 500 author email addresses in the repository link to GitHub users. The rest will appear as anonymous contributors without associated GitHub user information. + GitHub identifies contributors by author email address. This endpoint groups contribution counts by GitHub user, + which includes all associated email addresses. To improve performance, only the first 500 author email addresses + in the repository link to GitHub users. The rest will appear as anonymous contributors without associated GitHub user information. .EXAMPLE Get-GitHubRepositoryContributor -Owner 'PSModule' -Repo 'GitHub' @@ -39,7 +42,7 @@ ) $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner','Repo' -RemoveTypes 'SwitchParameter' + Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner', 'Repo' -RemoveTypes 'SwitchParameter' $inputObject = @{ APIEndpoint = "/repos/$Owner/$Repo/contributors" diff --git a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositorySecurityFixes.ps1 b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositorySecurityFixes.ps1 index 396e8c487..a26bcd92e 100644 --- a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositorySecurityFixes.ps1 +++ b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositorySecurityFixes.ps1 @@ -4,7 +4,9 @@ Check if automated security fixes are enabled for a repository .DESCRIPTION - Shows whether automated security fixes are enabled, disabled or paused for a repository. The authenticated user must have admin read access to the repository. For more information, see "[Configuring automated security fixes](https://docs.github.com/articles/configuring-automated-security-fixes)". + Shows whether automated security fixes are enabled, disabled or paused for a repository. + The authenticated user must have admin read access to the repository. For more information, see + "[Configuring automated security fixes](https://docs.github.com/articles/configuring-automated-security-fixes)". .EXAMPLE Get-GitHubRepositorySecurityFixes -Owner 'PSModule' -Repo 'GitHub' @@ -28,7 +30,7 @@ ) $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner','Repo' -RemoveTypes 'SwitchParameter' + Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner', 'Repo' -RemoveTypes 'SwitchParameter' $inputObject = @{ APIEndpoint = "/repos/$Owner/$Repo/automated-security-fixes" From 747c50c34f0835a8c454257b2317f8afd4f868d7 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 27 Oct 2023 17:49:30 +0200 Subject: [PATCH 065/193] fix --- tools/utilities/StopWorkflowsCustom.ps1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/utilities/StopWorkflowsCustom.ps1 b/tools/utilities/StopWorkflowsCustom.ps1 index b73b89246..ea7c787e3 100644 --- a/tools/utilities/StopWorkflowsCustom.ps1 +++ b/tools/utilities/StopWorkflowsCustom.ps1 @@ -35,7 +35,7 @@ Get-GitHubRepoTeams (Get-GitHubWorkflow).count -Get-GitHubWorkflow | Select-Object -first 1 -Property * +Get-GitHubWorkflow | Select-Object -First 1 -Property * Get-GitHubWorkflow | Select-Object Name, state Get-GitHubWorkflow | Where-Object state -NE disabled_manually | Disable-GitHubWorkflow @@ -58,12 +58,12 @@ Get-GitHubWorkflowRun | Remove-GitHubWorkflowRun Get-GitHubWorkflowRun | Select-Object -Property name, display_title, created_at, run_started_at, updated_at, @{name = 'duration'; expression = { $_.updated_at - $_.run_started_at } }, @{name = 'wait_duration'; expression = { $_.updated_at - $_.created_at } } | Format-Table -AutoSize -Get-GitHubWorkflowRun | Where-Object run_started_at -le (Get-Date).AddDays(-1) | Remove-GitHubWorkflowRun +Get-GitHubWorkflowRun | Where-Object run_started_at -LE (Get-Date).AddDays(-1) | Remove-GitHubWorkflowRun Get-GitHubWorkflow | Where-Object name -NotLike '.*' | Start-GitHubWorkflow -Inputs @{ - staticValidation = $true + staticValidation = $true deploymentValidation = $false - removeDeployment = $true - prerelease = $false + removeDeployment = $true + prerelease = $false } From 9c2b4e1619a69e03c1229f7d956a975f39033324 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 27 Oct 2023 18:58:25 +0200 Subject: [PATCH 066/193] Fix shouldprocess --- .../private/Utilities/DynamicParam/New-DynamicParam.ps1 | 2 ++ .../Utilities/DynamicParam/New-DynamicParamDictionary.ps1 | 4 ++++ src/GitHub/public/Releases/Releases/New-GitHubRelease.ps1 | 6 ++++-- .../public/Releases/Releases/New-GitHubReleaseNotes.ps1 | 6 ++++-- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/GitHub/private/Utilities/DynamicParam/New-DynamicParam.ps1 b/src/GitHub/private/Utilities/DynamicParam/New-DynamicParam.ps1 index 139332e2b..2ce8a706b 100644 --- a/src/GitHub/private/Utilities/DynamicParam/New-DynamicParam.ps1 +++ b/src/GitHub/private/Utilities/DynamicParam/New-DynamicParam.ps1 @@ -17,6 +17,8 @@ # https://learn.microsoft.com/en-us/dotnet/api/system.management.automation.runtimedefinedparameter.value?view=powershellsdk-7.3.0 #> [OutputType([void])] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Long links')] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Justification = 'Function does not change state.')] [CmdletBinding()] param( # Specifies the name of the parameter. diff --git a/src/GitHub/private/Utilities/DynamicParam/New-DynamicParamDictionary.ps1 b/src/GitHub/private/Utilities/DynamicParam/New-DynamicParamDictionary.ps1 index 302a26345..78d11e2b5 100644 --- a/src/GitHub/private/Utilities/DynamicParam/New-DynamicParamDictionary.ps1 +++ b/src/GitHub/private/Utilities/DynamicParam/New-DynamicParamDictionary.ps1 @@ -12,6 +12,10 @@ Returns a new RuntimeDefinedParameterDictionary #> [OutputType([System.Management.Automation.RuntimeDefinedParameterDictionary])] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSUseShouldProcessForStateChangingFunctions', '', + Justification = 'Function does not change state.' + )] [CmdletBinding()] param() diff --git a/src/GitHub/public/Releases/Releases/New-GitHubRelease.ps1 b/src/GitHub/public/Releases/Releases/New-GitHubRelease.ps1 index c31cdcef2..25435edb0 100644 --- a/src/GitHub/public/Releases/Releases/New-GitHubRelease.ps1 +++ b/src/GitHub/public/Releases/Releases/New-GitHubRelease.ps1 @@ -21,7 +21,7 @@ #> [OutputType([pscustomobject])] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Contains a long link.')] - [CmdletBinding()] + [CmdletBinding(SupportsShouldProcess)] param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] @@ -93,6 +93,8 @@ Body = $requestBody } - (Invoke-GitHubAPI @inputObject).Response + if ($PSCmdlet.ShouldProcess("$Owner/$Repo", 'Create a release')) { + (Invoke-GitHubAPI @inputObject).Response + } } diff --git a/src/GitHub/public/Releases/Releases/New-GitHubReleaseNotes.ps1 b/src/GitHub/public/Releases/Releases/New-GitHubReleaseNotes.ps1 index 841d53e1a..48d86f30d 100644 --- a/src/GitHub/public/Releases/Releases/New-GitHubReleaseNotes.ps1 +++ b/src/GitHub/public/Releases/Releases/New-GitHubReleaseNotes.ps1 @@ -54,7 +54,7 @@ #> [OutputType([pscustomobject])] [Alias('Generate-GitHubReleaseNotes')] - [CmdletBinding()] + [CmdletBinding(SupportsShouldProcess)] param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] @@ -101,6 +101,8 @@ Body = $body } - (Invoke-GitHubAPI @inputObject).Response + if ($PSCmdlet.ShouldProcess("$Owner/$Repo", 'Create release notes')) { + (Invoke-GitHubAPI @inputObject).Response + } } From 107c7b569e1de99029f37ad96dbb9f27f9cf9ff3 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 27 Oct 2023 19:06:51 +0200 Subject: [PATCH 067/193] fix should process --- .../private/Utilities/Hashtable/Remove-HashTableEntries.ps1 | 5 +++++ src/GitHub/public/Releases/Releases/Set-GitHubRelease.ps1 | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/GitHub/private/Utilities/Hashtable/Remove-HashTableEntries.ps1 b/src/GitHub/private/Utilities/Hashtable/Remove-HashTableEntries.ps1 index 30a24a763..8d7d4802f 100644 --- a/src/GitHub/private/Utilities/Hashtable/Remove-HashTableEntries.ps1 +++ b/src/GitHub/private/Utilities/Hashtable/Remove-HashTableEntries.ps1 @@ -19,6 +19,11 @@ Remove keys with null or empty values #> [OutputType([void])] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSUseShouldProcessForStateChangingFunctions', + '', + Justification = 'Function does not change state.' + )] [CmdletBinding()] param ( # The hashtable to remove entries from. diff --git a/src/GitHub/public/Releases/Releases/Set-GitHubRelease.ps1 b/src/GitHub/public/Releases/Releases/Set-GitHubRelease.ps1 index 730570dd1..26d6fc35d 100644 --- a/src/GitHub/public/Releases/Releases/Set-GitHubRelease.ps1 +++ b/src/GitHub/public/Releases/Releases/Set-GitHubRelease.ps1 @@ -16,7 +16,7 @@ #> [OutputType([pscustomobject])] - [CmdletBinding()] + [CmdletBinding(SupportsShouldProcess)] param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] @@ -86,6 +86,8 @@ Body = $requestBody } - (Invoke-GitHubAPI @inputObject).Response + if ($PSCmdlet.ShouldProcess("release with ID [$ID] in [$Owner/$Repo]", "Update")) { + (Invoke-GitHubAPI @inputObject).Response + } } From 95e23f62e2ad61758359501f2b3d5b602164c837 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 27 Oct 2023 19:14:56 +0200 Subject: [PATCH 068/193] Fix --- .../public/Releases/Assets/Remove-GitHubReleaseAsset.ps1 | 6 ++++-- .../public/Releases/Releases/Remove-GitHubRelease.ps1 | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/GitHub/public/Releases/Assets/Remove-GitHubReleaseAsset.ps1 b/src/GitHub/public/Releases/Assets/Remove-GitHubReleaseAsset.ps1 index d232ee047..8e28b115a 100644 --- a/src/GitHub/public/Releases/Assets/Remove-GitHubReleaseAsset.ps1 +++ b/src/GitHub/public/Releases/Assets/Remove-GitHubReleaseAsset.ps1 @@ -15,7 +15,7 @@ https://docs.github.com/rest/releases/assets#delete-a-release-asset #> - [CmdletBinding()] + [CmdletBinding(SupportsShouldProcess)] param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] @@ -36,6 +36,8 @@ Method = 'DELETE' } - (Invoke-GitHubAPI @inputObject).Response + if ($PSCmdlet.ShouldProcess("Asset with ID [$ID] in [$Owner/$Repo]", 'Delete')) { + (Invoke-GitHubAPI @inputObject).Response + } } diff --git a/src/GitHub/public/Releases/Releases/Remove-GitHubRelease.ps1 b/src/GitHub/public/Releases/Releases/Remove-GitHubRelease.ps1 index 836fd519b..49bb78422 100644 --- a/src/GitHub/public/Releases/Releases/Remove-GitHubRelease.ps1 +++ b/src/GitHub/public/Releases/Releases/Remove-GitHubRelease.ps1 @@ -16,7 +16,7 @@ #> [OutputType([pscustomobject])] - [CmdletBinding()] + [CmdletBinding(SupportsShouldProcess)] param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] @@ -39,6 +39,8 @@ Method = 'DELETE' } - (Invoke-GitHubAPI @inputObject).Response + if ($PSCmdlet.ShouldProcess("Release with ID [$ID] in [$Owner/$Repo]", "Delete")) { + (Invoke-GitHubAPI @inputObject).Response + } } From e5515a53d23c681e38cb16be528d34bd0b752b73 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 27 Oct 2023 19:18:52 +0200 Subject: [PATCH 069/193] fix should process --- .../public/Releases/Assets/Set-GitHubReleaseAsset.ps1 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/GitHub/public/Releases/Assets/Set-GitHubReleaseAsset.ps1 b/src/GitHub/public/Releases/Assets/Set-GitHubReleaseAsset.ps1 index 5834d5574..052e7a5cb 100644 --- a/src/GitHub/public/Releases/Assets/Set-GitHubReleaseAsset.ps1 +++ b/src/GitHub/public/Releases/Assets/Set-GitHubReleaseAsset.ps1 @@ -14,9 +14,8 @@ .NOTES https://docs.github.com/rest/releases/assets#update-a-release-asset - #> - [CmdletBinding()] + [CmdletBinding(SupportsShouldProcess)] param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] @@ -55,6 +54,8 @@ Body = $requestBody } - (Invoke-GitHubAPI @inputObject).Response + if ($PSCmdlet.ShouldProcess("assets for release with ID [$ID] in [$Owner/$Repo]", 'Set')) { + (Invoke-GitHubAPI @inputObject).Response + } } From 40fb591ea0d322bc487bd67b93a762e5cf564c3f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 27 Oct 2023 19:22:53 +0200 Subject: [PATCH 070/193] Fix should process --- src/GitHub/public/Actions/Remove-GitHubWorkflowRun.ps1 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/GitHub/public/Actions/Remove-GitHubWorkflowRun.ps1 b/src/GitHub/public/Actions/Remove-GitHubWorkflowRun.ps1 index b24047ab9..c14589d09 100644 --- a/src/GitHub/public/Actions/Remove-GitHubWorkflowRun.ps1 +++ b/src/GitHub/public/Actions/Remove-GitHubWorkflowRun.ps1 @@ -16,7 +16,7 @@ .NOTES https://docs.github.com/rest/actions/workflow-runs#delete-a-workflow-run #> - [CmdletBinding()] + [CmdletBinding(SupportsShouldProcess)] param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] @@ -40,6 +40,8 @@ Method = 'DELETE' } - (Invoke-GitHubAPI @inputObject).Response + if ($PSCmdlet.ShouldProcess("workflow run with ID [$RunID] in [$Owner/$Repo]", "Delete")) { + (Invoke-GitHubAPI @inputObject).Response + } } From e5044230a676e2f1ec9107cb44a44ecb48d376f5 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 27 Oct 2023 19:31:49 +0200 Subject: [PATCH 071/193] fixed param doc and should process --- .../Actions/Start-GitHubWorkflowReRun.ps1 | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/GitHub/public/Actions/Start-GitHubWorkflowReRun.ps1 b/src/GitHub/public/Actions/Start-GitHubWorkflowReRun.ps1 index 3d4ae80b6..b0b5f1865 100644 --- a/src/GitHub/public/Actions/Start-GitHubWorkflowReRun.ps1 +++ b/src/GitHub/public/Actions/Start-GitHubWorkflowReRun.ps1 @@ -1,34 +1,28 @@ filter Start-GitHubWorkflowReRun { <# .SYNOPSIS - Short description + Re-run a workflow .DESCRIPTION - Long description - - .PARAMETER Owner - Parameter description - - .PARAMETER Repo - Parameter description - - .PARAMETER ID - Parameter description + Re-runs your workflow run using its `run_id`. You can also specify a branch or tag name to re-run a workflow run from a branch .EXAMPLE - An example + Start-GitHubWorkflowReRun -Owner 'octocat' -Repo 'Hello-World' -ID 123456789 .NOTES https://docs.github.com/rest/reference/actions#re-run-a-workflow #> [CmdletBinding()] param ( + # The account owner of the repository. The name is not case sensitive. [Parameter()] [string] $Owner = (Get-GitHubConfig -Name Owner), + # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] [string] $Repo = (Get-GitHubConfig -Name Repo), + # The unique identifier of the workflow run. [Alias('workflow_id')] [Parameter( Mandatory, @@ -42,6 +36,8 @@ APIEndpoint = "/repos/$Owner/$Repo/actions/runs/$ID/rerun" } - (Invoke-GitHubAPI @inputObject).Response + if ($PSCmdlet.ShouldProcess("workflow with ID [$ID] in [$Owner/$Repo]", 'Re-run')) { + (Invoke-GitHubAPI @inputObject).Response + } } From 2faf1ff9e6af01159f0c4713189b2f49bda36555 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 27 Oct 2023 19:43:33 +0200 Subject: [PATCH 072/193] fix should process --- src/GitHub/public/Actions/Start-GitHubWorkflowReRun.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GitHub/public/Actions/Start-GitHubWorkflowReRun.ps1 b/src/GitHub/public/Actions/Start-GitHubWorkflowReRun.ps1 index b0b5f1865..0c88288b7 100644 --- a/src/GitHub/public/Actions/Start-GitHubWorkflowReRun.ps1 +++ b/src/GitHub/public/Actions/Start-GitHubWorkflowReRun.ps1 @@ -12,7 +12,7 @@ .NOTES https://docs.github.com/rest/reference/actions#re-run-a-workflow #> - [CmdletBinding()] + [CmdletBinding(SupportsShouldProcess)] param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] From 39ecaae1d60a81e4cedba7911a1d1db77cb9379b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 27 Oct 2023 19:46:10 +0200 Subject: [PATCH 073/193] fix should process --- .../public/Actions/Stop-GitHubWorkflowRun.ps1 | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/GitHub/public/Actions/Stop-GitHubWorkflowRun.ps1 b/src/GitHub/public/Actions/Stop-GitHubWorkflowRun.ps1 index 7b8eb8ecf..a8713165f 100644 --- a/src/GitHub/public/Actions/Stop-GitHubWorkflowRun.ps1 +++ b/src/GitHub/public/Actions/Stop-GitHubWorkflowRun.ps1 @@ -1,27 +1,20 @@ filter Stop-GitHubWorkflowRun { <# .SYNOPSIS - Short description + Cancel a workflow run .DESCRIPTION - Long description - - .PARAMETER Owner - Parameter description - - .PARAMETER Repo - Parameter description - - .PARAMETER ID - Parameter description + Cancels a workflow run using its `run_id`. You can use this endpoint to cancel a workflow run that is in progress or waiting .EXAMPLE - An example + Stop-GitHubWorkflowRun -Owner 'octocat' -Repo 'Hello-World' -ID 123456789 + + Cancels the workflow run with the ID 123456789 from the 'Hello-World' repository owned by 'octocat' .NOTES https://docs.github.com/rest/reference/actions#cancel-a-workflow-run #> - [CmdletBinding()] + [CmdletBinding(SupportsShouldProcess)] [alias('Cancel-GitHubWorkflowRun')] param ( [Parameter()] @@ -44,6 +37,8 @@ APIEndpoint = "/repos/$Owner/$Repo/actions/runs/$ID/cancel" } - (Invoke-GitHubAPI @inputObject).Response + if ($PSCmdlet.ShouldProcess("workflow run with ID [$ID] in [$Owner/$Repo]", "Cancel/Stop")) { + (Invoke-GitHubAPI @inputObject).Response + } } From c42c058b5f5f55692d2f8f4a724476618adeed2c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 27 Oct 2023 19:53:37 +0200 Subject: [PATCH 074/193] Fix params and shouldprocess --- src/GitHub/public/Actions/Start-GitHubWorkflow.ps1 | 11 +++++++++-- src/GitHub/public/Actions/Stop-GitHubWorkflowRun.ps1 | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/GitHub/public/Actions/Start-GitHubWorkflow.ps1 b/src/GitHub/public/Actions/Start-GitHubWorkflow.ps1 index 1dc3a42a8..bdce42d60 100644 --- a/src/GitHub/public/Actions/Start-GitHubWorkflow.ps1 +++ b/src/GitHub/public/Actions/Start-GitHubWorkflow.ps1 @@ -18,14 +18,17 @@ # API Reference # https://docs.github.com/free-pro-team@latest/rest/actions/workflows?apiVersion=2022-11-28#create-a-workflow-dispatch-event #> - [CmdletBinding()] + [CmdletBinding(SupportsShouldProcess)] param ( + # The account owner of the repository. The name is not case sensitive. [Parameter()] [string] $Owner = (Get-GitHubConfig -Name Owner), + # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] [string] $Repo = (Get-GitHubConfig -Name Repo), + # The ID of the workflow. [Alias('workflow_id')] [Parameter( Mandatory, @@ -33,12 +36,14 @@ )] [string] $ID, + # The reference of the workflow run. The reference can be a branch, tag, or a commit SHA. [Parameter( ValueFromPipelineByPropertyName )] [Alias('branch', 'tag')] [string] $Ref = 'main', + # Input parameters for the workflow run. You can use the inputs and payload keys to pass custom data to your workflow. [Parameter()] [hashtable] $Inputs = @{} ) @@ -54,6 +59,8 @@ Body = $body } - (Invoke-GitHubAPI @inputObject).Response + if ($PSCmdlet.ShouldProcess("workflow with ID [$ID] in [$Owner/$Repo]", "Start")) { + (Invoke-GitHubAPI @inputObject).Response + } } diff --git a/src/GitHub/public/Actions/Stop-GitHubWorkflowRun.ps1 b/src/GitHub/public/Actions/Stop-GitHubWorkflowRun.ps1 index a8713165f..04527fa79 100644 --- a/src/GitHub/public/Actions/Stop-GitHubWorkflowRun.ps1 +++ b/src/GitHub/public/Actions/Stop-GitHubWorkflowRun.ps1 @@ -37,7 +37,7 @@ APIEndpoint = "/repos/$Owner/$Repo/actions/runs/$ID/cancel" } - if ($PSCmdlet.ShouldProcess("workflow run with ID [$ID] in [$Owner/$Repo]", "Cancel/Stop")) { + if ($PSCmdlet.ShouldProcess("workflow run with ID [$ID] in [$Owner/$Repo]", 'Cancel/Stop')) { (Invoke-GitHubAPI @inputObject).Response } From 32f12ee68082d86f123bab9621d54fbd8d8a9b03 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 27 Oct 2023 19:56:03 +0200 Subject: [PATCH 075/193] fix should process and example --- .../Repositories/Set-GitHubRepositoryTopic.ps1 | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/GitHub/public/Repositories/Repositories/Set-GitHubRepositoryTopic.ps1 b/src/GitHub/public/Repositories/Repositories/Set-GitHubRepositoryTopic.ps1 index a194bab50..27313b68c 100644 --- a/src/GitHub/public/Repositories/Repositories/Set-GitHubRepositoryTopic.ps1 +++ b/src/GitHub/public/Repositories/Repositories/Set-GitHubRepositoryTopic.ps1 @@ -7,12 +7,14 @@ Replace all repository topics .EXAMPLE + Set-GitHubRepositoryTopic -Owner 'octocat' -Repo 'hello-world' -Names 'octocat', 'octo', 'octocat/hello-world' + + Replaces all topics for the repository 'octocat/hello-world' with the topics 'octocat', 'octo', 'octocat/hello-world'. .NOTES https://docs.github.com/rest/repos/repos#replace-all-repository-topics - #> - [CmdletBinding()] + [CmdletBinding(SupportsShouldProcess)] param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] @@ -40,7 +42,9 @@ Body = $body } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response.names + if ($PSCmdlet.ShouldProcess("topics for repo [$Owner/$Repo]", "Set")) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response.names + } } } From 40deb4a5147634d85decf57d00083823fb57b6ba Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 27 Oct 2023 20:07:41 +0200 Subject: [PATCH 076/193] Fix ShouldProcess --- .../Repositories/Remove-GitHubRepository.ps1 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/GitHub/public/Repositories/Repositories/Remove-GitHubRepository.ps1 b/src/GitHub/public/Repositories/Repositories/Remove-GitHubRepository.ps1 index 099180627..33df26d47 100644 --- a/src/GitHub/public/Repositories/Repositories/Remove-GitHubRepository.ps1 +++ b/src/GitHub/public/Repositories/Repositories/Remove-GitHubRepository.ps1 @@ -16,9 +16,8 @@ .NOTES https://docs.github.com/rest/repos/repos#delete-a-repository - #> - [CmdletBinding()] + [CmdletBinding(SupportsShouldProcess)] param ( # The account owner of the repository. The name is not case sensitive. [Parameter(Mandatory)] @@ -36,8 +35,10 @@ Method = 'DELETE' } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + if ($PSCmdlet.ShouldProcess("repo [$Owner/$Repo]", "Delete")) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } } From e9b67d12c41814b1c77db8c57fff7ef23ccf80ec Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 27 Oct 2023 20:16:15 +0200 Subject: [PATCH 077/193] Fix should proc --- src/GitHub/public/Config/Set-GitHubConfig.ps1 | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/GitHub/public/Config/Set-GitHubConfig.ps1 b/src/GitHub/public/Config/Set-GitHubConfig.ps1 index 4f23a7b7a..c1b98c884 100644 --- a/src/GitHub/public/Config/Set-GitHubConfig.ps1 +++ b/src/GitHub/public/Config/Set-GitHubConfig.ps1 @@ -17,7 +17,7 @@ Sets a item called 'MyFavouriteRepo' in the GitHub configuration. #> [Alias('Set-GHConfig')] - [CmdletBinding()] + [CmdletBinding(SupportsShouldProcess)] param ( # Set the access token type. [Parameter()] @@ -109,7 +109,9 @@ Vault = $script:SecretVault.Name SecureStringSecret = $AccessToken } - Set-Secret @accessTokenSetParam + if ($PSCmdlet.ShouldProcess("secret [$secretName] in secret vault [$($script:SecretVault.Name)]", 'Set')) { + Set-Secret @accessTokenSetParam + } } if (Get-SecretInfo -Name $secretName) { @@ -118,7 +120,9 @@ Vault = $script:SecretVault.Name Metadata = $newSecretMetadata } - Set-SecretInfo @secretSetInfoParam + if ($PSCmdlet.ShouldProcess("secret [$secretName] in secret vault [$($script:SecretVault.Name)]", 'Set')) { + Set-SecretInfo @secretSetInfoParam + } } #endregion AccessToken @@ -156,7 +160,9 @@ Vault = $script:SecretVault.Name SecureStringSecret = $RefreshToken } - Set-Secret @refreshTokenSetParam + if ($PSCmdlet.ShouldProcess("secret [$secretName] in secret vault [$($script:SecretVault.Name)]", 'Set')) { + Set-Secret @refreshTokenSetParam + } } if (Get-SecretInfo -Name $secretName) { @@ -165,7 +171,9 @@ Vault = $script:SecretVault.Name Metadata = $newSecretMetadata } - Set-SecretInfo @secretSetInfoParam + if ($PSCmdlet.ShouldProcess("secret [$secretName] in secret vault [$($script:SecretVault.Name)]", 'Set')) { + Set-SecretInfo @secretSetInfoParam + } } #endregion AccessToken } From 8c68f81b2908477814a986426d95ac5d591ccfba Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 27 Oct 2023 20:27:35 +0200 Subject: [PATCH 078/193] fix --- .../private/Config/Reset-GitHubConfig.ps1 | 2 +- .../Set-GitHubOrganizationSecurityFeature.ps1 | 35 +++++++++++++++---- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/GitHub/private/Config/Reset-GitHubConfig.ps1 b/src/GitHub/private/Config/Reset-GitHubConfig.ps1 index 5bba90f60..9586c2137 100644 --- a/src/GitHub/private/Config/Reset-GitHubConfig.ps1 +++ b/src/GitHub/private/Config/Reset-GitHubConfig.ps1 @@ -58,7 +58,7 @@ } } } - if ($PSCmdlet.ShouldProcess("Module config", "Reset")) { + if ($PSCmdlet.ShouldProcess('Module config', 'Reset')) { Set-GitHubConfig @Settings } } diff --git a/src/GitHub/public/Organization/Set-GitHubOrganizationSecurityFeature.ps1 b/src/GitHub/public/Organization/Set-GitHubOrganizationSecurityFeature.ps1 index 7a7b88429..765fcbaff 100644 --- a/src/GitHub/public/Organization/Set-GitHubOrganizationSecurityFeature.ps1 +++ b/src/GitHub/public/Organization/Set-GitHubOrganizationSecurityFeature.ps1 @@ -22,7 +22,8 @@ https://docs.github.com/rest/orgs/orgs#enable-or-disable-a-security-feature-for-an-organization #> [OutputType([pscustomobject])] - [CmdletBinding()] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Long link in notes.')] + [CmdletBinding(SupportsShouldProcess)] param ( # The organization name. The name is not case sensitive. [Parameter(Mandatory)] @@ -34,19 +35,37 @@ # 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')] + [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. + # 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)] - [ValidateSet('enable_all', 'disable_all')] + [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. + # 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')] + [ValidateSet( + 'default', + 'extended' + )] [string] $QuerySuite ) @@ -60,6 +79,8 @@ Body = $body } - (Invoke-GitHubAPI @inputObject).Response + if ($PSCmdlet.ShouldProcess("security feature [$SecurityProduct] on organization [$OrganizationName]", "Set")) { + (Invoke-GitHubAPI @inputObject).Response + } } From 910c3a864825dfa11c73b08c2bfe946c1f86fded Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 27 Oct 2023 20:36:13 +0200 Subject: [PATCH 079/193] fix --- .../Organization/Set-GitHubOrganization.ps1 | 58 +++++++++++++------ 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 b/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 index 4f0e3e6b9..2b9b5a55f 100644 --- a/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 +++ b/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 @@ -4,9 +4,14 @@ 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). + **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. + 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' @@ -22,14 +27,15 @@ } Set-GitHubOrganization @param - Sets the repository creation permissions for the organization 'github' to allow all members to create public, private, and internal repositories. + 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()] + [CmdletBinding(SupportsShouldProcess)] param ( # The organization name. The name is not case sensitive. [Parameter( @@ -88,27 +94,36 @@ [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. + # 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(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. + # 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(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. + # 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(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. + # 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(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. + # 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(ValueFromPipelineByPropertyName)] [Alias('members_allowed_repository_creation_type')] [ValidateSet('all', 'private', 'none')] @@ -144,42 +159,48 @@ [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." + # 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(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." + # 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(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." + # 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(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." + # 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(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." + # 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(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." + # 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(ValueFromPipelineByPropertyName)] [Alias('secret_scanning_push_protection_enabled_for_new_repositories')] @@ -190,7 +211,8 @@ [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. + # 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(ValueFromPipelineByPropertyName)] [Alias('secret_scanning_push_protection_custom_link')] [string] $SecretScanningPushProtectionCustomLink @@ -205,6 +227,8 @@ Body = $body } - (Invoke-GitHubAPI @inputObject).Response + if ($PSCmdlet.ShouldProcess("organization [$OrganizationName]", 'Set')) { + (Invoke-GitHubAPI @inputObject).Response + } } From 2d300ea347a0c6d5cc1d1fc4fe88d5b532d9aa50 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 27 Oct 2023 20:54:20 +0200 Subject: [PATCH 080/193] Fix --- .../public/Organization/Remove-GitHubOrganization.ps1 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/GitHub/public/Organization/Remove-GitHubOrganization.ps1 b/src/GitHub/public/Organization/Remove-GitHubOrganization.ps1 index 7789ba0d6..ae0555530 100644 --- a/src/GitHub/public/Organization/Remove-GitHubOrganization.ps1 +++ b/src/GitHub/public/Organization/Remove-GitHubOrganization.ps1 @@ -18,7 +18,7 @@ https://docs.github.com/rest/orgs/orgs#delete-an-organization #> [OutputType([pscustomobject])] - [CmdletBinding()] + [CmdletBinding(SupportsShouldProcess)] param ( # The organization name. The name is not case sensitive. [Parameter( @@ -37,6 +37,8 @@ Method = 'DELETE' } - (Invoke-GitHubAPI @inputObject).Response + if ($PSCmdlet.ShouldProcess("organization [$OrganizationName]", 'Delete')) { + (Invoke-GitHubAPI @inputObject).Response + } } From 9fcb3971fd121b9cfe31d859eb9f1d8df1980686 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 27 Oct 2023 21:03:42 +0200 Subject: [PATCH 081/193] fix --- .../SSH-Signing-Keys/Remove-GitHubUserSigningKey.ps1 | 10 +++++++--- src/GitHub/public/Users/Set-GitHubUser.ps1 | 6 ++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/GitHub/public/Users/SSH-Signing-Keys/Remove-GitHubUserSigningKey.ps1 b/src/GitHub/public/Users/SSH-Signing-Keys/Remove-GitHubUserSigningKey.ps1 index 48a283c3d..ffef30ff1 100644 --- a/src/GitHub/public/Users/SSH-Signing-Keys/Remove-GitHubUserSigningKey.ps1 +++ b/src/GitHub/public/Users/SSH-Signing-Keys/Remove-GitHubUserSigningKey.ps1 @@ -5,7 +5,9 @@ .DESCRIPTION Deletes an SSH signing key from the authenticated user's GitHub account. - You must authenticate with Basic Authentication, or you must authenticate with OAuth with at least `admin:ssh_signing_key` scope. For more information, see "[Understanding scopes for OAuth apps](https://docs.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/)." + You must authenticate with Basic Authentication, or you must authenticate with OAuth with at least + `admin:ssh_signing_key` scope. For more information, see + "[Understanding scopes for OAuth apps](https://docs.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/)." .EXAMPLE Remove-GitHubUserSigningKey -ID '1234567' @@ -17,7 +19,7 @@ #> [OutputType([pscustomobject])] - [CmdletBinding()] + [CmdletBinding(SupportsShouldProcess)] param ( # The unique identifier of the SSH signing key. [Parameter( @@ -32,6 +34,8 @@ Method = 'DELETE' } - $null = (Invoke-GitHubAPI @inputObject).Response + if ($PSCmdlet.ShouldProcess("SSH signing key with ID [$ID]", "Delete")) { + $null = (Invoke-GitHubAPI @inputObject).Response + } } diff --git a/src/GitHub/public/Users/Set-GitHubUser.ps1 b/src/GitHub/public/Users/Set-GitHubUser.ps1 index 99ceabf61..65a2c3943 100644 --- a/src/GitHub/public/Users/Set-GitHubUser.ps1 +++ b/src/GitHub/public/Users/Set-GitHubUser.ps1 @@ -28,7 +28,7 @@ #> [OutputType([void])] [Alias('Update-GitHubUser')] - [CmdletBinding()] + [CmdletBinding(SupportsShouldProcess)] param ( # The new name of the user. [Parameter()] @@ -71,6 +71,8 @@ Method = 'PATCH' } - (Invoke-GitHubAPI @inputObject).Response + if ($PSCmdlet.ShouldProcess('authenticated user', 'Set')) { + (Invoke-GitHubAPI @inputObject).Response + } } From 3d788a4c186855c700797aed6b4a112ab388d787 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 27 Oct 2023 21:09:37 +0200 Subject: [PATCH 082/193] Fix --- .../public/Users/GPG-Keys/Remove-GitHubUserGpgKey.ps1 | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/GitHub/public/Users/GPG-Keys/Remove-GitHubUserGpgKey.ps1 b/src/GitHub/public/Users/GPG-Keys/Remove-GitHubUserGpgKey.ps1 index fac0d3ff2..fcf27ba79 100644 --- a/src/GitHub/public/Users/GPG-Keys/Remove-GitHubUserGpgKey.ps1 +++ b/src/GitHub/public/Users/GPG-Keys/Remove-GitHubUserGpgKey.ps1 @@ -5,7 +5,8 @@ .DESCRIPTION Removes a GPG key from the authenticated user's GitHub account. - Requires that you are authenticated via Basic Auth or via OAuth with at least `admin:gpg_key` [scope](https://docs.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/). + Requires that you are authenticated via Basic Auth or via OAuth with at least `admin:gpg_key` + [scope](https://docs.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/). .EXAMPLE Remove-GitHubUserGpgKey -ID '1234567' @@ -17,7 +18,7 @@ #> [OutputType([pscustomobject])] - [CmdletBinding()] + [CmdletBinding(SupportsShouldProcess)] param ( # The ID of the GPG key. [Parameter( @@ -32,6 +33,8 @@ Method = 'DELETE' } - $null = (Invoke-GitHubAPI @inputObject).Response + if ($PSCmdlet.ShouldProcess("GPG key with ID [$ID]", "Delete")) { + $null = (Invoke-GitHubAPI @inputObject).Response + } } From 5b02d00746b23f7b5666875c5d378f15f7ec0ebb Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 27 Oct 2023 21:10:33 +0200 Subject: [PATCH 083/193] fix hsouldp rocess --- .../public/Users/Followers/Remove-GitHubUserFollowing.ps1 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/GitHub/public/Users/Followers/Remove-GitHubUserFollowing.ps1 b/src/GitHub/public/Users/Followers/Remove-GitHubUserFollowing.ps1 index a601ba0b6..da063a264 100644 --- a/src/GitHub/public/Users/Followers/Remove-GitHubUserFollowing.ps1 +++ b/src/GitHub/public/Users/Followers/Remove-GitHubUserFollowing.ps1 @@ -17,7 +17,7 @@ #> [OutputType([pscustomobject])] [Alias('Unfollow-GitHubUser')] - [CmdletBinding()] + [CmdletBinding(SupportsShouldProcess)] param ( # The handle for the GitHub user account. [Parameter( @@ -33,6 +33,8 @@ Method = 'DELETE' } - $null = (Invoke-GitHubAPI @inputObject).Response + if ($PSCmdlet.ShouldProcess("User [$Username]", "Unfollow")) { + $null = (Invoke-GitHubAPI @inputObject).Response + } } From ec757c0e45ddf99cc117772abcaefe025c91f265 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 27 Oct 2023 21:11:18 +0200 Subject: [PATCH 084/193] Fix --- src/GitHub/public/Users/Emails/Remove-GitHubUserEmail.ps1 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/GitHub/public/Users/Emails/Remove-GitHubUserEmail.ps1 b/src/GitHub/public/Users/Emails/Remove-GitHubUserEmail.ps1 index 271090f22..83fecfcde 100644 --- a/src/GitHub/public/Users/Emails/Remove-GitHubUserEmail.ps1 +++ b/src/GitHub/public/Users/Emails/Remove-GitHubUserEmail.ps1 @@ -16,7 +16,7 @@ #> [OutputType([pscustomobject])] - [CmdletBinding()] + [CmdletBinding(SupportsShouldProcess)] param ( # Email addresses associated with the GitHub user account. [Parameter( @@ -35,6 +35,8 @@ Body = $body } - $null = (Invoke-GitHubAPI @inputObject).Response + if ($PSCmdlet.ShouldProcess("Email addresses [$($Emails -join ', ')]", "Delete")) { + $null = (Invoke-GitHubAPI @inputObject).Response + } } From 9aac440c95550ff20ec6e202a1d9ae54ffc1019e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 27 Oct 2023 21:12:03 +0200 Subject: [PATCH 085/193] fix --- .../public/Users/Emails/Set-GitHubUserEmailVisibility.ps1 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/GitHub/public/Users/Emails/Set-GitHubUserEmailVisibility.ps1 b/src/GitHub/public/Users/Emails/Set-GitHubUserEmailVisibility.ps1 index 598a79522..5e8578759 100644 --- a/src/GitHub/public/Users/Emails/Set-GitHubUserEmailVisibility.ps1 +++ b/src/GitHub/public/Users/Emails/Set-GitHubUserEmailVisibility.ps1 @@ -21,7 +21,7 @@ #> [OutputType([pscustomobject])] - [CmdletBinding()] + [CmdletBinding(SupportsShouldProcess)] param ( # Denotes whether an email is publicly visible. [Parameter( @@ -41,6 +41,8 @@ Body = $body } - (Invoke-GitHubAPI @inputObject).Response + if ($PSCmdlet.ShouldProcess("Email visibility [$Visibility]", "Set")) { + $null = (Invoke-GitHubAPI @inputObject).Response + } } From 8de209bad8a48b526b0cd50b9eb4b66cfb55e362 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 27 Oct 2023 21:13:48 +0200 Subject: [PATCH 086/193] Fix --- src/GitHub/public/Users/Keys/Remove-GitHubUserKey.ps1 | 9 ++++++--- .../Users/Social-Accounts/Remove-GitHubUserSocials.ps1 | 6 ++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/GitHub/public/Users/Keys/Remove-GitHubUserKey.ps1 b/src/GitHub/public/Users/Keys/Remove-GitHubUserKey.ps1 index 0c79573f6..7ac9129a5 100644 --- a/src/GitHub/public/Users/Keys/Remove-GitHubUserKey.ps1 +++ b/src/GitHub/public/Users/Keys/Remove-GitHubUserKey.ps1 @@ -5,7 +5,8 @@ .DESCRIPTION Removes a public SSH key from the authenticated user's GitHub account. - Requires that you are authenticated via Basic Auth or via OAuth with at least `admin:public_key` [scope](https://docs.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/). + Requires that you are authenticated via Basic Auth or via OAuth with at least `admin:public_key` + [scope](https://docs.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/). .EXAMPLE Remove-GitHubUserKey -ID '1234567' @@ -17,7 +18,7 @@ #> [OutputType([pscustomobject])] - [CmdletBinding()] + [CmdletBinding(SupportsShouldProcess)] param ( # The unique identifier of the key. [Parameter( @@ -32,6 +33,8 @@ Method = 'DELETE' } - $null = (Invoke-GitHubAPI @inputObject).Response + if ($PSCmdlet.ShouldProcess("Key with ID [$ID]", "Delete")) { + $null = (Invoke-GitHubAPI @inputObject).Response + } } diff --git a/src/GitHub/public/Users/Social-Accounts/Remove-GitHubUserSocials.ps1 b/src/GitHub/public/Users/Social-Accounts/Remove-GitHubUserSocials.ps1 index c7ca4de98..4e1aabd01 100644 --- a/src/GitHub/public/Users/Social-Accounts/Remove-GitHubUserSocials.ps1 +++ b/src/GitHub/public/Users/Social-Accounts/Remove-GitHubUserSocials.ps1 @@ -16,7 +16,7 @@ https://docs.github.com/rest/users/social-accounts#delete-social-accounts-for-the-authenticated-user #> [OutputType([void])] - [CmdletBinding()] + [CmdletBinding(SupportsShouldProcess)] param ( # Full URLs for the social media profiles to add. [Parameter(Mandatory)] @@ -32,6 +32,8 @@ Method = 'DELETE' } - (Invoke-GitHubAPI @inputObject).Response + if ($PSCmdlet.ShouldProcess("Social accounts [$($AccountUrls -join ', ')]", "Delete")) { + $null = (Invoke-GitHubAPI @inputObject).Response + } } From c61e453f421ceda490fb79e579a4d65c31620303 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 27 Oct 2023 21:35:09 +0200 Subject: [PATCH 087/193] plurals --- .../Assets/Get-GitHubReleaseAssetByReleaseID.ps1 | 2 +- .../Releases/Releases/Get-GitHubReleaseAll.ps1 | 2 +- .../Repositories/Get-GitHubMyRepositories.ps1 | 2 +- .../Repositories/Get-GitHubRepositoryListByOrg.ps1 | 2 +- .../Repositories/Get-GitHubRepositoryListByUser.ps1 | 2 +- .../Followers/Get-GitHubUserFollowersOfUser.ps1 | 2 +- .../Users/Followers/Get-GitHubUserFollowingUser.ps1 | 2 +- .../Users/GPG-Keys/Get-GitHubUserGpgKeyForUser.ps1 | 2 +- .../private/Users/Keys/Get-GitHubUserKeyForUser.ps1 | 2 +- .../Get-GitHubUserSigningKeyForUser.ps1 | 2 +- .../Utilities/Hashtable/Remove-HashTableEntries.ps1 | 4 ++-- src/GitHub/public/API/Invoke-GitHubAPI.ps1 | 4 ++-- src/GitHub/public/Config/Set-GitHubConfig.ps1 | 4 ++-- .../public/Organization/Set-GitHubOrganization.ps1 | 2 +- .../Releases/Assets/Add-GitHubReleaseAsset.ps1 | 4 ++-- .../Releases/Assets/Set-GitHubReleaseAsset.ps1 | 2 +- .../public/Releases/Releases/New-GitHubRelease.ps1 | 4 ++-- .../Releases/Releases/New-GitHubReleaseNotes.ps1 | 2 +- .../public/Releases/Releases/Set-GitHubRelease.ps1 | 2 +- .../Disable-GitHubRepositorySecurityFixes.ps1 | 2 +- .../Enable-GitHubRepositorySecurityFixes.ps1 | 2 +- .../Repositories/Get-GitHubRepository.ps1 | 12 ++++++------ .../Repositories/Get-GitHubRepositoryActivity.ps1 | 2 +- .../Get-GitHubRepositoryCodeownersError.ps1 | 2 +- .../Repositories/Get-GitHubRepositoryContributor.ps1 | 2 +- .../Get-GitHubRepositorySecurityFixes.ps1 | 2 +- .../Repositories/Get-GitHubRepositoryTags.ps1 | 2 +- .../Repositories/Get-GitHubRepositoryTeams.ps1 | 2 +- .../Repositories/Get-GitHubRepositoryTopic.ps1 | 2 +- .../Repositories/Move-GitHubRepository.ps1 | 2 +- .../Repositories/New-GitHubRepositoryOrg.ps1 | 4 ++-- .../Repositories/New-GitHubRepositoryUser.ps1 | 4 ++-- .../Repositories/Set-GitHubRepositoryTopic.ps1 | 2 +- 33 files changed, 45 insertions(+), 45 deletions(-) diff --git a/src/GitHub/private/Releases/Assets/Get-GitHubReleaseAssetByReleaseID.ps1 b/src/GitHub/private/Releases/Assets/Get-GitHubReleaseAssetByReleaseID.ps1 index 6adf119a9..963ff1538 100644 --- a/src/GitHub/private/Releases/Assets/Get-GitHubReleaseAssetByReleaseID.ps1 +++ b/src/GitHub/private/Releases/Assets/Get-GitHubReleaseAssetByReleaseID.ps1 @@ -40,7 +40,7 @@ ) $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner', 'Repo', 'ID' + Remove-HashtableEntry -Hashtable $body -RemoveNames 'Owner', 'Repo', 'ID' $inputObject = @{ APIEndpoint = "/repos/$Owner/$Repo/releases/$ID/assets" diff --git a/src/GitHub/private/Releases/Releases/Get-GitHubReleaseAll.ps1 b/src/GitHub/private/Releases/Releases/Get-GitHubReleaseAll.ps1 index 0c9615146..a445230f2 100644 --- a/src/GitHub/private/Releases/Releases/Get-GitHubReleaseAll.ps1 +++ b/src/GitHub/private/Releases/Releases/Get-GitHubReleaseAll.ps1 @@ -34,7 +34,7 @@ ) $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner', 'Repo' + Remove-HashtableEntry -Hashtable $body -RemoveNames 'Owner', 'Repo' $inputObject = @{ APIEndpoint = "/repos/$Owner/$Repo/releases" diff --git a/src/GitHub/private/Repositories/Repositories/Get-GitHubMyRepositories.ps1 b/src/GitHub/private/Repositories/Repositories/Get-GitHubMyRepositories.ps1 index 257b71993..fa20d1326 100644 --- a/src/GitHub/private/Repositories/Repositories/Get-GitHubMyRepositories.ps1 +++ b/src/GitHub/private/Repositories/Repositories/Get-GitHubMyRepositories.ps1 @@ -119,7 +119,7 @@ } $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntries -Hashtable $body -RemoveNames 'Affiliation', 'Since', 'Before' + Remove-HashtableEntry -Hashtable $body -RemoveNames 'Affiliation', 'Since', 'Before' if ($PSBoundParameters.ContainsKey('Affiliation')) { $body['affiliation'] = $Affiliation -join ',' diff --git a/src/GitHub/private/Repositories/Repositories/Get-GitHubRepositoryListByOrg.ps1 b/src/GitHub/private/Repositories/Repositories/Get-GitHubRepositoryListByOrg.ps1 index f9cafc59e..d6666f478 100644 --- a/src/GitHub/private/Repositories/Repositories/Get-GitHubRepositoryListByOrg.ps1 +++ b/src/GitHub/private/Repositories/Repositories/Get-GitHubRepositoryListByOrg.ps1 @@ -68,7 +68,7 @@ } $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner' + Remove-HashtableEntry -Hashtable $body -RemoveNames 'Owner' $inputObject = @{ APIEndpoint = "/orgs/$Owner/repos" diff --git a/src/GitHub/private/Repositories/Repositories/Get-GitHubRepositoryListByUser.ps1 b/src/GitHub/private/Repositories/Repositories/Get-GitHubRepositoryListByUser.ps1 index dc31410dd..2b00538b1 100644 --- a/src/GitHub/private/Repositories/Repositories/Get-GitHubRepositoryListByUser.ps1 +++ b/src/GitHub/private/Repositories/Repositories/Get-GitHubRepositoryListByUser.ps1 @@ -70,7 +70,7 @@ } $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntries -Hashtable $body -RemoveNames 'Username' + Remove-HashtableEntry -Hashtable $body -RemoveNames 'Username' $inputObject = @{ APIEndpoint = "/users/$Username/repos" diff --git a/src/GitHub/private/Users/Followers/Get-GitHubUserFollowersOfUser.ps1 b/src/GitHub/private/Users/Followers/Get-GitHubUserFollowersOfUser.ps1 index 651148238..e2cc580fb 100644 --- a/src/GitHub/private/Users/Followers/Get-GitHubUserFollowersOfUser.ps1 +++ b/src/GitHub/private/Users/Followers/Get-GitHubUserFollowersOfUser.ps1 @@ -34,7 +34,7 @@ ) $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntries -Hashtable $body -RemoveNames 'username' + Remove-HashtableEntry -Hashtable $body -RemoveNames 'username' $inputObject = @{ APIEndpoint = "/users/$Username/followers" diff --git a/src/GitHub/private/Users/Followers/Get-GitHubUserFollowingUser.ps1 b/src/GitHub/private/Users/Followers/Get-GitHubUserFollowingUser.ps1 index 503eae2ba..ae3685cc0 100644 --- a/src/GitHub/private/Users/Followers/Get-GitHubUserFollowingUser.ps1 +++ b/src/GitHub/private/Users/Followers/Get-GitHubUserFollowingUser.ps1 @@ -34,7 +34,7 @@ ) $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntries -Hashtable $body -RemoveNames 'username' + Remove-HashtableEntry -Hashtable $body -RemoveNames 'username' $inputObject = @{ APIEndpoint = "/users/$Username/following" diff --git a/src/GitHub/private/Users/GPG-Keys/Get-GitHubUserGpgKeyForUser.ps1 b/src/GitHub/private/Users/GPG-Keys/Get-GitHubUserGpgKeyForUser.ps1 index 547c82e28..4817b1005 100644 --- a/src/GitHub/private/Users/GPG-Keys/Get-GitHubUserGpgKeyForUser.ps1 +++ b/src/GitHub/private/Users/GPG-Keys/Get-GitHubUserGpgKeyForUser.ps1 @@ -32,7 +32,7 @@ ) $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntries -Hashtable $body -RemoveNames 'username' + Remove-HashtableEntry -Hashtable $body -RemoveNames 'username' $inputObject = @{ APIEndpoint = "/users/$Username/gpg_keys" diff --git a/src/GitHub/private/Users/Keys/Get-GitHubUserKeyForUser.ps1 b/src/GitHub/private/Users/Keys/Get-GitHubUserKeyForUser.ps1 index 5d8def2aa..213e41c41 100644 --- a/src/GitHub/private/Users/Keys/Get-GitHubUserKeyForUser.ps1 +++ b/src/GitHub/private/Users/Keys/Get-GitHubUserKeyForUser.ps1 @@ -32,7 +32,7 @@ ) $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntries -Hashtable $body -RemoveNames 'username' + Remove-HashtableEntry -Hashtable $body -RemoveNames 'username' $inputObject = @{ APIEndpoint = "/users/$Username/keys" diff --git a/src/GitHub/private/Users/SSH-Signing-Keys/Get-GitHubUserSigningKeyForUser.ps1 b/src/GitHub/private/Users/SSH-Signing-Keys/Get-GitHubUserSigningKeyForUser.ps1 index 8e88966f2..f87025841 100644 --- a/src/GitHub/private/Users/SSH-Signing-Keys/Get-GitHubUserSigningKeyForUser.ps1 +++ b/src/GitHub/private/Users/SSH-Signing-Keys/Get-GitHubUserSigningKeyForUser.ps1 @@ -32,7 +32,7 @@ ) $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntries -Hashtable $body -RemoveNames 'username' + Remove-HashtableEntry -Hashtable $body -RemoveNames 'username' $inputObject = @{ APIEndpoint = "/users/$Username/ssh_signing_keys" diff --git a/src/GitHub/private/Utilities/Hashtable/Remove-HashTableEntries.ps1 b/src/GitHub/private/Utilities/Hashtable/Remove-HashTableEntries.ps1 index 8d7d4802f..fc042b8d8 100644 --- a/src/GitHub/private/Utilities/Hashtable/Remove-HashTableEntries.ps1 +++ b/src/GitHub/private/Utilities/Hashtable/Remove-HashTableEntries.ps1 @@ -1,4 +1,4 @@ -filter Remove-HashtableEntries { +filter Remove-HashtableEntry { <# .SYNOPSIS Remove entries from a hashtable. @@ -14,7 +14,7 @@ 'Key4' = 'Value4' 'Key5' = '' } - $Hashtable | Remove-HashtableEntries -NullOrEmptyValues + $Hashtable | Remove-HashtableEntry -NullOrEmptyValues Remove keys with null or empty values #> diff --git a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 index 35f0c8167..8923c165d 100644 --- a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 +++ b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 @@ -95,7 +95,7 @@ 'X-GitHub-Api-Version' = $Version } - Remove-HashTableEntries -Hashtable $headers -NullOrEmptyValues + Remove-HashtableEntry -Hashtable $headers -NullOrEmptyValues if (-not $URI) { $URI = ("$ApiBaseUri/" -replace '/$', '') + ("/$ApiEndpoint" -replace '^/', '') @@ -133,7 +133,7 @@ OutFile = $DownloadFilePath } - $APICall | Remove-HashTableEntries -NullOrEmptyValues + $APICall | Remove-HashtableEntry -NullOrEmptyValues if ($Body) { # Use body to create the query string for certain situations diff --git a/src/GitHub/public/Config/Set-GitHubConfig.ps1 b/src/GitHub/public/Config/Set-GitHubConfig.ps1 index c1b98c884..ba389cd65 100644 --- a/src/GitHub/public/Config/Set-GitHubConfig.ps1 +++ b/src/GitHub/public/Config/Set-GitHubConfig.ps1 @@ -96,7 +96,7 @@ $updateSecretMetadata = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable Write-Verbose "updateSecretMetadata : $($updateSecretMetadata | Out-String)" Write-Verbose "updateSecretMetadataType : $($updateSecretMetadata.GetType())" - Remove-HashTableEntries -Hashtable $updateSecretMetadata -KeepTypes $keepTypes -RemoveNames $removeKeys + Remove-HashtableEntry -Hashtable $updateSecretMetadata -KeepTypes $keepTypes -RemoveNames $removeKeys Write-Verbose "updateSecretMetadata : $($updateSecretMetadata | Out-String)" $newSecretMetadata = Join-Object -Main $newSecretMetadata -Overrides $updateSecretMetadata -AsHashtable @@ -147,7 +147,7 @@ $updateSecretMetadata = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable Write-Verbose "updateSecretMetadata : $($updateSecretMetadata | Out-String)" Write-Verbose "updateSecretMetadataType : $($updateSecretMetadata.GetType())" - Remove-HashTableEntries -Hashtable $updateSecretMetadata -KeepTypes $keepTypes -RemoveNames $removeKeys + Remove-HashtableEntry -Hashtable $updateSecretMetadata -KeepTypes $keepTypes -RemoveNames $removeKeys Write-Verbose "updateSecretMetadata : $($updateSecretMetadata | Out-String)" $newSecretMetadata = Join-Object -Main $newSecretMetadata -Overrides $updateSecretMetadata -AsHashtable diff --git a/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 b/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 index 2b9b5a55f..fc6f814e1 100644 --- a/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 +++ b/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 @@ -219,7 +219,7 @@ ) $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashTableEntries -Hashtable $body -RemoveNames 'organization_name' + Remove-HashtableEntry -Hashtable $body -RemoveNames 'organization_name' $inputObject = @{ APIEndpoint = "/orgs/$OrganizationName" diff --git a/src/GitHub/public/Releases/Assets/Add-GitHubReleaseAsset.ps1 b/src/GitHub/public/Releases/Assets/Add-GitHubReleaseAsset.ps1 index 35139229d..81cdb57c1 100644 --- a/src/GitHub/public/Releases/Assets/Add-GitHubReleaseAsset.ps1 +++ b/src/GitHub/public/Releases/Assets/Add-GitHubReleaseAsset.ps1 @@ -102,12 +102,12 @@ } $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner', 'Repo', 'ID', 'FilePath' + Remove-HashtableEntry -Hashtable $body -RemoveNames 'Owner', 'Repo', 'ID', 'FilePath' $body['name'] = $Name $body['label'] = $Label - Remove-HashtableEntries -Hashtable $body -NullOrEmptyValues + Remove-HashtableEntry -Hashtable $body -NullOrEmptyValues $release = Get-GitHubRelease -Owner $Owner -Repo $Repo -ID $ID $uploadURI = $release.upload_url -replace '{\?name,label}', "?name=$($Name)&label=$($Label)" diff --git a/src/GitHub/public/Releases/Assets/Set-GitHubReleaseAsset.ps1 b/src/GitHub/public/Releases/Assets/Set-GitHubReleaseAsset.ps1 index 052e7a5cb..b6f08e94f 100644 --- a/src/GitHub/public/Releases/Assets/Set-GitHubReleaseAsset.ps1 +++ b/src/GitHub/public/Releases/Assets/Set-GitHubReleaseAsset.ps1 @@ -46,7 +46,7 @@ ) $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner', 'Repo', 'ID' + Remove-HashtableEntry -Hashtable $body -RemoveNames 'Owner', 'Repo', 'ID' $inputObject = @{ APIEndpoint = "/repos/$Owner/$Repo/releases/assets/$ID" diff --git a/src/GitHub/public/Releases/Releases/New-GitHubRelease.ps1 b/src/GitHub/public/Releases/Releases/New-GitHubRelease.ps1 index 25435edb0..22b3754bc 100644 --- a/src/GitHub/public/Releases/Releases/New-GitHubRelease.ps1 +++ b/src/GitHub/public/Releases/Releases/New-GitHubRelease.ps1 @@ -79,13 +79,13 @@ ) $requestBody = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntries -Hashtable $requestBody -RemoveNames 'Owner', 'Repo', 'GenerateReleaseNotes', 'Draft', 'Prerelease' + Remove-HashtableEntry -Hashtable $requestBody -RemoveNames 'Owner', 'Repo', 'GenerateReleaseNotes', 'Draft', 'Prerelease' $requestBody = Join-Object -AsHashtable -Main $requestBody -Overrides @{ generate_release_notes = $GenerateReleaseNotes.IsPresent draft = $Draft.IsPresent prerelease = $Prerelease.IsPresent } - Remove-HashtableEntries -Hashtable $requestBody -NullOrEmptyValues + Remove-HashtableEntry -Hashtable $requestBody -NullOrEmptyValues $inputObject = @{ APIEndpoint = "/repos/$Owner/$Repo/releases" diff --git a/src/GitHub/public/Releases/Releases/New-GitHubReleaseNotes.ps1 b/src/GitHub/public/Releases/Releases/New-GitHubReleaseNotes.ps1 index 48d86f30d..e53d88d1f 100644 --- a/src/GitHub/public/Releases/Releases/New-GitHubReleaseNotes.ps1 +++ b/src/GitHub/public/Releases/Releases/New-GitHubReleaseNotes.ps1 @@ -93,7 +93,7 @@ ) $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner', 'Repo' + Remove-HashtableEntry -Hashtable $body -RemoveNames 'Owner', 'Repo' $inputObject = @{ APIEndpoint = "/repos/$Owner/$Repo/releases/generate-notes" diff --git a/src/GitHub/public/Releases/Releases/Set-GitHubRelease.ps1 b/src/GitHub/public/Releases/Releases/Set-GitHubRelease.ps1 index 26d6fc35d..0002854ce 100644 --- a/src/GitHub/public/Releases/Releases/Set-GitHubRelease.ps1 +++ b/src/GitHub/public/Releases/Releases/Set-GitHubRelease.ps1 @@ -74,7 +74,7 @@ ) $requestBody = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntries -Hashtable $requestBody -RemoveNames 'Owner', 'Repo', 'Draft', 'Prerelease' + Remove-HashtableEntry -Hashtable $requestBody -RemoveNames 'Owner', 'Repo', 'Draft', 'Prerelease' $requestBody = Join-Object -AsHashtable -Main $requestBody -Overrides @{ draft = $Draft.IsPresent ? $Draft : $false prerelease = $Prerelease.IsPresent ? $Prerelease : $false diff --git a/src/GitHub/public/Repositories/Repositories/Disable-GitHubRepositorySecurityFixes.ps1 b/src/GitHub/public/Repositories/Repositories/Disable-GitHubRepositorySecurityFixes.ps1 index 0301b88ab..8c8f7a1c8 100644 --- a/src/GitHub/public/Repositories/Repositories/Disable-GitHubRepositorySecurityFixes.ps1 +++ b/src/GitHub/public/Repositories/Repositories/Disable-GitHubRepositorySecurityFixes.ps1 @@ -43,7 +43,7 @@ } $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner', 'Repo' -RemoveTypes 'SwitchParameter' + Remove-HashtableEntry -Hashtable $body -RemoveNames 'Owner', 'Repo' -RemoveTypes 'SwitchParameter' $inputObject = @{ APIEndpoint = "/repos/$Owner/$Repo/automated-security-fixes" diff --git a/src/GitHub/public/Repositories/Repositories/Enable-GitHubRepositorySecurityFixes.ps1 b/src/GitHub/public/Repositories/Repositories/Enable-GitHubRepositorySecurityFixes.ps1 index b5cc0d3b0..36c848806 100644 --- a/src/GitHub/public/Repositories/Repositories/Enable-GitHubRepositorySecurityFixes.ps1 +++ b/src/GitHub/public/Repositories/Repositories/Enable-GitHubRepositorySecurityFixes.ps1 @@ -43,7 +43,7 @@ } $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner', 'Repo' -RemoveTypes 'SwitchParameter' + Remove-HashtableEntry -Hashtable $body -RemoveNames 'Owner', 'Repo' -RemoveTypes 'SwitchParameter' $inputObject = @{ APIEndpoint = "/repos/$Owner/$Repo/automated-security-fixes" diff --git a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepository.ps1 b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepository.ps1 index 9d178daa0..6eff8a013 100644 --- a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepository.ps1 +++ b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepository.ps1 @@ -169,7 +169,7 @@ Since = $Since Before = $Before } - Remove-HashTableEntries -Hashtable $params -NullOrEmptyValues + Remove-HashtableEntry -Hashtable $params -NullOrEmptyValues Get-GitHubMyRepositories @params } 'MyRepos_Aff-Vis' { @@ -182,7 +182,7 @@ Since = $Since Before = $Before } - Remove-HashTableEntries -Hashtable $params -NullOrEmptyValues + Remove-HashtableEntry -Hashtable $params -NullOrEmptyValues Get-GitHubMyRepositories @params } 'ByName' { @@ -190,14 +190,14 @@ Owner = $Owner Repo = $Repo } - Remove-HashTableEntries -Hashtable $params -NullOrEmptyValues + Remove-HashtableEntry -Hashtable $params -NullOrEmptyValues Get-GitHubRepositoryByName @params } 'ListByID' { $params = @{ Since = $SinceID } - Remove-HashTableEntries -Hashtable $params -NullOrEmptyValues + Remove-HashtableEntry -Hashtable $params -NullOrEmptyValues Get-GitHubRepositoryListByID @params } 'ListByOrg' { @@ -208,7 +208,7 @@ Direction = $Direction PerPage = $PerPage } - Remove-HashTableEntries -Hashtable $params -NullOrEmptyValues + Remove-HashtableEntry -Hashtable $params -NullOrEmptyValues Get-GitHubRepositoryListByOrg @params } 'ListByUser' { @@ -219,7 +219,7 @@ Direction = $Direction PerPage = $PerPage } - Remove-HashTableEntries -Hashtable $params -NullOrEmptyValues + Remove-HashtableEntry -Hashtable $params -NullOrEmptyValues Get-GitHubRepositoryListByUser @params } } diff --git a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryActivity.ps1 b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryActivity.ps1 index d6875bdbc..843ad2527 100644 --- a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryActivity.ps1 +++ b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryActivity.ps1 @@ -121,7 +121,7 @@ } $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner', 'Repo' -RemoveTypes 'SwitchParameter' + Remove-HashtableEntry -Hashtable $body -RemoveNames 'Owner', 'Repo' -RemoveTypes 'SwitchParameter' $inputObject = @{ APIEndpoint = "/repos/$Owner/$Repo/activity" diff --git a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryCodeownersError.ps1 b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryCodeownersError.ps1 index a9504bfd5..e0e2154d3 100644 --- a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryCodeownersError.ps1 +++ b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryCodeownersError.ps1 @@ -52,7 +52,7 @@ } $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner','Repo' -RemoveTypes 'SwitchParameter' + Remove-HashtableEntry -Hashtable $body -RemoveNames 'Owner','Repo' -RemoveTypes 'SwitchParameter' $inputObject = @{ APIEndpoint = "/repos/$Owner/$Repo/codeowners/errors" diff --git a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryContributor.ps1 b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryContributor.ps1 index b87a7be75..cce0d857e 100644 --- a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryContributor.ps1 +++ b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryContributor.ps1 @@ -42,7 +42,7 @@ ) $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner', 'Repo' -RemoveTypes 'SwitchParameter' + Remove-HashtableEntry -Hashtable $body -RemoveNames 'Owner', 'Repo' -RemoveTypes 'SwitchParameter' $inputObject = @{ APIEndpoint = "/repos/$Owner/$Repo/contributors" diff --git a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositorySecurityFixes.ps1 b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositorySecurityFixes.ps1 index a26bcd92e..9fa74fdf8 100644 --- a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositorySecurityFixes.ps1 +++ b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositorySecurityFixes.ps1 @@ -30,7 +30,7 @@ ) $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner', 'Repo' -RemoveTypes 'SwitchParameter' + Remove-HashtableEntry -Hashtable $body -RemoveNames 'Owner', 'Repo' -RemoveTypes 'SwitchParameter' $inputObject = @{ APIEndpoint = "/repos/$Owner/$Repo/automated-security-fixes" diff --git a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryTags.ps1 b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryTags.ps1 index 24580724c..eb3f99baa 100644 --- a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryTags.ps1 +++ b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryTags.ps1 @@ -33,7 +33,7 @@ ) $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner', 'Repo' -RemoveTypes 'SwitchParameter' + Remove-HashtableEntry -Hashtable $body -RemoveNames 'Owner', 'Repo' -RemoveTypes 'SwitchParameter' $inputObject = @{ APIEndpoint = "/repos/$Owner/$Repo/tags" diff --git a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryTeams.ps1 b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryTeams.ps1 index be17dfc6b..571553cab 100644 --- a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryTeams.ps1 +++ b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryTeams.ps1 @@ -41,7 +41,7 @@ ) $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner', 'Repo' -RemoveTypes 'SwitchParameter' + Remove-HashtableEntry -Hashtable $body -RemoveNames 'Owner', 'Repo' -RemoveTypes 'SwitchParameter' $inputObject = @{ APIEndpoint = "/repos/$Owner/$Repo/teams" diff --git a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryTopic.ps1 b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryTopic.ps1 index 70b54088a..3764305ff 100644 --- a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryTopic.ps1 +++ b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryTopic.ps1 @@ -30,7 +30,7 @@ ) $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner','Repo' -RemoveTypes 'SwitchParameter' + Remove-HashtableEntry -Hashtable $body -RemoveNames 'Owner','Repo' -RemoveTypes 'SwitchParameter' $inputObject = @{ APIEndpoint = "/repos/$Owner/$Repo/topics" diff --git a/src/GitHub/public/Repositories/Repositories/Move-GitHubRepository.ps1 b/src/GitHub/public/Repositories/Repositories/Move-GitHubRepository.ps1 index 7e803c7f5..01a54c0b8 100644 --- a/src/GitHub/public/Repositories/Repositories/Move-GitHubRepository.ps1 +++ b/src/GitHub/public/Repositories/Repositories/Move-GitHubRepository.ps1 @@ -59,7 +59,7 @@ } $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner','Repo' -RemoveTypes 'SwitchParameter' + Remove-HashtableEntry -Hashtable $body -RemoveNames 'Owner','Repo' -RemoveTypes 'SwitchParameter' $inputObject = @{ APIEndpoint = "/repos/$Owner/$Repo/transfer" diff --git a/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 b/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 index 97a1dee2d..085c9ee10 100644 --- a/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 +++ b/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 @@ -226,7 +226,7 @@ } $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner' -RemoveTypes 'SwitchParameter' + Remove-HashtableEntry -Hashtable $body -RemoveNames 'Owner' -RemoveTypes 'SwitchParameter' $body['private'] = $Visibility -eq 'private' $body['has_issues'] = $HasIssues.IsPresent ? $HasIssues : $false @@ -241,7 +241,7 @@ $body['allow_auto_merge'] = $AllowAutoMerge.IsPresent ? $AllowAutoMerge : $false $body['delete_branch_on_merge'] = $DeleteBranchOnMerge.IsPresent ? $DeleteBranchOnMerge : $false - Remove-HashtableEntries -Hashtable $body -NullOrEmptyValues + Remove-HashtableEntry -Hashtable $body -NullOrEmptyValues $inputObject = @{ APIEndpoint = "/orgs/$Owner/repos" diff --git a/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryUser.ps1 b/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryUser.ps1 index 5e87c1056..bda9df454 100644 --- a/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryUser.ps1 +++ b/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryUser.ps1 @@ -221,7 +221,7 @@ } $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntries -Hashtable $body -RemoveNames 'visibility' -RemoveTypes 'SwitchParameter' + Remove-HashtableEntry -Hashtable $body -RemoveNames 'visibility' -RemoveTypes 'SwitchParameter' $body['private'] = $Visibility -eq 'private' $body['has_issues'] = $HasIssues.IsPresent ? $HasIssues : $false @@ -236,7 +236,7 @@ $body['allow_auto_merge'] = $AllowAutoMerge.IsPresent ? $AllowAutoMerge : $false $body['delete_branch_on_merge'] = $DeleteBranchOnMerge.IsPresent ? $DeleteBranchOnMerge : $false - Remove-HashtableEntries -Hashtable $body -NullOrEmptyValues + Remove-HashtableEntry -Hashtable $body -NullOrEmptyValues $inputObject = @{ APIEndpoint = '/user/repos' diff --git a/src/GitHub/public/Repositories/Repositories/Set-GitHubRepositoryTopic.ps1 b/src/GitHub/public/Repositories/Repositories/Set-GitHubRepositoryTopic.ps1 index 27313b68c..52bde9070 100644 --- a/src/GitHub/public/Repositories/Repositories/Set-GitHubRepositoryTopic.ps1 +++ b/src/GitHub/public/Repositories/Repositories/Set-GitHubRepositoryTopic.ps1 @@ -32,7 +32,7 @@ ) $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner', 'Repo' -RemoveTypes 'SwitchParameter' + Remove-HashtableEntry -Hashtable $body -RemoveNames 'Owner', 'Repo' -RemoveTypes 'SwitchParameter' $body.names = $body.names | ForEach-Object { $_.ToLower() } From 82e36132c2ad174b70815b82ec03d84a8d468147 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 27 Oct 2023 22:38:42 +0200 Subject: [PATCH 088/193] rename --- .../{Remove-HashTableEntries.ps1 => Remove-HashtableEntry.ps1} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/GitHub/private/Utilities/Hashtable/{Remove-HashTableEntries.ps1 => Remove-HashtableEntry.ps1} (100%) diff --git a/src/GitHub/private/Utilities/Hashtable/Remove-HashTableEntries.ps1 b/src/GitHub/private/Utilities/Hashtable/Remove-HashtableEntry.ps1 similarity index 100% rename from src/GitHub/private/Utilities/Hashtable/Remove-HashTableEntries.ps1 rename to src/GitHub/private/Utilities/Hashtable/Remove-HashtableEntry.ps1 From 69975914c2d7458e48bfee143dfb1f62d8368b97 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 27 Oct 2023 22:42:58 +0200 Subject: [PATCH 089/193] fix plurals --- .../{Get-GitHubApiVersions.ps1 => Get-GitHubApiVersion.ps1} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename src/GitHub/public/Meta/{Get-GitHubApiVersions.ps1 => Get-GitHubApiVersion.ps1} (88%) diff --git a/src/GitHub/public/Meta/Get-GitHubApiVersions.ps1 b/src/GitHub/public/Meta/Get-GitHubApiVersion.ps1 similarity index 88% rename from src/GitHub/public/Meta/Get-GitHubApiVersions.ps1 rename to src/GitHub/public/Meta/Get-GitHubApiVersion.ps1 index 20172b44e..1b2993d84 100644 --- a/src/GitHub/public/Meta/Get-GitHubApiVersions.ps1 +++ b/src/GitHub/public/Meta/Get-GitHubApiVersion.ps1 @@ -1,4 +1,4 @@ -filter Get-GitHubApiVersions { +filter Get-GitHubApiVersion { <# .SYNOPSIS Get all API versions. @@ -7,7 +7,7 @@ Get all supported GitHub API versions. .EXAMPLE - Get-GitHubApiVersions + Get-GitHubApiVersion Get all supported GitHub API versions. From dd9eddd5183fcc7b9711ffc3836b17ee597980d4 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 27 Oct 2023 23:08:20 +0200 Subject: [PATCH 090/193] fix --- src/GitHub/public/Emojis/Get-GitHubEmojis.ps1 | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/GitHub/public/Emojis/Get-GitHubEmojis.ps1 b/src/GitHub/public/Emojis/Get-GitHubEmojis.ps1 index 5342ae458..438e4288a 100644 --- a/src/GitHub/public/Emojis/Get-GitHubEmojis.ps1 +++ b/src/GitHub/public/Emojis/Get-GitHubEmojis.ps1 @@ -1,10 +1,28 @@ -filter Get-GitHubEmojis { +filter Get-GitHubEmoji { <# + .SYNOPSIS + Get emojis + + .DESCRIPTION + Lists all the emojis available to use on GitHub. + If you pass the `Destination` parameter, the emojis will be downloaded to the specified destination. + + .EXAMPLE + Get-GitHubEmoji + + Gets all the emojis available to use on GitHub. + + .EXAMPLE + Get-GitHubEmoji -Destination 'C:\Users\user\Documents\GitHub\Emojis' + + Downloads all the emojis available to use on GitHub to the specified destination. + .NOTES https://docs.github.com/rest/reference/emojis#get-emojis #> [CmdletBinding()] param ( + # The path to the directory where the emojis will be downloaded. [Parameter()] [string] $Destination ) From 224228ac304d4b733150f24fbe56f1cc8abe6aeb Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 27 Oct 2023 23:12:15 +0200 Subject: [PATCH 091/193] fix New-GitHubReleaseNotes --- ...-GitHubReleaseNotes.ps1 => New-GitHubReleaseNote.ps1} | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) rename src/GitHub/public/Releases/Releases/{New-GitHubReleaseNotes.ps1 => New-GitHubReleaseNote.ps1} (95%) diff --git a/src/GitHub/public/Releases/Releases/New-GitHubReleaseNotes.ps1 b/src/GitHub/public/Releases/Releases/New-GitHubReleaseNote.ps1 similarity index 95% rename from src/GitHub/public/Releases/Releases/New-GitHubReleaseNotes.ps1 rename to src/GitHub/public/Releases/Releases/New-GitHubReleaseNote.ps1 index e53d88d1f..a120ac11b 100644 --- a/src/GitHub/public/Releases/Releases/New-GitHubReleaseNotes.ps1 +++ b/src/GitHub/public/Releases/Releases/New-GitHubReleaseNote.ps1 @@ -1,4 +1,4 @@ -filter New-GitHubReleaseNotes { +filter New-GitHubReleaseNote { <# .SYNOPSIS List releases @@ -14,7 +14,7 @@ Repo = 'hello-world' TagName = 'v1.0.0' } - New-GitHubReleaseNotes @params + New-GitHubReleaseNote @params Creates a new release notes draft for the repository 'hello-world' owned by 'octocat' with the tag name 'v1.0.0'. In this example the tag 'v1.0.0' has to exist in the repository. @@ -27,7 +27,7 @@ TagName = 'v1.0.0' TargetCommitish = 'main' } - New-GitHubReleaseNotes @params + New-GitHubReleaseNote @params Creates a new release notes draft for the repository 'hello-world' owned by 'octocat' with the tag name 'v1.0.0'. In this example the tag 'v1.0.0' has to exist in the repository. @@ -42,7 +42,7 @@ PreviousTagName = 'v0.9.2' ConfigurationFilePath = '.github/custom_release_config.yml' } - New-GitHubReleaseNotes @params + New-GitHubReleaseNote @params Creates a new release notes draft for the repository 'hello-world' owned by 'octocat' with the tag name 'v1.0.0'. The release notes will be based on the changes between the tags 'v0.9.2' and 'v1.0.0' and generated based on the @@ -54,6 +54,7 @@ #> [OutputType([pscustomobject])] [Alias('Generate-GitHubReleaseNotes')] + [Alias('New-GitHubReleaseNotes')] [CmdletBinding(SupportsShouldProcess)] param ( # The account owner of the repository. The name is not case sensitive. From 8d73c9ec54becc51151d6c7f55677a6bf3162e7e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 27 Oct 2023 23:19:54 +0200 Subject: [PATCH 092/193] fix plural --- ...SecurityFixes.ps1 => Get-GitHubRepositorySecurityFix.ps1} | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) rename src/GitHub/public/Repositories/Repositories/{Get-GitHubRepositorySecurityFixes.ps1 => Get-GitHubRepositorySecurityFix.ps1} (90%) diff --git a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositorySecurityFixes.ps1 b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositorySecurityFix.ps1 similarity index 90% rename from src/GitHub/public/Repositories/Repositories/Get-GitHubRepositorySecurityFixes.ps1 rename to src/GitHub/public/Repositories/Repositories/Get-GitHubRepositorySecurityFix.ps1 index 9fa74fdf8..f51f38cce 100644 --- a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositorySecurityFixes.ps1 +++ b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositorySecurityFix.ps1 @@ -1,4 +1,4 @@ -filter Get-GitHubRepositorySecurityFixes { +filter Get-GitHubRepositorySecurityFix { <# .SYNOPSIS Check if automated security fixes are enabled for a repository @@ -9,7 +9,7 @@ "[Configuring automated security fixes](https://docs.github.com/articles/configuring-automated-security-fixes)". .EXAMPLE - Get-GitHubRepositorySecurityFixes -Owner 'PSModule' -Repo 'GitHub' + Get-GitHubRepositorySecurityFix -Owner 'PSModule' -Repo 'GitHub' Gets the automated security fixes status for the GitHub repository. @@ -18,6 +18,7 @@ #> [CmdletBinding()] + [Alias('Get-GitHubRepoSecurityFixes')] param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] From 5cc7752f1b25171ca006f56251c9bd55308070b7 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 27 Oct 2023 23:26:15 +0200 Subject: [PATCH 093/193] Fix --- ...-GitHubRepositoryTags.ps1 => Get-GitHubRepositoryTag.ps1} | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) rename src/GitHub/public/Repositories/Repositories/{Get-GitHubRepositoryTags.ps1 => Get-GitHubRepositoryTag.ps1} (89%) diff --git a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryTags.ps1 b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryTag.ps1 similarity index 89% rename from src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryTags.ps1 rename to src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryTag.ps1 index eb3f99baa..8279c33bd 100644 --- a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryTags.ps1 +++ b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryTag.ps1 @@ -1,4 +1,4 @@ -filter Get-GitHubRepositoryTags { +filter Get-GitHubRepositoryTag { <# .SYNOPSIS List repository tags @@ -7,7 +7,7 @@ List repository tags .EXAMPLE - Get-GitHubRepositoryTags -Owner 'PSModule' -Repo 'GitHub' + Get-GitHubRepositoryTag -Owner 'PSModule' -Repo 'GitHub' Gets all tags of the GitHub repository. @@ -16,6 +16,7 @@ #> [CmdletBinding()] + [Alias('Get-GitHubRepositoryTags')] param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] From 9a68f8c5df6d6e09861971e387c1fb5144c934b3 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 27 Oct 2023 23:28:00 +0200 Subject: [PATCH 094/193] fix Get-GitHubRepositoryTeam --- ...itHubRepositoryTeams.ps1 => Get-GitHubRepositoryTeam.ps1} | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) rename src/GitHub/public/Repositories/Repositories/{Get-GitHubRepositoryTeams.ps1 => Get-GitHubRepositoryTeam.ps1} (92%) diff --git a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryTeams.ps1 b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryTeam.ps1 similarity index 92% rename from src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryTeams.ps1 rename to src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryTeam.ps1 index 571553cab..9b65bfcfa 100644 --- a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryTeams.ps1 +++ b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryTeam.ps1 @@ -1,4 +1,4 @@ -filter Get-GitHubRepositoryTeams { +filter Get-GitHubRepositoryTeam { <# .SYNOPSIS List repository teams @@ -15,7 +15,7 @@ This endpoint is not compatible with fine-grained personal access tokens. .EXAMPLE - Get-GitHubRepositoryTeams -Owner 'PSModule' -Repo 'GitHub' + Get-GitHubRepositoryTeam -Owner 'PSModule' -Repo 'GitHub' Lists the teams that have access to the specified repository and that are also visible to the authenticated user. @@ -24,6 +24,7 @@ #> [CmdletBinding()] + [Alias('Get-GitHubRepositoryTeams')] param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] From 0f7bde3a67b2a26e64a1863fb2763f983dcb3c37 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 27 Oct 2023 23:31:49 +0200 Subject: [PATCH 095/193] fix for Disable-GitHubRepositorySecurityFixes --- ...Fixes.ps1 => Disable-GitHubRepositorySecurityFix.ps1} | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) rename src/GitHub/public/Repositories/Repositories/{Disable-GitHubRepositorySecurityFixes.ps1 => Disable-GitHubRepositorySecurityFix.ps1} (82%) diff --git a/src/GitHub/public/Repositories/Repositories/Disable-GitHubRepositorySecurityFixes.ps1 b/src/GitHub/public/Repositories/Repositories/Disable-GitHubRepositorySecurityFix.ps1 similarity index 82% rename from src/GitHub/public/Repositories/Repositories/Disable-GitHubRepositorySecurityFixes.ps1 rename to src/GitHub/public/Repositories/Repositories/Disable-GitHubRepositorySecurityFix.ps1 index 8c8f7a1c8..339f9f9c0 100644 --- a/src/GitHub/public/Repositories/Repositories/Disable-GitHubRepositorySecurityFixes.ps1 +++ b/src/GitHub/public/Repositories/Repositories/Disable-GitHubRepositorySecurityFix.ps1 @@ -1,13 +1,15 @@ -filter Disable-GitHubRepositorySecurityFixes { +filter Disable-GitHubRepositorySecurityFix { <# .SYNOPSIS Disable automated security fixes .DESCRIPTION - Disables automated security fixes for a repository. The authenticated user must have admin access to the repository. For more information, see "[Configuring automated security fixes](https://docs.github.com/articles/configuring-automated-security-fixes)". + Disables automated security fixes for a repository. The authenticated user must have admin access to the repository. + For more information, see + "[Configuring automated security fixes](https://docs.github.com/articles/configuring-automated-security-fixes)". .EXAMPLE - Disable-GitHubRepositorySecurityFixes -Owner 'PSModule' -Repo 'GitHub' + Disable-GitHubRepositorySecurityFix -Owner 'PSModule' -Repo 'GitHub' Disables automated security fixes for the repository. @@ -16,6 +18,7 @@ #> [CmdletBinding()] + [Alias('Disable-GitHubRepositorySecurityFixes')] param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] From 625ba781feaeed786076e7dd1d8f760a2badad33 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 27 Oct 2023 23:38:36 +0200 Subject: [PATCH 096/193] Fix --- ...yFixes.ps1 => Enable-GitHubRepositorySecurityFix.ps1} | 9 ++++++--- ...bStatusIncidents.ps1 => Get-GitHubStatusIncident.ps1} | 7 ++++--- 2 files changed, 10 insertions(+), 6 deletions(-) rename src/GitHub/public/Repositories/Repositories/{Enable-GitHubRepositorySecurityFixes.ps1 => Enable-GitHubRepositorySecurityFix.ps1} (83%) rename src/GitHub/public/Status/{Get-GitHubStatusIncidents.ps1 => Get-GitHubStatusIncident.ps1} (89%) diff --git a/src/GitHub/public/Repositories/Repositories/Enable-GitHubRepositorySecurityFixes.ps1 b/src/GitHub/public/Repositories/Repositories/Enable-GitHubRepositorySecurityFix.ps1 similarity index 83% rename from src/GitHub/public/Repositories/Repositories/Enable-GitHubRepositorySecurityFixes.ps1 rename to src/GitHub/public/Repositories/Repositories/Enable-GitHubRepositorySecurityFix.ps1 index 36c848806..cee381dca 100644 --- a/src/GitHub/public/Repositories/Repositories/Enable-GitHubRepositorySecurityFixes.ps1 +++ b/src/GitHub/public/Repositories/Repositories/Enable-GitHubRepositorySecurityFix.ps1 @@ -1,13 +1,15 @@ -filter Enable-GitHubRepositorySecurityFixes { +filter Enable-GitHubRepositorySecurityFix { <# .SYNOPSIS Enable automated security fixes .DESCRIPTION - Enables automated security fixes for a repository. The authenticated user must have admin access to the repository. For more information, see "[Configuring automated security fixes](https://docs.github.com/articles/configuring-automated-security-fixes)". + Enables automated security fixes for a repository. The authenticated user must have admin access to the repository. + For more information, see + "[Configuring automated security fixes](https://docs.github.com/articles/configuring-automated-security-fixes)". .EXAMPLE - Enable-GitHubRepositorySecurityFixes -Owner 'PSModule' -Repo 'GitHub' + Enable-GitHubRepositorySecurityFix -Owner 'PSModule' -Repo 'GitHub' Enables automated security fixes for the repository. @@ -16,6 +18,7 @@ #> [CmdletBinding()] + [Alias('Enable-GitHubRepositorySecurityFixes')] param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] diff --git a/src/GitHub/public/Status/Get-GitHubStatusIncidents.ps1 b/src/GitHub/public/Status/Get-GitHubStatusIncident.ps1 similarity index 89% rename from src/GitHub/public/Status/Get-GitHubStatusIncidents.ps1 rename to src/GitHub/public/Status/Get-GitHubStatusIncident.ps1 index 3c5a5bf2f..ac2085ef4 100644 --- a/src/GitHub/public/Status/Get-GitHubStatusIncidents.ps1 +++ b/src/GitHub/public/Status/Get-GitHubStatusIncident.ps1 @@ -1,4 +1,4 @@ -function Get-GitHubStatusIncidents { +function Get-GitHubStatusIncident { <# .SYNOPSIS Gets the status of GitHub incidents @@ -12,12 +12,12 @@ Impact: None (black), Minor (yellow), Major (orange), or Critical (red) .EXAMPLE - Get-GitHubStatusIncidents + Get-GitHubStatusIncident Gets the status of GitHub incidents .EXAMPLE - Get-GitHubStatusIncidents -Unresolved + Get-GitHubStatusIncident -Unresolved Gets the status of GitHub incidents that are unresolved @@ -25,6 +25,7 @@ https://www.githubstatus.com/api#incidents #> [OutputType([pscustomobject[]])] + [Alias('Get-GitHubStatusIncidents')] [CmdletBinding()] param( # Gets the status of GitHub incidents that are unresolved From c4fa799630b175745a5e8f0f7e030d7d633b10ae Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 27 Oct 2023 23:40:06 +0200 Subject: [PATCH 097/193] fix --- ...HubStatusComponents.ps1 => Get-GitHubStatusComponent.ps1} | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) rename src/GitHub/public/Status/{Get-GitHubStatusComponents.ps1 => Get-GitHubStatusComponent.ps1} (84%) diff --git a/src/GitHub/public/Status/Get-GitHubStatusComponents.ps1 b/src/GitHub/public/Status/Get-GitHubStatusComponent.ps1 similarity index 84% rename from src/GitHub/public/Status/Get-GitHubStatusComponents.ps1 rename to src/GitHub/public/Status/Get-GitHubStatusComponent.ps1 index 9da591488..7dcd79189 100644 --- a/src/GitHub/public/Status/Get-GitHubStatusComponents.ps1 +++ b/src/GitHub/public/Status/Get-GitHubStatusComponent.ps1 @@ -1,4 +1,4 @@ -function Get-GitHubStatusComponents { +function Get-GitHubStatusComponent { <# .SYNOPSIS Gets the status of GitHub components @@ -7,7 +7,7 @@ Get the components for the page. Each component is listed along with its status - one of operational, degraded_performance, partial_outage, or major_outage. .EXAMPLE - Get-GitHubStatusComponents + Get-GitHubStatusComponent Gets the status of GitHub components @@ -15,6 +15,7 @@ https://www.githubstatus.com/api#components #> [OutputType([pscustomobject[]])] + [Alias('Get-GitHubStatusComponents')] [CmdletBinding()] param() From 6d27eb1ac9376789758605bbfe1c1efac906784d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 27 Oct 2023 23:46:16 +0200 Subject: [PATCH 098/193] fix --- src/GitHub/public/Status/Get-GitHubStatusComponent.ps1 | 3 ++- ...itHubUserFollows.ps1 => Test-GitHubUserFollowing.ps1} | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) rename src/GitHub/public/Users/Followers/{Test-GitHubUserFollows.ps1 => Test-GitHubUserFollowing.ps1} (84%) diff --git a/src/GitHub/public/Status/Get-GitHubStatusComponent.ps1 b/src/GitHub/public/Status/Get-GitHubStatusComponent.ps1 index 7dcd79189..c646aae66 100644 --- a/src/GitHub/public/Status/Get-GitHubStatusComponent.ps1 +++ b/src/GitHub/public/Status/Get-GitHubStatusComponent.ps1 @@ -4,7 +4,8 @@ Gets the status of GitHub components .DESCRIPTION - Get the components for the page. Each component is listed along with its status - one of operational, degraded_performance, partial_outage, or major_outage. + Get the components for the page. Each component is listed along with its status - one of operational, + degraded_performance, partial_outage, or major_outage. .EXAMPLE Get-GitHubStatusComponent diff --git a/src/GitHub/public/Users/Followers/Test-GitHubUserFollows.ps1 b/src/GitHub/public/Users/Followers/Test-GitHubUserFollowing.ps1 similarity index 84% rename from src/GitHub/public/Users/Followers/Test-GitHubUserFollows.ps1 rename to src/GitHub/public/Users/Followers/Test-GitHubUserFollowing.ps1 index d8168159f..dbb950ba7 100644 --- a/src/GitHub/public/Users/Followers/Test-GitHubUserFollows.ps1 +++ b/src/GitHub/public/Users/Followers/Test-GitHubUserFollowing.ps1 @@ -1,4 +1,4 @@ -filter Test-GitHubUserFollows { +filter Test-GitHubUserFollowing { <# .SYNOPSIS Check if a given user or the authenticated user follows a person @@ -8,13 +8,13 @@ Returns a 404 if the user is not followed by a given user or the authenticated user. .EXAMPLE - Test-GitHubUserFollows -Follows 'octocat' - Test-GitHubUserFollows 'octocat' + Test-GitHubUserFollowing -Follows 'octocat' + Test-GitHubUserFollowing 'octocat' Checks if the authenticated user follows the user 'octocat'. .EXAMPLE - Test-GitHubUserFollows -Username 'octocat' -Follows 'ratstallion' + Test-GitHubUserFollowing -Username 'octocat' -Follows 'ratstallion' Checks if the user 'octocat' follows the user 'ratstallion'. @@ -24,6 +24,7 @@ #> [OutputType([bool])] + [Alias('Test-GitHubUserFollows')] [CmdletBinding()] param ( # The handle for the GitHub user account we want to check if is being followed. From 19d09ad65cf1b92b633186ead6d60762909f6f6a Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 28 Oct 2023 00:00:08 +0200 Subject: [PATCH 099/193] Fix --- ...-GitHubUserFollowers.ps1 => Get-GitHubUserFollower.ps1} | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) rename src/GitHub/public/Users/Followers/{Get-GitHubUserFollowers.ps1 => Get-GitHubUserFollower.ps1} (86%) diff --git a/src/GitHub/public/Users/Followers/Get-GitHubUserFollowers.ps1 b/src/GitHub/public/Users/Followers/Get-GitHubUserFollower.ps1 similarity index 86% rename from src/GitHub/public/Users/Followers/Get-GitHubUserFollowers.ps1 rename to src/GitHub/public/Users/Followers/Get-GitHubUserFollower.ps1 index 95ef3229b..780dadde0 100644 --- a/src/GitHub/public/Users/Followers/Get-GitHubUserFollowers.ps1 +++ b/src/GitHub/public/Users/Followers/Get-GitHubUserFollower.ps1 @@ -1,4 +1,4 @@ -filter Get-GitHubUserFollowers { +filter Get-GitHubUserFollower { <# .SYNOPSIS List followers of a given user or the authenticated user @@ -7,12 +7,12 @@ Lists the people following a given user or the authenticated user. .EXAMPLE - Get-GitHubUserFollowers + Get-GitHubUserFollower Gets all followers of the authenticated user. .EXAMPLE - Get-GitHubUserFollowers -Username 'octocat' + Get-GitHubUserFollower -Username 'octocat' Gets all followers of the user 'octocat'. @@ -21,6 +21,7 @@ #> [OutputType([pscustomobject])] + [Alias('Get-GitHubUserMyFollowers')] [CmdletBinding()] param ( # The handle for the GitHub user account. From 1a1196ff0815b9bb400d4c12e93389807393ee6f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 28 Oct 2023 00:05:07 +0200 Subject: [PATCH 100/193] Fix --- ...{Add-GitHubUserSocials.ps1 => Add-GitHubUserSocial.ps1} | 5 +++-- ...e-GitHubUserSocials.ps1 => Remove-GitHubUserSocial.ps1} | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) rename src/GitHub/public/Users/Social-Accounts/{Add-GitHubUserSocials.ps1 => Add-GitHubUserSocial.ps1} (83%) rename src/GitHub/public/Users/Social-Accounts/{Remove-GitHubUserSocials.ps1 => Remove-GitHubUserSocial.ps1} (84%) diff --git a/src/GitHub/public/Users/Social-Accounts/Add-GitHubUserSocials.ps1 b/src/GitHub/public/Users/Social-Accounts/Add-GitHubUserSocial.ps1 similarity index 83% rename from src/GitHub/public/Users/Social-Accounts/Add-GitHubUserSocials.ps1 rename to src/GitHub/public/Users/Social-Accounts/Add-GitHubUserSocial.ps1 index 89cfdcddf..202e1ebb1 100644 --- a/src/GitHub/public/Users/Social-Accounts/Add-GitHubUserSocials.ps1 +++ b/src/GitHub/public/Users/Social-Accounts/Add-GitHubUserSocial.ps1 @@ -1,4 +1,4 @@ -filter Add-GitHubUserSocials { +filter Add-GitHubUserSocial { <# .SYNOPSIS Add social accounts for the authenticated user @@ -7,7 +7,7 @@ Add one or more social accounts to the authenticated user's profile. This endpoint is accessible with the `user` scope. .EXAMPLE - Add-GitHubUserSocials -AccountUrls 'https://twitter.com/MyTwitterAccount', 'https://www.linkedin.com/company/MyCompany' + Add-GitHubUserSocial -AccountUrls 'https://twitter.com/MyTwitterAccount', 'https://www.linkedin.com/company/MyCompany' Adds the Twitter and LinkedIn accounts to the authenticated user's profile. @@ -15,6 +15,7 @@ https://docs.github.com/rest/users/social-accounts#add-social-accounts-for-the-authenticated-user #> [OutputType([void])] + [Alias('Add-GitHubUserSocials')] [CmdletBinding()] param ( # Full URLs for the social media profiles to add. diff --git a/src/GitHub/public/Users/Social-Accounts/Remove-GitHubUserSocials.ps1 b/src/GitHub/public/Users/Social-Accounts/Remove-GitHubUserSocial.ps1 similarity index 84% rename from src/GitHub/public/Users/Social-Accounts/Remove-GitHubUserSocials.ps1 rename to src/GitHub/public/Users/Social-Accounts/Remove-GitHubUserSocial.ps1 index 4e1aabd01..3368f39ee 100644 --- a/src/GitHub/public/Users/Social-Accounts/Remove-GitHubUserSocials.ps1 +++ b/src/GitHub/public/Users/Social-Accounts/Remove-GitHubUserSocial.ps1 @@ -1,4 +1,4 @@ -filter Remove-GitHubUserSocials { +filter Remove-GitHubUserSocial { <# .SYNOPSIS Delete social accounts for the authenticated user @@ -10,12 +10,13 @@ Parameter description .EXAMPLE - Remove-GitHubUserSocials -AccountUrls 'https://twitter.com/MyTwitterAccount' + Remove-GitHubUserSocial -AccountUrls 'https://twitter.com/MyTwitterAccount' .NOTES https://docs.github.com/rest/users/social-accounts#delete-social-accounts-for-the-authenticated-user #> [OutputType([void])] + [Alias('Remove-GitHubUserSocials')] [CmdletBinding(SupportsShouldProcess)] param ( # Full URLs for the social media profiles to add. @@ -32,7 +33,7 @@ Method = 'DELETE' } - if ($PSCmdlet.ShouldProcess("Social accounts [$($AccountUrls -join ', ')]", "Delete")) { + if ($PSCmdlet.ShouldProcess("Social accounts [$($AccountUrls -join ', ')]", 'Delete')) { $null = (Invoke-GitHubAPI @inputObject).Response } From 01d320bffd08911dc2ff4eec59dc132b85d455a1 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 28 Oct 2023 00:09:19 +0200 Subject: [PATCH 101/193] fixes --- src/GitHub/public/Config/Get-GitHubConfig.ps1 | 2 +- .../Get-GitHubRepositoryCodeownersError.ps1 | 2 +- .../Repositories/Get-GitHubRepositoryTopic.ps1 | 2 +- .../Repositories/Move-GitHubRepository.ps1 | 10 +++++++--- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/GitHub/public/Config/Get-GitHubConfig.ps1 b/src/GitHub/public/Config/Get-GitHubConfig.ps1 index 76c0b5afe..b82405f42 100644 --- a/src/GitHub/public/Config/Get-GitHubConfig.ps1 +++ b/src/GitHub/public/Config/Get-GitHubConfig.ps1 @@ -42,7 +42,7 @@ $AccessTokenData = (Get-SecretInfo -Name "$prefix`AccessToken").Metadata | ConvertFrom-HashTable | ConvertTo-HashTable $metadata = Join-Object -Main $RefreshTokenData -Overrides $AccessTokenData -AsHashtable - switch($Name) { + switch ($Name) { 'AccessToken' { Get-Secret -Name "$prefix`AccessToken" } diff --git a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryCodeownersError.ps1 b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryCodeownersError.ps1 index e0e2154d3..656be4b29 100644 --- a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryCodeownersError.ps1 +++ b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryCodeownersError.ps1 @@ -52,7 +52,7 @@ } $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntry -Hashtable $body -RemoveNames 'Owner','Repo' -RemoveTypes 'SwitchParameter' + Remove-HashtableEntry -Hashtable $body -RemoveNames 'Owner', 'Repo' -RemoveTypes 'SwitchParameter' $inputObject = @{ APIEndpoint = "/repos/$Owner/$Repo/codeowners/errors" diff --git a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryTopic.ps1 b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryTopic.ps1 index 3764305ff..abeefb20a 100644 --- a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryTopic.ps1 +++ b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryTopic.ps1 @@ -30,7 +30,7 @@ ) $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntry -Hashtable $body -RemoveNames 'Owner','Repo' -RemoveTypes 'SwitchParameter' + Remove-HashtableEntry -Hashtable $body -RemoveNames 'Owner', 'Repo' -RemoveTypes 'SwitchParameter' $inputObject = @{ APIEndpoint = "/repos/$Owner/$Repo/topics" diff --git a/src/GitHub/public/Repositories/Repositories/Move-GitHubRepository.ps1 b/src/GitHub/public/Repositories/Repositories/Move-GitHubRepository.ps1 index 01a54c0b8..f5e61c61f 100644 --- a/src/GitHub/public/Repositories/Repositories/Move-GitHubRepository.ps1 +++ b/src/GitHub/public/Repositories/Repositories/Move-GitHubRepository.ps1 @@ -4,8 +4,12 @@ Transfer a repository .DESCRIPTION - A transfer request will need to be accepted by the new owner when transferring a personal repository to another user. The response will contain the original `owner`, and the transfer will continue asynchronously. For more details on the requirements to transfer personal and organization-owned repositories, see [about repository transfers](https://docs.github.com/articles/about-repository-transfers/). - You must use a personal access token (classic) or an OAuth token for this endpoint. An installation access token or a fine-grained personal access token cannot be used because they are only granted access to a single account. + A transfer request will need to be accepted by the new owner when transferring a personal repository to another user. + The response will contain the original `owner`, and the transfer will continue asynchronously. For more details on + the requirements to transfer personal and organization-owned repositories, see + [about repository transfers](https://docs.github.com/articles/about-repository-transfers/). + You must use a personal access token (classic) or an OAuth token for this endpoint. An installation access token or + a fine-grained personal access token cannot be used because they are only granted access to a single account. .EXAMPLE Move-GitHubRepository -Owner 'PSModule' -Repo 'GitHub' -NewOwner 'GitHub' -NewName 'PowerShell' @@ -59,7 +63,7 @@ } $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntry -Hashtable $body -RemoveNames 'Owner','Repo' -RemoveTypes 'SwitchParameter' + Remove-HashtableEntry -Hashtable $body -RemoveNames 'Owner', 'Repo' -RemoveTypes 'SwitchParameter' $inputObject = @{ APIEndpoint = "/repos/$Owner/$Repo/transfer" From c66bfd180c33449ab1e36d4f3392b133703e4bef Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 28 Oct 2023 00:12:59 +0200 Subject: [PATCH 102/193] fix --- .../public/Emojis/{Get-GitHubEmojis.ps1 => Get-GitHubEmoji.ps1} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/GitHub/public/Emojis/{Get-GitHubEmojis.ps1 => Get-GitHubEmoji.ps1} (100%) diff --git a/src/GitHub/public/Emojis/Get-GitHubEmojis.ps1 b/src/GitHub/public/Emojis/Get-GitHubEmoji.ps1 similarity index 100% rename from src/GitHub/public/Emojis/Get-GitHubEmojis.ps1 rename to src/GitHub/public/Emojis/Get-GitHubEmoji.ps1 From 7d65fe701f94f804fca19eebc2b1daf95d4935b9 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 28 Oct 2023 00:17:12 +0200 Subject: [PATCH 103/193] Disable writehost warning --- src/GitHub/public/Auth/Disconnect-GitHubAccount.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/src/GitHub/public/Auth/Disconnect-GitHubAccount.ps1 b/src/GitHub/public/Auth/Disconnect-GitHubAccount.ps1 index 754786541..1450c9621 100644 --- a/src/GitHub/public/Auth/Disconnect-GitHubAccount.ps1 +++ b/src/GitHub/public/Auth/Disconnect-GitHubAccount.ps1 @@ -23,6 +23,7 @@ [Alias('Logoff-GitHub')] [Alias('Logoff-GH')] [OutputType([void])] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingRemove', '', Justification = 'Is the CLI part of the module.')] [CmdletBinding()] param () From 688cf8cd1c34091130849d9c7d60ecbfe24155c5 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 28 Oct 2023 00:22:40 +0200 Subject: [PATCH 104/193] fix --- src/GitHub/public/Auth/Disconnect-GitHubAccount.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GitHub/public/Auth/Disconnect-GitHubAccount.ps1 b/src/GitHub/public/Auth/Disconnect-GitHubAccount.ps1 index 1450c9621..57afb45d7 100644 --- a/src/GitHub/public/Auth/Disconnect-GitHubAccount.ps1 +++ b/src/GitHub/public/Auth/Disconnect-GitHubAccount.ps1 @@ -23,7 +23,7 @@ [Alias('Logoff-GitHub')] [Alias('Logoff-GH')] [OutputType([void])] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingRemove', '', Justification = 'Is the CLI part of the module.')] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Justification = 'Is the CLI part of the module.')] [CmdletBinding()] param () From 9dd93adf2b20f686977049b9bf985bda17e3533f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 28 Oct 2023 00:39:09 +0200 Subject: [PATCH 105/193] Fixa issues --- .vscode/settings.json | 5 ++++- src/GitHub/private/Users/Get-GitHubAllUser.ps1 | 6 ++++-- src/GitHub/public/Actions/Remove-GitHubWorkflowRun.ps1 | 2 +- src/GitHub/public/Actions/Start-GitHubWorkflow.ps1 | 2 +- .../Set-GitHubOrganizationSecurityFeature.ps1 | 2 +- src/GitHub/public/Rate-Limit/Get-GitHubRateLimit.ps1 | 9 ++++++--- .../public/Releases/Releases/Remove-GitHubRelease.ps1 | 2 +- .../public/Releases/Releases/Set-GitHubRelease.ps1 | 7 +++++-- .../Repositories/New-GitHubRepositoryOrg.ps1 | 2 +- .../Repositories/New-GitHubRepositoryUser.ps1 | 2 +- .../Repositories/Remove-GitHubRepository.ps1 | 2 +- .../Repositories/Set-GitHubRepositoryTopic.ps1 | 2 +- src/GitHub/public/Users/Emails/Add-GitHubUserEmail.ps1 | 2 +- .../public/Users/Emails/Remove-GitHubUserEmail.ps1 | 4 ++-- .../Users/Emails/Set-GitHubUserEmailVisibility.ps1 | 4 ++-- .../Users/Followers/Remove-GitHubUserFollowing.ps1 | 2 +- .../public/Users/GPG-Keys/Remove-GitHubUserGpgKey.ps1 | 2 +- src/GitHub/public/Users/Keys/Add-GitHubUserKey.ps1 | 5 +++-- src/GitHub/public/Users/Keys/Remove-GitHubUserKey.ps1 | 2 +- .../Users/SSH-Signing-Keys/Add-GitHubUserSigningKey.ps1 | 9 ++++++--- .../SSH-Signing-Keys/Remove-GitHubUserSigningKey.ps1 | 2 +- 21 files changed, 45 insertions(+), 30 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index e732ea127..bee7d916e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -29,7 +29,10 @@ "editor.insertSpaces": true, "editor.tabSize": 2 }, - "editor.rulers": [0, 150], + "editor.rulers": [ + 0, + 150 + ], "powershell.codeFormatting.autoCorrectAliases": true, "powershell.codeFormatting.newLineAfterCloseBrace": false, "powershell.codeFormatting.pipelineIndentationStyle": "IncreaseIndentationForFirstPipeline", diff --git a/src/GitHub/private/Users/Get-GitHubAllUser.ps1 b/src/GitHub/private/Users/Get-GitHubAllUser.ps1 index eff4bafa6..a4ba7eee3 100644 --- a/src/GitHub/private/Users/Get-GitHubAllUser.ps1 +++ b/src/GitHub/private/Users/Get-GitHubAllUser.ps1 @@ -6,7 +6,9 @@ .DESCRIPTION Lists all users, in the order that they signed up on GitHub. This list includes personal user accounts and organization accounts. - 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. + 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-GitHubAllUser -Since 17722253 @@ -32,7 +34,7 @@ $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case $inputObject = @{ - APIEndpoint = "/users" + APIEndpoint = '/users' Method = 'GET' Body = $body } diff --git a/src/GitHub/public/Actions/Remove-GitHubWorkflowRun.ps1 b/src/GitHub/public/Actions/Remove-GitHubWorkflowRun.ps1 index c14589d09..e7e40c20d 100644 --- a/src/GitHub/public/Actions/Remove-GitHubWorkflowRun.ps1 +++ b/src/GitHub/public/Actions/Remove-GitHubWorkflowRun.ps1 @@ -40,7 +40,7 @@ Method = 'DELETE' } - if ($PSCmdlet.ShouldProcess("workflow run with ID [$RunID] in [$Owner/$Repo]", "Delete")) { + if ($PSCmdlet.ShouldProcess("workflow run with ID [$RunID] in [$Owner/$Repo]", 'Delete')) { (Invoke-GitHubAPI @inputObject).Response } diff --git a/src/GitHub/public/Actions/Start-GitHubWorkflow.ps1 b/src/GitHub/public/Actions/Start-GitHubWorkflow.ps1 index bdce42d60..0c4d633d4 100644 --- a/src/GitHub/public/Actions/Start-GitHubWorkflow.ps1 +++ b/src/GitHub/public/Actions/Start-GitHubWorkflow.ps1 @@ -59,7 +59,7 @@ Body = $body } - if ($PSCmdlet.ShouldProcess("workflow with ID [$ID] in [$Owner/$Repo]", "Start")) { + if ($PSCmdlet.ShouldProcess("workflow with ID [$ID] in [$Owner/$Repo]", 'Start')) { (Invoke-GitHubAPI @inputObject).Response } diff --git a/src/GitHub/public/Organization/Set-GitHubOrganizationSecurityFeature.ps1 b/src/GitHub/public/Organization/Set-GitHubOrganizationSecurityFeature.ps1 index 765fcbaff..7ac9dcfd5 100644 --- a/src/GitHub/public/Organization/Set-GitHubOrganizationSecurityFeature.ps1 +++ b/src/GitHub/public/Organization/Set-GitHubOrganizationSecurityFeature.ps1 @@ -79,7 +79,7 @@ Body = $body } - if ($PSCmdlet.ShouldProcess("security feature [$SecurityProduct] on organization [$OrganizationName]", "Set")) { + if ($PSCmdlet.ShouldProcess("security feature [$SecurityProduct] on organization [$OrganizationName]", 'Set')) { (Invoke-GitHubAPI @inputObject).Response } diff --git a/src/GitHub/public/Rate-Limit/Get-GitHubRateLimit.ps1 b/src/GitHub/public/Rate-Limit/Get-GitHubRateLimit.ps1 index b326334d7..8760454f9 100644 --- a/src/GitHub/public/Rate-Limit/Get-GitHubRateLimit.ps1 +++ b/src/GitHub/public/Rate-Limit/Get-GitHubRateLimit.ps1 @@ -6,7 +6,8 @@ .DESCRIPTION **Note:** Accessing this endpoint does not count against your REST API rate limit. - Some categories of endpoints have custom rate limits that are separate from the rate limit governing the other REST API endpoints. For this reason, the API response categorizes your rate limit. Under `resources`, you'll see objects relating to different categories: + Some categories of endpoints have custom rate limits that are separate from the rate limit governing the other REST API endpoints. + For this reason, the API response categorizes your rate limit. Under `resources`, you'll see objects relating to different categories: * The `core` object provides your rate limit status for all non-search-related resources in the REST API. * The `search` object provides your rate limit status for the REST API for searching (excluding code searches). For more information, see "[Search](https://docs.github.com/rest/search)." * The `code_search` object provides your rate limit status for the REST API for searching code. For more information, see "[Search code](https://docs.github.com/rest/search/search#search-code)." @@ -17,7 +18,8 @@ * The `actions_runner_registration` object provides your rate limit status for registering self-hosted runners in GitHub Actions. For more information, see "[Self-hosted runners](https://docs.github.com/rest/actions/self-hosted-runners)." * The `source_import` object is no longer in use for any API endpoints, and it will be removed in the next API version. For more information about API versions, see "[API Versions](https://docs.github.com/rest/overview/api-versions)." - **Note:** The `rate` object is deprecated. If you're writing new API client code or updating existing code, you should use the `core` object instead of the `rate` object. The `core` object contains the same information that is present in the `rate` object. + **Note:** The `rate` object is deprecated. If you're writing new API client code or updating existing code, you should use the `core` object + instead of the `rate` object. The `core` object contains the same information that is present in the `rate` object. .EXAMPLE Get-GitHubRateLimit @@ -29,11 +31,12 @@ #> [OutputType([pscustomobject])] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Contains a long link.')] [CmdletBinding()] param () $inputObject = @{ - APIEndpoint = "/rate_limit" + APIEndpoint = '/rate_limit' Method = 'GET' } diff --git a/src/GitHub/public/Releases/Releases/Remove-GitHubRelease.ps1 b/src/GitHub/public/Releases/Releases/Remove-GitHubRelease.ps1 index 49bb78422..3170f1c32 100644 --- a/src/GitHub/public/Releases/Releases/Remove-GitHubRelease.ps1 +++ b/src/GitHub/public/Releases/Releases/Remove-GitHubRelease.ps1 @@ -39,7 +39,7 @@ Method = 'DELETE' } - if ($PSCmdlet.ShouldProcess("Release with ID [$ID] in [$Owner/$Repo]", "Delete")) { + if ($PSCmdlet.ShouldProcess("Release with ID [$ID] in [$Owner/$Repo]", 'Delete')) { (Invoke-GitHubAPI @inputObject).Response } diff --git a/src/GitHub/public/Releases/Releases/Set-GitHubRelease.ps1 b/src/GitHub/public/Releases/Releases/Set-GitHubRelease.ps1 index 0002854ce..3aad509bb 100644 --- a/src/GitHub/public/Releases/Releases/Set-GitHubRelease.ps1 +++ b/src/GitHub/public/Releases/Releases/Set-GitHubRelease.ps1 @@ -16,6 +16,7 @@ #> [OutputType([pscustomobject])] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Contains a long link.')] [CmdletBinding(SupportsShouldProcess)] param ( # The account owner of the repository. The name is not case sensitive. @@ -66,7 +67,9 @@ [Alias('discussion_category_name')] [string] $DiscussionCategoryName, - # Specifies whether this release should be set as the latest release for the repository. Drafts and prereleases cannot be set as latest. Defaults to true for newly published releases. legacy specifies that the latest release should be determined based on the release creation date and higher semantic version. + # Specifies whether this release should be set as the latest release for the repository. Drafts and prereleases cannot be set as latest. + # Defaults to true for newly published releases. legacy specifies that the latest release should be determined based on the release creation + # date and higher semantic version. [Parameter()] [Alias('make_latest')] [ValidateSet('true', 'false', 'legacy')] @@ -86,7 +89,7 @@ Body = $requestBody } - if ($PSCmdlet.ShouldProcess("release with ID [$ID] in [$Owner/$Repo]", "Update")) { + if ($PSCmdlet.ShouldProcess("release with ID [$ID] in [$Owner/$Repo]", 'Update')) { (Invoke-GitHubAPI @inputObject).Response } diff --git a/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 b/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 index 085c9ee10..9805beffe 100644 --- a/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 +++ b/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 @@ -249,7 +249,7 @@ Body = $body } - if ($PSCmdlet.ShouldProcess("Repository in organization $Owner", "Create")) { + if ($PSCmdlet.ShouldProcess("Repository in organization $Owner", 'Create')) { Invoke-GitHubAPI @inputObject | ForEach-Object { Write-Output $_.Response } diff --git a/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryUser.ps1 b/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryUser.ps1 index bda9df454..46b1dfcae 100644 --- a/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryUser.ps1 +++ b/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryUser.ps1 @@ -244,7 +244,7 @@ Body = $body } - if ($PSCmdlet.ShouldProcess("Repository for user", 'Create')) { + if ($PSCmdlet.ShouldProcess('Repository for user', 'Create')) { Invoke-GitHubAPI @inputObject | ForEach-Object { Write-Output $_.Response } diff --git a/src/GitHub/public/Repositories/Repositories/Remove-GitHubRepository.ps1 b/src/GitHub/public/Repositories/Repositories/Remove-GitHubRepository.ps1 index 33df26d47..b993f0508 100644 --- a/src/GitHub/public/Repositories/Repositories/Remove-GitHubRepository.ps1 +++ b/src/GitHub/public/Repositories/Repositories/Remove-GitHubRepository.ps1 @@ -35,7 +35,7 @@ Method = 'DELETE' } - if ($PSCmdlet.ShouldProcess("repo [$Owner/$Repo]", "Delete")) { + if ($PSCmdlet.ShouldProcess("repo [$Owner/$Repo]", 'Delete')) { Invoke-GitHubAPI @inputObject | ForEach-Object { Write-Output $_.Response } diff --git a/src/GitHub/public/Repositories/Repositories/Set-GitHubRepositoryTopic.ps1 b/src/GitHub/public/Repositories/Repositories/Set-GitHubRepositoryTopic.ps1 index 52bde9070..58cd803be 100644 --- a/src/GitHub/public/Repositories/Repositories/Set-GitHubRepositoryTopic.ps1 +++ b/src/GitHub/public/Repositories/Repositories/Set-GitHubRepositoryTopic.ps1 @@ -42,7 +42,7 @@ Body = $body } - if ($PSCmdlet.ShouldProcess("topics for repo [$Owner/$Repo]", "Set")) { + if ($PSCmdlet.ShouldProcess("topics for repo [$Owner/$Repo]", 'Set')) { Invoke-GitHubAPI @inputObject | ForEach-Object { Write-Output $_.Response.names } diff --git a/src/GitHub/public/Users/Emails/Add-GitHubUserEmail.ps1 b/src/GitHub/public/Users/Emails/Add-GitHubUserEmail.ps1 index 6d7096598..91cb4377a 100644 --- a/src/GitHub/public/Users/Emails/Add-GitHubUserEmail.ps1 +++ b/src/GitHub/public/Users/Emails/Add-GitHubUserEmail.ps1 @@ -33,7 +33,7 @@ $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case $inputObject = @{ - APIEndpoint = "/user/emails" + APIEndpoint = '/user/emails' Method = 'POST' Body = $body } diff --git a/src/GitHub/public/Users/Emails/Remove-GitHubUserEmail.ps1 b/src/GitHub/public/Users/Emails/Remove-GitHubUserEmail.ps1 index 83fecfcde..4191bff9a 100644 --- a/src/GitHub/public/Users/Emails/Remove-GitHubUserEmail.ps1 +++ b/src/GitHub/public/Users/Emails/Remove-GitHubUserEmail.ps1 @@ -30,12 +30,12 @@ $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case $inputObject = @{ - APIEndpoint = "/user/emails" + APIEndpoint = '/user/emails' Method = 'DELETE' Body = $body } - if ($PSCmdlet.ShouldProcess("Email addresses [$($Emails -join ', ')]", "Delete")) { + if ($PSCmdlet.ShouldProcess("Email addresses [$($Emails -join ', ')]", 'Delete')) { $null = (Invoke-GitHubAPI @inputObject).Response } diff --git a/src/GitHub/public/Users/Emails/Set-GitHubUserEmailVisibility.ps1 b/src/GitHub/public/Users/Emails/Set-GitHubUserEmailVisibility.ps1 index 5e8578759..e0d24f17f 100644 --- a/src/GitHub/public/Users/Emails/Set-GitHubUserEmailVisibility.ps1 +++ b/src/GitHub/public/Users/Emails/Set-GitHubUserEmailVisibility.ps1 @@ -36,12 +36,12 @@ $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case $inputObject = @{ - APIEndpoint = "/user/email/visibility" + APIEndpoint = '/user/email/visibility' Method = 'PATCH' Body = $body } - if ($PSCmdlet.ShouldProcess("Email visibility [$Visibility]", "Set")) { + if ($PSCmdlet.ShouldProcess("Email visibility [$Visibility]", 'Set')) { $null = (Invoke-GitHubAPI @inputObject).Response } diff --git a/src/GitHub/public/Users/Followers/Remove-GitHubUserFollowing.ps1 b/src/GitHub/public/Users/Followers/Remove-GitHubUserFollowing.ps1 index da063a264..7bc849106 100644 --- a/src/GitHub/public/Users/Followers/Remove-GitHubUserFollowing.ps1 +++ b/src/GitHub/public/Users/Followers/Remove-GitHubUserFollowing.ps1 @@ -33,7 +33,7 @@ Method = 'DELETE' } - if ($PSCmdlet.ShouldProcess("User [$Username]", "Unfollow")) { + if ($PSCmdlet.ShouldProcess("User [$Username]", 'Unfollow')) { $null = (Invoke-GitHubAPI @inputObject).Response } diff --git a/src/GitHub/public/Users/GPG-Keys/Remove-GitHubUserGpgKey.ps1 b/src/GitHub/public/Users/GPG-Keys/Remove-GitHubUserGpgKey.ps1 index fcf27ba79..77cdc6620 100644 --- a/src/GitHub/public/Users/GPG-Keys/Remove-GitHubUserGpgKey.ps1 +++ b/src/GitHub/public/Users/GPG-Keys/Remove-GitHubUserGpgKey.ps1 @@ -33,7 +33,7 @@ Method = 'DELETE' } - if ($PSCmdlet.ShouldProcess("GPG key with ID [$ID]", "Delete")) { + if ($PSCmdlet.ShouldProcess("GPG key with ID [$ID]", 'Delete')) { $null = (Invoke-GitHubAPI @inputObject).Response } diff --git a/src/GitHub/public/Users/Keys/Add-GitHubUserKey.ps1 b/src/GitHub/public/Users/Keys/Add-GitHubUserKey.ps1 index 6d2670829..28f123efc 100644 --- a/src/GitHub/public/Users/Keys/Add-GitHubUserKey.ps1 +++ b/src/GitHub/public/Users/Keys/Add-GitHubUserKey.ps1 @@ -5,7 +5,8 @@ .DESCRIPTION Adds a public SSH key to the authenticated user's GitHub account. - Requires that you are authenticated via Basic Auth, or OAuth with at least `write:public_key` [scope](https://docs.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/). + Requires that you are authenticated via Basic Auth, or OAuth with at least `write:public_key` + [scope](https://docs.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/). .EXAMPLE Add-GitHubUserKey -Title 'ssh-rsa AAAAB3NzaC1yc2EAAA' -Key '2Sg8iYjAxxmI2LvUXpJjkYrMxURPc8r+dB7TJyvv1234' @@ -39,7 +40,7 @@ $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case $inputObject = @{ - APIEndpoint = "/user/keys" + APIEndpoint = '/user/keys' Method = 'POST' Body = $body } diff --git a/src/GitHub/public/Users/Keys/Remove-GitHubUserKey.ps1 b/src/GitHub/public/Users/Keys/Remove-GitHubUserKey.ps1 index 7ac9129a5..973da6051 100644 --- a/src/GitHub/public/Users/Keys/Remove-GitHubUserKey.ps1 +++ b/src/GitHub/public/Users/Keys/Remove-GitHubUserKey.ps1 @@ -33,7 +33,7 @@ Method = 'DELETE' } - if ($PSCmdlet.ShouldProcess("Key with ID [$ID]", "Delete")) { + if ($PSCmdlet.ShouldProcess("Key with ID [$ID]", 'Delete')) { $null = (Invoke-GitHubAPI @inputObject).Response } diff --git a/src/GitHub/public/Users/SSH-Signing-Keys/Add-GitHubUserSigningKey.ps1 b/src/GitHub/public/Users/SSH-Signing-Keys/Add-GitHubUserSigningKey.ps1 index cb55dc119..1b46088ed 100644 --- a/src/GitHub/public/Users/SSH-Signing-Keys/Add-GitHubUserSigningKey.ps1 +++ b/src/GitHub/public/Users/SSH-Signing-Keys/Add-GitHubUserSigningKey.ps1 @@ -5,7 +5,9 @@ .DESCRIPTION Creates an SSH signing key for the authenticated user's GitHub account. - You must authenticate with Basic Authentication, or you must authenticate with OAuth with at least `write:ssh_signing_key` scope. For more information, see "[Understanding scopes for OAuth apps](https://docs.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/)." + You must authenticate with Basic Authentication, or you must authenticate with OAuth with at least `write:ssh_signing_key` scope. + For more information, see + "[Understanding scopes for OAuth apps](https://docs.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/)." .EXAMPLE Add-GitHubUserSigningKey -Title 'ssh-rsa AAAAB3NzaC1yc2EAAA' -Key '2Sg8iYjAxxmI2LvUXpJjkYrMxURPc8r+dB7TJyvv1234' @@ -27,7 +29,8 @@ [Alias('name')] [string] $Title, - # The public SSH key to add to your GitHub account. For more information, see [Checking for existing SSH keys](https://docs.github.com/authentication/connecting-to-github-with-ssh/checking-for-existing-ssh-keys)." + # The public SSH key to add to your GitHub account. For more information, see + # [Checking for existing SSH keys](https://docs.github.com/authentication/connecting-to-github-with-ssh/checking-for-existing-ssh-keys)." [Parameter( Mandatory, ValueFromPipelineByPropertyName @@ -39,7 +42,7 @@ $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case $inputObject = @{ - APIEndpoint = "/user/ssh_signing_keys" + APIEndpoint = '/user/ssh_signing_keys' Method = 'POST' Body = $body } diff --git a/src/GitHub/public/Users/SSH-Signing-Keys/Remove-GitHubUserSigningKey.ps1 b/src/GitHub/public/Users/SSH-Signing-Keys/Remove-GitHubUserSigningKey.ps1 index ffef30ff1..e04faf374 100644 --- a/src/GitHub/public/Users/SSH-Signing-Keys/Remove-GitHubUserSigningKey.ps1 +++ b/src/GitHub/public/Users/SSH-Signing-Keys/Remove-GitHubUserSigningKey.ps1 @@ -34,7 +34,7 @@ Method = 'DELETE' } - if ($PSCmdlet.ShouldProcess("SSH signing key with ID [$ID]", "Delete")) { + if ($PSCmdlet.ShouldProcess("SSH signing key with ID [$ID]", 'Delete')) { $null = (Invoke-GitHubAPI @inputObject).Response } From 6a6a8c28235698b3bc5e4970557f036ff770bcfe Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 28 Oct 2023 00:47:50 +0200 Subject: [PATCH 106/193] fix --- .github/dependabot.yml | 12 +++++----- CODE_OF_CONDUCT.md | 22 +++++++++---------- README.md | 9 ++++++++ .../Users/GPG-Keys/Add-GitHubUserGpgKey.ps1 | 13 ++++++++--- 4 files changed, 36 insertions(+), 20 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 270f2ef5e..ed7677cb0 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -5,11 +5,11 @@ version: 2 updates: - - package-ecosystem: "github-actions" # See documentation for possible values - directory: "/" # Location of package manifests + - package-ecosystem: 'github-actions' # See documentation for possible values + directory: '/' # Location of package manifests schedule: - interval: "weekly" - - package-ecosystem: "nuget" # See documentation for possible values - directory: "/" # Location of package manifests + interval: 'weekly' + - package-ecosystem: 'nuget' # See documentation for possible values + directory: '/' # Location of package manifests schedule: - interval: "weekly" + interval: 'weekly' diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 5620c53fc..1cd88506a 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -17,23 +17,23 @@ diverse, inclusive, and healthy community. Examples of behavior that contributes to a positive environment for our community include: -* Demonstrating empathy and kindness toward other people -* Being respectful of differing opinions, viewpoints, and experiences -* Giving and gracefully accepting constructive feedback -* Accepting responsibility and apologizing to those affected by our mistakes, +- Demonstrating empathy and kindness toward other people +- Being respectful of differing opinions, viewpoints, and experiences +- Giving and gracefully accepting constructive feedback +- Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience -* Focusing on what is best not just for us as individuals, but for the +- Focusing on what is best not just for us as individuals, but for the overall community Examples of unacceptable behavior include: -* The use of sexualized language or imagery, and sexual attention or +- The use of sexualized language or imagery, and sexual attention or advances of any kind -* Trolling, insulting or derogatory comments, and personal or political attacks -* Public or private harassment -* Publishing others' private information, such as a physical or email +- Trolling, insulting or derogatory comments, and personal or political attacks +- Public or private harassment +- Publishing others' private information, such as a physical or email address, without their explicit permission -* Other conduct which could reasonably be considered inappropriate in a +- Other conduct which could reasonably be considered inappropriate in a professional setting ## Enforcement Responsibilities @@ -106,7 +106,7 @@ Violating these terms may lead to a permanent ban. ### 4. Permanent Ban **Community Impact**: Demonstrating a pattern of violation of community -standards, including sustained inappropriate behavior, harassment of an +standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals. **Consequence**: A permanent ban from any sort of public interaction within diff --git a/README.md b/README.md index 6b7b037dd..3efabbd92 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,7 @@ Press Enter to open github.com in your browser...: ``` #### Personal access token + This is the least secure method of authentication, but it is also the simplest. Running the `Connect-GitHubAccount` command with the `-AccessToken` parameter will send you to the GitHub website where you can create a new personal access token. Give it the access you need and paste it into the terminal. @@ -100,6 +101,7 @@ Connect-GitHubAccount -AccessToken ``` #### System Access Token + The module also detects the presence of a system access token and uses that if it is present. This is useful if you are running the module in a CI/CD pipeline or in a scheduled task. The function looks for the `GH_TOKEN` and `GITHUB_TOKEN` environment variables (in order). @@ -110,6 +112,7 @@ Connect-GitHubAccount ``` ### Command Exploration + Familiarize yourself with the available cmdlets using the module's comprehensive documentation or inline help. ```powershell @@ -144,25 +147,31 @@ For a detailed understanding of the framework, [read more about PSModule here](h ## References ### Official GitHub Resources: + - [REST API Description](https://github.com/github/rest-api-description) - [GitHub CLI Manual](https://cli.github.com/manual/) - [GitHub Platform Samples](https://github.com/github/platform-samples) ### General Web References: + - [Generic HTTP Status Codes (MDN)](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status) ### Tools Planned for Development: + - [Azure AutoRest (OpenAPI Specification Code Generator)](https://github.com/Azure/autorest) ### Inspiration Behind the Project: + - [Microsoft's PowerShellForGitHub](https://github.com/microsoft/PowerShellForGitHub) - [PSGitHub by pcgeek86](https://github.com/pcgeek86/PSGitHub) - [PSSodium by TylerLeonhardt](https://github.com/TylerLeonhardt/PSSodium) - [libsodium NuGet Package](https://www.nuget.org/packages/Sodium.Core/) ### Authentication and Login: + - [PowerShell for GitHub on GitHub Marketplace](https://github.com/apps/powershell-for-github) - [Building a CLI with a GitHub App](https://docs.github.com/en/apps/creating-github-apps/writing-code-for-a-github-app/building-a-cli-with-a-github-app) ### Module Configuration and Environment: + - [GH Environment for GitHub CLI](https://cli.github.com/manual/gh_help_environment) diff --git a/src/GitHub/public/Users/GPG-Keys/Add-GitHubUserGpgKey.ps1 b/src/GitHub/public/Users/GPG-Keys/Add-GitHubUserGpgKey.ps1 index fee17853e..8358a709c 100644 --- a/src/GitHub/public/Users/GPG-Keys/Add-GitHubUserGpgKey.ps1 +++ b/src/GitHub/public/Users/GPG-Keys/Add-GitHubUserGpgKey.ps1 @@ -5,10 +5,17 @@ .DESCRIPTION Adds a GPG key to the authenticated user's GitHub account. - Requires that you are authenticated via Basic Auth, or OAuth with at least `write:gpg_key` [scope](https://docs.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/). + Requires that you are authenticated via Basic Auth, or OAuth with at least `write:gpg_key` + [scope](https://docs.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/). .EXAMPLE - Add-GitHubUserGpgKey -Name 'GPG key for GitHub' -ArmoredPublicKey '-----BEGIN PGP PUBLIC KEY BLOCK-----\nVersion: GnuPG v1\n\nmQINBFnZ2ZIBEADQ2Z7Z7\n-----END PGP PUBLIC KEY BLOCK-----' + Add-GitHubUserGpgKey -Name 'GPG key for GitHub' -ArmoredPublicKey @' + -----BEGIN PGP PUBLIC KEY BLOCK----- + Version: GnuPG v1 + + mQINBFnZ2ZIBEADQ2Z7Z7 + -----END PGP PUBLIC KEY BLOCK----- + '@ Adds a GPG key to the authenticated user's GitHub account. @@ -40,7 +47,7 @@ $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case $inputObject = @{ - APIEndpoint = "/user/gpg_keys" + APIEndpoint = '/user/gpg_keys' Method = 'POST' Body = $body } From 846b9f979649a385fca4bab33ccbb5e69d11b684 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 28 Oct 2023 20:17:33 +0200 Subject: [PATCH 107/193] fix --- src/GitHub/GitHub.psd1 | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/GitHub/GitHub.psd1 b/src/GitHub/GitHub.psd1 index f7d4ad99d..f73419373 100644 --- a/src/GitHub/GitHub.psd1 +++ b/src/GitHub/GitHub.psd1 @@ -1,15 +1,13 @@ @{ - # Author of this module - Author = 'Marius Storhaug' - # Version number of this module ModuleVersion = '0.3.0' # Description of the functionality provided by this module Description = 'GitHub PowerShell Module' - # Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. - PrivateData = @{ + # Private data to pass to the module specified in RootModule/ModuleToProcess. + # This may also contain a PSData hashtable with additional module metadata used by PowerShell. + PrivateData = @{ PSData = @{ From a6bcd01e7178969be74e2889110ef5dec5252df3 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 28 Oct 2023 23:16:37 +0200 Subject: [PATCH 108/193] Long line fixes --- src/GitHub/private/Users/Get-GitHubMyUser.ps1 | 6 ++-- .../private/Users/Get-GitHubUserByName.ps1 | 15 +++++++-- .../Get-GitHubUserMySigningKeyById.ps1 | 4 ++- .../Casing/Convert-StringCasingStyle.ps1 | 4 ++- .../Utilities/Hashtable/Join-Object.ps1 | 10 ++++-- .../Utilities/Web/ConvertTo-QueryString.ps1 | 8 +++-- .../Assets/Add-GitHubReleaseAsset.ps1 | 32 +++++++++++++------ 7 files changed, 57 insertions(+), 22 deletions(-) diff --git a/src/GitHub/private/Users/Get-GitHubMyUser.ps1 b/src/GitHub/private/Users/Get-GitHubMyUser.ps1 index 3bec059c4..1e17aedce 100644 --- a/src/GitHub/private/Users/Get-GitHubMyUser.ps1 +++ b/src/GitHub/private/Users/Get-GitHubMyUser.ps1 @@ -4,8 +4,10 @@ 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. + 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 diff --git a/src/GitHub/private/Users/Get-GitHubUserByName.ps1 b/src/GitHub/private/Users/Get-GitHubUserByName.ps1 index c4f008817..b8b7b8a0f 100644 --- a/src/GitHub/private/Users/Get-GitHubUserByName.ps1 +++ b/src/GitHub/private/Users/Get-GitHubUserByName.ps1 @@ -5,9 +5,17 @@ .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)". + 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' @@ -18,6 +26,7 @@ https://docs.github.com/rest/users/users#get-a-user #> [OutputType([pscustomobject])] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Contains a long link.')] [CmdletBinding()] param ( # The handle for the GitHub user account. diff --git a/src/GitHub/private/Users/SSH-Signing-Keys/Get-GitHubUserMySigningKeyById.ps1 b/src/GitHub/private/Users/SSH-Signing-Keys/Get-GitHubUserMySigningKeyById.ps1 index 677d197de..092eb26a8 100644 --- a/src/GitHub/private/Users/SSH-Signing-Keys/Get-GitHubUserMySigningKeyById.ps1 +++ b/src/GitHub/private/Users/SSH-Signing-Keys/Get-GitHubUserMySigningKeyById.ps1 @@ -5,7 +5,9 @@ .DESCRIPTION Gets extended details for an SSH signing key. - You must authenticate with Basic Authentication, or you must authenticate with OAuth with at least `read:ssh_signing_key` scope. For more information, see "[Understanding scopes for OAuth apps](https://docs.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/)." + You must authenticate with Basic Authentication, or you must authenticate with OAuth with at least `read:ssh_signing_key` scope. + For more information, see + "[Understanding scopes for OAuth apps](https://docs.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/)." .EXAMPLE Get-GitHubUserMySigningKeyById -ID '1234567' diff --git a/src/GitHub/private/Utilities/Casing/Convert-StringCasingStyle.ps1 b/src/GitHub/private/Utilities/Casing/Convert-StringCasingStyle.ps1 index 780ebbe75..25a659f77 100644 --- a/src/GitHub/private/Utilities/Casing/Convert-StringCasingStyle.ps1 +++ b/src/GitHub/private/Utilities/Casing/Convert-StringCasingStyle.ps1 @@ -62,7 +62,9 @@ '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 '') } + '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/Hashtable/Join-Object.ps1 b/src/GitHub/private/Utilities/Hashtable/Join-Object.ps1 index 9f4bb4355..7f93a32a6 100644 --- a/src/GitHub/private/Utilities/Hashtable/Join-Object.ps1 +++ b/src/GitHub/private/Utilities/Hashtable/Join-Object.ps1 @@ -4,7 +4,9 @@ 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. + 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} @@ -16,7 +18,8 @@ - - - - - 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. + 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} @@ -29,7 +32,8 @@ 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. + 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 diff --git a/src/GitHub/private/Utilities/Web/ConvertTo-QueryString.ps1 b/src/GitHub/private/Utilities/Web/ConvertTo-QueryString.ps1 index fed644eef..6fce4ecba 100644 --- a/src/GitHub/private/Utilities/Web/ConvertTo-QueryString.ps1 +++ b/src/GitHub/private/Utilities/Web/ConvertTo-QueryString.ps1 @@ -39,9 +39,13 @@ } $parameters = if ($AsURLEncoded) { - ($InputObject.GetEnumerator() | ForEach-Object { "$([System.Web.HttpUtility]::UrlEncode($_.Key))=$([System.Web.HttpUtility]::UrlEncode($_.Value))" }) -join '&' + ($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 '&' + ($InputObject.GetEnumerator() | ForEach-Object { + "$([System.Uri]::EscapeDataString($_.Key))=$([System.Uri]::EscapeDataString($_.Value))" + }) -join '&' } if ($parameters) { diff --git a/src/GitHub/public/Releases/Assets/Add-GitHubReleaseAsset.ps1 b/src/GitHub/public/Releases/Assets/Add-GitHubReleaseAsset.ps1 index 81cdb57c1..3a2198d00 100644 --- a/src/GitHub/public/Releases/Assets/Add-GitHubReleaseAsset.ps1 +++ b/src/GitHub/public/Releases/Assets/Add-GitHubReleaseAsset.ps1 @@ -4,25 +4,37 @@ Upload a release asset .DESCRIPTION - This endpoint makes use of [a Hypermedia relation](https://docs.github.com/rest/overview/resources-in-the-rest-api#hypermedia) to determine which URL to access. The endpoint you call to upload release assets is specific to your release. Use the `upload_url` returned in - the response of the [Create a release endpoint](https://docs.github.com/rest/releases/releases#create-a-release) to upload a release asset. + This endpoint makes use of [a Hypermedia relation](https://docs.github.com/rest/overview/resources-in-the-rest-api#hypermedia) + to determine which URL to access. The endpoint you call to upload release assets is specific to your release. Use the + `upload_url` returned in + the response of the [Create a release endpoint](https://docs.github.com/rest/releases/releases#create-a-release) to upload + a release asset. - You need to use an HTTP client which supports [SNI](http://en.wikipedia.org/wiki/Server_Name_Indication) to make calls to this endpoint. + You need to use an HTTP client which supports [SNI](http://en.wikipedia.org/wiki/Server_Name_Indication) to make calls to + this endpoint. - Most libraries will set the required `Content-Length` header automatically. Use the required `Content-Type` header to provide the media type of the asset. For a list of media types, see [Media Types](https://www.iana.org/assignments/media-types/media-types.xhtml). For example: + Most libraries will set the required `Content-Length` header automatically. Use the required `Content-Type` header to provide + the media type of the asset. For a list of media types, see + [Media Types](https://www.iana.org/assignments/media-types/media-types.xhtml). For example: `application/zip` - GitHub expects the asset data in its raw binary form, rather than JSON. You will send the raw binary content of the asset as the request body. Everything else about the endpoint is the same as the rest of the API. For example, + GitHub expects the asset data in its raw binary form, rather than JSON. You will send the raw binary content of the asset + as the request body. Everything else about the endpoint is the same as the rest of the API. For example, you'll still need to pass your authentication to be able to upload an asset. - When an upstream failure occurs, you will receive a `502 Bad Gateway` status. This may leave an empty asset with a state of `starter`. It can be safely deleted. + When an upstream failure occurs, you will receive a `502 Bad Gateway` status. This may leave an empty asset with a state + of `starter`. It can be safely deleted. **Notes:** - * GitHub renames asset filenames that have special characters, non-alphanumeric characters, and leading or trailing periods. The "[List release assets](https://docs.github.com/rest/releases/assets#list-release-assets)" - endpoint lists the renamed filenames. For more information and help, contact [GitHub Support](https://support.github.com/contact?tags=dotcom-rest-api). - * To find the `release_id` query the [`GET /repos/{owner}/{repo}/releases/latest` endpoint](https://docs.github.com/rest/releases/releases#get-the-latest-release). - * If you upload an asset with the same filename as another uploaded asset, you'll receive an error and must delete the old file before you can re-upload the new asset. + * GitHub renames asset filenames that have special characters, non-alphanumeric characters, and leading or trailing periods. + The "[List release assets](https://docs.github.com/rest/releases/assets#list-release-assets)" + endpoint lists the renamed filenames. For more information and help, contact + [GitHub Support](https://support.github.com/contact?tags=dotcom-rest-api). + * To find the `release_id` query the + [`GET /repos/{owner}/{repo}/releases/latest` endpoint](https://docs.github.com/rest/releases/releases#get-the-latest-release). + * If you upload an asset with the same filename as another uploaded asset, you'll receive an error and must delete + the old file before you can re-upload the new asset. .EXAMPLE Add-GitHubReleaseAsset -Owner 'octocat' -Repo 'hello-world' -ID '7654321' -FilePath 'C:\Users\octocat\Downloads\hello-world.zip' From 49475db1cd458925328b45960af409ca16f9007a Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 29 Oct 2023 09:26:14 +0100 Subject: [PATCH 109/193] fix long lines --- src/GitHub/public/Meta/Get-GitHubMeta.ps1 | 6 ++++-- .../Get-GitHubOrganizationAppInstallation.ps1 | 3 ++- src/GitHub/public/Status/Get-GitHubStatus.ps1 | 13 +++++++++---- .../public/Users/Emails/Get-GitHubUserEmail.ps1 | 3 ++- src/GitHub/public/Users/Get-GitHubUserCard.ps1 | 7 +++++-- src/GitHub/public/Users/Keys/Get-GitHubUserKey.ps1 | 3 ++- 6 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/GitHub/public/Meta/Get-GitHubMeta.ps1 b/src/GitHub/public/Meta/Get-GitHubMeta.ps1 index 0dd7b568e..90978f07c 100644 --- a/src/GitHub/public/Meta/Get-GitHubMeta.ps1 +++ b/src/GitHub/public/Meta/Get-GitHubMeta.ps1 @@ -4,13 +4,15 @@ Get GitHub meta information. .DESCRIPTION - Returns meta information about GitHub, including a list of GitHub's IP addresses. For more information, see "[About GitHub's IP addresses](https://docs.github.com/articles/about-github-s-ip-addresses/)." + Returns meta information about GitHub, including a list of GitHub's IP addresses. For more information, see + "[About GitHub's IP addresses](https://docs.github.com/articles/about-github-s-ip-addresses/)." The API's response also includes a list of GitHub's domain names. The values shown in the documentation's response are example values. You must always query the API directly to get the latest values. - **Note:** This endpoint returns both IPv4 and IPv6 addresses. However, not all features support IPv6. You should refer to the specific documentation for each feature to determine if IPv6 is supported. + **Note:** This endpoint returns both IPv4 and IPv6 addresses. However, not all features support IPv6. You should refer to the specific + documentation for each feature to determine if IPv6 is supported. .EXAMPLE Get-GitHubMeta diff --git a/src/GitHub/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 b/src/GitHub/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 index e6e5bcea2..7a3d3a53f 100644 --- a/src/GitHub/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 +++ b/src/GitHub/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 @@ -4,7 +4,8 @@ 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. + 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' diff --git a/src/GitHub/public/Status/Get-GitHubStatus.ps1 b/src/GitHub/public/Status/Get-GitHubStatus.ps1 index 9b7f0e1d7..04c0088a4 100644 --- a/src/GitHub/public/Status/Get-GitHubStatus.ps1 +++ b/src/GitHub/public/Status/Get-GitHubStatus.ps1 @@ -4,8 +4,11 @@ Gets the status of GitHub services .DESCRIPTION - Get a summary of the status page, including a status indicator, component statuses, unresolved incidents, and any upcoming or in-progress scheduled maintenances. - Get the status rollup for the whole page. This endpoint includes an indicator - one of none, minor, major, or critical, as well as a human description of the blended component status. Examples of the blended status include "All Systems Operational", "Partial System Outage", and "Major Service Outage". + Get a summary of the status page, including a status indicator, component statuses, unresolved incidents, + and any upcoming or in-progress scheduled maintenances. Get the status rollup for the whole page. This endpoint + includes an indicator - one of none, minor, major, or critical, as well as a human description of the blended + component status. Examples of the blended status include "All Systems Operational", "Partial System Outage", + and "Major Service Outage". .EXAMPLE Get-GitHubStatus @@ -15,7 +18,8 @@ .EXAMPLE Get-GitHubStatus -Summary - Gets a summary of the status page, including a status indicator, component statuses, unresolved incidents, and any upcoming or in-progress scheduled maintenances. + Gets a summary of the status page, including a status indicator, component statuses, unresolved incidents, + and any upcoming or in-progress scheduled maintenances. .NOTES https://www.githubstatus.com/api#summary @@ -24,7 +28,8 @@ [OutputType([pscustomobject])] [CmdletBinding()] param( - # Gets a summary of the status page, including a status indicator, component statuses, unresolved incidents, and any upcoming or in-progress scheduled maintenances. + # Gets a summary of the status page, including a status indicator, component statuses, unresolved incidents, + # and any upcoming or in-progress scheduled maintenances. [Parameter()] [switch] $Summary ) diff --git a/src/GitHub/public/Users/Emails/Get-GitHubUserEmail.ps1 b/src/GitHub/public/Users/Emails/Get-GitHubUserEmail.ps1 index 31f92a9d5..3d9530913 100644 --- a/src/GitHub/public/Users/Emails/Get-GitHubUserEmail.ps1 +++ b/src/GitHub/public/Users/Emails/Get-GitHubUserEmail.ps1 @@ -5,7 +5,8 @@ .DESCRIPTION Lists all of your email addresses, and specifies which one is visible to the public. This endpoint is accessible with the `user:email` scope. - Specifying '-Public' will return only the publicly visible email address, which you can set with the [Set primary email visibility for the authenticated user](https://docs.github.com/rest/users/emails#set-primary-email-visibility-for-the-authenticated-user) endpoint. + Specifying '-Public' will return only the publicly visible email address, which you can set with the [Set primary email visibility for the + authenticated user](https://docs.github.com/rest/users/emails#set-primary-email-visibility-for-the-authenticated-user) endpoint. .EXAMPLE Get-GitHubUserEmail diff --git a/src/GitHub/public/Users/Get-GitHubUserCard.ps1 b/src/GitHub/public/Users/Get-GitHubUserCard.ps1 index ee7e7d427..5b2d8abef 100644 --- a/src/GitHub/public/Users/Get-GitHubUserCard.ps1 +++ b/src/GitHub/public/Users/Get-GitHubUserCard.ps1 @@ -4,9 +4,12 @@ Get contextual information for a user .DESCRIPTION - Provides hovercard information when authenticated through basic auth or OAuth with the `repo` scope. You can find out more about someone in relation to their pull requests, issues, repositories, and organizations. + Provides hovercard information when authenticated through basic auth or OAuth with the `repo` scope. + You can find out more about someone in relation to their pull requests, issues, repositories, and organizations. - The `subject_type` and `subject_id` parameters provide context for the person's hovercard, which returns more information than without the parameters. For example, if you wanted to find out more about `octocat` who owns the `Spoon-Knife` repository via cURL, it would look like this: + The `subject_type` and `subject_id` parameters provide context for the person's hovercard, which returns + more information than without the parameters. For example, if you wanted to find out more about `octocat` + who owns the `Spoon-Knife` repository via cURL, it would look like this: ```shell curl -u username:token diff --git a/src/GitHub/public/Users/Keys/Get-GitHubUserKey.ps1 b/src/GitHub/public/Users/Keys/Get-GitHubUserKey.ps1 index bec99e8b4..6b59eb858 100644 --- a/src/GitHub/public/Users/Keys/Get-GitHubUserKey.ps1 +++ b/src/GitHub/public/Users/Keys/Get-GitHubUserKey.ps1 @@ -5,7 +5,8 @@ .DESCRIPTION Lists a given user's or the current user's public SSH keys. - For the authenticated users keys, it requires that you are authenticated via Basic Auth or via OAuth with at least `read:public_key` [scope](https://docs.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/). + For the authenticated users keys, it requires that you are authenticated via Basic Auth or via OAuth with + at least `read:public_key` [scope](https://docs.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/). Keys from a given user are accessible by anyone. .EXAMPLE From b6f2fa8aaeb9163b07cc4a15dd0ce3b76bb01708 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 29 Oct 2023 09:46:57 +0100 Subject: [PATCH 110/193] Fix --- .../public/Auth/Connect-GitHubAccount.ps1 | 262 +++++++++--------- 1 file changed, 138 insertions(+), 124 deletions(-) diff --git a/src/GitHub/public/Auth/Connect-GitHubAccount.ps1 b/src/GitHub/public/Auth/Connect-GitHubAccount.ps1 index 9b0b5eda0..cebf0553a 100644 --- a/src/GitHub/public/Auth/Connect-GitHubAccount.ps1 +++ b/src/GitHub/public/Auth/Connect-GitHubAccount.ps1 @@ -43,7 +43,11 @@ [OutputType([void])] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', 'AccessToken', Justification = 'Required for parameter set')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Justification = 'Is the CLI part of the module.')] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Justification = 'Is the CLI part of the module.')] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidUsingConvertToSecureStringWithPlainText', + '', + Justification = 'The tokens are recieved as clear text. Mitigating exposure by removing variables and performing garbage collection.' + )] [CmdletBinding(DefaultParameterSetName = 'DeviceFlow')] param ( # Choose between authentication methods, either OAuthApp or GitHubApp. @@ -88,148 +92,158 @@ [switch] $Silent ) - $envVars = Get-ChildItem -Path 'Env:' - $systemToken = $envVars | Where-Object Name -In 'GH_TOKEN', 'GITHUB_TOKEN' | Select-Object -First 1 - $systemTokenPresent = $systemToken.count -gt 0 - $AuthType = $systemTokenPresent ? 'sPAT' : $PSCmdlet.ParameterSetName - - switch ($AuthType) { - 'DeviceFlow' { - Write-Verbose 'Logging in using device flow...' - $clientID = $script:Auth.$Mode.ClientID - if ($Mode -ne (Get-GitHubConfig -Name DeviceFlowType -ErrorAction SilentlyContinue)) { - Write-Verbose "Using $Mode authentication..." - $tokenResponse = Invoke-GitHubDeviceFlowLogin -ClientID $clientID -Scope $Scope - } else { - $accessTokenValidity = [datetime](Get-GitHubConfig -Name 'AccessTokenExpirationDate') - (Get-Date) - $accessTokenIsValid = $accessTokenValidity.Seconds -gt 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 $script:Auth.AccessTokenGracePeriodInHours) { - if (-not $Silent) { - Write-Host '✓ ' -ForegroundColor Green -NoNewline - Write-Host "Access token is still valid for $accessTokenValidityText ..." + process { + $envVars = Get-ChildItem -Path 'Env:' + $systemToken = $envVars | Where-Object Name -In 'GH_TOKEN', 'GITHUB_TOKEN' | Select-Object -First 1 + $systemTokenPresent = $systemToken.count -gt 0 + $AuthType = $systemTokenPresent ? 'sPAT' : $PSCmdlet.ParameterSetName + + switch ($AuthType) { + 'DeviceFlow' { + Write-Verbose 'Logging in using device flow...' + $clientID = $script:Auth.$Mode.ClientID + if ($Mode -ne (Get-GitHubConfig -Name DeviceFlowType -ErrorAction SilentlyContinue)) { + Write-Verbose "Using $Mode authentication..." + $tokenResponse = Invoke-GitHubDeviceFlowLogin -ClientID $clientID -Scope $Scope + } else { + $accessTokenValidity = [datetime](Get-GitHubConfig -Name 'AccessTokenExpirationDate') - (Get-Date) + $accessTokenIsValid = $accessTokenValidity.Seconds -gt 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 $script:Auth.AccessTokenGracePeriodInHours) { + if (-not $Silent) { + Write-Host '✓ ' -ForegroundColor Green -NoNewline + Write-Host "Access token is still valid for $accessTokenValidityText ..." + } + break + } else { + if (-not $Silent) { + Write-Host '⚠ ' -ForegroundColor Yellow -NoNewline + Write-Host "Access token remaining validity $accessTokenValidityText. Refreshing access token..." + } + $tokenResponse = Invoke-GitHubDeviceFlowLogin -ClientID $clientID -RefreshToken (Get-GitHubConfig -Name RefreshToken) } - break } else { - if (-not $Silent) { - Write-Host '⚠ ' -ForegroundColor Yellow -NoNewline - Write-Host "Access token remaining validity $accessTokenValidityText. Refreshing access token..." + $refreshTokenValidity = [datetime](Get-GitHubConfig -Name 'RefreshTokenExpirationDate') - (Get-Date) + $refreshTokenIsValid = $refreshTokenValidity.Seconds -gt 0 + if ($refreshTokenIsValid) { + if (-not $Silent) { + Write-Host '⚠ ' -ForegroundColor Yellow -NoNewline + Write-Host 'Access token expired. Refreshing access token...' + } + $tokenResponse = Invoke-GitHubDeviceFlowLogin -ClientID $clientID -RefreshToken (Get-GitHubConfig -Name RefreshToken) + } else { + Write-Verbose "Using $Mode authentication..." + $tokenResponse = Invoke-GitHubDeviceFlowLogin -ClientID $clientID -Scope $Scope } - $tokenResponse = Invoke-GitHubDeviceFlowLogin -ClientID $clientID -RefreshToken (Get-GitHubConfig -Name RefreshToken) } - } else { - $refreshTokenValidity = [datetime](Get-GitHubConfig -Name 'RefreshTokenExpirationDate') - (Get-Date) - $refreshTokenIsValid = $refreshTokenValidity.Seconds -gt 0 - if ($refreshTokenIsValid) { - if (-not $Silent) { - Write-Host '⚠ ' -ForegroundColor Yellow -NoNewline - Write-Host 'Access token expired. Refreshing access token...' + } + Reset-GitHubConfig -Scope 'Auth' + switch ($Mode) { + 'GitHubApp' { + $settings = @{ + AccessToken = ConvertTo-SecureString -AsPlainText $tokenResponse.access_token + AccessTokenExpirationDate = (Get-Date).AddSeconds($tokenResponse.expires_in) + AccessTokenType = $tokenResponse.access_token -replace '_.*$', '_*' + ApiBaseUri = 'https://api.github.com' + ApiVersion = '2022-11-28' + AuthType = $AuthType + DeviceFlowType = $Mode + RefreshToken = ConvertTo-SecureString -AsPlainText $tokenResponse.refresh_token + RefreshTokenExpirationDate = (Get-Date).AddSeconds($tokenResponse.refresh_token_expires_in) + Scope = $tokenResponse.scope + } + } + 'OAuthApp' { + $settings = @{ + AccessToken = ConvertTo-SecureString -AsPlainText $tokenResponse.access_token + AccessTokenType = $tokenResponse.access_token -replace '_.*$', '_*' + ApiBaseUri = 'https://api.github.com' + ApiVersion = '2022-11-28' + AuthType = $AuthType + DeviceFlowType = $Mode + Scope = $tokenResponse.scope } - $tokenResponse = Invoke-GitHubDeviceFlowLogin -ClientID $clientID -RefreshToken (Get-GitHubConfig -Name RefreshToken) - } else { - Write-Verbose "Using $Mode authentication..." - $tokenResponse = Invoke-GitHubDeviceFlowLogin -ClientID $clientID -Scope $Scope } } + Set-GitHubConfig @settings + break } - Reset-GitHubConfig -Scope 'Auth' - switch ($Mode) { - 'GitHubApp' { - $settings = @{ - AccessToken = ConvertTo-SecureString -AsPlainText $tokenResponse.access_token - AccessTokenExpirationDate = (Get-Date).AddSeconds($tokenResponse.expires_in) - AccessTokenType = $tokenResponse.access_token -replace '_.*$', '_*' - ApiBaseUri = 'https://api.github.com' - ApiVersion = '2022-11-28' - AuthType = $AuthType - DeviceFlowType = $Mode - RefreshToken = ConvertTo-SecureString -AsPlainText $tokenResponse.refresh_token - RefreshTokenExpirationDate = (Get-Date).AddSeconds($tokenResponse.refresh_token_expires_in) - Scope = $tokenResponse.scope - } + 'PAT' { + Write-Verbose 'Logging in using personal access token...' + Reset-GitHubConfig -Scope 'Auth' + Write-Host '! ' -ForegroundColor DarkYellow -NoNewline + Start-Process 'https://github.com/settings/tokens' + $accessTokenValue = Read-Host -Prompt 'Enter your personal access token' -AsSecureString + $accessTokenType = (ConvertFrom-SecureString $accessTokenValue -AsPlainText) -replace '_.*$', '_*' + if ($accessTokenType -notmatch '^ghp_|^github_pat_') { + Write-Warning '⚠ ' -ForegroundColor Yellow -NoNewline + Write-Warning "Unexpected access token format: $accessTokenType" } - 'OAuthApp' { - $settings = @{ - AccessToken = ConvertTo-SecureString -AsPlainText $tokenResponse.access_token - AccessTokenType = $tokenResponse.access_token -replace '_.*$', '_*' - ApiBaseUri = 'https://api.github.com' - ApiVersion = '2022-11-28' - AuthType = $AuthType - DeviceFlowType = $Mode - Scope = $tokenResponse.scope - } + $settings = @{ + AccessToken = $accessTokenValue + AccessTokenType = $accessTokenType + ApiBaseUri = 'https://api.github.com' + ApiVersion = '2022-11-28' + AuthType = $AuthType } + Set-GitHubConfig @settings + break } - Set-GitHubConfig @settings - break - } - 'PAT' { - Write-Verbose 'Logging in using personal access token...' - Reset-GitHubConfig -Scope 'Auth' - Write-Host '! ' -ForegroundColor DarkYellow -NoNewline - Start-Process 'https://github.com/settings/tokens' - $accessTokenValue = Read-Host -Prompt 'Enter your personal access token' -AsSecureString - $accessTokenType = (ConvertFrom-SecureString $accessTokenValue -AsPlainText) -replace '_.*$', '_*' - if ($accessTokenType -notmatch '^ghp_|^github_pat_') { - Write-Warning '⚠ ' -ForegroundColor Yellow -NoNewline - Write-Warning "Unexpected access token format: $accessTokenType" - } - $settings = @{ - AccessToken = $accessTokenValue - AccessTokenType = $accessTokenType - ApiBaseUri = 'https://api.github.com' - ApiVersion = '2022-11-28' - AuthType = $AuthType + 'sPAT' { + Write-Verbose 'Logging in using system access token...' + Reset-GitHubConfig -Scope 'Auth' + $prefix = $systemToken.Value -replace '_.*$', '_*' + $settings = @{ + AccessToken = ConvertTo-SecureString -AsPlainText $systemToken.Value + AccessTokenType = $prefix + ApiBaseUri = 'https://api.github.com' + ApiVersion = '2022-11-28' + AuthType = 'sPAT' + } + Set-GitHubConfig @settings } - Set-GitHubConfig @settings - break } - 'sPAT' { - Write-Verbose 'Logging in using system access token...' - Reset-GitHubConfig -Scope 'Auth' - $prefix = $systemToken.Value -replace '_.*$', '_*' - $settings = @{ - AccessToken = ConvertTo-SecureString -AsPlainText $systemToken.Value - AccessTokenType = $prefix - ApiBaseUri = 'https://api.github.com' - ApiVersion = '2022-11-28' - AuthType = 'sPAT' - } - Set-GitHubConfig @settings + + if ($AuthType -ne 'sPAT') { + $user = Get-GitHubUser + $username = $user.login + Set-GitHubConfig -UserName $username + } else { + $username = 'system' } - } - if ($AuthType -ne 'sPAT') { - $user = Get-GitHubUser - $username = $user.login - Set-GitHubConfig -UserName $username - } else { - $username = 'system' - } + if (-not $Silent) { + Write-Host '✓ ' -ForegroundColor Green -NoNewline + Write-Host "Logged in as $username!" + } - if (-not $Silent) { - Write-Host '✓ ' -ForegroundColor Green -NoNewline - Write-Host "Logged in as $username!" - } + $systemRepo = $envVars | Where-Object Name -EQ 'GITHUB_REPOSITORY' + $systemRepoPresent = $systemRepo.count -gt 0 - $systemRepo = $envVars | Where-Object Name -EQ 'GITHUB_REPOSITORY' - $systemRepoPresent = $systemRepo.count -gt 0 + if ($Owner) { + Set-GitHubConfig -Owner $Owner + } elseif ($systemRepoPresent) { + $owner = $systemRepo.Value.Split('/')[0] + Set-GitHubConfig -Owner $owner + } - if ($Owner) { - Set-GitHubConfig -Owner $Owner - } elseif ($systemRepoPresent) { - $owner = $systemRepo.Value.Split('/')[0] - Set-GitHubConfig -Owner $owner + if ($Repo) { + Set-GitHubConfig -Repo $Repo + } elseif ($systemRepoPresent) { + $repo = $systemRepo.Value.Split('/')[-1] + Set-GitHubConfig -Repo $repo + } } - if ($Repo) { - Set-GitHubConfig -Repo $Repo - } elseif ($systemRepoPresent) { - $repo = $systemRepo.Value.Split('/')[-1] - Set-GitHubConfig -Repo $repo + # Using clean to make sure we remove the access token in plain text from memory. + #Requires -Version 7.3 + clean { + Remove-Variable -Name tokenResponse -ErrorAction SilentlyContinue + Remove-Variable -Name settings -ErrorAction SilentlyContinue + [System.GC]::Collect() } } From b3c573b5b19f88d94246caf9cb30002c3cb15b8f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 29 Oct 2023 13:21:19 +0100 Subject: [PATCH 111/193] Fix for PWSH 7.0 --- .../public/Auth/Connect-GitHubAccount.ps1 | 261 +++++++++--------- 1 file changed, 128 insertions(+), 133 deletions(-) diff --git a/src/GitHub/public/Auth/Connect-GitHubAccount.ps1 b/src/GitHub/public/Auth/Connect-GitHubAccount.ps1 index cebf0553a..c2645e198 100644 --- a/src/GitHub/public/Auth/Connect-GitHubAccount.ps1 +++ b/src/GitHub/public/Auth/Connect-GitHubAccount.ps1 @@ -92,158 +92,153 @@ [switch] $Silent ) - process { - $envVars = Get-ChildItem -Path 'Env:' - $systemToken = $envVars | Where-Object Name -In 'GH_TOKEN', 'GITHUB_TOKEN' | Select-Object -First 1 - $systemTokenPresent = $systemToken.count -gt 0 - $AuthType = $systemTokenPresent ? 'sPAT' : $PSCmdlet.ParameterSetName - - switch ($AuthType) { - 'DeviceFlow' { - Write-Verbose 'Logging in using device flow...' - $clientID = $script:Auth.$Mode.ClientID - if ($Mode -ne (Get-GitHubConfig -Name DeviceFlowType -ErrorAction SilentlyContinue)) { - Write-Verbose "Using $Mode authentication..." - $tokenResponse = Invoke-GitHubDeviceFlowLogin -ClientID $clientID -Scope $Scope - } else { - $accessTokenValidity = [datetime](Get-GitHubConfig -Name 'AccessTokenExpirationDate') - (Get-Date) - $accessTokenIsValid = $accessTokenValidity.Seconds -gt 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 $script:Auth.AccessTokenGracePeriodInHours) { - if (-not $Silent) { - Write-Host '✓ ' -ForegroundColor Green -NoNewline - Write-Host "Access token is still valid for $accessTokenValidityText ..." - } - break - } else { - if (-not $Silent) { - Write-Host '⚠ ' -ForegroundColor Yellow -NoNewline - Write-Host "Access token remaining validity $accessTokenValidityText. Refreshing access token..." - } - $tokenResponse = Invoke-GitHubDeviceFlowLogin -ClientID $clientID -RefreshToken (Get-GitHubConfig -Name RefreshToken) + $envVars = Get-ChildItem -Path 'Env:' + $systemToken = $envVars | Where-Object Name -In 'GH_TOKEN', 'GITHUB_TOKEN' | Select-Object -First 1 + $systemTokenPresent = $systemToken.count -gt 0 + $AuthType = $systemTokenPresent ? 'sPAT' : $PSCmdlet.ParameterSetName + + switch ($AuthType) { + 'DeviceFlow' { + Write-Verbose 'Logging in using device flow...' + $clientID = $script:Auth.$Mode.ClientID + if ($Mode -ne (Get-GitHubConfig -Name DeviceFlowType -ErrorAction SilentlyContinue)) { + Write-Verbose "Using $Mode authentication..." + $tokenResponse = Invoke-GitHubDeviceFlowLogin -ClientID $clientID -Scope $Scope + } else { + $accessTokenValidity = [datetime](Get-GitHubConfig -Name 'AccessTokenExpirationDate') - (Get-Date) + $accessTokenIsValid = $accessTokenValidity.Seconds -gt 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 $script:Auth.AccessTokenGracePeriodInHours) { + if (-not $Silent) { + Write-Host '✓ ' -ForegroundColor Green -NoNewline + Write-Host "Access token is still valid for $accessTokenValidityText ..." } + break } else { - $refreshTokenValidity = [datetime](Get-GitHubConfig -Name 'RefreshTokenExpirationDate') - (Get-Date) - $refreshTokenIsValid = $refreshTokenValidity.Seconds -gt 0 - if ($refreshTokenIsValid) { - if (-not $Silent) { - Write-Host '⚠ ' -ForegroundColor Yellow -NoNewline - Write-Host 'Access token expired. Refreshing access token...' - } - $tokenResponse = Invoke-GitHubDeviceFlowLogin -ClientID $clientID -RefreshToken (Get-GitHubConfig -Name RefreshToken) - } else { - Write-Verbose "Using $Mode authentication..." - $tokenResponse = Invoke-GitHubDeviceFlowLogin -ClientID $clientID -Scope $Scope + if (-not $Silent) { + Write-Host '⚠ ' -ForegroundColor Yellow -NoNewline + Write-Host "Access token remaining validity $accessTokenValidityText. Refreshing access token..." } + $tokenResponse = Invoke-GitHubDeviceFlowLogin -ClientID $clientID -RefreshToken (Get-GitHubConfig -Name RefreshToken) } - } - Reset-GitHubConfig -Scope 'Auth' - switch ($Mode) { - 'GitHubApp' { - $settings = @{ - AccessToken = ConvertTo-SecureString -AsPlainText $tokenResponse.access_token - AccessTokenExpirationDate = (Get-Date).AddSeconds($tokenResponse.expires_in) - AccessTokenType = $tokenResponse.access_token -replace '_.*$', '_*' - ApiBaseUri = 'https://api.github.com' - ApiVersion = '2022-11-28' - AuthType = $AuthType - DeviceFlowType = $Mode - RefreshToken = ConvertTo-SecureString -AsPlainText $tokenResponse.refresh_token - RefreshTokenExpirationDate = (Get-Date).AddSeconds($tokenResponse.refresh_token_expires_in) - Scope = $tokenResponse.scope - } - } - 'OAuthApp' { - $settings = @{ - AccessToken = ConvertTo-SecureString -AsPlainText $tokenResponse.access_token - AccessTokenType = $tokenResponse.access_token -replace '_.*$', '_*' - ApiBaseUri = 'https://api.github.com' - ApiVersion = '2022-11-28' - AuthType = $AuthType - DeviceFlowType = $Mode - Scope = $tokenResponse.scope + } else { + $refreshTokenValidity = [datetime](Get-GitHubConfig -Name 'RefreshTokenExpirationDate') - (Get-Date) + $refreshTokenIsValid = $refreshTokenValidity.Seconds -gt 0 + if ($refreshTokenIsValid) { + if (-not $Silent) { + Write-Host '⚠ ' -ForegroundColor Yellow -NoNewline + Write-Host 'Access token expired. Refreshing access token...' } + $tokenResponse = Invoke-GitHubDeviceFlowLogin -ClientID $clientID -RefreshToken (Get-GitHubConfig -Name RefreshToken) + } else { + Write-Verbose "Using $Mode authentication..." + $tokenResponse = Invoke-GitHubDeviceFlowLogin -ClientID $clientID -Scope $Scope } } - Set-GitHubConfig @settings - break } - 'PAT' { - Write-Verbose 'Logging in using personal access token...' - Reset-GitHubConfig -Scope 'Auth' - Write-Host '! ' -ForegroundColor DarkYellow -NoNewline - Start-Process 'https://github.com/settings/tokens' - $accessTokenValue = Read-Host -Prompt 'Enter your personal access token' -AsSecureString - $accessTokenType = (ConvertFrom-SecureString $accessTokenValue -AsPlainText) -replace '_.*$', '_*' - if ($accessTokenType -notmatch '^ghp_|^github_pat_') { - Write-Warning '⚠ ' -ForegroundColor Yellow -NoNewline - Write-Warning "Unexpected access token format: $accessTokenType" + Reset-GitHubConfig -Scope 'Auth' + switch ($Mode) { + 'GitHubApp' { + $settings = @{ + AccessToken = ConvertTo-SecureString -AsPlainText $tokenResponse.access_token + AccessTokenExpirationDate = (Get-Date).AddSeconds($tokenResponse.expires_in) + AccessTokenType = $tokenResponse.access_token -replace '_.*$', '_*' + ApiBaseUri = 'https://api.github.com' + ApiVersion = '2022-11-28' + AuthType = $AuthType + DeviceFlowType = $Mode + RefreshToken = ConvertTo-SecureString -AsPlainText $tokenResponse.refresh_token + RefreshTokenExpirationDate = (Get-Date).AddSeconds($tokenResponse.refresh_token_expires_in) + Scope = $tokenResponse.scope + } } - $settings = @{ - AccessToken = $accessTokenValue - AccessTokenType = $accessTokenType - ApiBaseUri = 'https://api.github.com' - ApiVersion = '2022-11-28' - AuthType = $AuthType + 'OAuthApp' { + $settings = @{ + AccessToken = ConvertTo-SecureString -AsPlainText $tokenResponse.access_token + AccessTokenType = $tokenResponse.access_token -replace '_.*$', '_*' + ApiBaseUri = 'https://api.github.com' + ApiVersion = '2022-11-28' + AuthType = $AuthType + DeviceFlowType = $Mode + Scope = $tokenResponse.scope + } } - Set-GitHubConfig @settings - break } - 'sPAT' { - Write-Verbose 'Logging in using system access token...' - Reset-GitHubConfig -Scope 'Auth' - $prefix = $systemToken.Value -replace '_.*$', '_*' - $settings = @{ - AccessToken = ConvertTo-SecureString -AsPlainText $systemToken.Value - AccessTokenType = $prefix - ApiBaseUri = 'https://api.github.com' - ApiVersion = '2022-11-28' - AuthType = 'sPAT' - } - Set-GitHubConfig @settings + Set-GitHubConfig @settings + break + } + 'PAT' { + Write-Verbose 'Logging in using personal access token...' + Reset-GitHubConfig -Scope 'Auth' + Write-Host '! ' -ForegroundColor DarkYellow -NoNewline + Start-Process 'https://github.com/settings/tokens' + $accessTokenValue = Read-Host -Prompt 'Enter your personal access token' -AsSecureString + $accessTokenType = (ConvertFrom-SecureString $accessTokenValue -AsPlainText) -replace '_.*$', '_*' + if ($accessTokenType -notmatch '^ghp_|^github_pat_') { + Write-Warning '⚠ ' -ForegroundColor Yellow -NoNewline + Write-Warning "Unexpected access token format: $accessTokenType" } + $settings = @{ + AccessToken = $accessTokenValue + AccessTokenType = $accessTokenType + ApiBaseUri = 'https://api.github.com' + ApiVersion = '2022-11-28' + AuthType = $AuthType + } + Set-GitHubConfig @settings + break } - - if ($AuthType -ne 'sPAT') { - $user = Get-GitHubUser - $username = $user.login - Set-GitHubConfig -UserName $username - } else { - $username = 'system' + 'sPAT' { + Write-Verbose 'Logging in using system access token...' + Reset-GitHubConfig -Scope 'Auth' + $prefix = $systemToken.Value -replace '_.*$', '_*' + $settings = @{ + AccessToken = ConvertTo-SecureString -AsPlainText $systemToken.Value + AccessTokenType = $prefix + ApiBaseUri = 'https://api.github.com' + ApiVersion = '2022-11-28' + AuthType = 'sPAT' + } + Set-GitHubConfig @settings } + } - if (-not $Silent) { - Write-Host '✓ ' -ForegroundColor Green -NoNewline - Write-Host "Logged in as $username!" - } + if ($AuthType -ne 'sPAT') { + $user = Get-GitHubUser + $username = $user.login + Set-GitHubConfig -UserName $username + } else { + $username = 'system' + } - $systemRepo = $envVars | Where-Object Name -EQ 'GITHUB_REPOSITORY' - $systemRepoPresent = $systemRepo.count -gt 0 + if (-not $Silent) { + Write-Host '✓ ' -ForegroundColor Green -NoNewline + Write-Host "Logged in as $username!" + } - if ($Owner) { - Set-GitHubConfig -Owner $Owner - } elseif ($systemRepoPresent) { - $owner = $systemRepo.Value.Split('/')[0] - Set-GitHubConfig -Owner $owner - } + $systemRepo = $envVars | Where-Object Name -EQ 'GITHUB_REPOSITORY' + $systemRepoPresent = $systemRepo.count -gt 0 - if ($Repo) { - Set-GitHubConfig -Repo $Repo - } elseif ($systemRepoPresent) { - $repo = $systemRepo.Value.Split('/')[-1] - Set-GitHubConfig -Repo $repo - } + if ($Owner) { + Set-GitHubConfig -Owner $Owner + } elseif ($systemRepoPresent) { + $owner = $systemRepo.Value.Split('/')[0] + Set-GitHubConfig -Owner $owner } - # Using clean to make sure we remove the access token in plain text from memory. - #Requires -Version 7.3 - clean { - Remove-Variable -Name tokenResponse -ErrorAction SilentlyContinue - Remove-Variable -Name settings -ErrorAction SilentlyContinue - [System.GC]::Collect() + if ($Repo) { + Set-GitHubConfig -Repo $Repo + } elseif ($systemRepoPresent) { + $repo = $systemRepo.Value.Split('/')[-1] + Set-GitHubConfig -Repo $repo } + + Remove-Variable -Name tokenResponse -ErrorAction SilentlyContinue + Remove-Variable -Name settings -ErrorAction SilentlyContinue + [System.GC]::Collect() + } From a9648ae8f2db900021ad223533aac6f6ec011073 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 29 Oct 2023 13:23:39 +0100 Subject: [PATCH 112/193] ws fix --- 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 c2645e198..7aa368675 100644 --- a/src/GitHub/public/Auth/Connect-GitHubAccount.ps1 +++ b/src/GitHub/public/Auth/Connect-GitHubAccount.ps1 @@ -236,7 +236,7 @@ $repo = $systemRepo.Value.Split('/')[-1] Set-GitHubConfig -Repo $repo } - + Remove-Variable -Name tokenResponse -ErrorAction SilentlyContinue Remove-Variable -Name settings -ErrorAction SilentlyContinue [System.GC]::Collect() From d3f51a491941031a891c6d512520a81f2b4cdf36 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 29 Oct 2023 13:26:39 +0100 Subject: [PATCH 113/193] Fix --- src/GitHub/public/Users/Blocking/Block-GitHubUser.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/src/GitHub/public/Users/Blocking/Block-GitHubUser.ps1 b/src/GitHub/public/Users/Blocking/Block-GitHubUser.ps1 index 1a469cf4b..9e71bc02f 100644 --- a/src/GitHub/public/Users/Blocking/Block-GitHubUser.ps1 +++ b/src/GitHub/public/Users/Blocking/Block-GitHubUser.ps1 @@ -42,7 +42,6 @@ )] [Alias('org')] [Alias('owner')] - [Alias('login')] [string] $OrganizationName ) From ae88213ca438d789606a605b48cbf62db04ce829 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 29 Oct 2023 13:31:00 +0100 Subject: [PATCH 114/193] fix alias Test-GitHubBlockedUser --- src/GitHub/public/Users/Blocking/Test-GitHubBlockedUser.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/src/GitHub/public/Users/Blocking/Test-GitHubBlockedUser.ps1 b/src/GitHub/public/Users/Blocking/Test-GitHubBlockedUser.ps1 index 154c4aad7..62dbd99d6 100644 --- a/src/GitHub/public/Users/Blocking/Test-GitHubBlockedUser.ps1 +++ b/src/GitHub/public/Users/Blocking/Test-GitHubBlockedUser.ps1 @@ -42,7 +42,6 @@ )] [Alias('org')] [Alias('owner')] - [Alias('login')] [string] $OrganizationName, # The number of results per page (max 100). From 4beffeeec123be268a8b6b02212396c4e9a0290f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 29 Oct 2023 13:41:07 +0100 Subject: [PATCH 115/193] Fix Unblock-GitHubUser --- src/GitHub/public/Users/Blocking/Unblock-GitHubUser.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/src/GitHub/public/Users/Blocking/Unblock-GitHubUser.ps1 b/src/GitHub/public/Users/Blocking/Unblock-GitHubUser.ps1 index 854a1ef70..440bb0ae3 100644 --- a/src/GitHub/public/Users/Blocking/Unblock-GitHubUser.ps1 +++ b/src/GitHub/public/Users/Blocking/Unblock-GitHubUser.ps1 @@ -41,7 +41,6 @@ )] [Alias('org')] [Alias('owner')] - [Alias('login')] [string] $OrganizationName ) From 5efd451e102bcd3803f89facd4d2578fc18bfb16 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 29 Oct 2023 18:11:20 +0100 Subject: [PATCH 116/193] Fix --- .github/workflows/Process-PSModule.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/Process-PSModule.yml b/.github/workflows/Process-PSModule.yml index cb2eb1cc6..69e01c135 100644 --- a/.github/workflows/Process-PSModule.yml +++ b/.github/workflows/Process-PSModule.yml @@ -11,3 +11,5 @@ jobs: Process-PSModule: uses: PSModule/Actions/.github/workflows/Process-PSModule.yml@main secrets: inherit + with: + TestModuleErrorAction: 'Continue' From c3b19467154bd2dc997c902fb70f683a3e989671 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 29 Oct 2023 18:42:55 +0100 Subject: [PATCH 117/193] Attempt to fix longline --- src/GitHub/private/License/Get-GitHubLicenseByName.ps1 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/GitHub/private/License/Get-GitHubLicenseByName.ps1 b/src/GitHub/private/License/Get-GitHubLicenseByName.ps1 index 77afc3d7a..638f5ab98 100644 --- a/src/GitHub/private/License/Get-GitHubLicenseByName.ps1 +++ b/src/GitHub/private/License/Get-GitHubLicenseByName.ps1 @@ -16,7 +16,12 @@ filter Get-GitHubLicenseByName { https://docs.github.com/rest/licenses/licenses#get-a-license #> - [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Contains a long link.')] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidLongLines', '', + Scope = 'function', + Target = 'Get-GitHubLicenseByName', + Justification = 'Contains a long link.' + )] [CmdletBinding()] param ( # The license keyword, license name, or license SPDX ID. For example, mit or mpl-2.0. From 27ec0fee624845c788b4e1c1d633da9b9fac1c74 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 29 Oct 2023 18:56:01 +0100 Subject: [PATCH 118/193] fix --- src/GitHub/private/License/Get-GitHubLicenseByName.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/src/GitHub/private/License/Get-GitHubLicenseByName.ps1 b/src/GitHub/private/License/Get-GitHubLicenseByName.ps1 index 638f5ab98..694c52de3 100644 --- a/src/GitHub/private/License/Get-GitHubLicenseByName.ps1 +++ b/src/GitHub/private/License/Get-GitHubLicenseByName.ps1 @@ -19,7 +19,6 @@ filter Get-GitHubLicenseByName { [Diagnostics.CodeAnalysis.SuppressMessageAttribute( 'PSAvoidLongLines', '', Scope = 'function', - Target = 'Get-GitHubLicenseByName', Justification = 'Contains a long link.' )] [CmdletBinding()] From 493240e6be8cd064ab49e1898a5509af555bff9a Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 29 Oct 2023 20:13:31 +0100 Subject: [PATCH 119/193] Add an attributes file for the module --- src/GitHub/attributes.txt | 1 + src/GitHub/private/License/Get-GitHubLicenseByName.ps1 | 6 +----- 2 files changed, 2 insertions(+), 5 deletions(-) create mode 100644 src/GitHub/attributes.txt diff --git a/src/GitHub/attributes.txt b/src/GitHub/attributes.txt new file mode 100644 index 000000000..657928f49 --- /dev/null +++ b/src/GitHub/attributes.txt @@ -0,0 +1 @@ +[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Contains a long link.')] diff --git a/src/GitHub/private/License/Get-GitHubLicenseByName.ps1 b/src/GitHub/private/License/Get-GitHubLicenseByName.ps1 index 694c52de3..77afc3d7a 100644 --- a/src/GitHub/private/License/Get-GitHubLicenseByName.ps1 +++ b/src/GitHub/private/License/Get-GitHubLicenseByName.ps1 @@ -16,11 +16,7 @@ filter Get-GitHubLicenseByName { https://docs.github.com/rest/licenses/licenses#get-a-license #> - [Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSAvoidLongLines', '', - Scope = 'function', - Justification = 'Contains a long link.' - )] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Contains a long link.')] [CmdletBinding()] param ( # The license keyword, license name, or license SPDX ID. For example, mit or mpl-2.0. From 6c2eef81846a26a526a994164c97ba6729850dea Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 29 Oct 2023 20:37:08 +0100 Subject: [PATCH 120/193] Remove the continue for errors on tests --- .github/workflows/Process-PSModule.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/Process-PSModule.yml b/.github/workflows/Process-PSModule.yml index 69e01c135..cb2eb1cc6 100644 --- a/.github/workflows/Process-PSModule.yml +++ b/.github/workflows/Process-PSModule.yml @@ -11,5 +11,3 @@ jobs: Process-PSModule: uses: PSModule/Actions/.github/workflows/Process-PSModule.yml@main secrets: inherit - with: - TestModuleErrorAction: 'Continue' From 7134cfc5bc420a68110934b89478611a9d819325 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 29 Oct 2023 21:29:10 +0100 Subject: [PATCH 121/193] Fix pipeline streaming --- .../Blocking/Get-GitHubBlockedUserByOrganization.ps1 | 5 +++-- .../private/Organization/Get-GitHubAllOrganization.ps1 | 4 +++- src/GitHub/private/Organization/Get-GitHubMyOrganization.ps1 | 5 +++-- .../private/Organization/Get-GitHubOrganizationByName.ps1 | 4 +++- .../private/Organization/Get-GitHubUserOrganization.ps1 | 5 +++-- .../private/Releases/Assets/Get-GitHubReleaseAssetByID.ps1 | 5 +++-- .../Releases/Assets/Get-GitHubReleaseAssetByReleaseID.ps1 | 5 +++-- .../private/Releases/Releases/Get-GitHubReleaseAll.ps1 | 4 +++- .../private/Releases/Releases/Get-GitHubReleaseByID.ps1 | 4 +++- .../private/Releases/Releases/Get-GitHubReleaseByTagName.ps1 | 4 +++- .../private/Releases/Releases/Get-GitHubReleaseLatest.ps1 | 4 +++- .../private/Users/Blocking/Get-GitHubBlockedUserByUser.ps1 | 4 +++- src/GitHub/private/Users/Emails/Get-GitHubUserAllEmail.ps1 | 4 +++- .../private/Users/Emails/Get-GitHubUserPublicEmail.ps1 | 4 +++- .../Users/Followers/Get-GitHubUserFollowersOfUser.ps1 | 4 +++- .../private/Users/Followers/Get-GitHubUserFollowingMe.ps1 | 4 +++- .../private/Users/Followers/Get-GitHubUserFollowingUser.ps1 | 4 +++- .../private/Users/Followers/Get-GitHubUserMyFollowers.ps1 | 4 +++- .../private/Users/GPG-Keys/Get-GitHubUserGpgKeyForUser.ps1 | 4 +++- src/GitHub/private/Users/GPG-Keys/Get-GitHubUserMyGpgKey.ps1 | 4 +++- .../private/Users/GPG-Keys/Get-GitHubUserMyGpgKeyById.ps1 | 4 +++- src/GitHub/private/Users/Get-GitHubAllUser.ps1 | 4 +++- src/GitHub/private/Users/Get-GitHubMyUser.ps1 | 4 +++- src/GitHub/private/Users/Get-GitHubUserByName.ps1 | 4 +++- src/GitHub/private/Users/Keys/Get-GitHubUserKeyForUser.ps1 | 4 +++- src/GitHub/private/Users/Keys/Get-GitHubUserMyKey.ps1 | 4 +++- src/GitHub/private/Users/Keys/Get-GitHubUserMyKeyById.ps1 | 4 +++- .../Users/SSH-Signing-Keys/Get-GitHubUserMySigningKey.ps1 | 4 +++- .../SSH-Signing-Keys/Get-GitHubUserMySigningKeyById.ps1 | 4 +++- .../SSH-Signing-Keys/Get-GitHubUserSigningKeyForUser.ps1 | 4 +++- .../Users/Social-Accounts/Get-GitHubMyUserSocials.ps1 | 4 +++- .../Users/Social-Accounts/Get-GitHubUserSocialsByName.ps1 | 4 +++- src/GitHub/public/Actions/Get-GitHubWorkflow.ps1 | 4 +++- src/GitHub/public/Actions/Get-GitHubWorkflowRun.ps1 | 4 +++- src/GitHub/public/Actions/Get-GitHubWorkflowUsage.ps1 | 4 +++- src/GitHub/public/Actions/Remove-GitHubWorkflowRun.ps1 | 4 +++- src/GitHub/public/Actions/Start-GitHubWorkflow.ps1 | 4 +++- src/GitHub/public/Actions/Start-GitHubWorkflowReRun.ps1 | 4 +++- src/GitHub/public/Actions/Stop-GitHubWorkflowRun.ps1 | 4 +++- src/GitHub/public/Branches/Get-GitHubRepoBranch.ps1 | 4 +++- src/GitHub/public/Emojis/Get-GitHubEmoji.ps1 | 4 +++- src/GitHub/public/Markdown/Get-GitHubMarkdown.ps1 | 4 +++- src/GitHub/public/Markdown/Get-GitHubMarkdownRaw.ps1 | 4 +++- src/GitHub/public/Meta/Get-GitHubApiVersion.ps1 | 4 +++- src/GitHub/public/Meta/Get-GitHubMeta.ps1 | 4 +++- src/GitHub/public/Meta/Get-GitHubOctocat.ps1 | 4 +++- src/GitHub/public/Meta/Get-GitHubRoot.ps1 | 4 +++- src/GitHub/public/Meta/Get-GitHubZen.ps1 | 4 +++- .../Organization/Get-GitHubOrganizationAppInstallation.ps1 | 4 +++- src/GitHub/public/Organization/Remove-GitHubOrganization.ps1 | 4 +++- src/GitHub/public/Organization/Set-GitHubOrganization.ps1 | 4 +++- .../Organization/Set-GitHubOrganizationSecurityFeature.ps1 | 4 +++- src/GitHub/public/Rate-Limit/Get-GitHubRateLimit.ps1 | 4 +++- src/GitHub/public/Releases/Assets/Add-GitHubReleaseAsset.ps1 | 4 +++- .../public/Releases/Assets/Remove-GitHubReleaseAsset.ps1 | 4 +++- src/GitHub/public/Releases/Assets/Set-GitHubReleaseAsset.ps1 | 4 +++- src/GitHub/public/Releases/Releases/New-GitHubRelease.ps1 | 4 +++- .../public/Releases/Releases/New-GitHubReleaseNote.ps1 | 4 +++- src/GitHub/public/Releases/Releases/Remove-GitHubRelease.ps1 | 4 +++- src/GitHub/public/Releases/Releases/Set-GitHubRelease.ps1 | 4 +++- src/GitHub/public/Teams/Get-GitHubRepoTeam.ps1 | 4 +++- src/GitHub/public/Users/Emails/Add-GitHubUserEmail.ps1 | 4 +++- src/GitHub/public/Users/Emails/Remove-GitHubUserEmail.ps1 | 4 +++- .../public/Users/Emails/Set-GitHubUserEmailVisibility.ps1 | 4 +++- .../public/Users/Followers/Add-GitHubUserFollowing.ps1 | 4 +++- .../public/Users/Followers/Remove-GitHubUserFollowing.ps1 | 4 +++- src/GitHub/public/Users/GPG-Keys/Add-GitHubUserGpgKey.ps1 | 4 +++- src/GitHub/public/Users/GPG-Keys/Remove-GitHubUserGpgKey.ps1 | 4 +++- src/GitHub/public/Users/Get-GitHubUserCard.ps1 | 4 +++- src/GitHub/public/Users/Keys/Add-GitHubUserKey.ps1 | 4 +++- src/GitHub/public/Users/Keys/Remove-GitHubUserKey.ps1 | 4 +++- .../Users/SSH-Signing-Keys/Add-GitHubUserSigningKey.ps1 | 4 +++- .../Users/SSH-Signing-Keys/Remove-GitHubUserSigningKey.ps1 | 4 +++- src/GitHub/public/Users/Set-GitHubUser.ps1 | 4 +++- .../public/Users/Social-Accounts/Add-GitHubUserSocial.ps1 | 4 +++- .../public/Users/Social-Accounts/Remove-GitHubUserSocial.ps1 | 4 +++- 76 files changed, 228 insertions(+), 81 deletions(-) diff --git a/src/GitHub/private/Organization/Blocking/Get-GitHubBlockedUserByOrganization.ps1 b/src/GitHub/private/Organization/Blocking/Get-GitHubBlockedUserByOrganization.ps1 index 42f317ac7..6a9d2bbfd 100644 --- a/src/GitHub/private/Organization/Blocking/Get-GitHubBlockedUserByOrganization.ps1 +++ b/src/GitHub/private/Organization/Blocking/Get-GitHubBlockedUserByOrganization.ps1 @@ -40,6 +40,7 @@ Body = $body } - (Invoke-GitHubAPI @inputObject).Response - + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/private/Organization/Get-GitHubAllOrganization.ps1 b/src/GitHub/private/Organization/Get-GitHubAllOrganization.ps1 index 924b7f4b1..630a82bfd 100644 --- a/src/GitHub/private/Organization/Get-GitHubAllOrganization.ps1 +++ b/src/GitHub/private/Organization/Get-GitHubAllOrganization.ps1 @@ -43,6 +43,8 @@ Body = $body } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/private/Organization/Get-GitHubMyOrganization.ps1 b/src/GitHub/private/Organization/Get-GitHubMyOrganization.ps1 index 353aadda9..eeb373552 100644 --- a/src/GitHub/private/Organization/Get-GitHubMyOrganization.ps1 +++ b/src/GitHub/private/Organization/Get-GitHubMyOrganization.ps1 @@ -41,6 +41,7 @@ Body = $body } - (Invoke-GitHubAPI @inputObject).Response - + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/private/Organization/Get-GitHubOrganizationByName.ps1 b/src/GitHub/private/Organization/Get-GitHubOrganizationByName.ps1 index 9e5517b04..5b2a78681 100644 --- a/src/GitHub/private/Organization/Get-GitHubOrganizationByName.ps1 +++ b/src/GitHub/private/Organization/Get-GitHubOrganizationByName.ps1 @@ -43,6 +43,8 @@ Method = 'GET' } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/private/Organization/Get-GitHubUserOrganization.ps1 b/src/GitHub/private/Organization/Get-GitHubUserOrganization.ps1 index 068a72ae0..cd2ea411d 100644 --- a/src/GitHub/private/Organization/Get-GitHubUserOrganization.ps1 +++ b/src/GitHub/private/Organization/Get-GitHubUserOrganization.ps1 @@ -43,6 +43,7 @@ Body = $body } - (Invoke-GitHubAPI @inputObject).Response - + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/private/Releases/Assets/Get-GitHubReleaseAssetByID.ps1 b/src/GitHub/private/Releases/Assets/Get-GitHubReleaseAssetByID.ps1 index 8eae21487..1ec06269f 100644 --- a/src/GitHub/private/Releases/Assets/Get-GitHubReleaseAssetByID.ps1 +++ b/src/GitHub/private/Releases/Assets/Get-GitHubReleaseAssetByID.ps1 @@ -39,6 +39,7 @@ Method = 'GET' } - (Invoke-GitHubAPI @inputObject).Response - + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/private/Releases/Assets/Get-GitHubReleaseAssetByReleaseID.ps1 b/src/GitHub/private/Releases/Assets/Get-GitHubReleaseAssetByReleaseID.ps1 index 963ff1538..cb3ac0b0d 100644 --- a/src/GitHub/private/Releases/Assets/Get-GitHubReleaseAssetByReleaseID.ps1 +++ b/src/GitHub/private/Releases/Assets/Get-GitHubReleaseAssetByReleaseID.ps1 @@ -48,6 +48,7 @@ Body = $body } - (Invoke-GitHubAPI @inputObject).Response - + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/private/Releases/Releases/Get-GitHubReleaseAll.ps1 b/src/GitHub/private/Releases/Releases/Get-GitHubReleaseAll.ps1 index a445230f2..7ebd6982c 100644 --- a/src/GitHub/private/Releases/Releases/Get-GitHubReleaseAll.ps1 +++ b/src/GitHub/private/Releases/Releases/Get-GitHubReleaseAll.ps1 @@ -42,6 +42,8 @@ Body = $body } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/private/Releases/Releases/Get-GitHubReleaseByID.ps1 b/src/GitHub/private/Releases/Releases/Get-GitHubReleaseByID.ps1 index b5d57a318..73d98433d 100644 --- a/src/GitHub/private/Releases/Releases/Get-GitHubReleaseByID.ps1 +++ b/src/GitHub/private/Releases/Releases/Get-GitHubReleaseByID.ps1 @@ -39,6 +39,8 @@ Method = 'GET' } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/private/Releases/Releases/Get-GitHubReleaseByTagName.ps1 b/src/GitHub/private/Releases/Releases/Get-GitHubReleaseByTagName.ps1 index 57c4b0dca..4ed7ccf35 100644 --- a/src/GitHub/private/Releases/Releases/Get-GitHubReleaseByTagName.ps1 +++ b/src/GitHub/private/Releases/Releases/Get-GitHubReleaseByTagName.ps1 @@ -38,6 +38,8 @@ Method = 'GET' } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/private/Releases/Releases/Get-GitHubReleaseLatest.ps1 b/src/GitHub/private/Releases/Releases/Get-GitHubReleaseLatest.ps1 index 2391d72e2..8cc417614 100644 --- a/src/GitHub/private/Releases/Releases/Get-GitHubReleaseLatest.ps1 +++ b/src/GitHub/private/Releases/Releases/Get-GitHubReleaseLatest.ps1 @@ -34,6 +34,8 @@ Method = 'GET' } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/private/Users/Blocking/Get-GitHubBlockedUserByUser.ps1 b/src/GitHub/private/Users/Blocking/Get-GitHubBlockedUserByUser.ps1 index 35d8a55fd..6cbae2096 100644 --- a/src/GitHub/private/Users/Blocking/Get-GitHubBlockedUserByUser.ps1 +++ b/src/GitHub/private/Users/Blocking/Get-GitHubBlockedUserByUser.ps1 @@ -31,6 +31,8 @@ Body = $body } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/private/Users/Emails/Get-GitHubUserAllEmail.ps1 b/src/GitHub/private/Users/Emails/Get-GitHubUserAllEmail.ps1 index 02709351d..fe6b37397 100644 --- a/src/GitHub/private/Users/Emails/Get-GitHubUserAllEmail.ps1 +++ b/src/GitHub/private/Users/Emails/Get-GitHubUserAllEmail.ps1 @@ -33,6 +33,8 @@ Body = $body } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/private/Users/Emails/Get-GitHubUserPublicEmail.ps1 b/src/GitHub/private/Users/Emails/Get-GitHubUserPublicEmail.ps1 index 26fa21c20..fe3cd4d52 100644 --- a/src/GitHub/private/Users/Emails/Get-GitHubUserPublicEmail.ps1 +++ b/src/GitHub/private/Users/Emails/Get-GitHubUserPublicEmail.ps1 @@ -35,6 +35,8 @@ Body = $body } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/private/Users/Followers/Get-GitHubUserFollowersOfUser.ps1 b/src/GitHub/private/Users/Followers/Get-GitHubUserFollowersOfUser.ps1 index e2cc580fb..9c7af7cec 100644 --- a/src/GitHub/private/Users/Followers/Get-GitHubUserFollowersOfUser.ps1 +++ b/src/GitHub/private/Users/Followers/Get-GitHubUserFollowersOfUser.ps1 @@ -42,6 +42,8 @@ Body = $body } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/private/Users/Followers/Get-GitHubUserFollowingMe.ps1 b/src/GitHub/private/Users/Followers/Get-GitHubUserFollowingMe.ps1 index bf73f7d48..7f60cde66 100644 --- a/src/GitHub/private/Users/Followers/Get-GitHubUserFollowingMe.ps1 +++ b/src/GitHub/private/Users/Followers/Get-GitHubUserFollowingMe.ps1 @@ -32,6 +32,8 @@ Body = $body } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/private/Users/Followers/Get-GitHubUserFollowingUser.ps1 b/src/GitHub/private/Users/Followers/Get-GitHubUserFollowingUser.ps1 index ae3685cc0..a6a75fadc 100644 --- a/src/GitHub/private/Users/Followers/Get-GitHubUserFollowingUser.ps1 +++ b/src/GitHub/private/Users/Followers/Get-GitHubUserFollowingUser.ps1 @@ -42,6 +42,8 @@ Body = $body } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/private/Users/Followers/Get-GitHubUserMyFollowers.ps1 b/src/GitHub/private/Users/Followers/Get-GitHubUserMyFollowers.ps1 index 9edf72d65..8948c5e35 100644 --- a/src/GitHub/private/Users/Followers/Get-GitHubUserMyFollowers.ps1 +++ b/src/GitHub/private/Users/Followers/Get-GitHubUserMyFollowers.ps1 @@ -33,6 +33,8 @@ Body = $body } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/private/Users/GPG-Keys/Get-GitHubUserGpgKeyForUser.ps1 b/src/GitHub/private/Users/GPG-Keys/Get-GitHubUserGpgKeyForUser.ps1 index 4817b1005..458232ac4 100644 --- a/src/GitHub/private/Users/GPG-Keys/Get-GitHubUserGpgKeyForUser.ps1 +++ b/src/GitHub/private/Users/GPG-Keys/Get-GitHubUserGpgKeyForUser.ps1 @@ -40,6 +40,8 @@ Body = $body } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/private/Users/GPG-Keys/Get-GitHubUserMyGpgKey.ps1 b/src/GitHub/private/Users/GPG-Keys/Get-GitHubUserMyGpgKey.ps1 index 1d41bec40..55c9e6094 100644 --- a/src/GitHub/private/Users/GPG-Keys/Get-GitHubUserMyGpgKey.ps1 +++ b/src/GitHub/private/Users/GPG-Keys/Get-GitHubUserMyGpgKey.ps1 @@ -34,6 +34,8 @@ Body = $body } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/private/Users/GPG-Keys/Get-GitHubUserMyGpgKeyById.ps1 b/src/GitHub/private/Users/GPG-Keys/Get-GitHubUserMyGpgKeyById.ps1 index 1e6b5f872..670d5eb22 100644 --- a/src/GitHub/private/Users/GPG-Keys/Get-GitHubUserMyGpgKeyById.ps1 +++ b/src/GitHub/private/Users/GPG-Keys/Get-GitHubUserMyGpgKeyById.ps1 @@ -33,6 +33,8 @@ Method = 'GET' } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/private/Users/Get-GitHubAllUser.ps1 b/src/GitHub/private/Users/Get-GitHubAllUser.ps1 index a4ba7eee3..5e86f7a4d 100644 --- a/src/GitHub/private/Users/Get-GitHubAllUser.ps1 +++ b/src/GitHub/private/Users/Get-GitHubAllUser.ps1 @@ -39,6 +39,8 @@ Body = $body } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/private/Users/Get-GitHubMyUser.ps1 b/src/GitHub/private/Users/Get-GitHubMyUser.ps1 index 1e17aedce..88490d3b0 100644 --- a/src/GitHub/private/Users/Get-GitHubMyUser.ps1 +++ b/src/GitHub/private/Users/Get-GitHubMyUser.ps1 @@ -27,6 +27,8 @@ Method = 'GET' } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/private/Users/Get-GitHubUserByName.ps1 b/src/GitHub/private/Users/Get-GitHubUserByName.ps1 index b8b7b8a0f..d60ca0d61 100644 --- a/src/GitHub/private/Users/Get-GitHubUserByName.ps1 +++ b/src/GitHub/private/Users/Get-GitHubUserByName.ps1 @@ -44,6 +44,8 @@ Method = 'GET' } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/private/Users/Keys/Get-GitHubUserKeyForUser.ps1 b/src/GitHub/private/Users/Keys/Get-GitHubUserKeyForUser.ps1 index 213e41c41..9f035a1e3 100644 --- a/src/GitHub/private/Users/Keys/Get-GitHubUserKeyForUser.ps1 +++ b/src/GitHub/private/Users/Keys/Get-GitHubUserKeyForUser.ps1 @@ -40,6 +40,8 @@ Body = $body } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/private/Users/Keys/Get-GitHubUserMyKey.ps1 b/src/GitHub/private/Users/Keys/Get-GitHubUserMyKey.ps1 index 711d125c5..3ab88f46c 100644 --- a/src/GitHub/private/Users/Keys/Get-GitHubUserMyKey.ps1 +++ b/src/GitHub/private/Users/Keys/Get-GitHubUserMyKey.ps1 @@ -34,6 +34,8 @@ Body = $body } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/private/Users/Keys/Get-GitHubUserMyKeyById.ps1 b/src/GitHub/private/Users/Keys/Get-GitHubUserMyKeyById.ps1 index 793098551..6db617b4f 100644 --- a/src/GitHub/private/Users/Keys/Get-GitHubUserMyKeyById.ps1 +++ b/src/GitHub/private/Users/Keys/Get-GitHubUserMyKeyById.ps1 @@ -33,6 +33,8 @@ Method = 'GET' } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/private/Users/SSH-Signing-Keys/Get-GitHubUserMySigningKey.ps1 b/src/GitHub/private/Users/SSH-Signing-Keys/Get-GitHubUserMySigningKey.ps1 index df562ad1b..2573b3424 100644 --- a/src/GitHub/private/Users/SSH-Signing-Keys/Get-GitHubUserMySigningKey.ps1 +++ b/src/GitHub/private/Users/SSH-Signing-Keys/Get-GitHubUserMySigningKey.ps1 @@ -34,6 +34,8 @@ Body = $body } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/private/Users/SSH-Signing-Keys/Get-GitHubUserMySigningKeyById.ps1 b/src/GitHub/private/Users/SSH-Signing-Keys/Get-GitHubUserMySigningKeyById.ps1 index 092eb26a8..5620df3ed 100644 --- a/src/GitHub/private/Users/SSH-Signing-Keys/Get-GitHubUserMySigningKeyById.ps1 +++ b/src/GitHub/private/Users/SSH-Signing-Keys/Get-GitHubUserMySigningKeyById.ps1 @@ -34,6 +34,8 @@ Method = 'GET' } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/private/Users/SSH-Signing-Keys/Get-GitHubUserSigningKeyForUser.ps1 b/src/GitHub/private/Users/SSH-Signing-Keys/Get-GitHubUserSigningKeyForUser.ps1 index f87025841..87f0590f0 100644 --- a/src/GitHub/private/Users/SSH-Signing-Keys/Get-GitHubUserSigningKeyForUser.ps1 +++ b/src/GitHub/private/Users/SSH-Signing-Keys/Get-GitHubUserSigningKeyForUser.ps1 @@ -40,6 +40,8 @@ Body = $body } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/private/Users/Social-Accounts/Get-GitHubMyUserSocials.ps1 b/src/GitHub/private/Users/Social-Accounts/Get-GitHubMyUserSocials.ps1 index 717ec15fb..569e706f0 100644 --- a/src/GitHub/private/Users/Social-Accounts/Get-GitHubMyUserSocials.ps1 +++ b/src/GitHub/private/Users/Social-Accounts/Get-GitHubMyUserSocials.ps1 @@ -32,6 +32,8 @@ Body = $body } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/private/Users/Social-Accounts/Get-GitHubUserSocialsByName.ps1 b/src/GitHub/private/Users/Social-Accounts/Get-GitHubUserSocialsByName.ps1 index aea79703d..12e0c421c 100644 --- a/src/GitHub/private/Users/Social-Accounts/Get-GitHubUserSocialsByName.ps1 +++ b/src/GitHub/private/Users/Social-Accounts/Get-GitHubUserSocialsByName.ps1 @@ -32,6 +32,8 @@ Method = 'GET' } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/public/Actions/Get-GitHubWorkflow.ps1 b/src/GitHub/public/Actions/Get-GitHubWorkflow.ps1 index 15f0b5692..a568b78d8 100644 --- a/src/GitHub/public/Actions/Get-GitHubWorkflow.ps1 +++ b/src/GitHub/public/Actions/Get-GitHubWorkflow.ps1 @@ -46,6 +46,8 @@ Body = $body } - (Invoke-GitHubAPI @inputObject).Response.workflows + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response.workflows + } } diff --git a/src/GitHub/public/Actions/Get-GitHubWorkflowRun.ps1 b/src/GitHub/public/Actions/Get-GitHubWorkflowRun.ps1 index 2616124ad..882f58709 100644 --- a/src/GitHub/public/Actions/Get-GitHubWorkflowRun.ps1 +++ b/src/GitHub/public/Actions/Get-GitHubWorkflowRun.ps1 @@ -44,6 +44,8 @@ Body = $body } - (Invoke-GitHubAPI @inputObject).Response.workflow_runs + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response.workflow_runs + } } diff --git a/src/GitHub/public/Actions/Get-GitHubWorkflowUsage.ps1 b/src/GitHub/public/Actions/Get-GitHubWorkflowUsage.ps1 index 2d541c094..ef0ca56fb 100644 --- a/src/GitHub/public/Actions/Get-GitHubWorkflowUsage.ps1 +++ b/src/GitHub/public/Actions/Get-GitHubWorkflowUsage.ps1 @@ -43,6 +43,8 @@ APIEndpoint = "/repos/$Owner/$Repo/actions/workflows/$ID/timing" } - (Invoke-GitHubAPI @inputObject).Response.billable + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response.billable + } } diff --git a/src/GitHub/public/Actions/Remove-GitHubWorkflowRun.ps1 b/src/GitHub/public/Actions/Remove-GitHubWorkflowRun.ps1 index e7e40c20d..f833e225b 100644 --- a/src/GitHub/public/Actions/Remove-GitHubWorkflowRun.ps1 +++ b/src/GitHub/public/Actions/Remove-GitHubWorkflowRun.ps1 @@ -41,7 +41,9 @@ } if ($PSCmdlet.ShouldProcess("workflow run with ID [$RunID] in [$Owner/$Repo]", 'Delete')) { - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } } diff --git a/src/GitHub/public/Actions/Start-GitHubWorkflow.ps1 b/src/GitHub/public/Actions/Start-GitHubWorkflow.ps1 index 0c4d633d4..18099dfe6 100644 --- a/src/GitHub/public/Actions/Start-GitHubWorkflow.ps1 +++ b/src/GitHub/public/Actions/Start-GitHubWorkflow.ps1 @@ -60,7 +60,9 @@ } if ($PSCmdlet.ShouldProcess("workflow with ID [$ID] in [$Owner/$Repo]", 'Start')) { - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } } diff --git a/src/GitHub/public/Actions/Start-GitHubWorkflowReRun.ps1 b/src/GitHub/public/Actions/Start-GitHubWorkflowReRun.ps1 index 0c88288b7..44015911b 100644 --- a/src/GitHub/public/Actions/Start-GitHubWorkflowReRun.ps1 +++ b/src/GitHub/public/Actions/Start-GitHubWorkflowReRun.ps1 @@ -37,7 +37,9 @@ } if ($PSCmdlet.ShouldProcess("workflow with ID [$ID] in [$Owner/$Repo]", 'Re-run')) { - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } } diff --git a/src/GitHub/public/Actions/Stop-GitHubWorkflowRun.ps1 b/src/GitHub/public/Actions/Stop-GitHubWorkflowRun.ps1 index 04527fa79..33df927fd 100644 --- a/src/GitHub/public/Actions/Stop-GitHubWorkflowRun.ps1 +++ b/src/GitHub/public/Actions/Stop-GitHubWorkflowRun.ps1 @@ -38,7 +38,9 @@ } if ($PSCmdlet.ShouldProcess("workflow run with ID [$ID] in [$Owner/$Repo]", 'Cancel/Stop')) { - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } } diff --git a/src/GitHub/public/Branches/Get-GitHubRepoBranch.ps1 b/src/GitHub/public/Branches/Get-GitHubRepoBranch.ps1 index 62869ec21..52b97d71a 100644 --- a/src/GitHub/public/Branches/Get-GitHubRepoBranch.ps1 +++ b/src/GitHub/public/Branches/Get-GitHubRepoBranch.ps1 @@ -30,6 +30,8 @@ Method = 'GET' } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/public/Emojis/Get-GitHubEmoji.ps1 b/src/GitHub/public/Emojis/Get-GitHubEmoji.ps1 index 438e4288a..33fba1287 100644 --- a/src/GitHub/public/Emojis/Get-GitHubEmoji.ps1 +++ b/src/GitHub/public/Emojis/Get-GitHubEmoji.ps1 @@ -32,7 +32,9 @@ Method = 'GET' } - $response = (Invoke-GitHubAPI @inputObject).Response + $response = Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } if (Test-Path -Path $Destination) { $response.PSObject.Properties | ForEach-Object -Parallel { diff --git a/src/GitHub/public/Markdown/Get-GitHubMarkdown.ps1 b/src/GitHub/public/Markdown/Get-GitHubMarkdown.ps1 index 8070f9131..44b71d6f8 100644 --- a/src/GitHub/public/Markdown/Get-GitHubMarkdown.ps1 +++ b/src/GitHub/public/Markdown/Get-GitHubMarkdown.ps1 @@ -32,6 +32,8 @@ Body = $body } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/public/Markdown/Get-GitHubMarkdownRaw.ps1 b/src/GitHub/public/Markdown/Get-GitHubMarkdownRaw.ps1 index 053764516..8a9e18bef 100644 --- a/src/GitHub/public/Markdown/Get-GitHubMarkdownRaw.ps1 +++ b/src/GitHub/public/Markdown/Get-GitHubMarkdownRaw.ps1 @@ -16,6 +16,8 @@ Method = 'POST' } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/public/Meta/Get-GitHubApiVersion.ps1 b/src/GitHub/public/Meta/Get-GitHubApiVersion.ps1 index 1b2993d84..e26969a66 100644 --- a/src/GitHub/public/Meta/Get-GitHubApiVersion.ps1 +++ b/src/GitHub/public/Meta/Get-GitHubApiVersion.ps1 @@ -23,6 +23,8 @@ Method = 'GET' } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/public/Meta/Get-GitHubMeta.ps1 b/src/GitHub/public/Meta/Get-GitHubMeta.ps1 index 90978f07c..c1b9e48ba 100644 --- a/src/GitHub/public/Meta/Get-GitHubMeta.ps1 +++ b/src/GitHub/public/Meta/Get-GitHubMeta.ps1 @@ -31,6 +31,8 @@ Method = 'GET' } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/public/Meta/Get-GitHubOctocat.ps1 b/src/GitHub/public/Meta/Get-GitHubOctocat.ps1 index 49f2fd89c..1c18ea414 100644 --- a/src/GitHub/public/Meta/Get-GitHubOctocat.ps1 +++ b/src/GitHub/public/Meta/Get-GitHubOctocat.ps1 @@ -39,6 +39,8 @@ Body = $body } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/public/Meta/Get-GitHubRoot.ps1 b/src/GitHub/public/Meta/Get-GitHubRoot.ps1 index 5637d66ee..55d8dff9d 100644 --- a/src/GitHub/public/Meta/Get-GitHubRoot.ps1 +++ b/src/GitHub/public/Meta/Get-GitHubRoot.ps1 @@ -22,6 +22,8 @@ Method = 'GET' } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/public/Meta/Get-GitHubZen.ps1 b/src/GitHub/public/Meta/Get-GitHubZen.ps1 index b4609085b..375cb9037 100644 --- a/src/GitHub/public/Meta/Get-GitHubZen.ps1 +++ b/src/GitHub/public/Meta/Get-GitHubZen.ps1 @@ -22,6 +22,8 @@ Method = 'GET' } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 b/src/GitHub/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 index 7a3d3a53f..eaa30d69d 100644 --- a/src/GitHub/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 +++ b/src/GitHub/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 @@ -46,6 +46,8 @@ Body = $body } - (Invoke-GitHubAPI @inputObject).Response.installations + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response.installations + } } diff --git a/src/GitHub/public/Organization/Remove-GitHubOrganization.ps1 b/src/GitHub/public/Organization/Remove-GitHubOrganization.ps1 index ae0555530..cdc4093b0 100644 --- a/src/GitHub/public/Organization/Remove-GitHubOrganization.ps1 +++ b/src/GitHub/public/Organization/Remove-GitHubOrganization.ps1 @@ -38,7 +38,9 @@ } if ($PSCmdlet.ShouldProcess("organization [$OrganizationName]", 'Delete')) { - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } } diff --git a/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 b/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 index fc6f814e1..dcd883e64 100644 --- a/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 +++ b/src/GitHub/public/Organization/Set-GitHubOrganization.ps1 @@ -228,7 +228,9 @@ } if ($PSCmdlet.ShouldProcess("organization [$OrganizationName]", 'Set')) { - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } } diff --git a/src/GitHub/public/Organization/Set-GitHubOrganizationSecurityFeature.ps1 b/src/GitHub/public/Organization/Set-GitHubOrganizationSecurityFeature.ps1 index 7ac9dcfd5..f8a491f0f 100644 --- a/src/GitHub/public/Organization/Set-GitHubOrganizationSecurityFeature.ps1 +++ b/src/GitHub/public/Organization/Set-GitHubOrganizationSecurityFeature.ps1 @@ -80,7 +80,9 @@ } if ($PSCmdlet.ShouldProcess("security feature [$SecurityProduct] on organization [$OrganizationName]", 'Set')) { - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } } diff --git a/src/GitHub/public/Rate-Limit/Get-GitHubRateLimit.ps1 b/src/GitHub/public/Rate-Limit/Get-GitHubRateLimit.ps1 index 8760454f9..5fd6b9317 100644 --- a/src/GitHub/public/Rate-Limit/Get-GitHubRateLimit.ps1 +++ b/src/GitHub/public/Rate-Limit/Get-GitHubRateLimit.ps1 @@ -40,6 +40,8 @@ Method = 'GET' } - (Invoke-GitHubAPI @inputObject).Response.Resources + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response.Resources + } } diff --git a/src/GitHub/public/Releases/Assets/Add-GitHubReleaseAsset.ps1 b/src/GitHub/public/Releases/Assets/Add-GitHubReleaseAsset.ps1 index 3a2198d00..46119404b 100644 --- a/src/GitHub/public/Releases/Assets/Add-GitHubReleaseAsset.ps1 +++ b/src/GitHub/public/Releases/Assets/Add-GitHubReleaseAsset.ps1 @@ -131,6 +131,8 @@ UploadFilePath = $FilePath } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/public/Releases/Assets/Remove-GitHubReleaseAsset.ps1 b/src/GitHub/public/Releases/Assets/Remove-GitHubReleaseAsset.ps1 index 8e28b115a..70e61f0af 100644 --- a/src/GitHub/public/Releases/Assets/Remove-GitHubReleaseAsset.ps1 +++ b/src/GitHub/public/Releases/Assets/Remove-GitHubReleaseAsset.ps1 @@ -37,7 +37,9 @@ } if ($PSCmdlet.ShouldProcess("Asset with ID [$ID] in [$Owner/$Repo]", 'Delete')) { - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } } diff --git a/src/GitHub/public/Releases/Assets/Set-GitHubReleaseAsset.ps1 b/src/GitHub/public/Releases/Assets/Set-GitHubReleaseAsset.ps1 index b6f08e94f..e5daffd16 100644 --- a/src/GitHub/public/Releases/Assets/Set-GitHubReleaseAsset.ps1 +++ b/src/GitHub/public/Releases/Assets/Set-GitHubReleaseAsset.ps1 @@ -55,7 +55,9 @@ } if ($PSCmdlet.ShouldProcess("assets for release with ID [$ID] in [$Owner/$Repo]", 'Set')) { - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } } diff --git a/src/GitHub/public/Releases/Releases/New-GitHubRelease.ps1 b/src/GitHub/public/Releases/Releases/New-GitHubRelease.ps1 index 22b3754bc..5c1954afb 100644 --- a/src/GitHub/public/Releases/Releases/New-GitHubRelease.ps1 +++ b/src/GitHub/public/Releases/Releases/New-GitHubRelease.ps1 @@ -94,7 +94,9 @@ } if ($PSCmdlet.ShouldProcess("$Owner/$Repo", 'Create a release')) { - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } } diff --git a/src/GitHub/public/Releases/Releases/New-GitHubReleaseNote.ps1 b/src/GitHub/public/Releases/Releases/New-GitHubReleaseNote.ps1 index a120ac11b..114293bc9 100644 --- a/src/GitHub/public/Releases/Releases/New-GitHubReleaseNote.ps1 +++ b/src/GitHub/public/Releases/Releases/New-GitHubReleaseNote.ps1 @@ -103,7 +103,9 @@ } if ($PSCmdlet.ShouldProcess("$Owner/$Repo", 'Create release notes')) { - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } } diff --git a/src/GitHub/public/Releases/Releases/Remove-GitHubRelease.ps1 b/src/GitHub/public/Releases/Releases/Remove-GitHubRelease.ps1 index 3170f1c32..857e4663a 100644 --- a/src/GitHub/public/Releases/Releases/Remove-GitHubRelease.ps1 +++ b/src/GitHub/public/Releases/Releases/Remove-GitHubRelease.ps1 @@ -40,7 +40,9 @@ } if ($PSCmdlet.ShouldProcess("Release with ID [$ID] in [$Owner/$Repo]", 'Delete')) { - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } } diff --git a/src/GitHub/public/Releases/Releases/Set-GitHubRelease.ps1 b/src/GitHub/public/Releases/Releases/Set-GitHubRelease.ps1 index 3aad509bb..5af672e75 100644 --- a/src/GitHub/public/Releases/Releases/Set-GitHubRelease.ps1 +++ b/src/GitHub/public/Releases/Releases/Set-GitHubRelease.ps1 @@ -90,7 +90,9 @@ } if ($PSCmdlet.ShouldProcess("release with ID [$ID] in [$Owner/$Repo]", 'Update')) { - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } } diff --git a/src/GitHub/public/Teams/Get-GitHubRepoTeam.ps1 b/src/GitHub/public/Teams/Get-GitHubRepoTeam.ps1 index c07dd89f1..10b17a1df 100644 --- a/src/GitHub/public/Teams/Get-GitHubRepoTeam.ps1 +++ b/src/GitHub/public/Teams/Get-GitHubRepoTeam.ps1 @@ -17,6 +17,8 @@ filter Get-GitHubRepoTeam { APIEndpoint = "/repos/$Owner/$Repo/teams" } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/public/Users/Emails/Add-GitHubUserEmail.ps1 b/src/GitHub/public/Users/Emails/Add-GitHubUserEmail.ps1 index 91cb4377a..1a1276fa1 100644 --- a/src/GitHub/public/Users/Emails/Add-GitHubUserEmail.ps1 +++ b/src/GitHub/public/Users/Emails/Add-GitHubUserEmail.ps1 @@ -38,6 +38,8 @@ Body = $body } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/public/Users/Emails/Remove-GitHubUserEmail.ps1 b/src/GitHub/public/Users/Emails/Remove-GitHubUserEmail.ps1 index 4191bff9a..9202fb247 100644 --- a/src/GitHub/public/Users/Emails/Remove-GitHubUserEmail.ps1 +++ b/src/GitHub/public/Users/Emails/Remove-GitHubUserEmail.ps1 @@ -36,7 +36,9 @@ } if ($PSCmdlet.ShouldProcess("Email addresses [$($Emails -join ', ')]", 'Delete')) { - $null = (Invoke-GitHubAPI @inputObject).Response + $null = Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } } diff --git a/src/GitHub/public/Users/Emails/Set-GitHubUserEmailVisibility.ps1 b/src/GitHub/public/Users/Emails/Set-GitHubUserEmailVisibility.ps1 index e0d24f17f..d2da272b3 100644 --- a/src/GitHub/public/Users/Emails/Set-GitHubUserEmailVisibility.ps1 +++ b/src/GitHub/public/Users/Emails/Set-GitHubUserEmailVisibility.ps1 @@ -42,7 +42,9 @@ } if ($PSCmdlet.ShouldProcess("Email visibility [$Visibility]", 'Set')) { - $null = (Invoke-GitHubAPI @inputObject).Response + $null = Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } } diff --git a/src/GitHub/public/Users/Followers/Add-GitHubUserFollowing.ps1 b/src/GitHub/public/Users/Followers/Add-GitHubUserFollowing.ps1 index 8bd70f467..3a9ed24ea 100644 --- a/src/GitHub/public/Users/Followers/Add-GitHubUserFollowing.ps1 +++ b/src/GitHub/public/Users/Followers/Add-GitHubUserFollowing.ps1 @@ -35,6 +35,8 @@ Method = 'PUT' } - $null = (Invoke-GitHubAPI @inputObject).Response + $null = Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/public/Users/Followers/Remove-GitHubUserFollowing.ps1 b/src/GitHub/public/Users/Followers/Remove-GitHubUserFollowing.ps1 index 7bc849106..2bcaa62e5 100644 --- a/src/GitHub/public/Users/Followers/Remove-GitHubUserFollowing.ps1 +++ b/src/GitHub/public/Users/Followers/Remove-GitHubUserFollowing.ps1 @@ -34,7 +34,9 @@ } if ($PSCmdlet.ShouldProcess("User [$Username]", 'Unfollow')) { - $null = (Invoke-GitHubAPI @inputObject).Response + $null = Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } } diff --git a/src/GitHub/public/Users/GPG-Keys/Add-GitHubUserGpgKey.ps1 b/src/GitHub/public/Users/GPG-Keys/Add-GitHubUserGpgKey.ps1 index 8358a709c..597d618d0 100644 --- a/src/GitHub/public/Users/GPG-Keys/Add-GitHubUserGpgKey.ps1 +++ b/src/GitHub/public/Users/GPG-Keys/Add-GitHubUserGpgKey.ps1 @@ -52,6 +52,8 @@ Body = $body } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/public/Users/GPG-Keys/Remove-GitHubUserGpgKey.ps1 b/src/GitHub/public/Users/GPG-Keys/Remove-GitHubUserGpgKey.ps1 index 77cdc6620..3a8f99a79 100644 --- a/src/GitHub/public/Users/GPG-Keys/Remove-GitHubUserGpgKey.ps1 +++ b/src/GitHub/public/Users/GPG-Keys/Remove-GitHubUserGpgKey.ps1 @@ -34,7 +34,9 @@ } if ($PSCmdlet.ShouldProcess("GPG key with ID [$ID]", 'Delete')) { - $null = (Invoke-GitHubAPI @inputObject).Response + $null = Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } } diff --git a/src/GitHub/public/Users/Get-GitHubUserCard.ps1 b/src/GitHub/public/Users/Get-GitHubUserCard.ps1 index 5b2d8abef..1e72a909c 100644 --- a/src/GitHub/public/Users/Get-GitHubUserCard.ps1 +++ b/src/GitHub/public/Users/Get-GitHubUserCard.ps1 @@ -49,6 +49,8 @@ Body = $body } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/public/Users/Keys/Add-GitHubUserKey.ps1 b/src/GitHub/public/Users/Keys/Add-GitHubUserKey.ps1 index 28f123efc..654681958 100644 --- a/src/GitHub/public/Users/Keys/Add-GitHubUserKey.ps1 +++ b/src/GitHub/public/Users/Keys/Add-GitHubUserKey.ps1 @@ -45,6 +45,8 @@ Body = $body } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/public/Users/Keys/Remove-GitHubUserKey.ps1 b/src/GitHub/public/Users/Keys/Remove-GitHubUserKey.ps1 index 973da6051..725c35552 100644 --- a/src/GitHub/public/Users/Keys/Remove-GitHubUserKey.ps1 +++ b/src/GitHub/public/Users/Keys/Remove-GitHubUserKey.ps1 @@ -34,7 +34,9 @@ } if ($PSCmdlet.ShouldProcess("Key with ID [$ID]", 'Delete')) { - $null = (Invoke-GitHubAPI @inputObject).Response + $null = Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } } diff --git a/src/GitHub/public/Users/SSH-Signing-Keys/Add-GitHubUserSigningKey.ps1 b/src/GitHub/public/Users/SSH-Signing-Keys/Add-GitHubUserSigningKey.ps1 index 1b46088ed..0a398a572 100644 --- a/src/GitHub/public/Users/SSH-Signing-Keys/Add-GitHubUserSigningKey.ps1 +++ b/src/GitHub/public/Users/SSH-Signing-Keys/Add-GitHubUserSigningKey.ps1 @@ -47,6 +47,8 @@ Body = $body } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/public/Users/SSH-Signing-Keys/Remove-GitHubUserSigningKey.ps1 b/src/GitHub/public/Users/SSH-Signing-Keys/Remove-GitHubUserSigningKey.ps1 index e04faf374..4ea9fca38 100644 --- a/src/GitHub/public/Users/SSH-Signing-Keys/Remove-GitHubUserSigningKey.ps1 +++ b/src/GitHub/public/Users/SSH-Signing-Keys/Remove-GitHubUserSigningKey.ps1 @@ -35,7 +35,9 @@ } if ($PSCmdlet.ShouldProcess("SSH signing key with ID [$ID]", 'Delete')) { - $null = (Invoke-GitHubAPI @inputObject).Response + $null = Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } } diff --git a/src/GitHub/public/Users/Set-GitHubUser.ps1 b/src/GitHub/public/Users/Set-GitHubUser.ps1 index 65a2c3943..3ce3ff34f 100644 --- a/src/GitHub/public/Users/Set-GitHubUser.ps1 +++ b/src/GitHub/public/Users/Set-GitHubUser.ps1 @@ -72,7 +72,9 @@ } if ($PSCmdlet.ShouldProcess('authenticated user', 'Set')) { - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } } diff --git a/src/GitHub/public/Users/Social-Accounts/Add-GitHubUserSocial.ps1 b/src/GitHub/public/Users/Social-Accounts/Add-GitHubUserSocial.ps1 index 202e1ebb1..aeca19aaa 100644 --- a/src/GitHub/public/Users/Social-Accounts/Add-GitHubUserSocial.ps1 +++ b/src/GitHub/public/Users/Social-Accounts/Add-GitHubUserSocial.ps1 @@ -32,6 +32,8 @@ Method = 'POST' } - (Invoke-GitHubAPI @inputObject).Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } diff --git a/src/GitHub/public/Users/Social-Accounts/Remove-GitHubUserSocial.ps1 b/src/GitHub/public/Users/Social-Accounts/Remove-GitHubUserSocial.ps1 index 3368f39ee..c1b46603c 100644 --- a/src/GitHub/public/Users/Social-Accounts/Remove-GitHubUserSocial.ps1 +++ b/src/GitHub/public/Users/Social-Accounts/Remove-GitHubUserSocial.ps1 @@ -34,7 +34,9 @@ } if ($PSCmdlet.ShouldProcess("Social accounts [$($AccountUrls -join ', ')]", 'Delete')) { - $null = (Invoke-GitHubAPI @inputObject).Response + $null = Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } } From e326e080ca990719096257c6faa99e60eb7ceb7b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 29 Oct 2023 21:40:46 +0100 Subject: [PATCH 122/193] fix indentation --- src/GitHub/public/Users/GPG-Keys/Remove-GitHubUserGpgKey.ps1 | 4 ++-- src/GitHub/public/Users/Set-GitHubUser.ps1 | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/GitHub/public/Users/GPG-Keys/Remove-GitHubUserGpgKey.ps1 b/src/GitHub/public/Users/GPG-Keys/Remove-GitHubUserGpgKey.ps1 index 3a8f99a79..648995db1 100644 --- a/src/GitHub/public/Users/GPG-Keys/Remove-GitHubUserGpgKey.ps1 +++ b/src/GitHub/public/Users/GPG-Keys/Remove-GitHubUserGpgKey.ps1 @@ -35,8 +35,8 @@ if ($PSCmdlet.ShouldProcess("GPG key with ID [$ID]", 'Delete')) { $null = Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + Write-Output $_.Response + } } } diff --git a/src/GitHub/public/Users/Set-GitHubUser.ps1 b/src/GitHub/public/Users/Set-GitHubUser.ps1 index 3ce3ff34f..2a38756ec 100644 --- a/src/GitHub/public/Users/Set-GitHubUser.ps1 +++ b/src/GitHub/public/Users/Set-GitHubUser.ps1 @@ -73,8 +73,8 @@ if ($PSCmdlet.ShouldProcess('authenticated user', 'Set')) { Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + Write-Output $_.Response + } } } From 1a69d1b6d6bf2fc81405291bc1cafa599b5e9496 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 30 Oct 2023 21:15:59 +0100 Subject: [PATCH 123/193] Add Enable-GitHubRepositoryVulnerabilityAlert --- src/GitHub/attributes.txt | 2 +- ...ble-GitHubRepositoryVulnerabilityAlert.ps1 | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 src/GitHub/public/Repositories/Repositories/Enable-GitHubRepositoryVulnerabilityAlert.ps1 diff --git a/src/GitHub/attributes.txt b/src/GitHub/attributes.txt index 657928f49..750c3db8b 100644 --- a/src/GitHub/attributes.txt +++ b/src/GitHub/attributes.txt @@ -1 +1 @@ -[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Contains a long link.')] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Contains long links.')] diff --git a/src/GitHub/public/Repositories/Repositories/Enable-GitHubRepositoryVulnerabilityAlert.ps1 b/src/GitHub/public/Repositories/Repositories/Enable-GitHubRepositoryVulnerabilityAlert.ps1 new file mode 100644 index 000000000..665820760 --- /dev/null +++ b/src/GitHub/public/Repositories/Repositories/Enable-GitHubRepositoryVulnerabilityAlert.ps1 @@ -0,0 +1,43 @@ +filter Enable-GitHubRepositoryVulnerabilityAlert { + <# + .SYNOPSIS + Enable vulnerability alerts + + .DESCRIPTION + Enables dependency alerts and the dependency graph for a repository. + The authenticated user must have admin access to the repository. + For more information, see + "[About security alerts for vulnerable dependencies](https://docs.github.com/articles/about-security-alerts-for-vulnerable-dependencies)". + + .EXAMPLE + Enable-GitHubRepositoryVulnerabilityAlert -Owner 'octocat' -Repo 'hello-world' + + Enables vulnerability alerts for the 'octocat/hello-world' repository. + + .NOTES + https://docs.github.com/rest/repos/repos#enable-vulnerability-alerts + #> + [CmdletBinding(SupportsShouldProcess)] + [Alias('Enable-GitHubRepositoryVulnerabilityAlerts')] + param ( + # The account owner of the repository. The name is not case sensitive. + [Parameter()] + [Alias('org')] + [string] $Owner = (Get-GitHubConfig -Name Owner), + + # The name of the repository without the .git extension. The name is not case sensitive. + [Parameter()] + [string] $Repo = (Get-GitHubConfig -Name Repo) + ) + + $inputObject = @{ + APIEndpoint = "/repos/$Owner/$Repo/vulnerability-alerts" + Method = 'PUT' + } + + if ($PSCmdlet.ShouldProcess("Vulnerability Alerts for [$Owner/$Repo]", "Enable")) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } +} From ef93292d3d2b95be6748f9a4cd4bd0acc15453c1 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 30 Oct 2023 21:24:24 +0100 Subject: [PATCH 124/193] Fix + add Disable VulnAlert --- .../Disable-GitHubRepositorySecurityFix.ps1 | 27 +++--------- ...ble-GitHubRepositoryVulnerabilityAlert.ps1 | 42 +++++++++++++++++++ .../Enable-GitHubRepositorySecurityFix.ps1 | 27 +++--------- 3 files changed, 52 insertions(+), 44 deletions(-) create mode 100644 src/GitHub/public/Repositories/Repositories/Disable-GitHubRepositoryVulnerabilityAlert.ps1 diff --git a/src/GitHub/public/Repositories/Repositories/Disable-GitHubRepositorySecurityFix.ps1 b/src/GitHub/public/Repositories/Repositories/Disable-GitHubRepositorySecurityFix.ps1 index 339f9f9c0..fe967fa05 100644 --- a/src/GitHub/public/Repositories/Repositories/Disable-GitHubRepositorySecurityFix.ps1 +++ b/src/GitHub/public/Repositories/Repositories/Disable-GitHubRepositorySecurityFix.ps1 @@ -17,7 +17,7 @@ https://docs.github.com/rest/repos/repos#disable-automated-security-fixes #> - [CmdletBinding()] + [CmdletBinding(SupportsShouldProcess)] [Alias('Disable-GitHubRepositorySecurityFixes')] param ( # The account owner of the repository. The name is not case sensitive. @@ -30,31 +30,14 @@ [string] $Repo = (Get-GitHubConfig -Name Repo) ) - $PSCmdlet.MyInvocation.MyCommand.Parameters.GetEnumerator() | ForEach-Object { - $paramName = $_.Key - $paramDefaultValue = Get-Variable -Name $paramName -ValueOnly -ErrorAction SilentlyContinue - $providedValue = $PSBoundParameters[$paramName] - Write-Verbose "[$paramName]" - Write-Verbose " - Default: [$paramDefaultValue]" - Write-Verbose " - Provided: [$providedValue]" - if (-not $PSBoundParameters.ContainsKey($paramName) -and ($null -ne $paramDefaultValue)) { - Write-Verbose ' - Using default value' - $PSBoundParameters[$paramName] = $paramDefaultValue - } else { - Write-Verbose ' - Using provided value' - } - } - - $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntry -Hashtable $body -RemoveNames 'Owner', 'Repo' -RemoveTypes 'SwitchParameter' - $inputObject = @{ APIEndpoint = "/repos/$Owner/$Repo/automated-security-fixes" Method = 'DELETE' - Body = $body } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response.names + if ($PSCmdlet.ShouldProcess("Security Fixes for [$Owner/$Repo]", 'Disable')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } } diff --git a/src/GitHub/public/Repositories/Repositories/Disable-GitHubRepositoryVulnerabilityAlert.ps1 b/src/GitHub/public/Repositories/Repositories/Disable-GitHubRepositoryVulnerabilityAlert.ps1 new file mode 100644 index 000000000..cc76adfc4 --- /dev/null +++ b/src/GitHub/public/Repositories/Repositories/Disable-GitHubRepositoryVulnerabilityAlert.ps1 @@ -0,0 +1,42 @@ +filter Disable-GitHubRepositoryVulnerabilityAlert { + <# + .SYNOPSIS + Disable vulnerability alerts + + .DESCRIPTION + Disables dependency alerts and the dependency graph for a repository. + The authenticated user must have admin access to the repository. For more information, see + "[About security alerts for vulnerable dependencies](https://docs.github.com/articles/about-security-alerts-for-vulnerable-dependencies)". + + .EXAMPLE + Disable-GitHubRepositoryVulnerabilityAlert -Owner 'octocat' -Repo 'hello-world' + + Disables vulnerability alerts for the 'octocat/hello-world' repository. + + .NOTES + https://docs.github.com/rest/repos/repos#disable-vulnerability-alerts + #> + [CmdletBinding(SupportsShouldProcess)] + [Alias('Disable-GitHubRepositoryVulnerabilityAlerts')] + param ( + # The account owner of the repository. The name is not case sensitive. + [Parameter()] + [Alias('org')] + [string] $Owner = (Get-GitHubConfig -Name Owner), + + # The name of the repository without the .git extension. The name is not case sensitive. + [Parameter()] + [string] $Repo = (Get-GitHubConfig -Name Repo) + ) + + $inputObject = @{ + APIEndpoint = "/repos/$Owner/$Repo/vulnerability-alerts" + Method = 'DELETE' + } + + if ($PSCmdlet.ShouldProcess("Vulnerability Alerts for [$Owner/$Repo]", 'Disable')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } +} diff --git a/src/GitHub/public/Repositories/Repositories/Enable-GitHubRepositorySecurityFix.ps1 b/src/GitHub/public/Repositories/Repositories/Enable-GitHubRepositorySecurityFix.ps1 index cee381dca..e69b55d88 100644 --- a/src/GitHub/public/Repositories/Repositories/Enable-GitHubRepositorySecurityFix.ps1 +++ b/src/GitHub/public/Repositories/Repositories/Enable-GitHubRepositorySecurityFix.ps1 @@ -17,7 +17,7 @@ https://docs.github.com/rest/repos/repos#enable-automated-security-fixes #> - [CmdletBinding()] + [CmdletBinding(SupportsShouldProcess)] [Alias('Enable-GitHubRepositorySecurityFixes')] param ( # The account owner of the repository. The name is not case sensitive. @@ -30,31 +30,14 @@ [string] $Repo = (Get-GitHubConfig -Name Repo) ) - $PSCmdlet.MyInvocation.MyCommand.Parameters.GetEnumerator() | ForEach-Object { - $paramName = $_.Key - $paramDefaultValue = Get-Variable -Name $paramName -ValueOnly -ErrorAction SilentlyContinue - $providedValue = $PSBoundParameters[$paramName] - Write-Verbose "[$paramName]" - Write-Verbose " - Default: [$paramDefaultValue]" - Write-Verbose " - Provided: [$providedValue]" - if (-not $PSBoundParameters.ContainsKey($paramName) -and ($null -ne $paramDefaultValue)) { - Write-Verbose ' - Using default value' - $PSBoundParameters[$paramName] = $paramDefaultValue - } else { - Write-Verbose ' - Using provided value' - } - } - - $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntry -Hashtable $body -RemoveNames 'Owner', 'Repo' -RemoveTypes 'SwitchParameter' - $inputObject = @{ APIEndpoint = "/repos/$Owner/$Repo/automated-security-fixes" Method = 'PUT' - Body = $body } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response.names + if ($PSCmdlet.ShouldProcess("Security Fixes for [$Owner/$Repo]", 'Enable')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } } From 75c304023a113b007d207c9116044757f5cec8e7 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 30 Oct 2023 21:45:35 +0100 Subject: [PATCH 125/193] test rules --- .../Repositories/Disable-GitHubRepositorySecurityFix.ps1 | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/GitHub/public/Repositories/Repositories/Disable-GitHubRepositorySecurityFix.ps1 b/src/GitHub/public/Repositories/Repositories/Disable-GitHubRepositorySecurityFix.ps1 index fe967fa05..59fb53949 100644 --- a/src/GitHub/public/Repositories/Repositories/Disable-GitHubRepositorySecurityFix.ps1 +++ b/src/GitHub/public/Repositories/Repositories/Disable-GitHubRepositorySecurityFix.ps1 @@ -4,9 +4,7 @@ Disable automated security fixes .DESCRIPTION - Disables automated security fixes for a repository. The authenticated user must have admin access to the repository. - For more information, see - "[Configuring automated security fixes](https://docs.github.com/articles/configuring-automated-security-fixes)". + Disables automated security fixes for a repository. The authenticated user must have admin access to the repository. For more information, see "[Configuring automated security fixes](https://docs.github.com/articles/configuring-automated-security-fixes)". .EXAMPLE Disable-GitHubRepositorySecurityFix -Owner 'PSModule' -Repo 'GitHub' From fad19497229a2129001b46e45ad78cad0655174a Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 30 Oct 2023 21:54:08 +0100 Subject: [PATCH 126/193] Fix longline --- .../Repositories/Disable-GitHubRepositorySecurityFix.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/GitHub/public/Repositories/Repositories/Disable-GitHubRepositorySecurityFix.ps1 b/src/GitHub/public/Repositories/Repositories/Disable-GitHubRepositorySecurityFix.ps1 index 59fb53949..fe967fa05 100644 --- a/src/GitHub/public/Repositories/Repositories/Disable-GitHubRepositorySecurityFix.ps1 +++ b/src/GitHub/public/Repositories/Repositories/Disable-GitHubRepositorySecurityFix.ps1 @@ -4,7 +4,9 @@ Disable automated security fixes .DESCRIPTION - Disables automated security fixes for a repository. The authenticated user must have admin access to the repository. For more information, see "[Configuring automated security fixes](https://docs.github.com/articles/configuring-automated-security-fixes)". + Disables automated security fixes for a repository. The authenticated user must have admin access to the repository. + For more information, see + "[Configuring automated security fixes](https://docs.github.com/articles/configuring-automated-security-fixes)". .EXAMPLE Disable-GitHubRepositorySecurityFix -Owner 'PSModule' -Repo 'GitHub' From 679e9269b7a642bb3127037273db9620c2550f54 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 30 Oct 2023 22:38:30 +0100 Subject: [PATCH 127/193] Fix + Add Get-repo lang --- .../Get-GitHubRepositoryLanguage.ps1 | 40 +++++++++++++++++++ .../Get-GitHubRepositorySecurityFix.ps1 | 4 -- 2 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryLanguage.ps1 diff --git a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryLanguage.ps1 b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryLanguage.ps1 new file mode 100644 index 000000000..e9b0ef81a --- /dev/null +++ b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryLanguage.ps1 @@ -0,0 +1,40 @@ +filter Get-GitHubRepositoryLanguage { + <# + .SYNOPSIS + List repository languages + + .DESCRIPTION + Lists languages for the specified repository. The value shown for each language is the number of + bytes of code written in that language. + + .EXAMPLE + Get-GitHubRepositoryLanguage -Owner 'octocat' -Repo 'hello-world' + + Gets the languages for the 'hello-world' repository owned by 'octocat'. + + .NOTES + https://docs.github.com/rest/repos/repos#list-repository-languages + + #> + [CmdletBinding()] + [Alias('Get-GitHubRepositoryLanguages')] + param ( + # The account owner of the repository. The name is not case sensitive. + [Parameter()] + [Alias('org')] + [string] $Owner = (Get-GitHubConfig -Name Owner), + + # The name of the repository without the .git extension. The name is not case sensitive. + [Parameter()] + [string] $Repo = (Get-GitHubConfig -Name Repo) + ) + + $inputObject = @{ + APIEndpoint = "/repos/$Owner/$Repo/languages" + Method = 'GET' + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } +} diff --git a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositorySecurityFix.ps1 b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositorySecurityFix.ps1 index f51f38cce..e2647fa3f 100644 --- a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositorySecurityFix.ps1 +++ b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositorySecurityFix.ps1 @@ -30,13 +30,9 @@ [string] $Repo = (Get-GitHubConfig -Name Repo) ) - $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntry -Hashtable $body -RemoveNames 'Owner', 'Repo' -RemoveTypes 'SwitchParameter' - $inputObject = @{ APIEndpoint = "/repos/$Owner/$Repo/automated-security-fixes" Method = 'GET' - Body = $body } Invoke-GitHubAPI @inputObject | ForEach-Object { From 1fc123e4285346ac03283f35db7d1d359fa4b4f1 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 30 Oct 2023 22:54:03 +0100 Subject: [PATCH 128/193] Adding vulnerabilityreporting coms --- ...epositoryPrivateVulnerabilityReporting.ps1 | 43 +++++++++++++++++++ ...epositoryPrivateVulnerabilityReporting.ps1 | 43 +++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 src/GitHub/public/Repositories/Repositories/Disable-GitHubRepositoryPrivateVulnerabilityReporting.ps1 create mode 100644 src/GitHub/public/Repositories/Repositories/Enable-GitHubRepositoryPrivateVulnerabilityReporting.ps1 diff --git a/src/GitHub/public/Repositories/Repositories/Disable-GitHubRepositoryPrivateVulnerabilityReporting.ps1 b/src/GitHub/public/Repositories/Repositories/Disable-GitHubRepositoryPrivateVulnerabilityReporting.ps1 new file mode 100644 index 000000000..8615a4ec2 --- /dev/null +++ b/src/GitHub/public/Repositories/Repositories/Disable-GitHubRepositoryPrivateVulnerabilityReporting.ps1 @@ -0,0 +1,43 @@ +filter Disable-GitHubRepositoryPrivateVulnerabilityReporting { + <# + .SYNOPSIS + Disable private vulnerability reporting for a repository + + .DESCRIPTION + Disables private vulnerability reporting for a repository. The authenticated user must have admin access + to the repository. For more information, see + "[Privately reporting a security vulnerability](https://docs.github.com/code-security/security-advisories/guidance-on-reporting-and-writing/privately-reporting-a-security-vulnerability)". + + .EXAMPLE + Disable-GitHubRepositoryPrivateVulnerabilityReporting -Owner 'PSModule' -Repo 'GitHub' + + Disables private vulnerability reporting for the PSModule/GitHub repository. + + .NOTES + https://docs.github.com/rest/repos/repos#disable-private-vulnerability-reporting-for-a-repository + + #> + [CmdletBinding(SupportsShouldProcess)] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Long links')] + param ( + # The account owner of the repository. The name is not case sensitive. + [Parameter()] + [Alias('org')] + [string] $Owner = (Get-GitHubConfig -Name Owner), + + # The name of the repository without the .git extension. The name is not case sensitive. + [Parameter()] + [string] $Repo = (Get-GitHubConfig -Name Repo) + ) + + $inputObject = @{ + APIEndpoint = "/repos/$Owner/$Repo/private-vulnerability-reporting" + Method = 'DELETE' + } + + if ($PSCmdlet.ShouldProcess("Private Vulnerability Reporting for [$Owner/$Repo]", 'Disable')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } +} diff --git a/src/GitHub/public/Repositories/Repositories/Enable-GitHubRepositoryPrivateVulnerabilityReporting.ps1 b/src/GitHub/public/Repositories/Repositories/Enable-GitHubRepositoryPrivateVulnerabilityReporting.ps1 new file mode 100644 index 000000000..c5b2058da --- /dev/null +++ b/src/GitHub/public/Repositories/Repositories/Enable-GitHubRepositoryPrivateVulnerabilityReporting.ps1 @@ -0,0 +1,43 @@ +filter Enable-GitHubRepositoryPrivateVulnerabilityReporting { + <# + .SYNOPSIS + Enable private vulnerability reporting for a repository + + .DESCRIPTION + Enables private vulnerability reporting for a repository. The authenticated user must have admin access + to the repository. For more information, see + "[Privately reporting a security vulnerability](https://docs.github.com/code-security/security-advisories/guidance-on-reporting-and-writing/privately-reporting-a-security-vulnerability)." + + .EXAMPLE + Enable-GitHubRepositoryPrivateVulnerabilityReporting -Owner 'PSModule' -Repo 'GitHub' + + Enables private vulnerability reporting for the PSModule/GitHub repository. + + .NOTES + https://docs.github.com/rest/repos/repos#enable-private-vulnerability-reporting-for-a-repository + + #> + [CmdletBinding(SupportsShouldProcess)] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Long links')] + param ( + # The account owner of the repository. The name is not case sensitive. + [Parameter()] + [Alias('org')] + [string] $Owner = (Get-GitHubConfig -Name Owner), + + # The name of the repository without the .git extension. The name is not case sensitive. + [Parameter()] + [string] $Repo = (Get-GitHubConfig -Name Repo) + ) + + $inputObject = @{ + APIEndpoint = "/repos/$Owner/$Repo/private-vulnerability-reporting" + Method = 'PUT' + } + + if ($PSCmdlet.ShouldProcess("Private Vulnerability Reporting for [$Owner/$Repo]", 'Enable')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } +} From 9e7a3c7b7dc399285db53e4f6529e8c00897a571 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 30 Oct 2023 23:06:29 +0100 Subject: [PATCH 129/193] Add Test-RepoVulnerabiltyAlerts --- ...est-GitHubRepositoryVulnerabilityAlert.ps1 | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/GitHub/public/Repositories/Repositories/Test-GitHubRepositoryVulnerabilityAlert.ps1 diff --git a/src/GitHub/public/Repositories/Repositories/Test-GitHubRepositoryVulnerabilityAlert.ps1 b/src/GitHub/public/Repositories/Repositories/Test-GitHubRepositoryVulnerabilityAlert.ps1 new file mode 100644 index 000000000..b9cca9ade --- /dev/null +++ b/src/GitHub/public/Repositories/Repositories/Test-GitHubRepositoryVulnerabilityAlert.ps1 @@ -0,0 +1,49 @@ +filter Test-GitHubRepositoryVulnerabilityAlert { + <# + .SYNOPSIS + Check if vulnerability alerts are enabled for a repository + + .DESCRIPTION + Shows whether dependency alerts are enabled or disabled for a repository. + The authenticated user must have admin read access to the repository. + For more information, see + "[About security alerts for vulnerable dependencies](https://docs.github.com/articles/about-security-alerts-for-vulnerable-dependencies)". + + .EXAMPLE + Test-GitHubRepositoryVulnerabilityAlert -Owner 'PSModule' -Repo 'GitHub' + + Checks if vulnerability alerts are enabled for the PSModule/GitHub repository. + + .NOTES + https://docs.github.com/rest/repos/repos#list-repository-tags + + #> + [OutputType([bool])] + [CmdletBinding()] + [Alias('Test-GitHubRepositoryVulnerabilityAlerts')] + param ( + # The account owner of the repository. The name is not case sensitive. + [Parameter()] + [Alias('org')] + [string] $Owner = (Get-GitHubConfig -Name Owner), + + # The name of the repository without the .git extension. The name is not case sensitive. + [Parameter()] + [string] $Repo = (Get-GitHubConfig -Name Repo) + ) + + $inputObject = @{ + APIEndpoint = "/repos/$Owner/$Repo/vulnerability-alerts" + Method = 'GET' + } + + try { + (Invoke-GitHubAPI @inputObject).StatusCode -eq 204 + } catch { + if ($_.Exception.Response.StatusCode.Value__ -eq 404) { + return $false + } else { + throw $_ + } + } +} From e222812b8c421df36cfd8c96d1e1ab6f18ed47fc Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 31 Oct 2023 08:17:54 +0100 Subject: [PATCH 130/193] Added a remaining file --- src/GitHub/public/Repositories/Repositories/remaining.txt | 3 +++ tools/utilities/GitHubAPI.ps1 | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 src/GitHub/public/Repositories/Repositories/remaining.txt diff --git a/src/GitHub/public/Repositories/Repositories/remaining.txt b/src/GitHub/public/Repositories/Repositories/remaining.txt new file mode 100644 index 000000000..6fa53c87d --- /dev/null +++ b/src/GitHub/public/Repositories/Repositories/remaining.txt @@ -0,0 +1,3 @@ +Update a repository +Create a repository dispatch event +Create a repository using a template diff --git a/tools/utilities/GitHubAPI.ps1 b/tools/utilities/GitHubAPI.ps1 index 70f95bc42..50c4e0881 100644 --- a/tools/utilities/GitHubAPI.ps1 +++ b/tools/utilities/GitHubAPI.ps1 @@ -21,7 +21,7 @@ $response = Invoke-RestMethod -Uri $APIDocURI -Method Get # @{n = 'PUT'; e = { (($_.value.psobject.Properties.Name) -contains 'PUT') } }, ` # @{n = 'PATCH'; e = { (($_.value.psobject.Properties.Name) -contains 'PATCH') } } | Format-Table -$path = '/repositories/{repository_id}/environments/{environment_name}/secrets/{secret_name}' +$path = '/repos/{owner}/{repo}/vulnerability-alerts' $method = 'get' $response.paths.$path.$method $response.paths.$path.$method.tags | clip # -> Namespace/foldername From ef12cbe6668277d317777bda927dc15b685768e2 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 31 Oct 2023 08:39:41 +0100 Subject: [PATCH 131/193] Create a NewRepoWrapper function --- .../Repositories/Get-GitHubRepository.ps1 | 4 +- .../Repositories/New-GitHubRepository.ps1 | 276 ++++++++++++++++++ .../Repositories/New-GitHubRepositoryOrg.ps1 | 4 +- .../Repositories/New-GitHubRepositoryUser.ps1 | 4 +- 4 files changed, 283 insertions(+), 5 deletions(-) create mode 100644 src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 diff --git a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepository.ps1 b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepository.ps1 index 6eff8a013..2c90839be 100644 --- a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepository.ps1 +++ b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepository.ps1 @@ -156,9 +156,11 @@ return $DynamicParamDictionary } - Process { + Begin { $Type = $PSBoundParameters['Type'] + } + Process { switch ($PSCmdlet.ParameterSetName) { 'MyRepos_Type' { $params = @{ diff --git a/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 b/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 new file mode 100644 index 000000000..93c7847b8 --- /dev/null +++ b/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 @@ -0,0 +1,276 @@ +filter New-GitHubRepository { + <# + .SYNOPSIS + Create a repository for a user or an organization. + + .DESCRIPTION + Creates a new repository for a user or in a specified organization. + + **OAuth scope requirements** + + When using [OAuth](https://docs.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/), authorizations must include: + + * `public_repo` scope or `repo` scope to create a public repository. Note: For GitHub AE, use `repo` scope to create an internal repository. + * `repo` scope to create a private repository + + + .EXAMPLE + $params = @{ + Name = 'Hello-World' + Description = 'This is your first repository' + Homepage = 'https://github.com' + HasIssues = $true + HasProjects = $true + HasWiki = $true + HasDiscussions = $true + HasDownloads = $true + IsTemplate = $true + AutoInit = $true + AllowSquashMerge = $true + AllowAutoMerge = $true + DeleteBranchOnMerge = $true + SquashMergeCommitTitle = 'PR_TITLE' + SquashMergeCommitMessage = 'PR_BODY' + } + New-GitHubRepositoryUser @params + + Creates a new public repository named "Hello-World" owned by the authenticated user. + + .EXAMPLE + $params = @{ + Owner = 'PSModule' + Name = 'Hello-World' + Description = 'This is your first repository' + Homepage = 'https://github.com' + HasIssues = $true + HasProjects = $true + HasWiki = $true + HasDownloads = $true + IsTemplate = $true + AutoInit = $true + AllowSquashMerge = $true + AllowAutoMerge = $true + DeleteBranchOnMerge = $true + SquashMergeCommitTitle = 'PR_TITLE' + SquashMergeCommitMessage = 'PR_BODY' + } + New-GitHubRepositoryOrg @params + + Creates a new public repository named "Hello-World" owned by the organization "PSModule". + + .PARAMETER GitignoreTemplate + Desired language or platform .gitignore template to apply. Use the name of the template without the extension. For example, "Haskell". + + .PARAMETER LicenseTemplate + Choose an open source license template that best suits your needs, and then use the license keyword as the license_template string. + For example, "mit" or "mpl-2.0". + + .NOTES + https://docs.github.com/rest/repos/repos#create-a-repository-for-the-authenticated-user + https://docs.github.com/rest/repos/repos#create-an-organization-repository + + #> + [OutputType([pscustomobject])] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSUseDeclaredVarsMoreThanAssignments', + 'GitignoreTemplate', + Justification = 'Parameter is used in dynamic parameter validation.' + )] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSUseDeclaredVarsMoreThanAssignments', + 'LicenseTemplate', + Justification = 'Parameter is used in dynamic parameter validation.' + )] + [CmdletBinding(SupportsShouldProcess)] + param ( + # The account owner of the repository. The name is not case sensitive. + [Parameter(ParameterSetName = 'org')] + [Alias('org')] + [string] $Owner = (Get-GitHubConfig -Name Owner), + + # The name of the repository. + [Parameter(Mandatory)] + [string] $Name, + + # A short description of the repository. + [Parameter()] + [string] $Description, + + # A URL with more information about the repository. + [Parameter()] + [ValidateNotNullOrEmpty()] + [uri] $Homepage, + + # The visibility of the repository. + [Parameter()] + [ValidateSet('public', 'private')] + [string] $Visibility = 'public', + + # Whether issues are enabled. + [Parameter()] + [Alias('has_issues')] + [switch] $HasIssues, + + # Whether projects are enabled. + [Parameter()] + [Alias('has_projects')] + [switch] $HasProjects, + + # Whether the wiki is enabled. + [Parameter()] + [Alias('has_wiki')] + [switch] $HasWiki, + + # Whether discussions are enabled. + [Parameter(ParameterSetName = 'user')] + [Alias('has_discussions')] + [switch] $HasDiscussions, + + # Whether downloads are enabled. + [Parameter()] + [Alias('has_downloads')] + [switch] $HasDownloads, + + # Whether this repository acts as a template that can be used to generate new repositories. + [Parameter()] + [Alias('is_template')] + [switch] $IsTemplate, + + # The id of the team that will be granted access to this repository. This is only valid when creating a repository in an organization. + [Parameter()] + [Alias('team_id')] + [int] $TeamId, + + # Pass true to create an initial commit with empty README. + [Parameter()] + [Alias('auto_init')] + [switch] $AutoInit, + + # Whether to allow squash merges for pull requests. + [Parameter()] + [Alias('allow_squash_merge')] + [switch] $AllowSquashMerge, + + # Whether to allow merge commits for pull requests. + [Parameter()] + [Alias('allow_merge_commit')] + [switch] $AllowMergeCommit, + + # Whether to allow rebase merges for pull requests. + [Parameter()] + [Alias('allow_rebase_merge')] + [switch] $AllowRebaseMerge, + + # Whether to allow Auto-merge to be used on pull requests. + [Parameter()] + [Alias('allow_auto_merge')] + [switch] $AllowAutoMerge, + + # Whether to delete head branches when pull requests are merged + [Parameter()] + [Alias('delete_branch_on_merge')] + [switch] $DeleteBranchOnMerge, + + # The default value for a squash merge commit title: + # - PR_TITLE - default to the pull request's title. + # - COMMIT_OR_PR_TITLE - default to the commit's title (if only one commit) or the pull request's title (when more than one commit). + [Parameter()] + [ValidateSet('PR_TITLE', 'COMMIT_OR_PR_TITLE')] + [Alias('squash_merge_commit_title')] + [string] $SquashMergeCommitTitle, + + # The default value for a squash merge commit message: + # - PR_BODY - default to the pull request's body. + # - COMMIT_MESSAGES - default to the branch's commit messages. + # - BLANK - default to a blank commit message. + [Parameter()] + [ValidateSet('PR_BODY', 'COMMIT_MESSAGES', 'BLANK')] + [Alias('squash_merge_commit_message')] + [string] $SquashMergeCommitMessage, + + # The default value for a merge commit title. + # - PR_TITLE - default to the pull request's title. + # - MERGE_MESSAGE - default to the classic title for a merge message (e.g.,Merge pull request #123 from branch-name). + [Parameter()] + [ValidateSet('PR_TITLE', 'MERGE_MESSAGE')] + [Alias('merge_commit_title')] + [string] $MergeCommitTitle, + + # The default value for a merge commit message. + # - PR_BODY - default to the pull request's body. + # - PR_TITLE - default to the pull request's title. + # - BLANK - default to a blank commit message. + [Parameter()] + [ValidateSet('PR_BODY', 'PR_TITLE', 'BLANK')] + [Alias('merge_commit_message')] + [string] $MergeCommitMessage + ) + + DynamicParam { + $DynamicParamDictionary = New-DynamicParamDictionary + + $dynParam = @{ + Name = 'GitignoreTemplate' + Alias = 'gitignore_template' + Type = [string] + ValidateSet = Get-GitHubGitignoreList + DynamicParamDictionary = $DynamicParamDictionary + } + New-DynamicParam @dynParam + + $dynParam2 = @{ + Name = 'LicenseTemplate' + Alias = 'license_template' + Type = [string] + ValidateSet = Get-GitHubLicenseList | Select-Object -ExpandProperty key + DynamicParamDictionary = $DynamicParamDictionary + } + New-DynamicParam @dynParam2 + + return $DynamicParamDictionary + } + + begin { + $GitignoreTemplate = $PSBoundParameters['GitignoreTemplate'] + $LicenseTemplate = $PSBoundParameters['LicenseTemplate'] + } + + Process { + $params = @{ + Owner = $Owner + Name = $Name + Description = $Description + Homepage = $Homepage + Visibility = $Visibility + HasIssues = $HasIssues + HasProjects = $HasProjects + HasWiki = $HasWiki + HasDiscussions = $HasDiscussions + HasDownloads = $HasDownloads + IsTemplate = $IsTemplate + TeamId = $TeamId + AutoInit = $AutoInit + AllowSquashMerge = $AllowSquashMerge + AllowMergeCommit = $AllowMergeCommit + AllowRebaseMerge = $AllowRebaseMerge + AllowAutoMerge = $AllowAutoMerge + DeleteBranchOnMerge = $DeleteBranchOnMerge + SquashMergeCommitTitle = $SquashMergeCommitTitle + SquashMergeCommitMessage = $SquashMergeCommitMessage + MergeCommitTitle = $MergeCommitTitle + MergeCommitMessage = $MergeCommitMessage + GitignoreTemplate = $GitignoreTemplate + LicenseTemplate = $LicenseTemplate + } + Remove-HashtableEntry -Hashtable $params -NullOrEmptyValues + + switch ($PSCmdlet.ParameterSetName) { + 'user' { + New-GitHubRepositoryUser @params + } + 'org' { + New-GitHubRepositoryOrg @params + } + } + } +} diff --git a/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 b/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 index 9805beffe..494c4ffc2 100644 --- a/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 +++ b/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 @@ -10,8 +10,8 @@ When using [OAuth](https://docs.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/), authorizations must include: - * `public_repo` scope or `repo` scope to create a public repository. Note: For GitHub AE, use `repo` scope to create an internal repository. - * `repo` scope to create a private repository + * `public_repo` scope or `repo` scope to create a public repository. Note: For GitHub AE, use `repo` scope to create an internal repository. + * `repo` scope to create a private repository .EXAMPLE $params = @{ diff --git a/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryUser.ps1 b/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryUser.ps1 index 46b1dfcae..eca573886 100644 --- a/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryUser.ps1 +++ b/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryUser.ps1 @@ -10,8 +10,8 @@ When using [OAuth](https://docs.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/), authorizations must include: - * `public_repo` scope or `repo` scope to create a public repository. Note: For GitHub AE, use `repo` scope to create an internal repository. - * `repo` scope to create a private repository. + * `public_repo` scope or `repo` scope to create a public repository. Note: For GitHub AE, use `repo` scope to create an internal repository. + * `repo` scope to create a private repository. .EXAMPLE $params = @{ From 5dee51e16d3d9d9427c2896a57be31df56f30e9e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 31 Oct 2023 08:40:30 +0100 Subject: [PATCH 132/193] Fix example function name --- .../public/Repositories/Repositories/New-GitHubRepository.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 b/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 index 93c7847b8..d6722383a 100644 --- a/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 +++ b/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 @@ -32,7 +32,7 @@ SquashMergeCommitTitle = 'PR_TITLE' SquashMergeCommitMessage = 'PR_BODY' } - New-GitHubRepositoryUser @params + New-GitHubRepository @params Creates a new public repository named "Hello-World" owned by the authenticated user. @@ -54,7 +54,7 @@ SquashMergeCommitTitle = 'PR_TITLE' SquashMergeCommitMessage = 'PR_BODY' } - New-GitHubRepositoryOrg @params + New-GitHubRepository @params Creates a new public repository named "Hello-World" owned by the organization "PSModule". From 982712fc9e498232e4d65631b18fae3534a73707 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 31 Oct 2023 08:44:56 +0100 Subject: [PATCH 133/193] Fix shoudprocess --- .../Repositories/Repositories/New-GitHubRepository.ps1 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 b/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 index d6722383a..aa0de853a 100644 --- a/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 +++ b/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 @@ -266,10 +266,14 @@ switch ($PSCmdlet.ParameterSetName) { 'user' { - New-GitHubRepositoryUser @params + if ($PSCmdlet.ShouldProcess("repository for user [$repo]", 'Create')) { + New-GitHubRepositoryUser @params + } } 'org' { - New-GitHubRepositoryOrg @params + if ($PSCmdlet.ShouldProcess("repository for organization [$Owner/$Repo]", 'Create')) { + New-GitHubRepositoryOrg @params + } } } } From 0f7f6fa3f69bf8f5d33de7212af7b14c37996bb6 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 31 Oct 2023 08:55:55 +0100 Subject: [PATCH 134/193] Test removing suppression --- .../Repositories/Repositories/New-GitHubRepository.ps1 | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 b/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 index aa0de853a..0b025e777 100644 --- a/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 +++ b/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 @@ -71,16 +71,6 @@ #> [OutputType([pscustomobject])] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSUseDeclaredVarsMoreThanAssignments', - 'GitignoreTemplate', - Justification = 'Parameter is used in dynamic parameter validation.' - )] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSUseDeclaredVarsMoreThanAssignments', - 'LicenseTemplate', - Justification = 'Parameter is used in dynamic parameter validation.' - )] [CmdletBinding(SupportsShouldProcess)] param ( # The account owner of the repository. The name is not case sensitive. From 645305720e265ba505c53c5e9feb3a16a0fdfdc9 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 31 Oct 2023 09:03:34 +0100 Subject: [PATCH 135/193] Move new-repo org and user to private --- .../Repositories/Repositories/New-GitHubRepositoryOrg.ps1 | 0 .../Repositories/Repositories/New-GitHubRepositoryUser.ps1 | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/GitHub/{public => private}/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 (100%) rename src/GitHub/{public => private}/Repositories/Repositories/New-GitHubRepositoryUser.ps1 (100%) diff --git a/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 b/src/GitHub/private/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 similarity index 100% rename from src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 rename to src/GitHub/private/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 diff --git a/src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryUser.ps1 b/src/GitHub/private/Repositories/Repositories/New-GitHubRepositoryUser.ps1 similarity index 100% rename from src/GitHub/public/Repositories/Repositories/New-GitHubRepositoryUser.ps1 rename to src/GitHub/private/Repositories/Repositories/New-GitHubRepositoryUser.ps1 From dfa5a4d583f57de6df32c88478fc1fa0946f1c2a Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 31 Oct 2023 22:11:43 +0100 Subject: [PATCH 136/193] Add new repo from template --- .../New-GitHubRepositoryFromTemplate.ps1 | 105 ++++++++++++++++ .../Repositories/New-GitHubRepository.ps1 | 113 +++++++++++++++--- .../Repositories/Repositories/remaining.txt | 1 - tools/utilities/GitHubAPI.ps1 | 4 +- 4 files changed, 201 insertions(+), 22 deletions(-) create mode 100644 src/GitHub/private/Repositories/Repositories/New-GitHubRepositoryFromTemplate.ps1 diff --git a/src/GitHub/private/Repositories/Repositories/New-GitHubRepositoryFromTemplate.ps1 b/src/GitHub/private/Repositories/Repositories/New-GitHubRepositoryFromTemplate.ps1 new file mode 100644 index 000000000..b7b240a0c --- /dev/null +++ b/src/GitHub/private/Repositories/Repositories/New-GitHubRepositoryFromTemplate.ps1 @@ -0,0 +1,105 @@ +filter New-GitHubRepositoryFromTemplate { + <# + .SYNOPSIS + Create a repository using a template + + .DESCRIPTION + Creates a new repository using a repository template. Use the `template_owner` and `template_repo` + route parameters to specify the repository to use as the template. If the repository is not public, + the authenticated user must own or be a member of an organization that owns the repository. + To check if a repository is available to use as a template, get the repository's information using the + [Get a repository](https://docs.github.com/rest/repos/repos#get-a-repository) endpoint and check that the `is_template` key is `true`. + + **OAuth scope requirements** + + When using [OAuth](https://docs.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/), authorizations must include: + + * `public_repo` scope or `repo` scope to create a public repository. Note: For GitHub AE, use `repo` scope to create an internal repository. + * `repo` scope to create a private repository + + .EXAMPLE + $params = @{ + TemplateOwner = 'GitHub' + TemplateRepo = 'octocat' + Owner = 'PSModule' + Name = 'MyNewRepo' + IncludeAllBranches = $true + Description = 'My new repo' + Private = $true + } + New-GitHubRepositoryFromTemplate @params + + Creates a new private repository named `MyNewRepo` from the `octocat` template repository owned by `GitHub`. + + .NOTES + https://docs.github.com/rest/repos/repos#create-a-repository-using-a-template + + #> + [OutputType([pscustomobject])] + [CmdletBinding(SupportsShouldProcess)] + param ( + # The account owner of the template repository. The name is not case sensitive. + [Parameter(Mandatory)] + [Alias('template_owner')] + [string] $TemplateOwner, + + # The name of the template repository without the .git extension. The name is not case sensitive. + [Parameter(Mandatory)] + [Alias('template_repo')] + [string] $TemplateRepo, + + # The organization or person who will own the new repository. + # To create a new repository in an organization, the authenticated user must be a member of the specified organization. + [Parameter()] + [Alias('org')] + [string] $Owner = (Get-GitHubConfig -Name Owner), + + # The name of the new repository. + [Parameter(Mandatory)] + [string] $Name, + + # A short description of the new repository. + [Parameter()] + [string] $Description, + + # Set to true to include the directory structure and files from all branches in the template repository, + # and not just the default branch. + [Parameter()] + [Alias('include_all_branches')] + [switch] $IncludeAllBranches, + + # Either true to create a new private repository or false to create a new public one. + [Parameter()] + [switch] $Private + ) + + $PSCmdlet.MyInvocation.MyCommand.Parameters.GetEnumerator() | ForEach-Object { + $paramName = $_.Key + $paramDefaultValue = Get-Variable -Name $paramName -ValueOnly -ErrorAction SilentlyContinue + $providedValue = $PSBoundParameters[$paramName] + Write-Verbose "[$paramName]" + Write-Verbose " - Default: [$paramDefaultValue]" + Write-Verbose " - Provided: [$providedValue]" + if (-not $PSBoundParameters.ContainsKey($paramName) -and ($null -ne $paramDefaultValue)) { + Write-Verbose ' - Using default value' + $PSBoundParameters[$paramName] = $paramDefaultValue + } else { + Write-Verbose ' - Using provided value' + } + } + + $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case + Remove-HashtableEntry -Hashtable $body -RemoveNames 'TemplateOwner', 'TemplateRepo' -RemoveTypes 'SwitchParameter' + + $inputObject = @{ + APIEndpoint = "/repos/$TemplateOwner/$TemplateRepo/generate" + Method = 'POST' + Body = $body + } + + if ($PSCmdlet.ShouldProcess("Repository [$Owner/$Name] from template [$TemplateOwner/$TemplateRepo]", 'Create')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } +} diff --git a/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 b/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 index 0b025e777..b27cdd38e 100644 --- a/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 +++ b/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 @@ -58,6 +58,24 @@ Creates a new public repository named "Hello-World" owned by the organization "PSModule". + .EXAMPLE + $params = @{ + TemplateOwner = 'GitHub' + TemplateRepo = 'octocat' + Owner = 'PSModule' + Name = 'MyNewRepo' + IncludeAllBranches = $true + Description = 'My new repo' + Private = $true + } + New-GitHubRepository @params + + Creates a new private repository named `MyNewRepo` from the `octocat` template repository owned by `GitHub`. + + .NOTES + https://docs.github.com/rest/repos/repos#create-a-repository-using-a-template + + .PARAMETER GitignoreTemplate Desired language or platform .gitignore template to apply. Use the name of the template without the extension. For example, "Haskell". @@ -71,7 +89,10 @@ #> [OutputType([pscustomobject])] - [CmdletBinding(SupportsShouldProcess)] + [CmdletBinding( + SupportsShouldProcess, + DefaultParameterSetName = 'user' + )] param ( # The account owner of the repository. The name is not case sensitive. [Parameter(ParameterSetName = 'org')] @@ -82,12 +103,35 @@ [Parameter(Mandatory)] [string] $Name, - # A short description of the repository. + # The account owner of the template repository. The name is not case sensitive. + [Parameter( + Mandatory, + ParameterSetName = 'template' + )] + [Alias('template_owner')] + [string] $TemplateOwner, + + # The name of the template repository without the .git extension. The name is not case sensitive. + [Parameter( + Mandatory, + ParameterSetName = 'template' + )] + [Alias('template_repo')] + [string] $TemplateRepo, + + # A short description of the new repository. [Parameter()] [string] $Description, + # Set to true to include the directory structure and files from all branches in the template repository, + # and not just the default branch. + [Parameter(ParameterSetName = 'template')] + [Alias('include_all_branches')] + [switch] $IncludeAllBranches, + # A URL with more information about the repository. - [Parameter()] + [Parameter(ParameterSetName = 'user')] + [Parameter(ParameterSetName = 'org')] [ValidateNotNullOrEmpty()] [uri] $Homepage, @@ -97,17 +141,20 @@ [string] $Visibility = 'public', # Whether issues are enabled. - [Parameter()] + [Parameter(ParameterSetName = 'user')] + [Parameter(ParameterSetName = 'org')] [Alias('has_issues')] [switch] $HasIssues, # Whether projects are enabled. - [Parameter()] + [Parameter(ParameterSetName = 'user')] + [Parameter(ParameterSetName = 'org')] [Alias('has_projects')] [switch] $HasProjects, # Whether the wiki is enabled. - [Parameter()] + [Parameter(ParameterSetName = 'user')] + [Parameter(ParameterSetName = 'org')] [Alias('has_wiki')] [switch] $HasWiki, @@ -117,54 +164,64 @@ [switch] $HasDiscussions, # Whether downloads are enabled. - [Parameter()] + [Parameter(ParameterSetName = 'user')] + [Parameter(ParameterSetName = 'org')] [Alias('has_downloads')] [switch] $HasDownloads, # Whether this repository acts as a template that can be used to generate new repositories. - [Parameter()] + [Parameter(ParameterSetName = 'user')] + [Parameter(ParameterSetName = 'org')] [Alias('is_template')] [switch] $IsTemplate, # The id of the team that will be granted access to this repository. This is only valid when creating a repository in an organization. - [Parameter()] + [Parameter(ParameterSetName = 'user')] + [Parameter(ParameterSetName = 'org')] [Alias('team_id')] [int] $TeamId, # Pass true to create an initial commit with empty README. - [Parameter()] + [Parameter(ParameterSetName = 'user')] + [Parameter(ParameterSetName = 'org')] [Alias('auto_init')] [switch] $AutoInit, # Whether to allow squash merges for pull requests. - [Parameter()] + [Parameter(ParameterSetName = 'user')] + [Parameter(ParameterSetName = 'org')] [Alias('allow_squash_merge')] [switch] $AllowSquashMerge, # Whether to allow merge commits for pull requests. - [Parameter()] + [Parameter(ParameterSetName = 'user')] + [Parameter(ParameterSetName = 'org')] [Alias('allow_merge_commit')] [switch] $AllowMergeCommit, # Whether to allow rebase merges for pull requests. - [Parameter()] + [Parameter(ParameterSetName = 'user')] + [Parameter(ParameterSetName = 'org')] [Alias('allow_rebase_merge')] [switch] $AllowRebaseMerge, # Whether to allow Auto-merge to be used on pull requests. - [Parameter()] + [Parameter(ParameterSetName = 'user')] + [Parameter(ParameterSetName = 'org')] [Alias('allow_auto_merge')] [switch] $AllowAutoMerge, # Whether to delete head branches when pull requests are merged - [Parameter()] + [Parameter(ParameterSetName = 'user')] + [Parameter(ParameterSetName = 'org')] [Alias('delete_branch_on_merge')] [switch] $DeleteBranchOnMerge, # The default value for a squash merge commit title: # - PR_TITLE - default to the pull request's title. # - COMMIT_OR_PR_TITLE - default to the commit's title (if only one commit) or the pull request's title (when more than one commit). - [Parameter()] + [Parameter(ParameterSetName = 'user')] + [Parameter(ParameterSetName = 'org')] [ValidateSet('PR_TITLE', 'COMMIT_OR_PR_TITLE')] [Alias('squash_merge_commit_title')] [string] $SquashMergeCommitTitle, @@ -173,7 +230,8 @@ # - PR_BODY - default to the pull request's body. # - COMMIT_MESSAGES - default to the branch's commit messages. # - BLANK - default to a blank commit message. - [Parameter()] + [Parameter(ParameterSetName = 'user')] + [Parameter(ParameterSetName = 'org')] [ValidateSet('PR_BODY', 'COMMIT_MESSAGES', 'BLANK')] [Alias('squash_merge_commit_message')] [string] $SquashMergeCommitMessage, @@ -181,7 +239,8 @@ # The default value for a merge commit title. # - PR_TITLE - default to the pull request's title. # - MERGE_MESSAGE - default to the classic title for a merge message (e.g.,Merge pull request #123 from branch-name). - [Parameter()] + [Parameter(ParameterSetName = 'user')] + [Parameter(ParameterSetName = 'org')] [ValidateSet('PR_TITLE', 'MERGE_MESSAGE')] [Alias('merge_commit_title')] [string] $MergeCommitTitle, @@ -190,7 +249,8 @@ # - PR_BODY - default to the pull request's body. # - PR_TITLE - default to the pull request's title. # - BLANK - default to a blank commit message. - [Parameter()] + [Parameter(ParameterSetName = 'user')] + [Parameter(ParameterSetName = 'org')] [ValidateSet('PR_BODY', 'PR_TITLE', 'BLANK')] [Alias('merge_commit_message')] [string] $MergeCommitMessage @@ -265,6 +325,21 @@ New-GitHubRepositoryOrg @params } } + 'template' { + if ($PSCmdlet.ShouldProcess("repository from template [$Owner/$Repo]", 'Create')) { + $params = @{ + TemplateOwner = $TemplateOwner + TemplateRepo = $TemplateRepo + Owner = $Owner + Name = $Name + IncludeAllBranches = $IncludeAllBranches + Description = $Description + Private = $Visibility -eq 'private' + } + Remove-HashtableEntry -Hashtable $params -NullOrEmptyValues + New-GitHubRepositoryFromTemplate @params + } + } } } } diff --git a/src/GitHub/public/Repositories/Repositories/remaining.txt b/src/GitHub/public/Repositories/Repositories/remaining.txt index 6fa53c87d..59d09949f 100644 --- a/src/GitHub/public/Repositories/Repositories/remaining.txt +++ b/src/GitHub/public/Repositories/Repositories/remaining.txt @@ -1,3 +1,2 @@ Update a repository Create a repository dispatch event -Create a repository using a template diff --git a/tools/utilities/GitHubAPI.ps1 b/tools/utilities/GitHubAPI.ps1 index 50c4e0881..42fb3eb1d 100644 --- a/tools/utilities/GitHubAPI.ps1 +++ b/tools/utilities/GitHubAPI.ps1 @@ -21,8 +21,8 @@ $response = Invoke-RestMethod -Uri $APIDocURI -Method Get # @{n = 'PUT'; e = { (($_.value.psobject.Properties.Name) -contains 'PUT') } }, ` # @{n = 'PATCH'; e = { (($_.value.psobject.Properties.Name) -contains 'PATCH') } } | Format-Table -$path = '/repos/{owner}/{repo}/vulnerability-alerts' -$method = 'get' +$path = '/repos/{template_owner}/{template_repo}/generate' +$method = 'post' $response.paths.$path.$method $response.paths.$path.$method.tags | clip # -> Namespace/foldername $response.paths.$path.$method.operationId | clip # -> FunctionName From b834ad5c5f1ab1696bdf5f94b185cac6d48a24eb Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 2 Nov 2023 22:15:09 +0100 Subject: [PATCH 137/193] Added Update repo --- .../Repositories/Update-GitHubRepository.ps1 | 225 ++++++++++++++++++ tools/utilities/GitHubAPI.ps1 | 4 +- 2 files changed, 227 insertions(+), 2 deletions(-) create mode 100644 src/GitHub/public/Repositories/Repositories/Update-GitHubRepository.ps1 diff --git a/src/GitHub/public/Repositories/Repositories/Update-GitHubRepository.ps1 b/src/GitHub/public/Repositories/Repositories/Update-GitHubRepository.ps1 new file mode 100644 index 000000000..0f4e09f1b --- /dev/null +++ b/src/GitHub/public/Repositories/Repositories/Update-GitHubRepository.ps1 @@ -0,0 +1,225 @@ +filter Update-GitHubRepository { + <# + .SYNOPSIS + Update a repository + + .DESCRIPTION + **Note**: To edit a repository's topics, use the + [Replace all repository topics](https://docs.github.com/rest/repos/repos#replace-all-repository-topics) endpoint. + + .EXAMPLE + Update-GitHubRepository -Name 'octocat' -Description 'Hello-World' -Homepage 'https://github.com' + + .EXAMPLE + $params = @{ + Owner = 'octocat' + Repo = 'Hello-World' + name = 'Hello-World-Repo + description = 'This is your first repository' + homepage = 'https://github.com' + } + Update-GitHubRepository @params + + .NOTES + https://docs.github.com/rest/repos/repos#update-a-repository + + #> + [CmdletBinding(SupportsShouldProcess)] + param ( + # The account owner of the repository. The name is not case sensitive. + [Parameter()] + [Alias('org')] + [string] $Owner = (Get-GitHubConfig -Name Owner), + + # The name of the repository without the .git extension. The name is not case sensitive. + [Parameter()] + [string] $Repo = (Get-GitHubConfig -Name Repo), + + # The name of the repository. + [Parameter()] + [string] $Name, + + # A short description of the repository. + [Parameter()] + [string] $Description, + + # A URL with more information about the repository. + [Parameter()] + [uri] $Homepage, + + # The visibility of the repository. + [Parameter()] + [ValidateSet('public', 'private')] + [string] $Visibility, + + # Use the status property to enable or disable GitHub Advanced Security for this repository. + # For more information, see "About GitHub Advanced Security." + [Parameter()] + [switch] $EnableAdvancedSecurity, + + # Use the status property to enable or disable secret scanning for this repository. + # For more information, see "About secret scanning." + [Parameter()] + [switch] $EnableSecretScanning, + + # Use the status property to enable or disable secret scanning push protection for this repository. + # For more information, see "Protecting pushes with secret scanning." + [Parameter()] + [switch] $EnableSecretScanningPushProtection, + + # Whether issues are enabled. + [Parameter()] + [Alias('has_issues')] + [switch] $HasIssues, + + # Whether projects are enabled. + [Parameter()] + [Alias('has_projects')] + [switch] $HasProjects, + + # Whether the wiki is enabled. + [Parameter()] + [Alias('has_wiki')] + [switch] $HasWiki, + + # Whether this repository acts as a template that can be used to generate new repositories. + [Parameter()] + [Alias('is_template')] + [switch] $IsTemplate, + + # Updates the default branch for this repository. + [Parameter()] + [Alias('default_branch')] + [string] $DefaultBranch, + + # Whether to allow squash merges for pull requests. + [Parameter()] + [Alias('allow_squash_merge')] + [switch] $AllowSquashMerge, + + # Whether to allow merge commits for pull requests. + [Parameter()] + [Alias('allow_merge_commit')] + [switch] $AllowMergeCommit, + + # Whether to allow rebase merges for pull requests. + [Parameter()] + [Alias('allow_rebase_merge')] + [switch] $AllowRebaseMerge, + + # Whether to allow Auto-merge to be used on pull requests. + [Parameter()] + [Alias('allow_auto_merge')] + [switch] $AllowAutoMerge, + + # Whether to delete head branches when pull requests are merged + [Parameter()] + [Alias('delete_branch_on_merge')] + [switch] $DeleteBranchOnMerge, + + # Either true to always allow a pull request head branch that is behind its base branch + # to be updated even if it is not required to be up to date before merging, or false otherwise. + [Parameter()] + [Alias('allow_update_branch')] + [switch] $AllowUpdateMerge, + + # The default value for a squash merge commit title: + # - PR_TITLE - default to the pull request's title. + # - COMMIT_OR_PR_TITLE - default to the commit's title (if only one commit) or the pull request's title (when more than one commit). + [Parameter()] + [ValidateSet('PR_TITLE', 'COMMIT_OR_PR_TITLE')] + [Alias('squash_merge_commit_title')] + [string] $SquashMergeCommitTitle, + + # The default value for a squash merge commit message: + # - PR_BODY - default to the pull request's body. + # - COMMIT_MESSAGES - default to the branch's commit messages. + # - BLANK - default to a blank commit message. + [Parameter()] + [ValidateSet('PR_BODY', 'COMMIT_MESSAGES', 'BLANK')] + [Alias('squash_merge_commit_message')] + [string] $SquashMergeCommitMessage, + + # The default value for a merge commit title. + # - PR_TITLE - default to the pull request's title. + # - MERGE_MESSAGE - default to the classic title for a merge message (e.g.,Merge pull request #123 from branch-name). + [Parameter()] + [ValidateSet('PR_TITLE', 'MERGE_MESSAGE')] + [Alias('merge_commit_title')] + [string] $MergeCommitTitle, + + # The default value for a merge commit message. + # - PR_BODY - default to the pull request's body. + # - PR_TITLE - default to the pull request's title. + # - BLANK - default to a blank commit message. + [Parameter()] + [ValidateSet('PR_BODY', 'PR_TITLE', 'BLANK')] + [Alias('merge_commit_message')] + [string] $MergeCommitMessage, + + # Whether to archive this repository. false will unarchive a previously archived repository. + [Parameter()] + [switch] $Archived, + + # Either true to allow private forks, or false to prevent private forks. + [Parameter()] + [Alias('allow_forking')] + [switch] $AllowForking, + + # Either true to require contributors to sign off on web-based commits, + # or false to not require contributors to sign off on web-based commits. + [Parameter()] + [Alias('web_commit_signoff_required')] + [switch] $WebCommitSignoffRequired + ) + + $body = @{ + name = $Name + description = $Description + homepage = $Homepage + visibility = $Visibility + private = $Visibility -eq 'private' + default_branch = $DefaultBranch + squash_merge_commit_title = $SquashMergeCommitTitle + squash_merge_commit_message = $SquashMergeCommitMessage + merge_commit_title = $MergeCommitTitle + merge_commit_message = $MergeCommitMessage + + advanced_security = $EnableAdvancedSecurity.IsPresent ? @{ + status = $EnableAdvancedSecurity ? 'enabled' : 'disabled' + } : $null + secret_scanning = $EnableSecretScanning.IsPresent ? @{ + status = $EnableSecretScanning ? 'enabled' : 'disabled' + } : $null + secret_scanning_push_protection = $EnableSecretScanningPushProtection.IsPresent ? @{ + status = $EnableSecretScanningPushProtection ? 'enabled' : 'disabled' + } : $null + has_issues = $HasIssues.IsPresent ? $HasIssues : $null + has_projects = $HasProjects.IsPresent ? $HasProjects : $null + has_wiki = $HasWiki.IsPresent ? $HasWiki : $null + is_template = $IsTemplate.IsPresent ? $IsTemplate : $null + allow_squash_merge = $AllowSquashMerge.IsPresent ? $AllowSquashMerge : $null + allow_merge_commit = $AllowMergeCommit.IsPresent ? $AllowMergeCommit : $null + allow_rebase_merge = $AllowRebaseMerge.IsPresent ? $AllowRebaseMerge : $null + allow_auto_merge = $AllowAutoMerge.IsPresent ? $AllowAutoMerge : $null + allow_update_branch = $AllowUpdateMerge.IsPresent ? $AllowUpdateMerge : $null + delete_branch_on_merge = $DeleteBranchOnMerge.IsPresent ? $DeleteBranchOnMerge : $null + archived = $Archived.IsPresent ? $Archived : $null + allow_forking = $AllowForking.IsPresent ? $AllowForking : $null + web_commit_signoff_required = $WebCommitSignoffRequired.IsPresent ? $WebCommitSignoffRequired : $null + } + + Remove-HashtableEntry -Hashtable $body -NullOrEmptyValues + + $inputObject = @{ + APIEndpoint = "/repos/$Owner/$Repo" + Method = 'PATCH' + Body = $body + } + + if ($PSCmdlet.ShouldProcess("Repository [$Owner/$Repo]", 'Update')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } +} diff --git a/tools/utilities/GitHubAPI.ps1 b/tools/utilities/GitHubAPI.ps1 index 42fb3eb1d..78a9f1b9e 100644 --- a/tools/utilities/GitHubAPI.ps1 +++ b/tools/utilities/GitHubAPI.ps1 @@ -21,8 +21,8 @@ $response = Invoke-RestMethod -Uri $APIDocURI -Method Get # @{n = 'PUT'; e = { (($_.value.psobject.Properties.Name) -contains 'PUT') } }, ` # @{n = 'PATCH'; e = { (($_.value.psobject.Properties.Name) -contains 'PATCH') } } | Format-Table -$path = '/repos/{template_owner}/{template_repo}/generate' -$method = 'post' +$path = '/repos/{owner}/{repo}' +$method = 'patch' $response.paths.$path.$method $response.paths.$path.$method.tags | clip # -> Namespace/foldername $response.paths.$path.$method.operationId | clip # -> FunctionName From 0038b649957227caf0a6637f232d2ac760aedc54 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 2 Nov 2023 22:15:59 +0100 Subject: [PATCH 138/193] Update remaining items --- src/GitHub/public/Repositories/Repositories/remaining.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/GitHub/public/Repositories/Repositories/remaining.txt b/src/GitHub/public/Repositories/Repositories/remaining.txt index 59d09949f..65b1d577b 100644 --- a/src/GitHub/public/Repositories/Repositories/remaining.txt +++ b/src/GitHub/public/Repositories/Repositories/remaining.txt @@ -1,2 +1 @@ -Update a repository Create a repository dispatch event From 35c40d30229ed44da6f2c462cf45b32d8233c8a4 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 3 Nov 2023 09:06:53 +0100 Subject: [PATCH 139/193] Test adding tests --- tests/GitHub/Get-GitHubRepository.Tests.ps1 | 45 +++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 tests/GitHub/Get-GitHubRepository.Tests.ps1 diff --git a/tests/GitHub/Get-GitHubRepository.Tests.ps1 b/tests/GitHub/Get-GitHubRepository.Tests.ps1 new file mode 100644 index 000000000..095503d2c --- /dev/null +++ b/tests/GitHub/Get-GitHubRepository.Tests.ps1 @@ -0,0 +1,45 @@ +Describe 'Get-GitHubRepository' { + It 'Function exists' { + Get-Command Get-GitHubRepository | Should -Not -BeNullOrEmpty + } + + Context 'Parameter Set: MyRepos_Type' { + It 'Can be called with no parameters' { + { Get-GitHubRepository } | Should -Not -Throw + } + + It 'Can be called with Type parameter' { + { Get-GitHubRepository -Type 'owner' } | Should -Not -Throw + } + } + + Context 'Parameter Set: MyRepos_Aff-Vis' { + It 'Can be called with Visibility and Affiliation parameters' { + { Get-GitHubRepository -Visibility 'public' -Affiliation 'owner' } | Should -Not -Throw + } + } + + Context 'Parameter Set: ByName' { + It 'Can be called with Owner and Repo parameters' { + { Get-GitHubRepository -Owner 'github' -Repo 'octocat' } | Should -Not -Throw + } + } + + Context 'Parameter Set: ListByID' { + It 'Can be called with SinceID parameter' { + { Get-GitHubRepository -SinceID 123456789 } | Select-Object -First 10 | Should -Not -Throw + } + } + + Context 'Parameter Set: ListByOrg' { + It 'Can be called with Owner parameter' { + { Get-GitHubRepository -Owner 'github' } | Should -Not -Throw + } + } + + Context 'Parameter Set: ListByUser' { + It 'Can be called with Username parameter' { + { Get-GitHubRepository -Username 'octocat' } | Should -Not -Throw + } + } +} From 9e128823a99c90ce713989c6ebd2e4ace3a622af Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 11:53:44 +0100 Subject: [PATCH 140/193] Add test for GitHubStatus --- tests/GitHub/Get-GitHubStatus.Tests.ps1 | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 tests/GitHub/Get-GitHubStatus.Tests.ps1 diff --git a/tests/GitHub/Get-GitHubStatus.Tests.ps1 b/tests/GitHub/Get-GitHubStatus.Tests.ps1 new file mode 100644 index 000000000..b1f34e700 --- /dev/null +++ b/tests/GitHub/Get-GitHubStatus.Tests.ps1 @@ -0,0 +1,17 @@ +Describe 'Get-GitHubStatus' { + It 'Function exists' { + Get-Command Get-GitHubStatus | Should -Not -BeNullOrEmpty + } + + Context 'Parameter Set: Default' { + It 'Can be called with no parameters' { + { Get-GitHubStatus } | Should -Not -Throw + } + } + + Context 'Parameter Set: Summary' { + It 'Can be called with Summary parameter' { + { Get-GitHubStatus -Summary } | Should -Not -Throw + } + } +} From 31becafaa35ab2e00c9684610c40dfbaa3ebc2ad Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 12:14:59 +0100 Subject: [PATCH 141/193] Added tests for Status --- .../Get-GitHubScheduledMaintenance.Tests.ps1 | 23 +++++++++++++++++++ .../{ => Status}/Get-GitHubStatus.Tests.ps1 | 0 .../Get-GitHubStatusComponent.Tests.ps1 | 9 ++++++++ .../Status/Get-GitHubStatusIncident.Tests.ps1 | 17 ++++++++++++++ 4 files changed, 49 insertions(+) create mode 100644 tests/GitHub/Status/Get-GitHubScheduledMaintenance.Tests.ps1 rename tests/GitHub/{ => Status}/Get-GitHubStatus.Tests.ps1 (100%) create mode 100644 tests/GitHub/Status/Get-GitHubStatusComponent.Tests.ps1 create mode 100644 tests/GitHub/Status/Get-GitHubStatusIncident.Tests.ps1 diff --git a/tests/GitHub/Status/Get-GitHubScheduledMaintenance.Tests.ps1 b/tests/GitHub/Status/Get-GitHubScheduledMaintenance.Tests.ps1 new file mode 100644 index 000000000..3e7601b65 --- /dev/null +++ b/tests/GitHub/Status/Get-GitHubScheduledMaintenance.Tests.ps1 @@ -0,0 +1,23 @@ +Describe 'Get-GitHubScheduledMaintenance' { + It 'Function exists' { + Get-Command Get-GitHubScheduledMaintenance | Should -Not -BeNullOrEmpty + } + + Context 'Parameter Set: Default' { + It 'Can be called with no parameters' { + { Get-GitHubScheduledMaintenance } | Should -Not -Throw + } + } + + Context 'Parameter Set: Active' { + It 'Can be called with Active parameter' { + { Get-GitHubScheduledMaintenance -Active } | Should -Not -Throw + } + } + + Context 'Parameter Set: Upcoming' { + It 'Can be called with Upcoming parameter' { + { Get-GitHubScheduledMaintenance -Upcoming } | Should -Not -Throw + } + } +} diff --git a/tests/GitHub/Get-GitHubStatus.Tests.ps1 b/tests/GitHub/Status/Get-GitHubStatus.Tests.ps1 similarity index 100% rename from tests/GitHub/Get-GitHubStatus.Tests.ps1 rename to tests/GitHub/Status/Get-GitHubStatus.Tests.ps1 diff --git a/tests/GitHub/Status/Get-GitHubStatusComponent.Tests.ps1 b/tests/GitHub/Status/Get-GitHubStatusComponent.Tests.ps1 new file mode 100644 index 000000000..7287968be --- /dev/null +++ b/tests/GitHub/Status/Get-GitHubStatusComponent.Tests.ps1 @@ -0,0 +1,9 @@ +Describe 'Get-GitHubStatusComponent' { + It 'Function exists' { + Get-Command Get-GitHubStatusComponent | Should -Not -BeNullOrEmpty + } + + It 'Can be called with no parameters' { + { Get-GitHubStatusComponent } | Should -Not -Throw + } +} diff --git a/tests/GitHub/Status/Get-GitHubStatusIncident.Tests.ps1 b/tests/GitHub/Status/Get-GitHubStatusIncident.Tests.ps1 new file mode 100644 index 000000000..d30058935 --- /dev/null +++ b/tests/GitHub/Status/Get-GitHubStatusIncident.Tests.ps1 @@ -0,0 +1,17 @@ +Describe 'Get-GitHubStatusIncident' { + It 'Function exists' { + Get-Command Get-GitHubStatusIncident | Should -Not -BeNullOrEmpty + } + + Context 'Parameter Set: Default' { + It 'Can be called with no parameters' { + { Get-GitHubStatusIncident } | Should -Not -Throw + } + } + + Context 'Parameter Set: Unresolved' { + It 'Can be called with Unresolved parameter' { + { Get-GitHubStatusIncident -Unresolved } | Should -Not -Throw + } + } +} From b88ff7b5531b2bb3d8501a88335c5bc93e71a02d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 12:22:29 +0100 Subject: [PATCH 142/193] Added tests for ratelimit --- tests/Rate-Limit/Get-GitHubRateLimit.Tests.ps1 | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 tests/Rate-Limit/Get-GitHubRateLimit.Tests.ps1 diff --git a/tests/Rate-Limit/Get-GitHubRateLimit.Tests.ps1 b/tests/Rate-Limit/Get-GitHubRateLimit.Tests.ps1 new file mode 100644 index 000000000..0e698a5ad --- /dev/null +++ b/tests/Rate-Limit/Get-GitHubRateLimit.Tests.ps1 @@ -0,0 +1,9 @@ +Describe 'Get-GitHubRateLimit' { + It 'Function exists' { + Get-Command Get-GitHubRateLimit | Should -Not -BeNullOrEmpty + } + + It 'Can be called with no parameters' { + { Get-GitHubRateLimit } | Should -Not -Throw + } +} From 46b8ff2a2425b475e9eeefdffb83ba4d418790ad Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 12:29:22 +0100 Subject: [PATCH 143/193] test --- src/GitHub/public/Config/Get-GitHubConfig.ps1 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/GitHub/public/Config/Get-GitHubConfig.ps1 b/src/GitHub/public/Config/Get-GitHubConfig.ps1 index b82405f42..318b4d94e 100644 --- a/src/GitHub/public/Config/Get-GitHubConfig.ps1 +++ b/src/GitHub/public/Config/Get-GitHubConfig.ps1 @@ -38,8 +38,10 @@ $prefix = $script:SecretVault.Prefix - $RefreshTokenData = (Get-SecretInfo -Name "$prefix`RefreshToken").Metadata | ConvertFrom-HashTable | ConvertTo-HashTable - $AccessTokenData = (Get-SecretInfo -Name "$prefix`AccessToken").Metadata | ConvertFrom-HashTable | ConvertTo-HashTable + $RefreshTokenData = Get-SecretInfo -Name "$prefix`RefreshToken" | + Select-Object -ExpandProperty Metadata | ConvertFrom-HashTable | ConvertTo-HashTable + $AccessTokenData = Get-SecretInfo -Name "$prefix`AccessToken" | + Select-Object -ExpandProperty Metadata | ConvertFrom-HashTable | ConvertTo-HashTable $metadata = Join-Object -Main $RefreshTokenData -Overrides $AccessTokenData -AsHashtable switch ($Name) { From a672d09bf059aa590ef1ac022ce0e12688f49e16 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 12:35:28 +0100 Subject: [PATCH 144/193] Fix get ghconfig --- src/GitHub/public/Config/Get-GitHubConfig.ps1 | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/GitHub/public/Config/Get-GitHubConfig.ps1 b/src/GitHub/public/Config/Get-GitHubConfig.ps1 index 318b4d94e..5c762348a 100644 --- a/src/GitHub/public/Config/Get-GitHubConfig.ps1 +++ b/src/GitHub/public/Config/Get-GitHubConfig.ps1 @@ -38,12 +38,6 @@ $prefix = $script:SecretVault.Prefix - $RefreshTokenData = Get-SecretInfo -Name "$prefix`RefreshToken" | - Select-Object -ExpandProperty Metadata | ConvertFrom-HashTable | ConvertTo-HashTable - $AccessTokenData = Get-SecretInfo -Name "$prefix`AccessToken" | - Select-Object -ExpandProperty Metadata | ConvertFrom-HashTable | ConvertTo-HashTable - $metadata = Join-Object -Main $RefreshTokenData -Overrides $AccessTokenData -AsHashtable - switch ($Name) { 'AccessToken' { Get-Secret -Name "$prefix`AccessToken" @@ -52,6 +46,19 @@ Get-Secret -Name "$prefix`RefreshToken" } default { + $RefreshTokenSecretInfo = Get-SecretInfo -Name "$prefix`RefreshToken" + if ($null -ne $RefreshTokenSecretInfo.Metadata) { + $RefreshTokenMetadata = $RefreshTokenSecretInfo.Metadata | + Select-Object -ExpandProperty Metadata | ConvertFrom-HashTable | ConvertTo-HashTable + } + + $AccessTokenSecretInfo = Get-SecretInfo -Name "$prefix`AccessToken" + if ($null -ne $AccessTokenSecretInfo.Metadata) { + $AccessTokenMetadata = $AccessTokenSecretInfo.Metadata | + Select-Object -ExpandProperty Metadata | ConvertFrom-HashTable | ConvertTo-HashTable + } + $metadata = Join-Object -Main $RefreshTokenMetadata -Overrides $AccessTokenMetadata -AsHashtable + if ($Name) { $metadata.$Name } else { From 5a2751b614ea59fa17c9808b291c392181ea4559 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 12:43:57 +0100 Subject: [PATCH 145/193] fix --- src/GitHub/public/Config/Get-GitHubConfig.ps1 | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/GitHub/public/Config/Get-GitHubConfig.ps1 b/src/GitHub/public/Config/Get-GitHubConfig.ps1 index 5c762348a..ecb5394cc 100644 --- a/src/GitHub/public/Config/Get-GitHubConfig.ps1 +++ b/src/GitHub/public/Config/Get-GitHubConfig.ps1 @@ -48,14 +48,12 @@ default { $RefreshTokenSecretInfo = Get-SecretInfo -Name "$prefix`RefreshToken" if ($null -ne $RefreshTokenSecretInfo.Metadata) { - $RefreshTokenMetadata = $RefreshTokenSecretInfo.Metadata | - Select-Object -ExpandProperty Metadata | ConvertFrom-HashTable | ConvertTo-HashTable + $RefreshTokenMetadata = $RefreshTokenSecretInfo.Metadata | ConvertFrom-HashTable | ConvertTo-HashTable } $AccessTokenSecretInfo = Get-SecretInfo -Name "$prefix`AccessToken" if ($null -ne $AccessTokenSecretInfo.Metadata) { - $AccessTokenMetadata = $AccessTokenSecretInfo.Metadata | - Select-Object -ExpandProperty Metadata | ConvertFrom-HashTable | ConvertTo-HashTable + $AccessTokenMetadata = $AccessTokenSecretInfo.Metadata | ConvertFrom-HashTable | ConvertTo-HashTable } $metadata = Join-Object -Main $RefreshTokenMetadata -Overrides $AccessTokenMetadata -AsHashtable From dcd62135ae455cd8be30f5a7cd588c4f6bfa2272 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 13:06:25 +0100 Subject: [PATCH 146/193] Added Auth tests --- .../Auth/Connect-GitHubAccount.Tests.ps1 | 25 +++++++++++++++++++ .../Auth/Disconnect-GitHubAccount.Tests.ps1 | 9 +++++++ 2 files changed, 34 insertions(+) create mode 100644 tests/GitHub/Auth/Connect-GitHubAccount.Tests.ps1 create mode 100644 tests/GitHub/Auth/Disconnect-GitHubAccount.Tests.ps1 diff --git a/tests/GitHub/Auth/Connect-GitHubAccount.Tests.ps1 b/tests/GitHub/Auth/Connect-GitHubAccount.Tests.ps1 new file mode 100644 index 000000000..962315327 --- /dev/null +++ b/tests/GitHub/Auth/Connect-GitHubAccount.Tests.ps1 @@ -0,0 +1,25 @@ +Describe 'Connect-GitHubAccount' { + It 'Function exists' { + Get-Command Connect-GitHubAccount | Should -Not -BeNullOrEmpty + } + + Context 'Parameter Set: DeviceFlow' { + It 'Can be called with no parameters' { + { Connect-GitHubAccount } | Should -Not -Throw + } + + It 'Can be called with Mode parameter' { + { Connect-GitHubAccount -Mode 'OAuthApp' } | Should -Not -Throw + } + + It 'Can be called with Scope parameter' { + { Connect-GitHubAccount -Scope 'gist read:org repo workflow' } | Should -Not -Throw + } + } + + Context 'Parameter Set: PAT' { + It 'Can be called with AccessToken parameter' { + { Connect-GitHubAccount -AccessToken } | Should -Not -Throw + } + } +} diff --git a/tests/GitHub/Auth/Disconnect-GitHubAccount.Tests.ps1 b/tests/GitHub/Auth/Disconnect-GitHubAccount.Tests.ps1 new file mode 100644 index 000000000..597216724 --- /dev/null +++ b/tests/GitHub/Auth/Disconnect-GitHubAccount.Tests.ps1 @@ -0,0 +1,9 @@ +Describe 'Disconnect-GitHubAccount' { + It 'Function exists' { + Get-Command Disconnect-GitHubAccount | Should -Not -BeNullOrEmpty + } + + It 'Can be called with no parameters' { + { Disconnect-GitHubAccount } | Should -Not -Throw + } +} From 510278792ad89ca85c21d6870485479836e2b741 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 13:12:16 +0100 Subject: [PATCH 147/193] test --- .../Auth/Connect-GitHubAccount.Tests.ps1 | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/tests/GitHub/Auth/Connect-GitHubAccount.Tests.ps1 b/tests/GitHub/Auth/Connect-GitHubAccount.Tests.ps1 index 962315327..f7af46500 100644 --- a/tests/GitHub/Auth/Connect-GitHubAccount.Tests.ps1 +++ b/tests/GitHub/Auth/Connect-GitHubAccount.Tests.ps1 @@ -3,23 +3,9 @@ Get-Command Connect-GitHubAccount | Should -Not -BeNullOrEmpty } - Context 'Parameter Set: DeviceFlow' { + Context 'Parameter Set: sPAT' { It 'Can be called with no parameters' { - { Connect-GitHubAccount } | Should -Not -Throw - } - - It 'Can be called with Mode parameter' { - { Connect-GitHubAccount -Mode 'OAuthApp' } | Should -Not -Throw - } - - It 'Can be called with Scope parameter' { - { Connect-GitHubAccount -Scope 'gist read:org repo workflow' } | Should -Not -Throw - } - } - - Context 'Parameter Set: PAT' { - It 'Can be called with AccessToken parameter' { - { Connect-GitHubAccount -AccessToken } | Should -Not -Throw + { Connect-GitHubAccount -Verbose } | Should -Not -Throw } } } From 06bc914ff19a538bf6f2942960c43c23e85c8e79 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 13:18:00 +0100 Subject: [PATCH 148/193] Add the gh token --- .github/workflows/Process-PSModule.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/Process-PSModule.yml b/.github/workflows/Process-PSModule.yml index cb2eb1cc6..0d00ea7b5 100644 --- a/.github/workflows/Process-PSModule.yml +++ b/.github/workflows/Process-PSModule.yml @@ -7,6 +7,9 @@ on: concurrency: group: ${{ github.workflow }} +env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + jobs: Process-PSModule: uses: PSModule/Actions/.github/workflows/Process-PSModule.yml@main From 3405eeeeadf6dfc53e743ef934e0e81e3c5ac8bb Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 13:21:24 +0100 Subject: [PATCH 149/193] GH token rename --- .github/workflows/Process-PSModule.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Process-PSModule.yml b/.github/workflows/Process-PSModule.yml index 0d00ea7b5..35dc4cb54 100644 --- a/.github/workflows/Process-PSModule.yml +++ b/.github/workflows/Process-PSModule.yml @@ -8,7 +8,7 @@ concurrency: group: ${{ github.workflow }} env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} jobs: Process-PSModule: From b5555c0ec4a636fcd73a999f3c3c8f7d86421f93 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 13:27:49 +0100 Subject: [PATCH 150/193] write verbose --- src/GitHub/public/Auth/Connect-GitHubAccount.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/GitHub/public/Auth/Connect-GitHubAccount.ps1 b/src/GitHub/public/Auth/Connect-GitHubAccount.ps1 index 7aa368675..b26f2afd1 100644 --- a/src/GitHub/public/Auth/Connect-GitHubAccount.ps1 +++ b/src/GitHub/public/Auth/Connect-GitHubAccount.ps1 @@ -95,8 +95,9 @@ $envVars = Get-ChildItem -Path 'Env:' $systemToken = $envVars | Where-Object Name -In 'GH_TOKEN', 'GITHUB_TOKEN' | Select-Object -First 1 $systemTokenPresent = $systemToken.count -gt 0 + Write-Verbose "System token present: [$systemTokenPresent]" $AuthType = $systemTokenPresent ? 'sPAT' : $PSCmdlet.ParameterSetName - + WRite-Verbose "AuthType: [$AuthType]" switch ($AuthType) { 'DeviceFlow' { Write-Verbose 'Logging in using device flow...' From 7d06a8306a34bbce800e1929777c301944416a47 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 13:35:40 +0100 Subject: [PATCH 151/193] Show envvars --- src/GitHub/public/Auth/Connect-GitHubAccount.ps1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/GitHub/public/Auth/Connect-GitHubAccount.ps1 b/src/GitHub/public/Auth/Connect-GitHubAccount.ps1 index b26f2afd1..c6fef0f24 100644 --- a/src/GitHub/public/Auth/Connect-GitHubAccount.ps1 +++ b/src/GitHub/public/Auth/Connect-GitHubAccount.ps1 @@ -93,7 +93,10 @@ ) $envVars = Get-ChildItem -Path 'Env:' + Write-Verbose "Environment variables:" + Write-Verbose ($envVars | Format-Table -AutoSize) $systemToken = $envVars | Where-Object Name -In 'GH_TOKEN', 'GITHUB_TOKEN' | Select-Object -First 1 + Write-Verbose "System token: [$systemToken]" $systemTokenPresent = $systemToken.count -gt 0 Write-Verbose "System token present: [$systemTokenPresent]" $AuthType = $systemTokenPresent ? 'sPAT' : $PSCmdlet.ParameterSetName From 74ea528c88a321ccbb3c40b4d99fa0d00a0cbdbc Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 13:39:47 +0100 Subject: [PATCH 152/193] outstring --- 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 c6fef0f24..dd1942c3f 100644 --- a/src/GitHub/public/Auth/Connect-GitHubAccount.ps1 +++ b/src/GitHub/public/Auth/Connect-GitHubAccount.ps1 @@ -94,7 +94,7 @@ $envVars = Get-ChildItem -Path 'Env:' Write-Verbose "Environment variables:" - Write-Verbose ($envVars | Format-Table -AutoSize) + Write-Verbose ($envVars | Format-Table -AutoSize | Out-String) $systemToken = $envVars | Where-Object Name -In 'GH_TOKEN', 'GITHUB_TOKEN' | Select-Object -First 1 Write-Verbose "System token: [$systemToken]" $systemTokenPresent = $systemToken.count -gt 0 From 016afd82ee9d05c16a9e6d1255ec932755326d57 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 13:57:03 +0100 Subject: [PATCH 153/193] try with GH tokens --- .github/workflows/Process-PSModule.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/Process-PSModule.yml b/.github/workflows/Process-PSModule.yml index 35dc4cb54..cb2eb1cc6 100644 --- a/.github/workflows/Process-PSModule.yml +++ b/.github/workflows/Process-PSModule.yml @@ -7,9 +7,6 @@ on: concurrency: group: ${{ github.workflow }} -env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - jobs: Process-PSModule: uses: PSModule/Actions/.github/workflows/Process-PSModule.yml@main From 492ea19e572fa6a2089702fdd678651f1371743c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 14:12:42 +0100 Subject: [PATCH 154/193] Test --- tests/GitHub/Auth/Connect-GitHubAccount.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/GitHub/Auth/Connect-GitHubAccount.Tests.ps1 b/tests/GitHub/Auth/Connect-GitHubAccount.Tests.ps1 index f7af46500..e7e06a3c6 100644 --- a/tests/GitHub/Auth/Connect-GitHubAccount.Tests.ps1 +++ b/tests/GitHub/Auth/Connect-GitHubAccount.Tests.ps1 @@ -5,7 +5,7 @@ Context 'Parameter Set: sPAT' { It 'Can be called with no parameters' { - { Connect-GitHubAccount -Verbose } | Should -Not -Throw + { Connect-GitHubAccount } | Should -Not -Throw } } } From 068aadad92c25da313e8312d8ac0bef7e7da85c1 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 14:20:13 +0100 Subject: [PATCH 155/193] test --- tests/GitHub/Auth/Disconnect-GitHubAccount.Tests.ps1 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/GitHub/Auth/Disconnect-GitHubAccount.Tests.ps1 b/tests/GitHub/Auth/Disconnect-GitHubAccount.Tests.ps1 index 597216724..811bcd1f3 100644 --- a/tests/GitHub/Auth/Disconnect-GitHubAccount.Tests.ps1 +++ b/tests/GitHub/Auth/Disconnect-GitHubAccount.Tests.ps1 @@ -6,4 +6,8 @@ It 'Can be called with no parameters' { { Disconnect-GitHubAccount } | Should -Not -Throw } + + It 'Can reconnect after disconnecting' { + { Connect-GitHubAccount } | Should -Not -Throw + } } From 9263e71c1d9328af33a842880ba1961105e135ef Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 14:25:40 +0100 Subject: [PATCH 156/193] test --- tests/Rate-Limit/Get-GitHubRateLimit.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Rate-Limit/Get-GitHubRateLimit.Tests.ps1 b/tests/Rate-Limit/Get-GitHubRateLimit.Tests.ps1 index 0e698a5ad..b2c3a433c 100644 --- a/tests/Rate-Limit/Get-GitHubRateLimit.Tests.ps1 +++ b/tests/Rate-Limit/Get-GitHubRateLimit.Tests.ps1 @@ -4,6 +4,6 @@ } It 'Can be called with no parameters' { - { Get-GitHubRateLimit } | Should -Not -Throw + Get-GitHubRateLimit | Should -Not -Throw } } From c96a2a5726bc1a5c39582527b5d12100bb0b5d20 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 14:40:35 +0100 Subject: [PATCH 157/193] test error output change --- src/GitHub/public/API/Invoke-GitHubAPI.ps1 | 38 ++++++++++++---------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 index 8923c165d..32f87d7c7 100644 --- a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 +++ b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 @@ -152,17 +152,17 @@ Invoke-RestMethod @APICall | ForEach-Object { $statusCode = $APICallStatusCode | ConvertTo-Json -Depth 100 | ConvertFrom-Json $responseHeaders = $APICallResponseHeaders | ConvertTo-Json -Depth 100 | ConvertFrom-Json - - Write-Verbose '----------------------------------' - Write-Verbose "StatusCode: $statusCode" - Write-Verbose '----------------------------------' - Write-Verbose 'Request:' - $APICall | ConvertFrom-HashTable | Format-List | Out-String -Stream | Write-Verbose - Write-Verbose '----------------------------------' - Write-Verbose 'ResponseHeaders:' - $responseHeaders | Format-List | Out-String -Stream | Write-Verbose - Write-Verbose '----------------------------------' - + Write-Verbose @" +---------------------------------- +StatusCode: $statusCode +---------------------------------- +Request: +$($APICall | ConvertFrom-HashTable | Format-List | Out-String -Stream) +'----------------------------------' +Write-Verbose 'ResponseHeaders:' +$($responseHeaders | Format-List | Out-String -Stream) +Write-Verbose '----------------------------------' +"@ [pscustomobject]@{ Request = $APICall Response = $_ @@ -171,14 +171,16 @@ } } } catch { - Write-Error 'Request:' - $APICall | ConvertFrom-HashTable | Format-List | Out-String -Stream | Write-Error + Write-Error @" +Request: +$($APICall | ConvertFrom-HashTable | Format-List | Out-String -Stream) - Write-Error 'Message:' - $_.Exception.Message | ConvertFrom-HashTable | Format-List | Out-String -Stream | Write-Error +Message: +$($_.Exception.Message | ConvertFrom-HashTable | Format-List | Out-String -Stream) - Write-Error 'Response:' - $_.Exception.Response | ConvertFrom-HashTable | Format-List | Out-String -Stream | Write-Error - throw $errorMessage +Response: +$($_.Exception.Response | ConvertFrom-HashTable | Format-List | Out-String -Stream) +"@ + throw $error.Message } } From f1c1f91853583eb39a5b3f3458522837e28d18d9 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 14:58:19 +0100 Subject: [PATCH 158/193] fix verbose --- src/GitHub/public/API/Invoke-GitHubAPI.ps1 | 26 +++++++++++++--------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 index 32f87d7c7..b1dc8d0c2 100644 --- a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 +++ b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 @@ -152,17 +152,19 @@ Invoke-RestMethod @APICall | ForEach-Object { $statusCode = $APICallStatusCode | ConvertTo-Json -Depth 100 | ConvertFrom-Json $responseHeaders = $APICallResponseHeaders | ConvertTo-Json -Depth 100 | ConvertFrom-Json - Write-Verbose @" + $verboseMessage = @" ---------------------------------- -StatusCode: $statusCode +StatusCode: +$statusCode ---------------------------------- Request: -$($APICall | ConvertFrom-HashTable | Format-List | Out-String -Stream) -'----------------------------------' -Write-Verbose 'ResponseHeaders:' -$($responseHeaders | Format-List | Out-String -Stream) -Write-Verbose '----------------------------------' +$($APICall | ConvertFrom-HashTable | Format-List | Out-String) +---------------------------------- +ResponseHeaders: +$($responseHeaders | Format-List | Out-String) +---------------------------------- "@ + Write-Verbose $verboseMessage [pscustomobject]@{ Request = $APICall Response = $_ @@ -171,16 +173,18 @@ Write-Verbose '----------------------------------' } } } catch { - Write-Error @" + $errorResult = @" +---------------------------------- Request: $($APICall | ConvertFrom-HashTable | Format-List | Out-String -Stream) - +---------------------------------- Message: $($_.Exception.Message | ConvertFrom-HashTable | Format-List | Out-String -Stream) - +---------------------------------- Response: $($_.Exception.Response | ConvertFrom-HashTable | Format-List | Out-String -Stream) +---------------------------------- "@ - throw $error.Message + throw $errorResult } } From 53ffbdb566c26e534b2d6c8c0906cdb71574dda6 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 15:03:26 +0100 Subject: [PATCH 159/193] test --- src/GitHub/public/API/Invoke-GitHubAPI.ps1 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 index b1dc8d0c2..c889fe84d 100644 --- a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 +++ b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 @@ -173,16 +173,17 @@ $($responseHeaders | Format-List | Out-String) } } } catch { + $failure = $_ $errorResult = @" ---------------------------------- Request: $($APICall | ConvertFrom-HashTable | Format-List | Out-String -Stream) ---------------------------------- Message: -$($_.Exception.Message | ConvertFrom-HashTable | Format-List | Out-String -Stream) +$($failure.Exception.Message | ConvertFrom-HashTable | Format-List | Out-String -Stream) ---------------------------------- Response: -$($_.Exception.Response | ConvertFrom-HashTable | Format-List | Out-String -Stream) +$($failure.Exception.Response | ConvertFrom-HashTable | Format-List | Out-String -Stream) ---------------------------------- "@ throw $errorResult From 1d04925c7e8b4969b4aeb5972c2db9394a81f163 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 15:10:47 +0100 Subject: [PATCH 160/193] Allow null on convertFrom-Hashtable --- .../private/Utilities/Hashtable/ConvertFrom-HashTable.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/GitHub/private/Utilities/Hashtable/ConvertFrom-HashTable.ps1 b/src/GitHub/private/Utilities/Hashtable/ConvertFrom-HashTable.ps1 index 1db300f69..df8f4052b 100644 --- a/src/GitHub/private/Utilities/Hashtable/ConvertFrom-HashTable.ps1 +++ b/src/GitHub/private/Utilities/Hashtable/ConvertFrom-HashTable.ps1 @@ -38,7 +38,8 @@ Mandatory, ValueFromPipeline )] - [object]$InputObject + [AllowNull()] + [object] $InputObject ) $InputObject | ConvertTo-Json -Depth 100 | ConvertFrom-Json } From b4f23aac64391476278a45c7288e8922d3cb1454 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 15:15:56 +0100 Subject: [PATCH 161/193] Format fix --- src/GitHub/public/API/Invoke-GitHubAPI.ps1 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 index c889fe84d..342333201 100644 --- a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 +++ b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 @@ -153,6 +153,7 @@ $statusCode = $APICallStatusCode | ConvertTo-Json -Depth 100 | ConvertFrom-Json $responseHeaders = $APICallResponseHeaders | ConvertTo-Json -Depth 100 | ConvertFrom-Json $verboseMessage = @" + ---------------------------------- StatusCode: $statusCode @@ -163,6 +164,7 @@ $($APICall | ConvertFrom-HashTable | Format-List | Out-String) ResponseHeaders: $($responseHeaders | Format-List | Out-String) ---------------------------------- + "@ Write-Verbose $verboseMessage [pscustomobject]@{ @@ -175,6 +177,7 @@ $($responseHeaders | Format-List | Out-String) } catch { $failure = $_ $errorResult = @" + ---------------------------------- Request: $($APICall | ConvertFrom-HashTable | Format-List | Out-String -Stream) @@ -185,6 +188,7 @@ $($failure.Exception.Message | ConvertFrom-HashTable | Format-List | Out-String Response: $($failure.Exception.Response | ConvertFrom-HashTable | Format-List | Out-String -Stream) ---------------------------------- + "@ throw $errorResult } From f04770bace187f65859e0848433b472b412221c8 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 15:16:49 +0100 Subject: [PATCH 162/193] Remove stream --- src/GitHub/public/API/Invoke-GitHubAPI.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 index 342333201..4607ba134 100644 --- a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 +++ b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 @@ -180,13 +180,13 @@ $($responseHeaders | Format-List | Out-String) ---------------------------------- Request: -$($APICall | ConvertFrom-HashTable | Format-List | Out-String -Stream) +$($APICall | ConvertFrom-HashTable | Format-List | Out-String) ---------------------------------- Message: -$($failure.Exception.Message | ConvertFrom-HashTable | Format-List | Out-String -Stream) +$($failure.Exception.Message | ConvertFrom-HashTable | Format-List | Out-String) ---------------------------------- Response: -$($failure.Exception.Response | ConvertFrom-HashTable | Format-List | Out-String -Stream) +$($failure.Exception.Response | ConvertFrom-HashTable | Format-List | Out-String) ---------------------------------- "@ From 6c86ef704ff0588a5ab536988117905021670556 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 15:21:58 +0100 Subject: [PATCH 163/193] Test --- 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 4607ba134..c602dbabe 100644 --- a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 +++ b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 @@ -51,7 +51,7 @@ # Specifies the HTTP version used for the request. [Parameter()] - [version] $HttpVersion = '2.0', + [version] $HttpVersion = 2.0, # Support Pagination Relation Links per RFC5988. [Parameter()] From f5c16c20378dd5b4647c267410aa48d569ea6220 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 15:26:06 +0100 Subject: [PATCH 164/193] Fix --- 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 c602dbabe..4607ba134 100644 --- a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 +++ b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 @@ -51,7 +51,7 @@ # Specifies the HTTP version used for the request. [Parameter()] - [version] $HttpVersion = 2.0, + [version] $HttpVersion = '2.0', # Support Pagination Relation Links per RFC5988. [Parameter()] From e159afbc4ab21e313217587c4bbbcd8af7e3c99f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 15:36:53 +0100 Subject: [PATCH 165/193] test --- tests/Rate-Limit/Get-GitHubRateLimit.Tests.ps1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Rate-Limit/Get-GitHubRateLimit.Tests.ps1 b/tests/Rate-Limit/Get-GitHubRateLimit.Tests.ps1 index b2c3a433c..15b85fac3 100644 --- a/tests/Rate-Limit/Get-GitHubRateLimit.Tests.ps1 +++ b/tests/Rate-Limit/Get-GitHubRateLimit.Tests.ps1 @@ -4,6 +4,8 @@ } It 'Can be called with no parameters' { + Get-Command Invoke-RestMethod + Get-Help Invoke-RestMethod -Full Get-GitHubRateLimit | Should -Not -Throw } } From 4439e38ed0d18737d4684b1029019b3d7f086632 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 15:40:53 +0100 Subject: [PATCH 166/193] test --- tests/Rate-Limit/Get-GitHubRateLimit.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Rate-Limit/Get-GitHubRateLimit.Tests.ps1 b/tests/Rate-Limit/Get-GitHubRateLimit.Tests.ps1 index 15b85fac3..fb4fa534c 100644 --- a/tests/Rate-Limit/Get-GitHubRateLimit.Tests.ps1 +++ b/tests/Rate-Limit/Get-GitHubRateLimit.Tests.ps1 @@ -4,8 +4,8 @@ } It 'Can be called with no parameters' { - Get-Command Invoke-RestMethod - Get-Help Invoke-RestMethod -Full + Write-Verbose (Get-Command Invoke-RestMethod | Out-String) + Write-Verbose (Get-Help Invoke-RestMethod -Full | Out-String) Get-GitHubRateLimit | Should -Not -Throw } } From 4ba1123eca1f975ee6baf40023b3a8d63d0516dc Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 15:53:55 +0100 Subject: [PATCH 167/193] Adding option for httpversion if psversion is -ge 7.3 --- src/GitHub/public/API/Invoke-GitHubAPI.ps1 | 6 +++++- tests/Rate-Limit/Get-GitHubRateLimit.Tests.ps1 | 2 -- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 index 4607ba134..27c688bd9 100644 --- a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 +++ b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 @@ -125,7 +125,6 @@ Authentication = 'Bearer' Token = $AccessToken ContentType = $ContentType - HttpVersion = $HttpVersion FollowRelLink = $FollowRelLink StatusCodeVariable = 'APICallStatusCode' ResponseHeadersVariable = 'APICallResponseHeaders' @@ -133,6 +132,11 @@ OutFile = $DownloadFilePath } + #If PSversion is higher than 7.1 use HttpVersion + if ($PSVersionTable.PSVersion -ge [version]'7.3') { + $APICall['HttpVersion'] = $HttpVersion + } + $APICall | Remove-HashtableEntry -NullOrEmptyValues if ($Body) { diff --git a/tests/Rate-Limit/Get-GitHubRateLimit.Tests.ps1 b/tests/Rate-Limit/Get-GitHubRateLimit.Tests.ps1 index fb4fa534c..b2c3a433c 100644 --- a/tests/Rate-Limit/Get-GitHubRateLimit.Tests.ps1 +++ b/tests/Rate-Limit/Get-GitHubRateLimit.Tests.ps1 @@ -4,8 +4,6 @@ } It 'Can be called with no parameters' { - Write-Verbose (Get-Command Invoke-RestMethod | Out-String) - Write-Verbose (Get-Help Invoke-RestMethod -Full | Out-String) Get-GitHubRateLimit | Should -Not -Throw } } From 289f79be9512651ce93955291a088f7c9d22937d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 16:30:30 +0100 Subject: [PATCH 168/193] test --- tests/GitHub/Get-GitHubRepository.Tests.ps1 | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/GitHub/Get-GitHubRepository.Tests.ps1 b/tests/GitHub/Get-GitHubRepository.Tests.ps1 index 095503d2c..3f3ca33e2 100644 --- a/tests/GitHub/Get-GitHubRepository.Tests.ps1 +++ b/tests/GitHub/Get-GitHubRepository.Tests.ps1 @@ -21,25 +21,25 @@ Context 'Parameter Set: ByName' { It 'Can be called with Owner and Repo parameters' { - { Get-GitHubRepository -Owner 'github' -Repo 'octocat' } | Should -Not -Throw + { Get-GitHubRepository -Owner 'PSModule' -Repo 'GitHub' } | Should -Not -Throw } } - Context 'Parameter Set: ListByID' { - It 'Can be called with SinceID parameter' { - { Get-GitHubRepository -SinceID 123456789 } | Select-Object -First 10 | Should -Not -Throw - } - } + # Context 'Parameter Set: ListByID' { + # It 'Can be called with SinceID parameter' { + # { Get-GitHubRepository -SinceID 123456789 } | Select-Object -First 10 | Should -Not -Throw + # } + # } Context 'Parameter Set: ListByOrg' { It 'Can be called with Owner parameter' { - { Get-GitHubRepository -Owner 'github' } | Should -Not -Throw + { Get-GitHubRepository -Owner 'PSModule' } | Should -Not -Throw } } Context 'Parameter Set: ListByUser' { It 'Can be called with Username parameter' { - { Get-GitHubRepository -Username 'octocat' } | Should -Not -Throw + { Get-GitHubRepository -Username 'MariusStorhaug' } | Should -Not -Throw } } } From 1ddf6473b40afc20eaac5ddd808fcf59149b84ce Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 16:36:08 +0100 Subject: [PATCH 169/193] fix --- tests/Rate-Limit/Get-GitHubRateLimit.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Rate-Limit/Get-GitHubRateLimit.Tests.ps1 b/tests/Rate-Limit/Get-GitHubRateLimit.Tests.ps1 index b2c3a433c..0e698a5ad 100644 --- a/tests/Rate-Limit/Get-GitHubRateLimit.Tests.ps1 +++ b/tests/Rate-Limit/Get-GitHubRateLimit.Tests.ps1 @@ -4,6 +4,6 @@ } It 'Can be called with no parameters' { - Get-GitHubRateLimit | Should -Not -Throw + { Get-GitHubRateLimit } | Should -Not -Throw } } From e676b81fb866d67942f7432cae9a9babcd828b5c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 16:49:02 +0100 Subject: [PATCH 170/193] Fixes --- tests/GitHub/Get-GitHubRepository.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/GitHub/Get-GitHubRepository.Tests.ps1 b/tests/GitHub/Get-GitHubRepository.Tests.ps1 index 3f3ca33e2..6fb67e6be 100644 --- a/tests/GitHub/Get-GitHubRepository.Tests.ps1 +++ b/tests/GitHub/Get-GitHubRepository.Tests.ps1 @@ -5,11 +5,11 @@ Context 'Parameter Set: MyRepos_Type' { It 'Can be called with no parameters' { - { Get-GitHubRepository } | Should -Not -Throw + { Get-GitHubRepository - } | Should -Not -Throw } It 'Can be called with Type parameter' { - { Get-GitHubRepository -Type 'owner' } | Should -Not -Throw + { Get-GitHubRepository -Type 'public' } | Should -Not -Throw } } From 3c67d74912ae495753a8c3280cfeb9dcb4209752 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 16:57:34 +0100 Subject: [PATCH 171/193] Remove some tests --- tests/GitHub/Get-GitHubRepository.Tests.ps1 | 26 ++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/GitHub/Get-GitHubRepository.Tests.ps1 b/tests/GitHub/Get-GitHubRepository.Tests.ps1 index 6fb67e6be..97ac96651 100644 --- a/tests/GitHub/Get-GitHubRepository.Tests.ps1 +++ b/tests/GitHub/Get-GitHubRepository.Tests.ps1 @@ -3,21 +3,21 @@ Get-Command Get-GitHubRepository | Should -Not -BeNullOrEmpty } - Context 'Parameter Set: MyRepos_Type' { - It 'Can be called with no parameters' { - { Get-GitHubRepository - } | Should -Not -Throw - } + # Context 'Parameter Set: MyRepos_Type' { + # It 'Can be called with no parameters' { + # { Get-GitHubRepository - } | Should -Not -Throw + # } - It 'Can be called with Type parameter' { - { Get-GitHubRepository -Type 'public' } | Should -Not -Throw - } - } + # It 'Can be called with Type parameter' { + # { Get-GitHubRepository -Type 'public' } | Should -Not -Throw + # } + # } - Context 'Parameter Set: MyRepos_Aff-Vis' { - It 'Can be called with Visibility and Affiliation parameters' { - { Get-GitHubRepository -Visibility 'public' -Affiliation 'owner' } | Should -Not -Throw - } - } + # Context 'Parameter Set: MyRepos_Aff-Vis' { + # It 'Can be called with Visibility and Affiliation parameters' { + # { Get-GitHubRepository -Visibility 'public' -Affiliation 'owner' } | Should -Not -Throw + # } + # } Context 'Parameter Set: ByName' { It 'Can be called with Owner and Repo parameters' { From 51903001063d7b4053e55f8dd6b1a02fc54fc333 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 20:01:27 +0100 Subject: [PATCH 172/193] Start repo event --- .../Start-GitHubRepositoryEvent.ps1 | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 src/GitHub/public/Repositories/Repositories/Start-GitHubRepositoryEvent.ps1 diff --git a/src/GitHub/public/Repositories/Repositories/Start-GitHubRepositoryEvent.ps1 b/src/GitHub/public/Repositories/Repositories/Start-GitHubRepositoryEvent.ps1 new file mode 100644 index 000000000..3cc74eb50 --- /dev/null +++ b/src/GitHub/public/Repositories/Repositories/Start-GitHubRepositoryEvent.ps1 @@ -0,0 +1,94 @@ +filter Start-GitHubRepositoryEvent { + <# + .SYNOPSIS + Create a repository dispatch event + + .DESCRIPTION + You can use this endpoint to trigger a webhook event called `repository_dispatch` when you want activity + that happens outside of GitHub to trigger a GitHub Actions workflow or GitHub App webhook. You must configure + your GitHub Actions workflow or GitHub App to run when the `repository_dispatch` + event occurs. For an example `repository_dispatch` webhook payload, see + "[RepositoryDispatchEvent](https://docs.github.com/webhooks/event-payloads/#repository_dispatch)." + + The `client_payload` parameter is available for any extra information that your workflow might need. + This parameter is a JSON payload that will be passed on when the webhook event is dispatched. For example, + the `client_payload` can include a message that a user would like to send using a GitHub Actions workflow. + Or the `client_payload` can be used as a test to debug your workflow. + + This endpoint requires write access to the repository by providing either: + + - Personal access tokens with `repo` scope. For more information, see + "[Creating a personal access token for the command line](https://docs.github.com/articles/creating-a-personal-access-token-for-the-command-line)" + in the GitHub Help documentation. + - GitHub Apps with both `metadata:read` and `contents:read&write` permissions. + + This input example shows how you can use the `client_payload` as a test to debug your workflow. + + .EXAMPLE + $params = @{ + EventType = 'on-demand-test' + ClientPayload = @{ + unit = false + integration = true + } + } + Start-GitHubRepositoryEvent @params + + Starts a repository event with the name `on-demand-test` and a `client_payload` that includes `unit` and `integration`. + + .NOTES + https://docs.github.com/rest/repos/repos#create-a-repository-dispatch-event + + #> + [CmdletBinding(SupportsShouldProcess)] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Long links')] + param ( + # The account owner of the repository. The name is not case sensitive. + [Parameter()] + [Alias('org')] + [string] $Owner = (Get-GitHubConfig -Name Owner), + + # The name of the repository without the .git extension. The name is not case sensitive. + [Parameter()] + [string] $Repo = (Get-GitHubConfig -Name Repo), + + # A custom webhook event name. Must be 100 characters or fewer. + [Parameter(Mandatory)] + [Alias('event_type')] + [string] $EventType, + + # JSON payload with extra information about the webhook event that your action or workflow may use. + # The maximum number of top-level properties is 10. + [Parameter()] + [Alias('client_payload')] + [object] $ClientPayload + ) + + $PSCmdlet.MyInvocation.MyCommand.Parameters.GetEnumerator() | ForEach-Object { + $paramName = $_.Key + $paramDefaultValue = Get-Variable -Name $paramName -ValueOnly -ErrorAction SilentlyContinue + $providedValue = $PSBoundParameters[$paramName] + Write-Verbose "[$paramName]" + Write-Verbose " - Default: [$paramDefaultValue]" + Write-Verbose " - Provided: [$providedValue]" + if (-not $PSBoundParameters.ContainsKey($paramName) -and ($null -ne $paramDefaultValue)) { + Write-Verbose ' - Using default value' + $PSBoundParameters[$paramName] = $paramDefaultValue + } else { + Write-Verbose ' - Using provided value' + } + } + + $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case + Remove-HashtableEntry -Hashtable $body -RemoveNames 'Owner', 'Repo' -RemoveTypes 'SwitchParameter' + + $inputObject = @{ + APIEndpoint = "/repos/$Owner/$Repo/dispatches" + Method = 'POST' + Body = $body + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } +} From faf446c55c09f4b31364726c623997e5949da1b4 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 21:01:30 +0100 Subject: [PATCH 173/193] Create repo as fork --- .../Fork/New-GitHubRepositoryAsFork.ps1 | 97 +++++++++++++++++++ .../Repositories/New-GitHubRepository.ps1 | 60 +++++++++++- tools/utilities/GitHubAPI.ps1 | 4 +- 3 files changed, 154 insertions(+), 7 deletions(-) create mode 100644 src/GitHub/private/Repositories/Fork/New-GitHubRepositoryAsFork.ps1 diff --git a/src/GitHub/private/Repositories/Fork/New-GitHubRepositoryAsFork.ps1 b/src/GitHub/private/Repositories/Fork/New-GitHubRepositoryAsFork.ps1 new file mode 100644 index 000000000..1cb7bf04b --- /dev/null +++ b/src/GitHub/private/Repositories/Fork/New-GitHubRepositoryAsFork.ps1 @@ -0,0 +1,97 @@ +filter New-GitHubRepositoryAsFork { + <# + .SYNOPSIS + Create a fork + + .DESCRIPTION + Create a fork for the authenticated user. + + **Note**: Forking a Repository happens asynchronously. You may have to wait a short period of time before you can access the git objects. + If this takes longer than 5 minutes, be sure to contact [GitHub Support](https://support.github.com/contact?tags=dotcom-rest-api). + + **Note**: Although this endpoint works with GitHub Apps, the GitHub App must be installed on the destination account with access to all + repositories and on the source account with access to the source repository. + + .EXAMPLE + New-GitHubRepositoryAsFork -ForkOwner 'github' -ForkRepo 'Hello-World' + + Fork the repository `Hello-World` owned by `github` for the authenticated user. + Repo will be named `Hello-World`, and all branches and tags will be forked. + + .EXAMPLE + New-GitHubRepositoryAsFork -ForkOwner 'github' -ForkRepo 'Hello-World' -Name 'Hello-World-2' + + Fork the repository `Hello-World` owned by `github` for the authenticated user, naming the resulting repository `Hello-World-2`. + + .EXAMPLE + New-GitHubRepositoryAsFork -ForkOwner 'github' -ForkRepo 'Hello-World' -Organization 'octocat' + + Fork the repository `Hello-World` owned by `github` for the organization `octocat`, naming the resulting repository `Hello-World`. + + .EXAMPLE + New-GitHubRepositoryAsFork -ForkOwner 'github' -ForkRepo 'Hello-World' -DefaultBranchOnly + + Fork the repository `Hello-World` owned by `github` for the authenticated user, forking only the default branch. + + .NOTES + https://docs.github.com/rest/repos/forks#create-a-fork + + #> + [OutputType([pscustomobject])] + [CmdletBinding(SupportsShouldProcess)] + param ( + # The account owner of the repository. The name is not case sensitive. + [Parameter(Mandatory)] + [Alias('owner')] + [string] $ForkOwner, + + # The name of the repository without the .git extension. The name is not case sensitive. + [Parameter(Mandatory)] + [Alias('repo')] + [string] $ForkRepo, + + # The organization or person who will own the new repository. + # To create a new repository in an organization, the authenticated user must be a member of the specified organization. + [Parameter()] + [string] $Organization = (Get-GitHubConfig -Name Owner), + + # The name of the new repository. + [Parameter()] + [string] $Name, + + # When forking from an existing repository, fork with only the default branch. + [Parameter()] + [Alias('default_branch_only')] + [switch] $DefaultBranchOnly + ) + + $PSCmdlet.MyInvocation.MyCommand.Parameters.GetEnumerator() | ForEach-Object { + $paramName = $_.Key + $paramDefaultValue = Get-Variable -Name $paramName -ValueOnly -ErrorAction SilentlyContinue + $providedValue = $PSBoundParameters[$paramName] + Write-Verbose "[$paramName]" + Write-Verbose " - Default: [$paramDefaultValue]" + Write-Verbose " - Provided: [$providedValue]" + if (-not $PSBoundParameters.ContainsKey($paramName) -and ($null -ne $paramDefaultValue)) { + Write-Verbose ' - Using default value' + $PSBoundParameters[$paramName] = $paramDefaultValue + } else { + Write-Verbose ' - Using provided value' + } + } + + $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case + Remove-HashtableEntry -Hashtable $body -RemoveNames 'TemplateOwner', 'TemplateRepo' -RemoveTypes 'SwitchParameter' + + $inputObject = @{ + APIEndpoint = "/repos/$ForkOwner/$ForkRepo/forks" + Method = 'POST' + Body = $body + } + + if ($PSCmdlet.ShouldProcess("Repository [$Owner/$Name] as fork of [$ForkOwner/$ForkRepo]", 'Create')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } +} diff --git a/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 b/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 index b27cdd38e..2712dc16c 100644 --- a/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 +++ b/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 @@ -72,6 +72,19 @@ Creates a new private repository named `MyNewRepo` from the `octocat` template repository owned by `GitHub`. + .EXAMPLE + $params = @{ + ForkOwner = 'octocat' + ForkRepo = 'Hello-World' + Owner = 'PSModule' + Name = 'MyNewRepo' + DefaultBranchOnly = $true + } + New-GitHubRepository @params + + Creates a new repository named `MyNewRepo` as a fork of `Hello-World` owned by `octocat`. + Only the default branch will be forked. + .NOTES https://docs.github.com/rest/repos/repos#create-a-repository-using-a-template @@ -96,6 +109,7 @@ param ( # The account owner of the repository. The name is not case sensitive. [Parameter(ParameterSetName = 'org')] + [Parameter(ParameterSetName = 'fork')] [Alias('org')] [string] $Owner = (Get-GitHubConfig -Name Owner), @@ -119,8 +133,29 @@ [Alias('template_repo')] [string] $TemplateRepo, + # The account owner of the repository. The name is not case sensitive. + [Parameter( + Mandatory, + ParameterSetName = 'fork' + )] + [string] $ForkOwner, + + # The name of the repository without the .git extension. The name is not case sensitive. + [Parameter( + Mandatory, + ParameterSetName = 'fork' + )] + [string] $ForkRepo, + + # When forking from an existing repository, fork with only the default branch. + [Parameter(ParameterSetName = 'fork')] + [Alias('default_branch_only')] + [switch] $DefaultBranchOnly, + # A short description of the new repository. - [Parameter()] + [Parameter(ParameterSetName = 'user')] + [Parameter(ParameterSetName = 'org')] + [Parameter(ParameterSetName = 'template')] [string] $Description, # Set to true to include the directory structure and files from all branches in the template repository, @@ -136,7 +171,9 @@ [uri] $Homepage, # The visibility of the repository. - [Parameter()] + [Parameter(ParameterSetName = 'user')] + [Parameter(ParameterSetName = 'org')] + [Parameter(ParameterSetName = 'template')] [ValidateSet('public', 'private')] [string] $Visibility = 'public', @@ -316,17 +353,17 @@ switch ($PSCmdlet.ParameterSetName) { 'user' { - if ($PSCmdlet.ShouldProcess("repository for user [$repo]", 'Create')) { + if ($PSCmdlet.ShouldProcess("repository for user [$Name]", 'Create')) { New-GitHubRepositoryUser @params } } 'org' { - if ($PSCmdlet.ShouldProcess("repository for organization [$Owner/$Repo]", 'Create')) { + if ($PSCmdlet.ShouldProcess("repository for organization [$Owner/$Name]", 'Create')) { New-GitHubRepositoryOrg @params } } 'template' { - if ($PSCmdlet.ShouldProcess("repository from template [$Owner/$Repo]", 'Create')) { + if ($PSCmdlet.ShouldProcess("repository [$Owner/$Name] from template [$TemplateOwner/$TemplateRepo]", 'Create')) { $params = @{ TemplateOwner = $TemplateOwner TemplateRepo = $TemplateRepo @@ -340,6 +377,19 @@ New-GitHubRepositoryFromTemplate @params } } + 'fork' { + if ($PSCmdlet.ShouldProcess("repository [$Owner/$Name] as fork from [$ForkOwner/$ForkRepo]", 'Create')) { + $params = @{ + ForkOwner = $ForkOwner + ForkRepo = $ForkRepo + Owner = $Owner + Name = $Name + DefaultBranchOnly = $DefaultBranchOnly + } + Remove-HashtableEntry -Hashtable $params -NullOrEmptyValues + New-GitHubRepositoryAsFork @params + } + } } } } diff --git a/tools/utilities/GitHubAPI.ps1 b/tools/utilities/GitHubAPI.ps1 index 78a9f1b9e..db5ce06b3 100644 --- a/tools/utilities/GitHubAPI.ps1 +++ b/tools/utilities/GitHubAPI.ps1 @@ -21,8 +21,8 @@ $response = Invoke-RestMethod -Uri $APIDocURI -Method Get # @{n = 'PUT'; e = { (($_.value.psobject.Properties.Name) -contains 'PUT') } }, ` # @{n = 'PATCH'; e = { (($_.value.psobject.Properties.Name) -contains 'PATCH') } } | Format-Table -$path = '/repos/{owner}/{repo}' -$method = 'patch' +$path = '/repos/{owner}/{repo}/forks' +$method = 'post' $response.paths.$path.$method $response.paths.$path.$method.tags | clip # -> Namespace/foldername $response.paths.$path.$method.operationId | clip # -> FunctionName From bc32cb7d2c589f035c1c728d2b5d16c7a57824ab Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 21:06:36 +0100 Subject: [PATCH 174/193] Get forks --- .../Repositories/Get-GitHubRepositoryFork.ps1 | 69 +++++++++++++++++++ tools/utilities/GitHubAPI.ps1 | 2 +- 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryFork.ps1 diff --git a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryFork.ps1 b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryFork.ps1 new file mode 100644 index 000000000..371d1eff9 --- /dev/null +++ b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryFork.ps1 @@ -0,0 +1,69 @@ +filter Get-GitHubRepositoryFork { + <# + .SYNOPSIS + List forks + + .DESCRIPTION + List forks of a named repository. + + .EXAMPLE + Get-GitHubRepositoryFork -Owner 'octocat' -Repo 'Hello-World' + + List forks of the 'Hello-World' repository owned by 'octocat'. + + .NOTES + https://docs.github.com/rest/repos/forks#list-forks + + #> + [CmdletBinding()] + param ( + # The account owner of the repository. The name is not case sensitive. + [Parameter()] + [Alias('org')] + [string] $Owner = (Get-GitHubConfig -Name Owner), + + # The name of the repository without the .git extension. The name is not case sensitive. + [Parameter()] + [string] $Repo = (Get-GitHubConfig -Name Repo), + + # The direction to sort the results by. + [Parameter()] + [ValidateSet('newest', 'oldest', 'stargazers', 'watchers')] + [string] $Sort = 'newest', + + # The number of results per page (max 100). + # Default: 30 + [Parameter()] + [ValidateRange(1, 100)] + [Alias('per_page')] + [int] $PerPage = 30 + ) + + $PSCmdlet.MyInvocation.MyCommand.Parameters.GetEnumerator() | ForEach-Object { + $paramName = $_.Key + $paramDefaultValue = Get-Variable -Name $paramName -ValueOnly -ErrorAction SilentlyContinue + $providedValue = $PSBoundParameters[$paramName] + Write-Verbose "[$paramName]" + Write-Verbose " - Default: [$paramDefaultValue]" + Write-Verbose " - Provided: [$providedValue]" + if (-not $PSBoundParameters.ContainsKey($paramName) -and ($null -ne $paramDefaultValue)) { + Write-Verbose ' - Using default value' + $PSBoundParameters[$paramName] = $paramDefaultValue + } else { + Write-Verbose ' - Using provided value' + } + } + + $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case + Remove-HashtableEntry -Hashtable $body -RemoveNames 'Owner', 'Repo' -RemoveTypes 'SwitchParameter' + + $inputObject = @{ + APIEndpoint = "/repos/$Owner/$Repo/forks" + Method = 'GET' + Body = $body + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } +} diff --git a/tools/utilities/GitHubAPI.ps1 b/tools/utilities/GitHubAPI.ps1 index db5ce06b3..0b7f16d5d 100644 --- a/tools/utilities/GitHubAPI.ps1 +++ b/tools/utilities/GitHubAPI.ps1 @@ -22,7 +22,7 @@ $response = Invoke-RestMethod -Uri $APIDocURI -Method Get # @{n = 'PATCH'; e = { (($_.value.psobject.Properties.Name) -contains 'PATCH') } } | Format-Table $path = '/repos/{owner}/{repo}/forks' -$method = 'post' +$method = 'get' $response.paths.$path.$method $response.paths.$path.$method.tags | clip # -> Namespace/foldername $response.paths.$path.$method.operationId | clip # -> FunctionName From 9661fb66f6570f907136f97d22e4cff3c9a31ad9 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 21:27:12 +0100 Subject: [PATCH 175/193] Set params for fork --- .../public/Repositories/Repositories/New-GitHubRepository.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 b/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 index 2712dc16c..e0528f403 100644 --- a/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 +++ b/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 @@ -115,6 +115,7 @@ # The name of the repository. [Parameter(Mandatory)] + [Parameter(ParameterSetName = 'fork')] [string] $Name, # The account owner of the template repository. The name is not case sensitive. From 7cd82c55d8341bcf67af07ade4ace8bf7b206573 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 21:37:35 +0100 Subject: [PATCH 176/193] fix param mandatory --- .../Repositories/Repositories/New-GitHubRepository.ps1 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 b/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 index e0528f403..f29100c67 100644 --- a/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 +++ b/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 @@ -114,8 +114,11 @@ [string] $Owner = (Get-GitHubConfig -Name Owner), # The name of the repository. + [Parameter( + Mandatory = $false, + ParameterSetName = 'fork' + )] [Parameter(Mandatory)] - [Parameter(ParameterSetName = 'fork')] [string] $Name, # The account owner of the template repository. The name is not case sensitive. From eb366fbb1caa30891f303092308d01ffbeaf65a8 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 21:50:18 +0100 Subject: [PATCH 177/193] fix fork --- .../private/Repositories/Fork/New-GitHubRepositoryAsFork.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GitHub/private/Repositories/Fork/New-GitHubRepositoryAsFork.ps1 b/src/GitHub/private/Repositories/Fork/New-GitHubRepositoryAsFork.ps1 index 1cb7bf04b..438ea504e 100644 --- a/src/GitHub/private/Repositories/Fork/New-GitHubRepositoryAsFork.ps1 +++ b/src/GitHub/private/Repositories/Fork/New-GitHubRepositoryAsFork.ps1 @@ -81,7 +81,7 @@ } $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntry -Hashtable $body -RemoveNames 'TemplateOwner', 'TemplateRepo' -RemoveTypes 'SwitchParameter' + Remove-HashtableEntry -Hashtable $body -RemoveNames 'ForkOwner', 'ForkRepo' -RemoveTypes 'SwitchParameter' $inputObject = @{ APIEndpoint = "/repos/$ForkOwner/$ForkRepo/forks" From a23600031b8e8c4c2b77beb5d51f61fe163b45bb Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 22:04:39 +0100 Subject: [PATCH 178/193] fix mandatory param --- .../Repositories/Repositories/New-GitHubRepository.ps1 | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 b/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 index f29100c67..a8b318b0b 100644 --- a/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 +++ b/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 @@ -114,11 +114,10 @@ [string] $Owner = (Get-GitHubConfig -Name Owner), # The name of the repository. - [Parameter( - Mandatory = $false, - ParameterSetName = 'fork' - )] - [Parameter(Mandatory)] + [Parameter(ParameterSetName = 'fork')] + [Parameter(Mandatory, ParameterSetName = 'user')] + [Parameter(Mandatory, ParameterSetName = 'org')] + [Parameter(Mandatory, ParameterSetName = 'template')] [string] $Name, # The account owner of the template repository. The name is not case sensitive. From b52bdf23d475920058ab906f653edb4a36bf6f3f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 22:14:19 +0100 Subject: [PATCH 179/193] fix --- .../Repositories/New-GitHubRepository.ps1 | 56 ++++++++++--------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 b/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 index a8b318b0b..7d40568a1 100644 --- a/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 +++ b/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 @@ -326,33 +326,35 @@ } Process { - $params = @{ - Owner = $Owner - Name = $Name - Description = $Description - Homepage = $Homepage - Visibility = $Visibility - HasIssues = $HasIssues - HasProjects = $HasProjects - HasWiki = $HasWiki - HasDiscussions = $HasDiscussions - HasDownloads = $HasDownloads - IsTemplate = $IsTemplate - TeamId = $TeamId - AutoInit = $AutoInit - AllowSquashMerge = $AllowSquashMerge - AllowMergeCommit = $AllowMergeCommit - AllowRebaseMerge = $AllowRebaseMerge - AllowAutoMerge = $AllowAutoMerge - DeleteBranchOnMerge = $DeleteBranchOnMerge - SquashMergeCommitTitle = $SquashMergeCommitTitle - SquashMergeCommitMessage = $SquashMergeCommitMessage - MergeCommitTitle = $MergeCommitTitle - MergeCommitMessage = $MergeCommitMessage - GitignoreTemplate = $GitignoreTemplate - LicenseTemplate = $LicenseTemplate + if ($PSCmdlet.ParameterSetName -in 'user', 'org') { + $params = @{ + Owner = $Owner + Name = $Name + Description = $Description + Homepage = $Homepage + Visibility = $Visibility + HasIssues = $HasIssues + HasProjects = $HasProjects + HasWiki = $HasWiki + HasDiscussions = $HasDiscussions + HasDownloads = $HasDownloads + IsTemplate = $IsTemplate + TeamId = $TeamId + AutoInit = $AutoInit + AllowSquashMerge = $AllowSquashMerge + AllowMergeCommit = $AllowMergeCommit + AllowRebaseMerge = $AllowRebaseMerge + AllowAutoMerge = $AllowAutoMerge + DeleteBranchOnMerge = $DeleteBranchOnMerge + SquashMergeCommitTitle = $SquashMergeCommitTitle + SquashMergeCommitMessage = $SquashMergeCommitMessage + MergeCommitTitle = $MergeCommitTitle + MergeCommitMessage = $MergeCommitMessage + GitignoreTemplate = $GitignoreTemplate + LicenseTemplate = $LicenseTemplate + } + Remove-HashtableEntry -Hashtable $params -NullOrEmptyValues } - Remove-HashtableEntry -Hashtable $params -NullOrEmptyValues switch ($PSCmdlet.ParameterSetName) { 'user' { @@ -385,7 +387,7 @@ $params = @{ ForkOwner = $ForkOwner ForkRepo = $ForkRepo - Owner = $Owner + Organization = $Owner Name = $Name DefaultBranchOnly = $DefaultBranchOnly } From 7959e1012c399384f7ebfc916c6cf4014de1fe20 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 22:21:41 +0100 Subject: [PATCH 180/193] Fix null or empty --- .../private/Utilities/Hashtable/Remove-HashtableEntry.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GitHub/private/Utilities/Hashtable/Remove-HashtableEntry.ps1 b/src/GitHub/private/Utilities/Hashtable/Remove-HashtableEntry.ps1 index fc042b8d8..b35c7f79f 100644 --- a/src/GitHub/private/Utilities/Hashtable/Remove-HashtableEntry.ps1 +++ b/src/GitHub/private/Utilities/Hashtable/Remove-HashtableEntry.ps1 @@ -56,7 +56,7 @@ if ($NullOrEmptyValues) { Write-Verbose 'Remove keys with null or empty values' - ($Hashtable.GetEnumerator() | Where-Object { -not $_.Value }) | ForEach-Object { + ($Hashtable.GetEnumerator() | Where-Object { [string]::IsNullOrEmpty($_.Value) }) | ForEach-Object { Write-Verbose " - [$($_.Name)] - Value: [$($_.Value)] - Remove" $Hashtable.Remove($_.Name) } From 1b7f71e9d9159d5cc3fea2db1061b0294f1ce820 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 22:41:12 +0100 Subject: [PATCH 181/193] Default forked repo name to the upstream name --- .../private/Repositories/Fork/New-GitHubRepositoryAsFork.ps1 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/GitHub/private/Repositories/Fork/New-GitHubRepositoryAsFork.ps1 b/src/GitHub/private/Repositories/Fork/New-GitHubRepositoryAsFork.ps1 index 438ea504e..f3188e3de 100644 --- a/src/GitHub/private/Repositories/Fork/New-GitHubRepositoryAsFork.ps1 +++ b/src/GitHub/private/Repositories/Fork/New-GitHubRepositoryAsFork.ps1 @@ -65,6 +65,10 @@ [switch] $DefaultBranchOnly ) + if ([string]::IsNullorEmpty($Name)) { + $Name = $ForkRepo + } + $PSCmdlet.MyInvocation.MyCommand.Parameters.GetEnumerator() | ForEach-Object { $paramName = $_.Key $paramDefaultValue = Get-Variable -Name $paramName -ValueOnly -ErrorAction SilentlyContinue From 322c7786b78fff1920720b6e421cf3b06ba7fee0 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 22:54:38 +0100 Subject: [PATCH 182/193] flip switch to bool --- .../private/Repositories/Fork/New-GitHubRepositoryAsFork.ps1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/GitHub/private/Repositories/Fork/New-GitHubRepositoryAsFork.ps1 b/src/GitHub/private/Repositories/Fork/New-GitHubRepositoryAsFork.ps1 index f3188e3de..9a2b9fc9e 100644 --- a/src/GitHub/private/Repositories/Fork/New-GitHubRepositoryAsFork.ps1 +++ b/src/GitHub/private/Repositories/Fork/New-GitHubRepositoryAsFork.ps1 @@ -87,6 +87,8 @@ $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case Remove-HashtableEntry -Hashtable $body -RemoveNames 'ForkOwner', 'ForkRepo' -RemoveTypes 'SwitchParameter' + $body['default_branch_only'] = $DefaultBranchOnly -eq $true + $inputObject = @{ APIEndpoint = "/repos/$ForkOwner/$ForkRepo/forks" Method = 'POST' From f777ec329bcd9f31b72bd65a1871a88374ea98f5 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 23:15:05 +0100 Subject: [PATCH 183/193] fix --- .../Repositories/Fork/New-GitHubRepositoryAsFork.ps1 | 6 ++---- .../Repositories/Repositories/New-GitHubRepository.ps1 | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/GitHub/private/Repositories/Fork/New-GitHubRepositoryAsFork.ps1 b/src/GitHub/private/Repositories/Fork/New-GitHubRepositoryAsFork.ps1 index 9a2b9fc9e..205c93dfa 100644 --- a/src/GitHub/private/Repositories/Fork/New-GitHubRepositoryAsFork.ps1 +++ b/src/GitHub/private/Repositories/Fork/New-GitHubRepositoryAsFork.ps1 @@ -42,13 +42,11 @@ param ( # The account owner of the repository. The name is not case sensitive. [Parameter(Mandatory)] - [Alias('owner')] - [string] $ForkOwner, + [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. [Parameter(Mandatory)] - [Alias('repo')] - [string] $ForkRepo, + [string] $Repo, # The organization or person who will own the new repository. # To create a new repository in an organization, the authenticated user must be a member of the specified organization. diff --git a/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 b/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 index 7d40568a1..410c16806 100644 --- a/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 +++ b/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 @@ -385,8 +385,8 @@ 'fork' { if ($PSCmdlet.ShouldProcess("repository [$Owner/$Name] as fork from [$ForkOwner/$ForkRepo]", 'Create')) { $params = @{ - ForkOwner = $ForkOwner - ForkRepo = $ForkRepo + Owner = $ForkOwner + Repo = $ForkRepo Organization = $Owner Name = $Name DefaultBranchOnly = $DefaultBranchOnly From 2c2cd87dd70acd8b831fe76d63b3ac0b316150fa Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 23:22:28 +0100 Subject: [PATCH 184/193] fix --- .../private/Repositories/Fork/New-GitHubRepositoryAsFork.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/GitHub/private/Repositories/Fork/New-GitHubRepositoryAsFork.ps1 b/src/GitHub/private/Repositories/Fork/New-GitHubRepositoryAsFork.ps1 index 205c93dfa..79ced1180 100644 --- a/src/GitHub/private/Repositories/Fork/New-GitHubRepositoryAsFork.ps1 +++ b/src/GitHub/private/Repositories/Fork/New-GitHubRepositoryAsFork.ps1 @@ -88,12 +88,12 @@ $body['default_branch_only'] = $DefaultBranchOnly -eq $true $inputObject = @{ - APIEndpoint = "/repos/$ForkOwner/$ForkRepo/forks" + APIEndpoint = "/repos/$Owner/$Repo/forks" Method = 'POST' Body = $body } - if ($PSCmdlet.ShouldProcess("Repository [$Owner/$Name] as fork of [$ForkOwner/$ForkRepo]", 'Create')) { + if ($PSCmdlet.ShouldProcess("Repository [$Organization/$Name] as fork of [$Owner/$Repo]", 'Create')) { Invoke-GitHubAPI @inputObject | ForEach-Object { Write-Output $_.Response } From e104352922822913da7abf27fa3d990009572b0c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 5 Nov 2023 23:23:14 +0100 Subject: [PATCH 185/193] fix fork params --- .../private/Repositories/Fork/New-GitHubRepositoryAsFork.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GitHub/private/Repositories/Fork/New-GitHubRepositoryAsFork.ps1 b/src/GitHub/private/Repositories/Fork/New-GitHubRepositoryAsFork.ps1 index 79ced1180..8b7d41d65 100644 --- a/src/GitHub/private/Repositories/Fork/New-GitHubRepositoryAsFork.ps1 +++ b/src/GitHub/private/Repositories/Fork/New-GitHubRepositoryAsFork.ps1 @@ -83,7 +83,7 @@ } $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntry -Hashtable $body -RemoveNames 'ForkOwner', 'ForkRepo' -RemoveTypes 'SwitchParameter' + Remove-HashtableEntry -Hashtable $body -RemoveNames 'Owner', 'Repo' -RemoveTypes 'SwitchParameter' $body['default_branch_only'] = $DefaultBranchOnly -eq $true From 1daf865840d81d78ca34fe2db871f9b51e1dd7ed Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 6 Nov 2023 20:45:07 +0100 Subject: [PATCH 186/193] Fix name if not provided --- .../public/Repositories/Repositories/New-GitHubRepository.ps1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 b/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 index 410c16806..16b9ead25 100644 --- a/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 +++ b/src/GitHub/public/Repositories/Repositories/New-GitHubRepository.ps1 @@ -383,6 +383,9 @@ } } 'fork' { + if ([string]::IsNullorEmpty($Name)) { + $Name = $ForkRepo + } if ($PSCmdlet.ShouldProcess("repository [$Owner/$Name] as fork from [$ForkOwner/$ForkRepo]", 'Create')) { $params = @{ Owner = $ForkOwner From 945417de0cdb6882ebef63f37e9daecf88d7a826 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 6 Nov 2023 20:59:13 +0100 Subject: [PATCH 187/193] troubleshooting --- src/GitHub/public/API/Invoke-GitHubAPI.ps1 | 2 ++ .../Repositories/Repositories/Get-GitHubRepositoryFork.ps1 | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 index 27c688bd9..7956eee58 100644 --- a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 +++ b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 @@ -190,7 +190,9 @@ Message: $($failure.Exception.Message | ConvertFrom-HashTable | Format-List | Out-String) ---------------------------------- Response: +$($failure.Exception.Response | Format-List | Out-String) $($failure.Exception.Response | ConvertFrom-HashTable | Format-List | Out-String) +$($failure.Exception.Response | ConvertTo-Json -Depth 10 | Out-String) ---------------------------------- "@ diff --git a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryFork.ps1 b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryFork.ps1 index 371d1eff9..6bd122670 100644 --- a/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryFork.ps1 +++ b/src/GitHub/public/Repositories/Repositories/Get-GitHubRepositoryFork.ps1 @@ -31,8 +31,7 @@ [ValidateSet('newest', 'oldest', 'stargazers', 'watchers')] [string] $Sort = 'newest', - # The number of results per page (max 100). - # Default: 30 + # The number of results per page. [Parameter()] [ValidateRange(1, 100)] [Alias('per_page')] From d6703aeee8b6103d159a0ad65a3dea3befcdbc86 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 6 Nov 2023 22:12:59 +0100 Subject: [PATCH 188/193] fixes --- .../Fork/New-GitHubRepositoryAsFork.ps1 | 2 +- src/GitHub/public/API/Invoke-GitHubAPI.ps1 | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/GitHub/private/Repositories/Fork/New-GitHubRepositoryAsFork.ps1 b/src/GitHub/private/Repositories/Fork/New-GitHubRepositoryAsFork.ps1 index 8b7d41d65..f8b3d881b 100644 --- a/src/GitHub/private/Repositories/Fork/New-GitHubRepositoryAsFork.ps1 +++ b/src/GitHub/private/Repositories/Fork/New-GitHubRepositoryAsFork.ps1 @@ -85,7 +85,7 @@ $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case Remove-HashtableEntry -Hashtable $body -RemoveNames 'Owner', 'Repo' -RemoveTypes 'SwitchParameter' - $body['default_branch_only'] = $DefaultBranchOnly -eq $true + $body['default_branch_only'] = $DefaultBranchOnly $inputObject = @{ APIEndpoint = "/repos/$Owner/$Repo/forks" diff --git a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 index 7956eee58..ff2c897fd 100644 --- a/src/GitHub/public/API/Invoke-GitHubAPI.ps1 +++ b/src/GitHub/public/API/Invoke-GitHubAPI.ps1 @@ -166,7 +166,7 @@ Request: $($APICall | ConvertFrom-HashTable | Format-List | Out-String) ---------------------------------- ResponseHeaders: -$($responseHeaders | Format-List | Out-String) +$($responseHeaders.PSObject.Properties | Foreach-Object { $_ | Format-List | Out-String }) ---------------------------------- "@ @@ -182,20 +182,19 @@ $($responseHeaders | Format-List | Out-String) $failure = $_ $errorResult = @" ----------------------------------- +----------------------------------`n`r Request: $($APICall | ConvertFrom-HashTable | Format-List | Out-String) ----------------------------------- +----------------------------------`n`r Message: $($failure.Exception.Message | ConvertFrom-HashTable | Format-List | Out-String) ----------------------------------- +----------------------------------`n`r Response: -$($failure.Exception.Response | Format-List | Out-String) $($failure.Exception.Response | ConvertFrom-HashTable | Format-List | Out-String) -$($failure.Exception.Response | ConvertTo-Json -Depth 10 | Out-String) ----------------------------------- +----------------------------------`n`r "@ - throw $errorResult + $errorResult.Split([System.Environment]::NewLine) | ForEach-Object { Write-Error $_ } + throw $failure.Exception.Message } } From 9fa68b57e62354a1e4f8b2bc9f6ffe8ef802da88 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 6 Nov 2023 23:41:26 +0100 Subject: [PATCH 189/193] Add functions for autolinks --- .../Get-GitHubRepositoryAutolink.ps1 | 41 ++++++++++ .../New-GitHubRepositoryAutolink.ps1 | 76 +++++++++++++++++++ .../Remove-GitHubRepositoryAutolink.ps1 | 49 ++++++++++++ tools/utilities/GitHubAPI.ps1 | 4 +- 4 files changed, 168 insertions(+), 2 deletions(-) create mode 100644 src/GitHub/public/Repositories/Autolinks/Get-GitHubRepositoryAutolink.ps1 create mode 100644 src/GitHub/public/Repositories/Autolinks/New-GitHubRepositoryAutolink.ps1 create mode 100644 src/GitHub/public/Repositories/Autolinks/Remove-GitHubRepositoryAutolink.ps1 diff --git a/src/GitHub/public/Repositories/Autolinks/Get-GitHubRepositoryAutolink.ps1 b/src/GitHub/public/Repositories/Autolinks/Get-GitHubRepositoryAutolink.ps1 new file mode 100644 index 000000000..5cc457d67 --- /dev/null +++ b/src/GitHub/public/Repositories/Autolinks/Get-GitHubRepositoryAutolink.ps1 @@ -0,0 +1,41 @@ +filter Get-GitHubRepositoryAutolink { + <# + .SYNOPSIS + List all autolinks of a repository + + .DESCRIPTION + This returns a list of autolinks configured for the given repository. + + Information about autolinks are only available to repository administrators. + + .EXAMPLE + Get-GitHubRepositoryAutolink -Owner 'octocat' -Repo 'Hello-World' + + Gets all autolinks for the repository 'Hello-World' owned by 'octocat'. + + .NOTES + https://docs.github.com/rest/repos/autolinks#list-all-autolinks-of-a-repository + + #> + [Alias('Get-GitHubRepositoryAutolinks')] + [CmdletBinding()] + param ( + # The account owner of the repository. The name is not case sensitive. + [Parameter()] + [Alias('org')] + [string] $Owner = (Get-GitHubConfig -Name Owner), + + # The name of the repository without the .git extension. The name is not case sensitive. + [Parameter()] + [string] $Repo = (Get-GitHubConfig -Name Repo) + ) + + $inputObject = @{ + APIEndpoint = "/repos/$Owner/$Repo/autolinks" + Method = 'GET' + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } +} diff --git a/src/GitHub/public/Repositories/Autolinks/New-GitHubRepositoryAutolink.ps1 b/src/GitHub/public/Repositories/Autolinks/New-GitHubRepositoryAutolink.ps1 new file mode 100644 index 000000000..fe5ca1c59 --- /dev/null +++ b/src/GitHub/public/Repositories/Autolinks/New-GitHubRepositoryAutolink.ps1 @@ -0,0 +1,76 @@ +filter New-GitHubRepositoryAutolink { + <# + .SYNOPSIS + Create an autolink reference for a repository + + .DESCRIPTION + Users with admin access to the repository can create an autolink. + + .EXAMPLE + New-GitHubRepositoryAutolink -Owner 'octocat' -Repo 'Hello-World' -KeyPrefix 'GH-' -UrlTemplate 'https://www.example.com/issue/' + + Creates an autolink for the repository 'Hello-World' owned by 'octocat' that links to https://www.example.com/issue/ + when the prefix GH- is found in an issue, pull request, or commit. + + .NOTES + https://docs.github.com/rest/repos/autolinks#create-an-autolink-reference-for-a-repository + + #> + [OutputType([pscustomobject])] + [CmdletBinding(SupportsShouldProcess)] + param ( + # The account owner of the repository. The name is not case sensitive. + [Parameter(Mandatory)] + [string] $Owner, + + # The name of the repository without the .git extension. The name is not case sensitive. + [Parameter(Mandatory)] + [string] $Repo, + + # This prefix appended by certain characters will generate a link any time it is found in an issue, pull request, or commit. + [Parameter(Mandatory)] + [Alias('key_prefix')] + [string] $KeyPrefix, + + # The URL must contain for the reference number. matches different characters depending on the value of is_alphanumeric. + [Parameter(Mandatory)] + [Alias('url_template')] + [string] $UrlTemplate, + + # Whether this autolink reference matches alphanumeric characters. If true, the parameter of the url_template matches alphanumeric + # characters A-Z (case insensitive), 0-9, and -. If false, this autolink reference only matches numeric characters. + [Parameter()] + [Alias('is_alphanumeric')] + [bool] $IsAlphanumeric = $true + ) + + $PSCmdlet.MyInvocation.MyCommand.Parameters.GetEnumerator() | ForEach-Object { + $paramName = $_.Key + $paramDefaultValue = Get-Variable -Name $paramName -ValueOnly -ErrorAction SilentlyContinue + $providedValue = $PSBoundParameters[$paramName] + Write-Verbose "[$paramName]" + Write-Verbose " - Default: [$paramDefaultValue]" + Write-Verbose " - Provided: [$providedValue]" + if (-not $PSBoundParameters.ContainsKey($paramName) -and ($null -ne $paramDefaultValue)) { + Write-Verbose ' - Using default value' + $PSBoundParameters[$paramName] = $paramDefaultValue + } else { + Write-Verbose ' - Using provided value' + } + } + + $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case + Remove-HashtableEntry -Hashtable $body -RemoveNames 'Owner', 'Repo' -RemoveTypes 'SwitchParameter' + + $inputObject = @{ + APIEndpoint = "/repos/$Owner/$Repo/autolinks" + Method = 'POST' + Body = $body + } + + if ($PSCmdlet.ShouldProcess("Autolink for repository [$Owner/$Repo]", 'Create')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } +} diff --git a/src/GitHub/public/Repositories/Autolinks/Remove-GitHubRepositoryAutolink.ps1 b/src/GitHub/public/Repositories/Autolinks/Remove-GitHubRepositoryAutolink.ps1 new file mode 100644 index 000000000..5e430ca40 --- /dev/null +++ b/src/GitHub/public/Repositories/Autolinks/Remove-GitHubRepositoryAutolink.ps1 @@ -0,0 +1,49 @@ +filter Remove-GitHubRepositoryAutolink { + <# + .SYNOPSIS + Delete an autolink reference from a repository + + .DESCRIPTION + This deletes a single autolink reference by ID that was configured for the given repository. + + Information about autolinks are only available to repository administrators. + + .EXAMPLE + Remove-GitHubRepositoryAutolink -Owner 'octocat' -Repo 'Hello-World' -AutolinkId 1 + + Deletes the autolink with ID 1 for the repository 'Hello-World' owned by 'octocat'. + + .NOTES + https://docs.github.com/rest/repos/autolinks#delete-an-autolink-reference-from-a-repository + + #> + [OutputType([pscustomobject])] + [CmdletBinding(SupportsShouldProcess)] + param ( + # The account owner of the repository. The name is not case sensitive. + [Parameter(Mandatory)] + [string] $Owner, + + # The name of the repository without the .git extension. The name is not case sensitive. + [Parameter(Mandatory)] + [string] $Repo, + + # The unique identifier of the autolink. + [Parameter(Mandatory)] + [Alias('autolink_id')] + [Alias('Id')] + [int] $AutolinkId + ) + + $inputObject = @{ + APIEndpoint = "/repos/$Owner/$Repo/autolinks/$AutolinkId" + Method = 'DELETE' + Body = $body + } + + if ($PSCmdlet.ShouldProcess("Autolink with ID [$AutolinkId] for repository [$Owner/$Repo]", 'Delete')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } +} diff --git a/tools/utilities/GitHubAPI.ps1 b/tools/utilities/GitHubAPI.ps1 index 0b7f16d5d..6c0789651 100644 --- a/tools/utilities/GitHubAPI.ps1 +++ b/tools/utilities/GitHubAPI.ps1 @@ -21,8 +21,8 @@ $response = Invoke-RestMethod -Uri $APIDocURI -Method Get # @{n = 'PUT'; e = { (($_.value.psobject.Properties.Name) -contains 'PUT') } }, ` # @{n = 'PATCH'; e = { (($_.value.psobject.Properties.Name) -contains 'PATCH') } } | Format-Table -$path = '/repos/{owner}/{repo}/forks' -$method = 'get' +$path = '/repos/{owner}/{repo}/autolinks/{autolink_id}' +$method = 'delete' $response.paths.$path.$method $response.paths.$path.$method.tags | clip # -> Namespace/foldername $response.paths.$path.$method.operationId | clip # -> FunctionName From 175c0a4429f37ff71839b802abc5521525e757ed Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 7 Nov 2023 00:10:41 +0100 Subject: [PATCH 190/193] Add a wrapper for Get-GitHubRepositoryAutolink --- .../Get-GitHubRepositoryAutolinkById.ps1 | 46 +++++++++++++++++++ .../Get-GitHubRepositoryAutolinkList.ps1 | 40 ++++++++++++++++ .../Get-GitHubRepositoryAutolink.ps1 | 25 ++++++---- tools/utilities/GitHubAPI.ps1 | 2 +- 4 files changed, 104 insertions(+), 9 deletions(-) create mode 100644 src/GitHub/private/Repositories/Autolinks/Get-GitHubRepositoryAutolinkById.ps1 create mode 100644 src/GitHub/private/Repositories/Autolinks/Get-GitHubRepositoryAutolinkList.ps1 diff --git a/src/GitHub/private/Repositories/Autolinks/Get-GitHubRepositoryAutolinkById.ps1 b/src/GitHub/private/Repositories/Autolinks/Get-GitHubRepositoryAutolinkById.ps1 new file mode 100644 index 000000000..770cc1fc8 --- /dev/null +++ b/src/GitHub/private/Repositories/Autolinks/Get-GitHubRepositoryAutolinkById.ps1 @@ -0,0 +1,46 @@ +filter Get-GitHubRepositoryAutolinkById { + <# + .SYNOPSIS + Get an autolink reference of a repository + + .DESCRIPTION + This returns a single autolink reference by ID that was configured for the given repository. + + Information about autolinks are only available to repository administrators. + + .EXAMPLE + Get-GitHubRepositoryAutolinkById -Owner 'octocat' -Repo 'Hello-World' -Id 1 + + Gets the autolink with the id 1 for the repository 'Hello-World' owned by 'octocat'. + + .NOTES + https://docs.github.com/rest/repos/autolinks#get-an-autolink-reference-of-a-repository + + #> + [CmdletBinding()] + param ( + # The account owner of the repository. The name is not case sensitive. + [Parameter()] + [Alias('org')] + [string] $Owner = (Get-GitHubConfig -Name Owner), + + # The name of the repository without the .git extension. The name is not case sensitive. + [Parameter()] + [string] $Repo = (Get-GitHubConfig -Name Repo), + + # The unique identifier of the autolink. + [Parameter(Mandatory)] + [Alias('autolink_id')] + [Alias('Id')] + [int] $AutolinkId + ) + + $inputObject = @{ + APIEndpoint = "/repos/$Owner/$Repo/autolinks/$AutolinkId" + Method = 'GET' + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } +} diff --git a/src/GitHub/private/Repositories/Autolinks/Get-GitHubRepositoryAutolinkList.ps1 b/src/GitHub/private/Repositories/Autolinks/Get-GitHubRepositoryAutolinkList.ps1 new file mode 100644 index 000000000..c3a49359e --- /dev/null +++ b/src/GitHub/private/Repositories/Autolinks/Get-GitHubRepositoryAutolinkList.ps1 @@ -0,0 +1,40 @@ +filter Get-GitHubRepositoryAutolinkList { + <# + .SYNOPSIS + List all autolinks of a repository + + .DESCRIPTION + This returns a list of autolinks configured for the given repository. + + Information about autolinks are only available to repository administrators. + + .EXAMPLE + Get-GitHubRepositoryAutolinkList -Owner 'octocat' -Repo 'Hello-World' + + Gets all autolinks for the repository 'Hello-World' owned by 'octocat'. + + .NOTES + https://docs.github.com/rest/repos/autolinks#list-all-autolinks-of-a-repository + + #> + [CmdletBinding()] + param ( + # The account owner of the repository. The name is not case sensitive. + [Parameter()] + [Alias('org')] + [string] $Owner = (Get-GitHubConfig -Name Owner), + + # The name of the repository without the .git extension. The name is not case sensitive. + [Parameter()] + [string] $Repo = (Get-GitHubConfig -Name Repo) + ) + + $inputObject = @{ + APIEndpoint = "/repos/$Owner/$Repo/autolinks" + Method = 'GET' + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } +} diff --git a/src/GitHub/public/Repositories/Autolinks/Get-GitHubRepositoryAutolink.ps1 b/src/GitHub/public/Repositories/Autolinks/Get-GitHubRepositoryAutolink.ps1 index 5cc457d67..08a77cbde 100644 --- a/src/GitHub/public/Repositories/Autolinks/Get-GitHubRepositoryAutolink.ps1 +++ b/src/GitHub/public/Repositories/Autolinks/Get-GitHubRepositoryAutolink.ps1 @@ -27,15 +27,24 @@ # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo) + [string] $Repo = (Get-GitHubConfig -Name Repo), + + # The unique identifier of the autolink. + [Parameter( + Mandatory, + ParameterSetName = 'ById' + )] + [Alias('autolink_id')] + [Alias('Id')] + [int] $AutolinkId ) - $inputObject = @{ - APIEndpoint = "/repos/$Owner/$Repo/autolinks" - Method = 'GET' - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + switch ($PSCmdlet.ParameterSetName) { + 'ById' { + Get-GitHubRepositoryAutolinkById -Owner $Owner -Repo $Repo -Id $AutolinkId + } + default { + Get-GitHubRepositoryAutolinkList -Owner $Owner -Repo $Repo + } } } diff --git a/tools/utilities/GitHubAPI.ps1 b/tools/utilities/GitHubAPI.ps1 index 6c0789651..a71989a12 100644 --- a/tools/utilities/GitHubAPI.ps1 +++ b/tools/utilities/GitHubAPI.ps1 @@ -22,7 +22,7 @@ $response = Invoke-RestMethod -Uri $APIDocURI -Method Get # @{n = 'PATCH'; e = { (($_.value.psobject.Properties.Name) -contains 'PATCH') } } | Format-Table $path = '/repos/{owner}/{repo}/autolinks/{autolink_id}' -$method = 'delete' +$method = 'get' $response.paths.$path.$method $response.paths.$path.$method.tags | clip # -> Namespace/foldername $response.paths.$path.$method.operationId | clip # -> FunctionName From c164043234ac42245f43d37a5665f629646bebff Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 7 Nov 2023 00:22:16 +0100 Subject: [PATCH 191/193] Update param set --- .../Repositories/Autolinks/Get-GitHubRepositoryAutolink.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GitHub/public/Repositories/Autolinks/Get-GitHubRepositoryAutolink.ps1 b/src/GitHub/public/Repositories/Autolinks/Get-GitHubRepositoryAutolink.ps1 index 08a77cbde..dca2ccfbc 100644 --- a/src/GitHub/public/Repositories/Autolinks/Get-GitHubRepositoryAutolink.ps1 +++ b/src/GitHub/public/Repositories/Autolinks/Get-GitHubRepositoryAutolink.ps1 @@ -18,7 +18,7 @@ #> [Alias('Get-GitHubRepositoryAutolinks')] - [CmdletBinding()] + [CmdletBinding(DefaultParameterSetName = 'Default')] param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] From 0fc6581562af669dfd70badc4aebef5197da955f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 7 Nov 2023 00:29:21 +0100 Subject: [PATCH 192/193] Added an example for get-autolink --- .../Repositories/Autolinks/Get-GitHubRepositoryAutolink.ps1 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/GitHub/public/Repositories/Autolinks/Get-GitHubRepositoryAutolink.ps1 b/src/GitHub/public/Repositories/Autolinks/Get-GitHubRepositoryAutolink.ps1 index dca2ccfbc..18d936b7b 100644 --- a/src/GitHub/public/Repositories/Autolinks/Get-GitHubRepositoryAutolink.ps1 +++ b/src/GitHub/public/Repositories/Autolinks/Get-GitHubRepositoryAutolink.ps1 @@ -13,6 +13,11 @@ Gets all autolinks for the repository 'Hello-World' owned by 'octocat'. + .EXAMPLE + Get-GitHubRepositoryAutolink -Owner 'octocat' -Repo 'Hello-World' -Id 1 + + Gets the autolink with the id 1 for the repository 'Hello-World' owned by 'octocat'. + .NOTES https://docs.github.com/rest/repos/autolinks#list-all-autolinks-of-a-repository From 7937a652594ca89e31c4e4d4d00dae60edae12ca Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 7 Nov 2023 20:33:47 +0100 Subject: [PATCH 193/193] Adds function for get repo custom props --- .../Get-GitHubRepositoryCustomProperty.ps1 | 41 +++++++++++++++++++ tools/utilities/GitHubAPI.ps1 | 2 +- 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/GitHub/public/Repositories/CustomProperties/Get-GitHubRepositoryCustomProperty.ps1 diff --git a/src/GitHub/public/Repositories/CustomProperties/Get-GitHubRepositoryCustomProperty.ps1 b/src/GitHub/public/Repositories/CustomProperties/Get-GitHubRepositoryCustomProperty.ps1 new file mode 100644 index 000000000..0c53ad085 --- /dev/null +++ b/src/GitHub/public/Repositories/CustomProperties/Get-GitHubRepositoryCustomProperty.ps1 @@ -0,0 +1,41 @@ +filter Get-GitHubRepositoryCustomProperty { + <# + .SYNOPSIS + Get all custom property values for a repository + + .DESCRIPTION + Gets all custom property values that are set for a repository. + Users with read access to the repository can use this endpoint. + + .EXAMPLE + Get-GitHubRepositoryCustomProperty -Owner 'octocat' -Repo 'hello-world' + + Gets all custom property values that are set for the 'hello-world' repository. + + .NOTES + https://docs.github.com/rest/repos/custom-properties#get-all-custom-property-values-for-a-repository + + #> + [OutputType([pscustomobject])] + [Alias('Get-GitHubRepositoryCustomProperties')] + [CmdletBinding()] + param ( + # The account owner of the repository. The name is not case sensitive. + [Parameter()] + [Alias('org')] + [string] $Owner = (Get-GitHubConfig -Name Owner), + + # The name of the repository without the .git extension. The name is not case sensitive. + [Parameter()] + [string] $Repo = (Get-GitHubConfig -Name Repo) + ) + + $inputObject = @{ + APIEndpoint = "/repos/$Owner/$Repo/properties/values" + Method = 'GET' + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } +} diff --git a/tools/utilities/GitHubAPI.ps1 b/tools/utilities/GitHubAPI.ps1 index a71989a12..559c09427 100644 --- a/tools/utilities/GitHubAPI.ps1 +++ b/tools/utilities/GitHubAPI.ps1 @@ -21,7 +21,7 @@ $response = Invoke-RestMethod -Uri $APIDocURI -Method Get # @{n = 'PUT'; e = { (($_.value.psobject.Properties.Name) -contains 'PUT') } }, ` # @{n = 'PATCH'; e = { (($_.value.psobject.Properties.Name) -contains 'PATCH') } } | Format-Table -$path = '/repos/{owner}/{repo}/autolinks/{autolink_id}' +$path = '/repos/{owner}/{repo}/properties/values' $method = 'get' $response.paths.$path.$method $response.paths.$path.$method.tags | clip # -> Namespace/foldername