From da7a9269afadb02ff52057068a27bc11f182ce2e Mon Sep 17 00:00:00 2001 From: Paul Matthews <6736509+pmatthews05@users.noreply.github.com> Date: Sun, 16 Mar 2025 07:42:16 +0000 Subject: [PATCH 01/85] Environments and Variables (#320) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description This includes new commands: - Get-GitHubVariable.ps1 - Set-GitHubVariable.ps1 - Remove-GitHubVariable.ps1 - Get-GitHubEnvironment.ps1 - Set-GitHubEnvironment.ps1 - Remove-GitHubEnvironment.ps1 ## Type of change - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [ ] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [x] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas --------- Co-authored-by: Marius Storhaug --- .../Environments/Get-GitHubEnvironment.ps1 | 91 ++++++++++ .../Environments/Remove-GitHubEnvironment.ps1 | 72 ++++++++ .../Environments/Set-GitHubEnvironment.ps1 | 96 ++++++++++ .../public/Variables/Get-GitHubVariable.ps1 | 105 +++++++++++ .../Variables/Remove-GitHubVariable.ps1 | 105 +++++++++++ .../public/Variables/Set-GitHubVariable.ps1 | 166 ++++++++++++++++++ 6 files changed, 635 insertions(+) create mode 100644 src/functions/public/Environments/Get-GitHubEnvironment.ps1 create mode 100644 src/functions/public/Environments/Remove-GitHubEnvironment.ps1 create mode 100644 src/functions/public/Environments/Set-GitHubEnvironment.ps1 create mode 100644 src/functions/public/Variables/Get-GitHubVariable.ps1 create mode 100644 src/functions/public/Variables/Remove-GitHubVariable.ps1 create mode 100644 src/functions/public/Variables/Set-GitHubVariable.ps1 diff --git a/src/functions/public/Environments/Get-GitHubEnvironment.ps1 b/src/functions/public/Environments/Get-GitHubEnvironment.ps1 new file mode 100644 index 000000000..027083c48 --- /dev/null +++ b/src/functions/public/Environments/Get-GitHubEnvironment.ps1 @@ -0,0 +1,91 @@ +filter Get-GitHubEnvironment { + <# + .SYNOPSIS + List environments for a repository + + .DESCRIPTION + List environments for a repository + Get an environment for a repository + + .EXAMPLE + Get-GitHubEnvironment -Owner 'PSModule' -Repository 'Github' + + Lists all environments for the 'PSModule/GitHub' repository. + + .EXAMPLE + Get-GitHubEnvironment -Owner 'PSModule' -Repository 'Github' -Name 'Production' + + Get the 'Production' environment for the 'PSModule/GitHub' repository. + + .NOTES + [List environments](https://docs.github.com/en/rest/deployments/environments#list-environments) + #> + [OutputType([pscustomobject])] + [CmdletBinding()] + param( + # The name of the organization. + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName + )] + [Alias('Organization', 'User')] + [string] $Owner, + + # The name of the Repository. + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName + )] + [string] $Repository, + + # The name of the environment. + [Parameter( + Mandatory, + ParameterSetName = 'NamedEnv', + ValueFromPipelineByPropertyName + )] + [string] $Name, + + [Parameter()] + [ValidateRange(0, 100)] + [int] $PerPage, + + # The context to run the command in. Used to get the details for the API call. + # Can be either a string or a GitHubContext object. + [Parameter()] + [object] $Context = (Get-GitHubContext) + ) + + begin { + $stackPath = Get-PSCallStackPath + Write-Debug "[$stackPath] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + } + + process { + $body = @{ + per_page = $PerPage + } + + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/repos/$Owner/$Repository/environments" + Body = $body + Context = $Context + } + + if ($PSCmdlet.ParameterSetName -eq 'NamedEnv') { + $inputObject.APIEndpoint = "/repos/$Owner/$Repository/environments/$Name" + $inputObject.Remove('Body') + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } + + end { + Write-Debug "[$stackPath] - End" + } +} \ No newline at end of file diff --git a/src/functions/public/Environments/Remove-GitHubEnvironment.ps1 b/src/functions/public/Environments/Remove-GitHubEnvironment.ps1 new file mode 100644 index 000000000..1864e01ba --- /dev/null +++ b/src/functions/public/Environments/Remove-GitHubEnvironment.ps1 @@ -0,0 +1,72 @@ +filter Remove-GitHubEnvironment { + <# + .SYNOPSIS + Deletes an environment from a repository + + .DESCRIPTION + Deletes an environment from a repository + + .EXAMPLE + Remove-GitHubEnvironment -Owner 'PSModule' -Repository 'GitHub' -Name 'Production' + + Deletes the 'Production' environment from the 'PSModule/GitHub' repository. + + .NOTES + [Delete environments](https://docs.github.com/en/rest/deployments/environments?#delete-an-environment) + #> + [OutputType([pscustomobject])] + [CmdletBinding(SupportsShouldProcess)] + param( + # The name of the organization. + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName + )] + [Alias('Organization', 'User')] + [string] $Owner, + + # The name of the Repository. + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName + )] + [string] $Repository, + + # The name of the environment. + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName + )] + [string] $Name, + + # The context to run the command in. Used to get the details for the API call. + # Can be either a string or a GitHubContext object. + [Parameter()] + [object] $Context = (Get-GitHubContext) + ) + + begin { + $stackPath = Get-PSCallStackPath + Write-Debug "[$stackPath] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + } + + process { + $inputObject = @{ + Method = 'DELETE' + APIEndpoint = "/repos/$Owner/$Repository/environments/$Name" + Context = $Context + } + + if ($PSCmdlet.ShouldProcess("Environment [$Name]", 'DELETE')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } + } + + end { + Write-Debug "[$stackPath] - End" + } +} \ No newline at end of file diff --git a/src/functions/public/Environments/Set-GitHubEnvironment.ps1 b/src/functions/public/Environments/Set-GitHubEnvironment.ps1 new file mode 100644 index 000000000..0f90b099f --- /dev/null +++ b/src/functions/public/Environments/Set-GitHubEnvironment.ps1 @@ -0,0 +1,96 @@ +filter Set-GitHubEnvironment { + <# + .SYNOPSIS + Create or update an environment for a repository + + .DESCRIPTION + Create or update an environment for a repository + + + #> + [OutputType([pscustomobject])] + [CmdletBinding(SupportsShouldProcess)] + param( + # The name of the organization. + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName + )] + [Alias('Organization', 'User')] + [string] $Owner, + + # The name of the Repository. + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName + )] + [string] $Repository, + + # The name of the environment. + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName + )] + [string] $Name, + + # The amount of time to delay a job after the job is initially triggered. The time (in minutes). + [Parameter(ValueFromPipelineByPropertyName)] + [Alias('wait_timer')] + [ValidateRange(0, 43200)] + [int] $WaitTimer, + + # Whether or not a user who created the job is prevented from approving their own job. + [Parameter(ValueFromPipelineByPropertyName)] + [Alias('prevent_self_review')] + [switch] $PreventSelfReview, + + # The people or teams that may review jobs that reference the environment. You can list up to six users or teams as reviewers. + [Parameter(ValueFromPipelineByPropertyName)] + [Alias('reviewers')] + [array] $Reviewers, + + # The type of deployment branch policy for this environment. To allow all branches to deploy, set to null. + [parameter(ValueFromPipelineByPropertyName)] + [Alias('deployment_branch_policy')] + [object] $DeploymentBranchPolicy, + + # The context to run the command in. Used to get the details for the API call. + # Can be either a string or a GitHubContext object. + [Parameter()] + [object] $Context = (Get-GitHubContext) + ) + + begin { + $stackPath = Get-PSCallStackPath + Write-Debug "[$stackPath] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + } + + process { + $body = @{ + wait_timer = $PSBoundParameters.ContainsKey('WaitTimer') ? $WaitTimer : $null + prevent_self_review = $PSBoundParameters.ContainsKey('PreventSelfReview') ? $PreventSelfReview : $null + reviewers = $PSBoundParameters.ContainsKey('Reviewers') ? $Reviewers : $null + deployment_branch_policy = $PSBoundParameters.ContainsKey('DeploymentBranchPolicy') ? $DeploymentBranchPolicy : $null + } | Remove-HashtableEntry -NullOrEmptyValues + + $inputObject = @{ + Method = 'PUT' + APIEndpoint = "/repos/$Owner/$Repository/environments/$Name" + Body = $body + Context = $Context + } | Remove-HashtableEntry -NullOrEmptyValues + + + if ($PSCmdlet.ShouldProcess("Environment [$Name]", 'Set')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } + } + + end { + Write-Debug "[$stackPath] - End" + } +} \ No newline at end of file diff --git a/src/functions/public/Variables/Get-GitHubVariable.ps1 b/src/functions/public/Variables/Get-GitHubVariable.ps1 new file mode 100644 index 000000000..139f0d7d6 --- /dev/null +++ b/src/functions/public/Variables/Get-GitHubVariable.ps1 @@ -0,0 +1,105 @@ +function Get-GitHubVariable { + <# + .SYNOPSIS + Gets the GitHub variable details for a Organisation, Repository or Environment. + + .DESCRIPTION + Gets the GitHub variable details for a Organisation, Repository or Environment. + + .PARAMETER Owner + The account owner of the repository. The name is not case-sensitive. + + .PARAMETER Repository + The name of the repository. The name is not case-sensitive. + + .PARAMETER Environment + The name of the repository environment. + + .PARAMETER Name + The name of the variable. If left blank, all variable names are returned. + + .PARAMETER Context + The context to run the command in. Used to get the details for the API call. + + .EXAMPLE + Get-GitHubVariable -Owner "octocat" -Repository "Hello-World" -Environment "dev" + Get-GitHubVariable -Owner "octocat" -Repository "Hello-World" -Name "myVariable" + Get-GitHubVariable -Owner "octocat" -Name "myVariable" + + .NOTES + [Gets an Organisation Variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#get-an-organization-variable) + [Gets an Repository Variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#get-a-repository-variable) + [Gets an Environment Variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#get-an-environment-variable) + + .OUTPUTS + psobject[] + + #> + [OutputType([psobject[]])] + [CmdletBinding()] + param( + [Parameter(ParameterSetName = 'Environment', Mandatory)] + [Parameter(ParameterSetName = 'Organization', Mandatory)] + [Parameter(ParameterSetName = 'Repository', Mandatory)] + [Alias('Organization', 'User')] + [string] $Owner, + + # The name of the repository. The name is not case sensitive. + [Parameter(ParameterSetName = 'Environment', Mandatory)] + [Parameter(ParameterSetName = 'Repository', Mandatory)] + [string] $Repository, + + # The name of the repository environment. + [Parameter(ParameterSetName = 'Environment', Mandatory)] + [string] $Environment, + + # The name of the variable. + [Parameter()] + [string] $Name, + + # The context to run the command in. Used to get the details for the API call. + # Can be either a string or a GitHubContext object. + [Parameter()] + [object] $Context = (Get-GitHubContext) + ) + + begin { + $stackPath = Get-PSCallStackPath + Write-Debug "[$stackPath] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + } + + process { + $inputObject = @{ + Method = "Get" + APIEndpoint = switch ($PSCmdlet.ParameterSetName) { + 'Environment' { + "/repos/$Owner/$Repository/environments/$Environment/variables" + break + } + 'Repository' { + "/repos/$Owner/$Repository/actions/variables" + break + } + 'Organization' { + "/orgs/$Owner/actions/variables" + break + } + } + Context = $Context + } + + if(-not [string]::IsNullOrWhiteSpace($Name)) { + $inputObject.APIEndpoint += "/$Name" + } + + Invoke-GitHubAPI @inputObject | Foreach-Object { + Write-Output $_.Response + } + } + + end { + Write-Debug "[$stackPath] - End" + } +} \ No newline at end of file diff --git a/src/functions/public/Variables/Remove-GitHubVariable.ps1 b/src/functions/public/Variables/Remove-GitHubVariable.ps1 new file mode 100644 index 000000000..31574107d --- /dev/null +++ b/src/functions/public/Variables/Remove-GitHubVariable.ps1 @@ -0,0 +1,105 @@ +function Remove-GitHubVariable { + <# + .SYNOPSIS + Removes a GitHub variable from an Organisation, Repository or Environment. + + .DESCRIPTION + Removes a GitHub variable from an Organisation, Repository or Environment. + + .PARAMETER Owner + The account owner of the repository. The name is not case-sensitive. + + .PARAMETER Repository + The name of the repository. The name is not case-sensitive. + + .PARAMETER Environment + The name of the repository environment. + + .PARAMETER Name + The name of the variable. + + .PARAMETER Context + The context to run the command in. Used to get the details for the API call. + + .EXAMPLE + Remove-GitHubVariable -Owner "octocat" -Repository "Hello-World" -Environment "dev" -Name "myVariable" + Remove-GitHubVariable -Owner "octocat" -Repository "Hello-World" -Name "myVariable" + Remove-GitHubVariable -Owner "octocat" -Name "myVariable" + + .NOTES + [Delete an Organisation Variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#delete-an-organization-variable) + [Delete a Repository Variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#delete-a-repository-variable) + [Delete an Environment Variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#delete-an-environment-variable) + + .OUTPUTS + psobject[] + #> + [OutputType([psobject[]])] + [CmdletBinding(SupportsShouldProcess)] + param( + [Parameter(ParameterSetName = 'Organization', Mandatory)] + [Parameter(ParameterSetName = 'Repository', Mandatory)] + [Parameter(ParameterSetName = 'Environment', Mandatory)] + [Alias('Organization', 'User')] + [string] $Owner, + + # The name of the repository. The name is not case sensitive. + [Parameter(ParameterSetName = 'Repository', Mandatory)] + [Parameter(ParameterSetName = 'Environment', Mandatory)] + [string] $Repository, + + # The name of the repository environment. + [Parameter(ParameterSetName = 'Environment', Mandatory)] + [string] $Environment, + + # The name of the variable. + + [Parameter(ParameterSetName = 'Organization', Mandatory)] + [Parameter(ParameterSetName = 'Repository', Mandatory)] + [Parameter(ParameterSetName = 'Environment', Mandatory)] + [string] $Name, + + # The context to run the command in. Used to get the details for the API call. + # Can be either a string or a GitHubContext object. + [Parameter()] + [object] $Context = (Get-GitHubContext) + ) + + begin { + $stackPath = Get-PSCallStackPath + Write-Debug "[$stackPath] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + } + + process { + $inputObject = @{ + Method = "DELETE" + APIEndpoint = switch ($PSCmdlet.ParameterSetName) { + 'Environment' { + "/repos/$Owner/$Repository/environments/$Environment/variables/$Name" + break + } + 'Repository' { + "/repos/$Owner/$Repository/actions/variables/$Name" + break + } + 'Organization' { + "/orgs/$Owner/actions/variables/$Name" + break + } + } + Context = $Context + } + + if ($PSCmdlet.ShouldProcess("Variable [$Name]", 'DELETE')) { + Invoke-GitHubAPI @inputObject | ForeEach-Object { + Write-Output $_.Response + } + } + } + + end { + write-Debug "[$stackPath] - End" + } +} \ No newline at end of file diff --git a/src/functions/public/Variables/Set-GitHubVariable.ps1 b/src/functions/public/Variables/Set-GitHubVariable.ps1 new file mode 100644 index 000000000..4c1fb01cb --- /dev/null +++ b/src/functions/public/Variables/Set-GitHubVariable.ps1 @@ -0,0 +1,166 @@ +function Set-GitHubVariable { + <# + .SYNOPSIS + Creates/Updates a GitHub variable for a Organisation, Repository or Environment. + + .DESCRIPTION + Creates/Updates a GitHub variable for a Organisation, Repository or Environment. + + .PARAMETER Owner + The account owner of the repository. The name is not case-sensitive. + + .PARAMETER Repository + The name of the repository. The name is not case-sensitive. + + .PARAMETER Environment + The name of the repository environment. + + .PARAMETER Name + The name of the variable. + + .PARAMETER Value + The value of the variable. + + .PARAMETER Private + Set visibility to private (only applicable at the organization level). + + .PARAMETER SelectedRepositoryIds + List of numeric repository IDs where the variable should be visible (only applicable at the organization level). + + .PARAMETER Context + The context to run the command in. Used to get the details for the API call. + + .EXAMPLE + Sets a variable in an environment. + Set-GitHubVariable -Owner "octocat" -Repository "Hello-World" -Environment "dev" -Name "myVariable" -Value "myValue" + + .EXAMPLE + Sets a variable in a repository. + Set-GitHubVariable -Owner "octocat" -Repository "Hello-World" -Name "myVariable" -Value "myValue" + + .EXAMPLE + Sets a variable in an organisation. + Set-GitHubVariable -Owner "octocat" -Name "myVariable" -Value "myValue" + + .EXAMPLE + Sets a variable in an organisation with visibility set to private. + Set-GitHubVariable -Owner "octocat" -Name "myVariable" -Value "myValue" -Private + + .EXAMPLE + Sets a variable in an organisation with visibility set to selected repositories. + Set-GitHubVariable -Owner "octocat" -Name "myVariable" -Value "myValue" -SelectedRepositoryIds 123456, 654362 + + .NOTES + [Create an organization variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#create-an-organization-variable) + [Create a repository variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#create-a-repository-variable) + [Create an environment variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#create-an-environment-variable) + [Update an organization variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#update-an-organization-variable) + [Update a repository variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#update-a-repository-variable) + [Update an environment variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#update-an-environment-variable) + + .OUTPUTS + psobject[] + + #> + [OutputType([psobject[]])] + [CmdletBinding(SupportsShouldProcess)] + param( + [Parameter(ParameterSetName = 'Environment', Mandatory)] + [Parameter(ParameterSetName = 'Organization', Mandatory)] + [Parameter(ParameterSetName = 'Repository', Mandatory)] + [Alias('Organization', 'User')] + [string] $Owner, + + # The name of the repository. The name is not case sensitive. + [Parameter(ParameterSetName = 'Environment', Mandatory)] + [Parameter(ParameterSetName = 'Repository', Mandatory)] + [string] $Repository, + + # The name of the repository environment. + [Parameter(ParameterSetName = 'Environment', Mandatory)] + [string] $Environment, + + # The name of the variable. + [Parameter(Mandatory)] + [string] $Name, + + [Parameter(Mandatory)] + [string] $Value, + + [Parameter(ParameterSetName = 'Organization')] + [switch] $Private, + + [Parameter(ParameterSetName = 'Organization')] + [int[]] $SelectedRepositoryIDs, + + # The context to run the command in. Used to get the details for the API call. + # Can be either a string or a GitHubContext object. + [Parameter()] + [object] $Context = (Get-GitHubContext) + ) + + begin { + $stackPath = Get-PSCallStackPath + Write-Debug "[$stackPath] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + } + + process { + $getParams = $PSBoundParameters + $getParams | Remove-HashtableEntry -NullOrEmptyValues -RemoveNames 'Value','Private','SelectedRepositoryIDs','Context' + $variableFound = Get-GitHubVariable @getParams -Name $Name + + $body = @{ + name = $Name + value = $Value + } + + if ($PSCmdlet.ParameterSetName -eq 'Organization') { + if ($PSBoundParameters.ContainsKey('SelectedRepositoryIDs')) { + $body['selected_repository_ids'] = @($SelectedRepositoryIDs) + $body['visibility'] = 'selected' + } + elseif($Private) { + $body['visibility'] = 'private' + } + else{ + $body['visibility'] = 'all' + } + } + + $inputObject = @{ + Method = "Post" + APIEndpoint = switch ($PSCmdlet.ParameterSetName) { + 'Environment' { + "/repos/$Owner/$Repository/environments/$Environment/variables" + break + } + 'Repository' { + "/repos/$Owner/$Repository/actions/variables" + break + } + 'Organization' { + "/orgs/$Owner/actions/variables" + break + } + } + Body = $body + Context = $Context + } + + if ($variableFound) { + $inputObject.Method = "PATCH" + $inputObject.APIEndpoint = $inputObject.APIEndpoint + "/$Name" + } + + if($PSCmdlet.ShouldProcess("Variable [$Name]", 'CREATE/UPDATE')) { + $result = Invoke-GitHubAPI @inputObject + Write-Output $result.Response + } + } + + end { + Write-Debug "[$stackPath] - End" + } +} \ No newline at end of file From 796956e42a576fd6a92bbe5c7966ea80b5d26b5d Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions@users.noreply.github.com> Date: Sun, 16 Mar 2025 07:43:31 +0000 Subject: [PATCH 02/85] Auto-generated changes --- Coverage.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Coverage.md b/Coverage.md index 499d55703..18ec8a253 100644 --- a/Coverage.md +++ b/Coverage.md @@ -9,15 +9,15 @@ Covered functions - 160 + 164 Missing functions - 859 + 855 Coverage - 15.7% + 16.09% @@ -426,8 +426,8 @@ | `/repos/{owner}/{repo}/deployments/{deployment_id}/statuses` | | :x: | | :x: | | | `/repos/{owner}/{repo}/deployments/{deployment_id}/statuses/{status_id}` | | :x: | | | | | `/repos/{owner}/{repo}/dispatches` | | | | :white_check_mark: | | -| `/repos/{owner}/{repo}/environments` | | :x: | | | | -| `/repos/{owner}/{repo}/environments/{environment_name}` | :x: | :x: | | | :x: | +| `/repos/{owner}/{repo}/environments` | | :white_check_mark: | | | | +| `/repos/{owner}/{repo}/environments/{environment_name}` | :white_check_mark: | :white_check_mark: | | | :white_check_mark: | | `/repos/{owner}/{repo}/environments/{environment_name}/deployment-branch-policies` | | :x: | | :x: | | | `/repos/{owner}/{repo}/environments/{environment_name}/deployment-branch-policies/{branch_policy_id}` | :x: | :x: | | | :x: | | `/repos/{owner}/{repo}/environments/{environment_name}/deployment_protection_rules` | | :x: | | :x: | | From eb851e1e8c669d42e8c652495a47941778693895 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 17 Mar 2025 10:06:12 +0100 Subject: [PATCH 03/85] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Refactor=20vari?= =?UTF-8?q?able=20handling=20and=20improve=20code=20consistency=20in=20Git?= =?UTF-8?q?Hub=20variable=20functions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../public/Variables/Get-GitHubVariable.ps1 | 18 +-- .../Variables/Remove-GitHubVariable.ps1 | 12 +- .../public/Variables/Set-GitHubVariable.ps1 | 125 +++++++++--------- 3 files changed, 76 insertions(+), 79 deletions(-) diff --git a/src/functions/public/Variables/Get-GitHubVariable.ps1 b/src/functions/public/Variables/Get-GitHubVariable.ps1 index 139f0d7d6..66ddc663a 100644 --- a/src/functions/public/Variables/Get-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Get-GitHubVariable.ps1 @@ -16,7 +16,7 @@ function Get-GitHubVariable { The name of the repository environment. .PARAMETER Name - The name of the variable. If left blank, all variable names are returned. + The name of the variable. If left blank, all variable names are returned. .PARAMETER Context The context to run the command in. Used to get the details for the API call. @@ -72,29 +72,29 @@ function Get-GitHubVariable { process { $inputObject = @{ - Method = "Get" + Method = 'Get' APIEndpoint = switch ($PSCmdlet.ParameterSetName) { - 'Environment' { - "/repos/$Owner/$Repository/environments/$Environment/variables" + 'Environment' { + "/repos/$Owner/$Repository/environments/$Environment/variables" break } 'Repository' { "/repos/$Owner/$Repository/actions/variables" break - } + } 'Organization' { - "/orgs/$Owner/actions/variables" + "/orgs/$Owner/actions/variables" break } } Context = $Context } - if(-not [string]::IsNullOrWhiteSpace($Name)) { + if (-not [string]::IsNullOrWhiteSpace($Name)) { $inputObject.APIEndpoint += "/$Name" } - Invoke-GitHubAPI @inputObject | Foreach-Object { + Invoke-GitHubAPI @inputObject | ForEach-Object { Write-Output $_.Response } } @@ -102,4 +102,4 @@ function Get-GitHubVariable { end { Write-Debug "[$stackPath] - End" } -} \ No newline at end of file +} diff --git a/src/functions/public/Variables/Remove-GitHubVariable.ps1 b/src/functions/public/Variables/Remove-GitHubVariable.ps1 index 31574107d..f5b72b6a9 100644 --- a/src/functions/public/Variables/Remove-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Remove-GitHubVariable.ps1 @@ -53,7 +53,7 @@ function Remove-GitHubVariable { [string] $Environment, # The name of the variable. - + [Parameter(ParameterSetName = 'Organization', Mandatory)] [Parameter(ParameterSetName = 'Repository', Mandatory)] [Parameter(ParameterSetName = 'Environment', Mandatory)] @@ -74,7 +74,7 @@ function Remove-GitHubVariable { process { $inputObject = @{ - Method = "DELETE" + Method = 'DELETE' APIEndpoint = switch ($PSCmdlet.ParameterSetName) { 'Environment' { "/repos/$Owner/$Repository/environments/$Environment/variables/$Name" @@ -85,7 +85,7 @@ function Remove-GitHubVariable { break } 'Organization' { - "/orgs/$Owner/actions/variables/$Name" + "/orgs/$Owner/actions/variables/$Name" break } } @@ -95,11 +95,11 @@ function Remove-GitHubVariable { if ($PSCmdlet.ShouldProcess("Variable [$Name]", 'DELETE')) { Invoke-GitHubAPI @inputObject | ForeEach-Object { Write-Output $_.Response - } + } } } end { - write-Debug "[$stackPath] - End" + Write-Debug "[$stackPath] - End" } -} \ No newline at end of file +} diff --git a/src/functions/public/Variables/Set-GitHubVariable.ps1 b/src/functions/public/Variables/Set-GitHubVariable.ps1 index 4c1fb01cb..4ed662ed3 100644 --- a/src/functions/public/Variables/Set-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Set-GitHubVariable.ps1 @@ -1,66 +1,65 @@ function Set-GitHubVariable { <# - .SYNOPSIS - Creates/Updates a GitHub variable for a Organisation, Repository or Environment. + .SYNOPSIS + Creates/Updates a GitHub variable for a Organisation, Repository or Environment. - .DESCRIPTION - Creates/Updates a GitHub variable for a Organisation, Repository or Environment. + .DESCRIPTION + Creates/Updates a GitHub variable for a Organisation, Repository or Environment. - .PARAMETER Owner - The account owner of the repository. The name is not case-sensitive. + .PARAMETER Owner + The account owner of the repository. The name is not case-sensitive. - .PARAMETER Repository - The name of the repository. The name is not case-sensitive. + .PARAMETER Repository + The name of the repository. The name is not case-sensitive. - .PARAMETER Environment - The name of the repository environment. + .PARAMETER Environment + The name of the repository environment. - .PARAMETER Name - The name of the variable. + .PARAMETER Name + The name of the variable. - .PARAMETER Value - The value of the variable. + .PARAMETER Value + The value of the variable. - .PARAMETER Private - Set visibility to private (only applicable at the organization level). + .PARAMETER Private + Set visibility to private (only applicable at the organization level). - .PARAMETER SelectedRepositoryIds - List of numeric repository IDs where the variable should be visible (only applicable at the organization level). + .PARAMETER SelectedRepositoryIds + List of numeric repository IDs where the variable should be visible (only applicable at the organization level). - .PARAMETER Context - The context to run the command in. Used to get the details for the API call. + .PARAMETER Context + The context to run the command in. Used to get the details for the API call. - .EXAMPLE - Sets a variable in an environment. - Set-GitHubVariable -Owner "octocat" -Repository "Hello-World" -Environment "dev" -Name "myVariable" -Value "myValue" + .EXAMPLE + Sets a variable in an environment. + Set-GitHubVariable -Owner "octocat" -Repository "Hello-World" -Environment "dev" -Name "myVariable" -Value "myValue" - .EXAMPLE - Sets a variable in a repository. - Set-GitHubVariable -Owner "octocat" -Repository "Hello-World" -Name "myVariable" -Value "myValue" + .EXAMPLE + Sets a variable in a repository. + Set-GitHubVariable -Owner "octocat" -Repository "Hello-World" -Name "myVariable" -Value "myValue" - .EXAMPLE - Sets a variable in an organisation. - Set-GitHubVariable -Owner "octocat" -Name "myVariable" -Value "myValue" + .EXAMPLE + Sets a variable in an organisation. + Set-GitHubVariable -Owner "octocat" -Name "myVariable" -Value "myValue" - .EXAMPLE - Sets a variable in an organisation with visibility set to private. - Set-GitHubVariable -Owner "octocat" -Name "myVariable" -Value "myValue" -Private + .EXAMPLE + Sets a variable in an organisation with visibility set to private. + Set-GitHubVariable -Owner "octocat" -Name "myVariable" -Value "myValue" -Private - .EXAMPLE - Sets a variable in an organisation with visibility set to selected repositories. - Set-GitHubVariable -Owner "octocat" -Name "myVariable" -Value "myValue" -SelectedRepositoryIds 123456, 654362 + .EXAMPLE + Sets a variable in an organisation with visibility set to selected repositories. + Set-GitHubVariable -Owner "octocat" -Name "myVariable" -Value "myValue" -SelectedRepositoryIds 123456, 654362 - .NOTES - [Create an organization variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#create-an-organization-variable) - [Create a repository variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#create-a-repository-variable) - [Create an environment variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#create-an-environment-variable) - [Update an organization variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#update-an-organization-variable) - [Update a repository variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#update-a-repository-variable) - [Update an environment variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#update-an-environment-variable) - - .OUTPUTS - psobject[] + .NOTES + [Create an organization variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#create-an-organization-variable) + [Create a repository variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#create-a-repository-variable) + [Create an environment variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#create-an-environment-variable) + [Update an organization variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#update-an-organization-variable) + [Update a repository variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#update-a-repository-variable) + [Update an environment variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#update-an-environment-variable) + .OUTPUTS + psobject[] #> [OutputType([psobject[]])] [CmdletBinding(SupportsShouldProcess)] @@ -108,8 +107,8 @@ function Set-GitHubVariable { process { $getParams = $PSBoundParameters - $getParams | Remove-HashtableEntry -NullOrEmptyValues -RemoveNames 'Value','Private','SelectedRepositoryIDs','Context' - $variableFound = Get-GitHubVariable @getParams -Name $Name + $getParams | Remove-HashtableEntry -NullOrEmptyValues -RemoveNames 'Value', 'Private', 'SelectedRepositoryIDs', 'Context' + $variableFound = Get-GitHubVariable @getParams -Name $Name $body = @{ name = $Name @@ -120,47 +119,45 @@ function Set-GitHubVariable { if ($PSBoundParameters.ContainsKey('SelectedRepositoryIDs')) { $body['selected_repository_ids'] = @($SelectedRepositoryIDs) $body['visibility'] = 'selected' - } - elseif($Private) { + } elseif ($Private) { $body['visibility'] = 'private' - } - else{ + } else { $body['visibility'] = 'all' } } $inputObject = @{ - Method = "Post" + Method = 'Post' APIEndpoint = switch ($PSCmdlet.ParameterSetName) { - 'Environment' { - "/repos/$Owner/$Repository/environments/$Environment/variables" + 'Environment' { + "/repos/$Owner/$Repository/environments/$Environment/variables" break } - 'Repository' { - "/repos/$Owner/$Repository/actions/variables" + 'Repository' { + "/repos/$Owner/$Repository/actions/variables" break } - 'Organization' { + 'Organization' { "/orgs/$Owner/actions/variables" - break + break } } Body = $body Context = $Context } - if ($variableFound) { - $inputObject.Method = "PATCH" - $inputObject.APIEndpoint = $inputObject.APIEndpoint + "/$Name" + if ($variableFound) { + $inputObject.Method = 'PATCH' + $inputObject.APIEndpoint = $inputObject.APIEndpoint + "/$Name" } - if($PSCmdlet.ShouldProcess("Variable [$Name]", 'CREATE/UPDATE')) { + if ($PSCmdlet.ShouldProcess("Variable [$Name]", 'CREATE/UPDATE')) { $result = Invoke-GitHubAPI @inputObject Write-Output $result.Response - } + } } end { Write-Debug "[$stackPath] - End" } -} \ No newline at end of file +} From d52ac4fb964e80d41740d6ff75c7336a9b018bc7 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions@users.noreply.github.com> Date: Mon, 17 Mar 2025 09:07:44 +0000 Subject: [PATCH 04/85] Auto-generated changes --- Coverage.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Coverage.md b/Coverage.md index 18ec8a253..5910c644e 100644 --- a/Coverage.md +++ b/Coverage.md @@ -9,15 +9,15 @@ Covered functions - 164 + 173 Missing functions - 855 + 846 Coverage - 16.09% + 16.98% @@ -131,8 +131,8 @@ | `/orgs/{org}/actions/secrets/{secret_name}` | :x: | :x: | | | :x: | | `/orgs/{org}/actions/secrets/{secret_name}/repositories` | | :x: | | | :x: | | `/orgs/{org}/actions/secrets/{secret_name}/repositories/{repository_id}` | :x: | | | | :x: | -| `/orgs/{org}/actions/variables` | | :x: | | :x: | | -| `/orgs/{org}/actions/variables/{name}` | :x: | :x: | :x: | | | +| `/orgs/{org}/actions/variables` | | :white_check_mark: | | :white_check_mark: | | +| `/orgs/{org}/actions/variables/{name}` | :white_check_mark: | :x: | :x: | | | | `/orgs/{org}/actions/variables/{name}/repositories` | | :x: | | | :x: | | `/orgs/{org}/actions/variables/{name}/repositories/{repository_id}` | :x: | | | | :x: | | `/orgs/{org}/attestations/{subject_digest}` | | :x: | | | | @@ -329,8 +329,8 @@ | `/repos/{owner}/{repo}/actions/secrets` | | :x: | | | | | `/repos/{owner}/{repo}/actions/secrets/public-key` | | :x: | | | | | `/repos/{owner}/{repo}/actions/secrets/{secret_name}` | :x: | :x: | | | :x: | -| `/repos/{owner}/{repo}/actions/variables` | | :x: | | :x: | | -| `/repos/{owner}/{repo}/actions/variables/{name}` | :x: | :x: | :x: | | | +| `/repos/{owner}/{repo}/actions/variables` | | :white_check_mark: | | :white_check_mark: | | +| `/repos/{owner}/{repo}/actions/variables/{name}` | :white_check_mark: | :x: | :x: | | | | `/repos/{owner}/{repo}/actions/workflows` | | :white_check_mark: | | | | | `/repos/{owner}/{repo}/actions/workflows/{workflow_id}` | | :white_check_mark: | | | | | `/repos/{owner}/{repo}/actions/workflows/{workflow_id}/disable` | | | | | :white_check_mark: | @@ -436,8 +436,8 @@ | `/repos/{owner}/{repo}/environments/{environment_name}/secrets` | | :x: | | | | | `/repos/{owner}/{repo}/environments/{environment_name}/secrets/public-key` | | :x: | | | | | `/repos/{owner}/{repo}/environments/{environment_name}/secrets/{secret_name}` | :x: | :x: | | | :x: | -| `/repos/{owner}/{repo}/environments/{environment_name}/variables` | | :x: | | :x: | | -| `/repos/{owner}/{repo}/environments/{environment_name}/variables/{name}` | :x: | :x: | :x: | | | +| `/repos/{owner}/{repo}/environments/{environment_name}/variables` | | :white_check_mark: | | :white_check_mark: | | +| `/repos/{owner}/{repo}/environments/{environment_name}/variables/{name}` | :white_check_mark: | :x: | :x: | | | | `/repos/{owner}/{repo}/events` | | :x: | | | | | `/repos/{owner}/{repo}/forks` | | :white_check_mark: | | :white_check_mark: | | | `/repos/{owner}/{repo}/git/blobs` | | | | :x: | | From e35e2527749c71a7d391cc63f17bc5a3999f11cd Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 17 Mar 2025 10:08:12 +0100 Subject: [PATCH 05/85] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Standardize=20f?= =?UTF-8?q?ormatting=20and=20improve=20documentation=20for=20GitHub=20vari?= =?UTF-8?q?able=20functions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../public/Variables/Get-GitHubVariable.ps1 | 49 +++++++++---------- .../Variables/Remove-GitHubVariable.ps1 | 48 +++++++++--------- 2 files changed, 48 insertions(+), 49 deletions(-) diff --git a/src/functions/public/Variables/Get-GitHubVariable.ps1 b/src/functions/public/Variables/Get-GitHubVariable.ps1 index 66ddc663a..abf4b7191 100644 --- a/src/functions/public/Variables/Get-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Get-GitHubVariable.ps1 @@ -1,39 +1,38 @@ function Get-GitHubVariable { <# - .SYNOPSIS - Gets the GitHub variable details for a Organisation, Repository or Environment. + .SYNOPSIS + Gets the GitHub variable details for a Organisation, Repository or Environment. - .DESCRIPTION - Gets the GitHub variable details for a Organisation, Repository or Environment. + .DESCRIPTION + Gets the GitHub variable details for a Organisation, Repository or Environment. - .PARAMETER Owner - The account owner of the repository. The name is not case-sensitive. + .PARAMETER Owner + The account owner of the repository. The name is not case-sensitive. - .PARAMETER Repository - The name of the repository. The name is not case-sensitive. + .PARAMETER Repository + The name of the repository. The name is not case-sensitive. - .PARAMETER Environment - The name of the repository environment. + .PARAMETER Environment + The name of the repository environment. - .PARAMETER Name - The name of the variable. If left blank, all variable names are returned. + .PARAMETER Name + The name of the variable. If left blank, all variable names are returned. - .PARAMETER Context - The context to run the command in. Used to get the details for the API call. + .PARAMETER Context + The context to run the command in. Used to get the details for the API call. - .EXAMPLE - Get-GitHubVariable -Owner "octocat" -Repository "Hello-World" -Environment "dev" - Get-GitHubVariable -Owner "octocat" -Repository "Hello-World" -Name "myVariable" - Get-GitHubVariable -Owner "octocat" -Name "myVariable" + .EXAMPLE + Get-GitHubVariable -Owner "octocat" -Repository "Hello-World" -Environment "dev" + Get-GitHubVariable -Owner "octocat" -Repository "Hello-World" -Name "myVariable" + Get-GitHubVariable -Owner "octocat" -Name "myVariable" - .NOTES - [Gets an Organisation Variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#get-an-organization-variable) - [Gets an Repository Variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#get-a-repository-variable) - [Gets an Environment Variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#get-an-environment-variable) - - .OUTPUTS - psobject[] + .NOTES + [Gets an Organisation Variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#get-an-organization-variable) + [Gets an Repository Variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#get-a-repository-variable) + [Gets an Environment Variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#get-an-environment-variable) + .OUTPUTS + psobject[] #> [OutputType([psobject[]])] [CmdletBinding()] diff --git a/src/functions/public/Variables/Remove-GitHubVariable.ps1 b/src/functions/public/Variables/Remove-GitHubVariable.ps1 index f5b72b6a9..e722dae03 100644 --- a/src/functions/public/Variables/Remove-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Remove-GitHubVariable.ps1 @@ -1,38 +1,38 @@ function Remove-GitHubVariable { <# - .SYNOPSIS - Removes a GitHub variable from an Organisation, Repository or Environment. + .SYNOPSIS + Removes a GitHub variable from an Organisation, Repository or Environment. - .DESCRIPTION - Removes a GitHub variable from an Organisation, Repository or Environment. + .DESCRIPTION + Removes a GitHub variable from an Organisation, Repository or Environment. - .PARAMETER Owner - The account owner of the repository. The name is not case-sensitive. + .PARAMETER Owner + The account owner of the repository. The name is not case-sensitive. - .PARAMETER Repository - The name of the repository. The name is not case-sensitive. + .PARAMETER Repository + The name of the repository. The name is not case-sensitive. - .PARAMETER Environment - The name of the repository environment. + .PARAMETER Environment + The name of the repository environment. - .PARAMETER Name - The name of the variable. + .PARAMETER Name + The name of the variable. - .PARAMETER Context - The context to run the command in. Used to get the details for the API call. + .PARAMETER Context + The context to run the command in. Used to get the details for the API call. - .EXAMPLE - Remove-GitHubVariable -Owner "octocat" -Repository "Hello-World" -Environment "dev" -Name "myVariable" - Remove-GitHubVariable -Owner "octocat" -Repository "Hello-World" -Name "myVariable" - Remove-GitHubVariable -Owner "octocat" -Name "myVariable" + .EXAMPLE + Remove-GitHubVariable -Owner "octocat" -Repository "Hello-World" -Environment "dev" -Name "myVariable" + Remove-GitHubVariable -Owner "octocat" -Repository "Hello-World" -Name "myVariable" + Remove-GitHubVariable -Owner "octocat" -Name "myVariable" - .NOTES - [Delete an Organisation Variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#delete-an-organization-variable) - [Delete a Repository Variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#delete-a-repository-variable) - [Delete an Environment Variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#delete-an-environment-variable) + .NOTES + [Delete an Organisation Variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#delete-an-organization-variable) + [Delete a Repository Variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#delete-a-repository-variable) + [Delete an Environment Variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#delete-an-environment-variable) - .OUTPUTS - psobject[] + .OUTPUTS + psobject[] #> [OutputType([psobject[]])] [CmdletBinding(SupportsShouldProcess)] From 6efd65d66ec7b7eea9b2fd1284d49f388da3a1e3 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 17 Mar 2025 14:55:17 +0100 Subject: [PATCH 06/85] Get-GitHubVariable --- .../public/Repositories/GitHubRepository.ps1 | 51 +++++ .../public/Variables/GitHubVariable.ps1 | 45 +++++ src/formats/GitHubVariable.Format.ps1xml | 93 +++++++++ .../Get-GitHubRepositoryByName.ps1 | 4 +- .../Get-GitHubVariableEnvironmentByName.ps1 | 89 +++++++++ .../Get-GitHubVariableEnvironmentList.ps1 | 90 +++++++++ .../Get-GitHubVariableOwnerByName.ps1 | 85 ++++++++ .../Variables/Get-GitHubVariableOwnerList.ps1 | 101 ++++++++++ .../Get-GitHubVariableRepositoryByName.ps1 | 77 +++++++ .../Get-GitHubVariableRepositoryList.ps1 | 88 ++++++++ .../Get-GitHubVariableVisibilityList.ps1 | 93 +++++++++ .../public/Variables/Get-GitHubVariable.ps1 | 189 +++++++++++++----- 12 files changed, 953 insertions(+), 52 deletions(-) create mode 100644 src/classes/public/Repositories/GitHubRepository.ps1 create mode 100644 src/classes/public/Variables/GitHubVariable.ps1 create mode 100644 src/formats/GitHubVariable.Format.ps1xml create mode 100644 src/functions/private/Variables/Get-GitHubVariableEnvironmentByName.ps1 create mode 100644 src/functions/private/Variables/Get-GitHubVariableEnvironmentList.ps1 create mode 100644 src/functions/private/Variables/Get-GitHubVariableOwnerByName.ps1 create mode 100644 src/functions/private/Variables/Get-GitHubVariableOwnerList.ps1 create mode 100644 src/functions/private/Variables/Get-GitHubVariableRepositoryByName.ps1 create mode 100644 src/functions/private/Variables/Get-GitHubVariableRepositoryList.ps1 create mode 100644 src/functions/private/Variables/Get-GitHubVariableVisibilityList.ps1 diff --git a/src/classes/public/Repositories/GitHubRepository.ps1 b/src/classes/public/Repositories/GitHubRepository.ps1 new file mode 100644 index 000000000..5e7f12297 --- /dev/null +++ b/src/classes/public/Repositories/GitHubRepository.ps1 @@ -0,0 +1,51 @@ +class GitHubRepository { + # The name of the repository. + [string] $Name + + # The full name of the repository. + # This is the name of the repository including the owner. + # Example: "octocat/Hello-World". + [string] $FullName + + # The ID of the repository. + [string] $NodeID + + # The database ID of the repository. + [UInt64] $DatabaseID + + # The description of the repository. + [string] $Description + + # The owner of the repository. + [string] $Owner + + # The URL of the repository. + [string] $Url + + # The date and time the repository was created. + [System.Nullable[datetime]] $CreatedAt + + # The date and time the repository was last updated. + [System.Nullable[datetime]] $UpdatedAt + + # Simple parameterless constructor + GitHubRepository() {} + + # Creates a object from a hashtable of key-vaule pairs. + GitHubRepository([hashtable]$Properties) { + foreach ($Property in $Properties.Keys) { + $this.$Property = $Properties.$Property + } + } + + # Creates a object from a PSCustomObject. + GitHubRepository([PSCustomObject]$Object) { + $Object.PSObject.Properties | ForEach-Object { + $this.($_.Name) = $_.Value + } + } + + [string] ToString() { + return $this.Name + } +} diff --git a/src/classes/public/Variables/GitHubVariable.ps1 b/src/classes/public/Variables/GitHubVariable.ps1 new file mode 100644 index 000000000..67419e320 --- /dev/null +++ b/src/classes/public/Variables/GitHubVariable.ps1 @@ -0,0 +1,45 @@ +class GitHubVariable { + # The name of the variable. + [string] $Name + + # The value of the variable. + [string] $Value + + # The name of the organization or user the variable is associated with. + [string] $Owner + + # The name of the repository the variable is associated with. + [string] $Repository + + # The name of the environment the variable is associated with. + [string] $Environment + + # The date and time the variable was created. + [datetime] $CreatedAt + + # The date and time the variable was last updated. + [datetime] $UpdatedAt + + # The visibility of the variable. + [string] $Visibility + + # The ids of the repositories that the variable is visible to. + [GitHubRepository[]] $SelectedRepositories + + # Simple parameterless constructor + GitHubVariable() {} + + # Creates a object from a hashtable of key-vaule pairs. + GitHubVariable([hashtable]$Properties) { + foreach ($Property in $Properties.Keys) { + $this.$Property = $Properties.$Property + } + } + + # Creates a object from a PSCustomObject. + GitHubVariable([PSCustomObject]$Object) { + $Object.PSObject.Properties | ForEach-Object { + $this.($_.Name) = $_.Value + } + } +} diff --git a/src/formats/GitHubVariable.Format.ps1xml b/src/formats/GitHubVariable.Format.ps1xml new file mode 100644 index 000000000..9bb37b683 --- /dev/null +++ b/src/formats/GitHubVariable.Format.ps1xml @@ -0,0 +1,93 @@ + + + + + GitHubVariableTable + + GitHubVariable + + + + + + + + + + + + + + + + + + + + + + + + + Name + + + Value + + + Owner + + + Repository + + + Environment + + + + + + + + GitHubVariableList + + GitHubVariable + + + + + + + Name + + + Value + + + Owner + + + Repository + + + Environment + + + CreatedAt + + + UpdatedAt + + + Visibility + + + SelectedRepositories + + + + + + + + diff --git a/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryByName.ps1 b/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryByName.ps1 index c70381b38..41d0a59e5 100644 --- a/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryByName.ps1 +++ b/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryByName.ps1 @@ -28,7 +28,7 @@ # The name of the repository without the .git extension. The name is not case sensitive. [Parameter(Mandatory)] - [string] $Repository, + [string] $Name, # The context to run the command in. Used to get the details for the API call. # Can be either a string or a GitHubContext object. @@ -45,7 +45,7 @@ process { $inputObject = @{ Method = 'GET' - APIEndpoint = "/repos/$Owner/$Repository" + APIEndpoint = "/repos/$Owner/$Name" Context = $Context } diff --git a/src/functions/private/Variables/Get-GitHubVariableEnvironmentByName.ps1 b/src/functions/private/Variables/Get-GitHubVariableEnvironmentByName.ps1 new file mode 100644 index 000000000..c4287f0d5 --- /dev/null +++ b/src/functions/private/Variables/Get-GitHubVariableEnvironmentByName.ps1 @@ -0,0 +1,89 @@ +function Get-GitHubVariableEnvironmentByName { + <# + .SYNOPSIS + Retrieves a specific variable from a GitHub repository. + + .DESCRIPTION + Gets a specific variable in an environment of a repository on GitHub. + Authenticated users must have collaborator access to a repository to create, update, or read variables. + OAuth tokens and personal access tokens (classic) need the `repo` scope to use this endpoint. + + .EXAMPLE + Get-GitHubVariableEnvironmentByName -Owner 'octocat' -Repository 'Hello-World' -Environment 'dev' -Name 'NAME' -Context $GitHubContext + + Output: + ```powershell + Name : NAME + Value : John Doe + Owner : octocat + Repository : Hello-World + Environment : dev + ``` + + Retrieves the specified variable from the specified environment. + + .OUTPUTS + GitHubVariable + + .NOTES + Returns an GitHubVariable object containing details about the environment variable, + including its name, value, associated repository, and environment details. + + .LINK + [Get an environment variable](https://docs.github.com/rest/actions/variables#get-an-environment-variable) + #> + [OutputType([GitHubVariable])] + [CmdletBinding()] + 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] $Repository, + + # The name of the environment. + [Parameter(Mandatory)] + [string] $Environment, + + # The name of the variable. + [Parameter(Mandatory)] + [string] $Name, + + # The context to run the command in. Used to get the details for the API call. + # Can be either a string or a GitHubContext object. + [Parameter(Mandatory)] + [object] $Context + ) + + begin { + $stackPath = Get-PSCallStackPath + Write-Debug "[$stackPath] - Start" + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + } + + process { + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/repos/$Owner/$Repository/environments/$Environment/variables/$Name" + Context = $Context + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + [GitHubVariable]@{ + Name = $_.Response.name + Value = $_.Response.value + CreatedAt = $_.Response.created_at + UpdatedAt = $_.Response.updated_at + Owner = $Owner + Repository = $Repository + Environment = $Environment + } + } + } + + end { + Write-Debug "[$stackPath] - End" + } +} diff --git a/src/functions/private/Variables/Get-GitHubVariableEnvironmentList.ps1 b/src/functions/private/Variables/Get-GitHubVariableEnvironmentList.ps1 new file mode 100644 index 000000000..dea862f16 --- /dev/null +++ b/src/functions/private/Variables/Get-GitHubVariableEnvironmentList.ps1 @@ -0,0 +1,90 @@ +function Get-GitHubVariableEnvironmentList { + <# + .SYNOPSIS + Retrieves all variables for a specified environment in a GitHub repository. + + .DESCRIPTION + Lists all environment variables in a specified repository environment. + Authenticated users must have collaborator access to a repository to create, update, or read variables. + OAuth app tokens and personal access tokens (classic) need the `repo` scope to use this endpoint. + + .EXAMPLE + Get-GitHubVariableEnvironmentList -Owner 'octocat' -Repository 'Hello-World' -Environment 'dev' -Context $GitHubContext + + Output: + ```powershell + Name : NAME + Value : John Doe + Owner : octocat + Repository : Hello-World + Environment : dev + + Name : EMAIL + Value : John.Doe@example.com + Owner : octocat + Repository : Hello-World + Environment : dev + ``` + + Retrieves all variables for the specified environment. + + .OUTPUTS + GitHubVariable[]. An array of GitHubVariable objects representing the environment variables. + Each object contains Name, Value, CreatedAt, UpdatedAt, Owner, Repository, and Environment properties. + + .LINK + https://psmodule.io/GitHub/Functions/Get-GitHubVariableEnvironmentList + #> + [OutputType([GitHubVariable[]])] + [CmdletBinding()] + 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] $Repository, + + # The name of the environment. + [Parameter(Mandatory)] + [string] $Environment, + + # The context to run the command in. Used to get the details for the API call. + # Can be either a string or a GitHubContext object. + [Parameter(Mandatory)] + [object] $Context + ) + + begin { + $stackPath = Get-PSCallStackPath + Write-Debug "[$stackPath] - Start" + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + } + + process { + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/repos/$Owner/$Repository/environments/$Environment/variables" + Context = $Context + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + $_.Response.variables | ForEach-Object { + [GitHubVariable]@{ + Name = $_.name + Value = $_.value + CreatedAt = $_.created_at + UpdatedAt = $_.updated_at + Owner = $Owner + Repository = $Repository + Environment = $Environment + } + } + } + } + + end { + Write-Debug "[$stackPath] - End" + } +} diff --git a/src/functions/private/Variables/Get-GitHubVariableOwnerByName.ps1 b/src/functions/private/Variables/Get-GitHubVariableOwnerByName.ps1 new file mode 100644 index 000000000..1645f3c3e --- /dev/null +++ b/src/functions/private/Variables/Get-GitHubVariableOwnerByName.ps1 @@ -0,0 +1,85 @@ +function Get-GitHubVariableOwnerByName { + <# + .SYNOPSIS + Get an organization variable. + + .DESCRIPTION + Gets a specific variable in an organization. + The authenticated user must have collaborator access to a repository to create, update, or read variables. + OAuth tokens and personal access tokens (classic) need the`admin:org` scope to use this endpoint. If the repository is private, + OAuth tokens and personal access tokens (classic) need the `repo` scope to use this endpoint. + + .EXAMPLE + Get-GitHubVariableOwnerByName -Owner 'PSModule' -Name 'SELECTEDVAR' -Context (Get-GitHubContext) + + Output: + ```powershell + Name : SELECTEDVAR + Value : Varselected + Owner : PSModule + Repository : + Environment : + CreatedAt : 3/17/2025 10:56:39 AM + UpdatedAt : 3/17/2025 10:56:39 AM + Visibility : selected + SelectedRepositories : {Build-PSModule, Test-PSModule} + ``` + + Retrieves the specified variable from the specified organization. + + .LINK + [Get an organization variable](https://docs.github.com/rest/actions/variables#get-an-organization-variable) + #> + [OutputType([GitHubVariable])] + [CmdletBinding()] + param( + # The account owner of the repository. The name is not case sensitive. + [Parameter(Mandatory)] + [string] $Owner, + + # The name of the variable. + [Parameter(Mandatory)] + [string] $Name, + + # The context to run the command in. Used to get the details for the API call. + # Can be either a string or a GitHubContext object. + [Parameter(Mandatory)] + [object] $Context + ) + + begin { + $stackPath = Get-PSCallStackPath + Write-Debug "[$stackPath] - Start" + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + } + + process { + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/orgs/$Owner/actions/variables/$Name" + Context = $Context + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + $_.Response | ForEach-Object { + $selectedRepositories = @() + if ($_.visibility -eq 'selected') { + $selectedRepositories = Get-GitHubVariableVisibilityList -Owner $Owner -Name $_.name -Context $Context + } + [GitHubVariable]@{ + Name = $_.name + Value = $_.value + CreatedAt = $_.created_at + UpdatedAt = $_.updated_at + Owner = $Owner + Visibility = $_.visibility + SelectedRepositories = $selectedRepositories + } + } + } + } + + end { + Write-Debug "[$stackPath] - End" + } +} diff --git a/src/functions/private/Variables/Get-GitHubVariableOwnerList.ps1 b/src/functions/private/Variables/Get-GitHubVariableOwnerList.ps1 new file mode 100644 index 000000000..9ec90ba8c --- /dev/null +++ b/src/functions/private/Variables/Get-GitHubVariableOwnerList.ps1 @@ -0,0 +1,101 @@ +function Get-GitHubVariableOwnerList { + <# + .SYNOPSIS + List organization variables + + .DESCRIPTION + Lists all organization variables. + Authenticated users must have collaborator access to a repository to create, update, or read variables. + OAuth app tokens and personal access tokens (classic) need the `admin:org` scope to use this endpoint. If the repository is private, + the `repo` scope is also required. + + .EXAMPLE + Get-GitHubVariableOwnerList -Owner 'PSModule' -Context (Get-GitHubContext) + + Output: + ```powershell + Name : AVAILVAR + Value : ValueVar + Owner : PSModule + Repository : + Environment : + CreatedAt : 3/17/2025 10:56:22 AM + UpdatedAt : 3/17/2025 10:56:22 AM + Visibility : all + SelectedRepositories : {} + + Name : SELECTEDVAR + Value : Varselected + Owner : PSModule + Repository : + Environment : + CreatedAt : 3/17/2025 10:56:39 AM + UpdatedAt : 3/17/2025 10:56:39 AM + Visibility : selected + SelectedRepositories : {Build-PSModule, Test-PSModule} + + Name : TESTVAR + Value : VarTest + Owner : PSModule + Repository : + Environment : + CreatedAt : 3/17/2025 10:56:05 AM + UpdatedAt : 3/17/2025 10:56:05 AM + Visibility : private + SelectedRepositories : {} + ``` + + Retrieves all variables from the specified organization. + + .LINK + List organization variables](https://docs.github.com/rest/actions/variables#list-organization-variables) + #> + [OutputType([GitHubVariable[]])] + [CmdletBinding()] + param( + # The account owner of the repository. The name is not case sensitive. + [Parameter(Mandatory)] + [string] $Owner, + + # The context to run the command in. Used to get the details for the API call. + # Can be either a string or a GitHubContext object. + [Parameter(Mandatory)] + [object] $Context + ) + + begin { + $stackPath = Get-PSCallStackPath + Write-Debug "[$stackPath] - Start" + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + } + + process { + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/orgs/$Owner/actions/variables" + Context = $Context + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + $_.Response.variables | ForEach-Object { + $selectedRepositories = @() + if ($_.visibility -eq 'selected') { + $selectedRepositories = Get-GitHubVariableVisibilityList -Owner $Owner -Name $_.name -Context $Context + } + [GitHubVariable]@{ + Name = $_.name + Value = $_.value + CreatedAt = $_.created_at + UpdatedAt = $_.updated_at + Owner = $Owner + Visibility = $_.visibility + SelectedRepositories = $selectedRepositories + } + } + } + } + + end { + Write-Debug "[$stackPath] - End" + } +} diff --git a/src/functions/private/Variables/Get-GitHubVariableRepositoryByName.ps1 b/src/functions/private/Variables/Get-GitHubVariableRepositoryByName.ps1 new file mode 100644 index 000000000..2b845a5bd --- /dev/null +++ b/src/functions/private/Variables/Get-GitHubVariableRepositoryByName.ps1 @@ -0,0 +1,77 @@ +function Get-GitHubVariableRepositoryByName { + <# + .SYNOPSIS + Get a repository variable + + .DESCRIPTION + Gets a specific variable in a repository. + The authenticated user must have collaborator access to the repository to use this endpoint. + OAuth app tokens and personal access tokens (classic) need the `repo` scope to use this endpoint. + + .EXAMPLE + Get-GitHubVariableRepositoryByName -Owner 'PSModule' -Repository 'Hello-World' -Name 'EMAIL' -Context (Get-GitHubContext) + + Output: + ```powershell + Name : EMAIL + Value : John.Doe@example.com + Owner : octocat + Repository : Hello-World + Environment : + ``` + + Retrieves the specified variable from the specified repository. + + .LINK + [Get a repository variable](https://docs.github.com/rest/actions/variables#get-a-repository-variable) + #> + [OutputType([GitHubVariable])] + [CmdletBinding()] + 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] $Repository, + + # The name of the variable. + [Parameter(Mandatory)] + [string] $Name, + + # The context to run the command in. Used to get the details for the API call. + # Can be either a string or a GitHubContext object. + [Parameter(Mandatory)] + [object] $Context + ) + + begin { + $stackPath = Get-PSCallStackPath + Write-Debug "[$stackPath] - Start" + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + } + + process { + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/repos/$Owner/$Repository/actions/variables/$Name" + Context = $Context + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + [GitHubVariable]@{ + Name = $_.Response.name + Value = $_.Response.value + CreatedAt = $_.Response.created_at + UpdatedAt = $_.Response.updated_at + Owner = $Owner + Repository = $Repository + } + } + } + + end { + Write-Debug "[$stackPath] - End" + } +} diff --git a/src/functions/private/Variables/Get-GitHubVariableRepositoryList.ps1 b/src/functions/private/Variables/Get-GitHubVariableRepositoryList.ps1 new file mode 100644 index 000000000..cad40d84e --- /dev/null +++ b/src/functions/private/Variables/Get-GitHubVariableRepositoryList.ps1 @@ -0,0 +1,88 @@ +function Get-GitHubVariableRepositoryList { + <# + .SYNOPSIS + List repository variables. + + .DESCRIPTION + Lists all repository variables. + Authenticated users must have collaborator access to a repository to create, update, or read variables. + OAuth app tokens and personal access tokens (classic) need the `repo` scope to use this endpoint. + + .EXAMPLE + Get-GitHubVariableRepositoryList -Owner 'PSModule' -Repository 'Hello-World' -Context (Get-GitHubContext) + + Output: + ```powershell + Name : NAME + Value : John Doe + Owner : octocat + Repository : Hello-World + Environment : + + Name : EMAIL + Value : John.Doe@example.com + Owner : octocat + Repository : Hello-World + Environment : + ``` + + Retrieves all variables for the specified repository. + + .OUTPUTS + GitHubVariable + + .NOTES + Returns an GitHubVariable object containing details about the environment variable, + including its name, value, associated repository, and environment details. + + .LINK + [List repository variables](https://docs.github.com/rest/actions/variables#list-repository-variables) + #> + [OutputType([GitHubVariable[]])] + [CmdletBinding()] + 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] $Repository, + + # The context to run the command in. Used to get the details for the API call. + # Can be either a string or a GitHubContext object. + [Parameter(Mandatory)] + [object] $Context + ) + + begin { + $stackPath = Get-PSCallStackPath + Write-Debug "[$stackPath] - Start" + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + } + + process { + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/repos/$Owner/$Repository/actions/variables" + Context = $Context + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + $_.Response.variables | ForEach-Object { + [GitHubVariable]@{ + Name = $_.name + Value = $_.value + CreatedAt = $_.created_at + UpdatedAt = $_.updated_at + Owner = $Owner + Repository = $Repository + } + } + } + } + + end { + Write-Debug "[$stackPath] - End" + } +} diff --git a/src/functions/private/Variables/Get-GitHubVariableVisibilityList.ps1 b/src/functions/private/Variables/Get-GitHubVariableVisibilityList.ps1 new file mode 100644 index 000000000..3cf783c13 --- /dev/null +++ b/src/functions/private/Variables/Get-GitHubVariableVisibilityList.ps1 @@ -0,0 +1,93 @@ +function Get-GitHubVariableVisibilityList { + <# + .SYNOPSIS + List selected repositories for an organization variable. + + .DESCRIPTION + Lists all repositories that can access an organization variable that is available to selected repositories. + Authenticated users must have collaborator access to a repository to create, update, or read variables. + OAuth app tokens and personal access tokens (classic) need the `admin:org` scope to use this endpoint. If the repository is private, + the `repo` scope is also required. + + .EXAMPLE + Get-GitHubVariableVisibilityList -Owner 'PSModule' -Name 'SELECTEDVAR' -Context (Get-GitHubContext) + + .LINK + [List selected repositories for an organization variable](https://docs.github.com/rest/actions/variables#list-selected-repositories-for-an-organization-variable) + #> + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidLongLines', '', + Justification = 'Long links' + )] + [OutputType([pscustomobject])] + [CmdletBinding()] + param( + # The account owner of the repository. The name is not case sensitive. + [Parameter(Mandatory)] + [string] $Owner, + + # The name of the variable. + [Parameter(Mandatory)] + [string] $Name, + + # The context to run the command in. Used to get the details for the API call. + # Can be either a string or a GitHubContext object. + [Parameter(Mandatory)] + [object] $Context, + + [Parameter()] + [ValidateSet('json', 'pscustomobject', 'class', 'raw')] + [string] $Output = 'class' + ) + + begin { + # $stackPath = Get-PSCallStackPath + # Write-Debug "[$stackPath] - Start" + # Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + } + + process { + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/orgs/$Owner/actions/variables/$Name/repositories" + Context = $Context + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + $apiReturn = $_ + $repositories = $apiReturn.Response.repositories + switch ($Output) { + 'raw' { + $apiReturn + break + } + 'json' { + $repositories | ConvertTo-Json -Depth 5 + break + } + 'pscustomobject' { + $repositories + break + } + 'class' { + $repositories | ForEach-Object { + [GitHubRepository]@{ + Name = $_.name + FullName = $_.full_name + NodeID = $_.node_id + DatabaseID = $_.id + Description = $_.description + Owner = $_.owner.login + URL = $_.html_url + } + } + break + } + } + } + } + + end { + Write-Debug "[$stackPath] - End" + } +} diff --git a/src/functions/public/Variables/Get-GitHubVariable.ps1 b/src/functions/public/Variables/Get-GitHubVariable.ps1 index abf4b7191..ce0c0101d 100644 --- a/src/functions/public/Variables/Get-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Get-GitHubVariable.ps1 @@ -1,55 +1,144 @@ function Get-GitHubVariable { <# .SYNOPSIS - Gets the GitHub variable details for a Organisation, Repository or Environment. + Retrieves a variable from GitHub based on the specified scope. .DESCRIPTION - Gets the GitHub variable details for a Organisation, Repository or Environment. + Gets a variable from GitHub, which can be at the organization, repository, or environment level. + This function determines the appropriate API call based on the provided parameters. + Authenticated users must have the required access rights to read variables. + OAuth tokens and personal access tokens (classic) need the `repo` scope for repositories, + `admin:org` for organizations, and collaborator access for environments. - .PARAMETER Owner - The account owner of the repository. The name is not case-sensitive. + .EXAMPLE + Get-GitHubVariable -Owner 'octocat' -Name 'HOST_NAME' -Context $GitHubContext + + Output: + ```powershell + Name : HOST_NAME + Value : github.com + Owner : octocat + Repository : + Environment : + ``` - .PARAMETER Repository - The name of the repository. The name is not case-sensitive. + Retrieves the specified variable from the organization level. - .PARAMETER Environment - The name of the repository environment. + .EXAMPLE + Get-GitHubVariable -Owner 'octocat' -Repository 'Hello-World' -Name 'GUID' -Context $GitHubContext - .PARAMETER Name - The name of the variable. If left blank, all variable names are returned. + Output: + ```powershell + Name : GUID + Value : 354aa0b0-65b1-46c8-9c3e-1576f4167a41 + Owner : octocat + Repository : Hello-World + Environment : + ``` - .PARAMETER Context - The context to run the command in. Used to get the details for the API call. + Retrieves the specified variable from the repository level. .EXAMPLE - Get-GitHubVariable -Owner "octocat" -Repository "Hello-World" -Environment "dev" - Get-GitHubVariable -Owner "octocat" -Repository "Hello-World" -Name "myVariable" - Get-GitHubVariable -Owner "octocat" -Name "myVariable" + Get-GitHubVariable -Owner 'octocat' -Repository 'Hello-World' -Environment 'dev' -Name 'DB_SERVER' -Context $GitHubContext - .NOTES - [Gets an Organisation Variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#get-an-organization-variable) - [Gets an Repository Variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#get-a-repository-variable) - [Gets an Environment Variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#get-an-environment-variable) + Output: + ```powershell + Name : DB_SERVER + Value : db.example.com + Owner : octocat + Repository : Hello-World + Environment : dev + ``` + + Retrieves the specified variable from the environment level within a repository. + + .EXAMPLE + Get-GitHubVariable -Owner 'octocat' -Context $GitHubContext + + Output: + ```powershell + Name : MAX_THREADS + Value : 10 + Owner : octocat + Repository : + Environment : + + Name : API_TIMEOUT + Value : 30 + Owner : octocat + Repository : + Environment : + ``` + + Retrieves all variables available at the organization level. + + .EXAMPLE + Get-GitHubVariable -Owner 'octocat' -Repository 'Hello-World' -Context $GitHubContext + + Output: + ```powershell + Name : LOG_LEVEL + Value : INFO + Owner : octocat + Repository : Hello-World + Environment : + + Name : FEATURE_FLAG + Value : Enabled + Owner : octocat + Repository : Hello-World + Environment : + ``` + + Retrieves all variables available at the repository level. + + .EXAMPLE + Get-GitHubVariable -Owner 'octocat' -Repository 'Hello-World' -Environment 'staging' -Context $GitHubContext + + Output: + ```powershell + Name : CACHE_DURATION + Value : 3600 + Owner : octocat + Repository : Hello-World + Environment : staging + + Name : CONNECTION_RETRIES + Value : 5 + Owner : octocat + Repository : Hello-World + Environment : staging + ``` + + Retrieves all variables available in the 'staging' environment within the repository. .OUTPUTS - psobject[] + GitHubVariable + + .NOTES + An object representing the GitHub variable, containing Name, Value, Owner, + Repository, and Environment details. + + .LINK + https://psmodule.io/GitHub/Functions/Variables/Get-GitHubVariable #> - [OutputType([psobject[]])] + [OutputType([GitHubVariable])] [CmdletBinding()] param( - [Parameter(ParameterSetName = 'Environment', Mandatory)] - [Parameter(ParameterSetName = 'Organization', Mandatory)] - [Parameter(ParameterSetName = 'Repository', Mandatory)] + # The account owner of the repository. The name is not case sensitive. + [Parameter(Mandatory, ParameterSetName = 'Owner')] + [Parameter(Mandatory, ParameterSetName = 'Repository')] + [Parameter(Mandatory, ParameterSetName = 'Environment')] [Alias('Organization', 'User')] [string] $Owner, - # The name of the repository. The name is not case sensitive. - [Parameter(ParameterSetName = 'Environment', Mandatory)] - [Parameter(ParameterSetName = 'Repository', Mandatory)] + # The name of the repository without the .git extension. The name is not case sensitive. + [Parameter(Mandatory, ParameterSetName = 'Repository')] + [Parameter(Mandatory, ParameterSetName = 'Environment')] [string] $Repository, - # The name of the repository environment. - [Parameter(ParameterSetName = 'Environment', Mandatory)] + # The name of the environment. + [Parameter(Mandatory, ParameterSetName = 'Environment')] [string] $Environment, # The name of the variable. @@ -70,31 +159,31 @@ function Get-GitHubVariable { } process { - $inputObject = @{ - Method = 'Get' - APIEndpoint = switch ($PSCmdlet.ParameterSetName) { - 'Environment' { - "/repos/$Owner/$Repository/environments/$Environment/variables" - break + switch ($PSCmdlet.ParameterSetName) { + 'Owner' { + if ($Name) { + Get-GitHubVariableOwnerByName -Owner $Owner -Name $Name -Context $Context + } else { + Get-GitHubVariableOwnerList -Owner $Owner -Context $Context } - 'Repository' { - "/repos/$Owner/$Repository/actions/variables" - break + break + } + 'Repository' { + if ($Name) { + Get-GitHubVariableRepositoryByName -Owner $Owner -Repository $Repository -Name $Name -Context $Context + } else { + Get-GitHubVariableRepositoryList -Owner $Owner -Repository $Repository -Context $Context } - 'Organization' { - "/orgs/$Owner/actions/variables" - break + break + } + 'Environment' { + if ($Name) { + Get-GitHubVariableEnvironmentByName -Owner $Owner -Repository $Repository -Environment $Environment -Name $Name -Context $Context + } else { + Get-GitHubVariableEnvironmentList -Owner $Owner -Repository $Repository -Environment $Environment -Context $Context } + break } - Context = $Context - } - - if (-not [string]::IsNullOrWhiteSpace($Name)) { - $inputObject.APIEndpoint += "/$Name" - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response } } From 998f92ea73bf51afd927161c5de6425aca84bcce Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 17 Mar 2025 15:44:42 +0100 Subject: [PATCH 07/85] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20parame?= =?UTF-8?q?ter=20set=20names=20and=20add=20new=20functions=20for=20creatin?= =?UTF-8?q?g=20GitHub=20variables=20on=20repositories=20and=20environments?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../New-GitHubVariableOnEnvironment.ps1 | 85 ++++++++++++++++ .../Variables/New-GitHubVariableOnOwner.ps1 | 91 +++++++++++++++++ .../New-GitHubVariableOnRepository.ps1 | 73 ++++++++++++++ .../public/Variables/Get-GitHubVariable.ps1 | 4 +- .../public/Variables/New-GitHubVariable.ps1 | 98 +++++++++++++++++++ 5 files changed, 349 insertions(+), 2 deletions(-) create mode 100644 src/functions/private/Variables/New-GitHubVariableOnEnvironment.ps1 create mode 100644 src/functions/private/Variables/New-GitHubVariableOnOwner.ps1 create mode 100644 src/functions/private/Variables/New-GitHubVariableOnRepository.ps1 create mode 100644 src/functions/public/Variables/New-GitHubVariable.ps1 diff --git a/src/functions/private/Variables/New-GitHubVariableOnEnvironment.ps1 b/src/functions/private/Variables/New-GitHubVariableOnEnvironment.ps1 new file mode 100644 index 000000000..d1cd48899 --- /dev/null +++ b/src/functions/private/Variables/New-GitHubVariableOnEnvironment.ps1 @@ -0,0 +1,85 @@ +function New-GitHubVariableOnEnvironment { + <# + .SYNOPSIS + Create an environment variable. + + .DESCRIPTION + Create an environment variable that you can reference in a GitHub Actions workflow. + Authenticated users must have collaborator access to a repository to create, update, or read variables. + OAuth tokens and personal access tokens (classic) need the `repo` scope to use this endpoint. + + .EXAMPLE + $params = @{ + Owner = 'octocat' + Repository = 'Hello-World' + Environment = 'dev' + Name = 'HOST_NAME' + Value = 'github.com' + Context = $GitHubContext + } + New-GitHubVariableOnEnvironment @params + + Creates a new environment variable named `HOST_NAME` with the value `github.com` in the specified environment. + + .LINK + [Create an environment variable](https://docs.github.com/rest/actions/variables#create-an-environment-variable) + #> + [OutputType([void])] + [CmdletBinding(SupportsShouldProcess)] + param( + # The account owner of the repository. The name is not case sensitive. + [Parameter(Mandatory)] + [string] $Owner, + + # The name of the repository. The name is not case sensitive. + [Parameter(Mandatory)] + [string] $Repository, + + # The name of the repository environment. + [Parameter(Mandatory)] + [string] $Environment, + + # The name of the variable. + [Parameter(Mandatory)] + [string] $Name, + + # The value of the variable. + [Parameter(Mandatory)] + [string] $Value, + + # The context to run the command in. Used to get the details for the API call. + # Can be either a string or a GitHubContext object. + [Parameter(Mandatory)] + [object] $Context + ) + + begin { + $stackPath = Get-PSCallStackPath + Write-Debug "[$stackPath] - Start" + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + } + + process { + $body = @{ + name = $Name + value = $Value + } + + $inputObject = @{ + Method = 'POST' + APIEndpoint = "/repos/$Owner/$Repository/environments/$Environment/variables" + Body = $body + Context = $Context + } + + if ($PSCmdlet.ShouldProcess("variable [$Name] on [$Owner/$Repository/$Environment]", 'Create')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } + } + + end { + Write-Debug "[$stackPath] - End" + } +} diff --git a/src/functions/private/Variables/New-GitHubVariableOnOwner.ps1 b/src/functions/private/Variables/New-GitHubVariableOnOwner.ps1 new file mode 100644 index 000000000..8a396f1f1 --- /dev/null +++ b/src/functions/private/Variables/New-GitHubVariableOnOwner.ps1 @@ -0,0 +1,91 @@ +function New-GitHubVariableOnOwner { + <# + .SYNOPSIS + Create an organization variable. + + .DESCRIPTION + Creates an organization variable that you can reference in a GitHub Actions workflow. + Authenticated users must have collaborator access to a repository to create, update, or read variables. + OAuth tokens and personal access tokens (classic) need the`admin:org` scope to use this endpoint. If the repository is private, + OAuth tokens and personal access tokens (classic) need the `repo` scope to use this endpoint. + + .EXAMPLE + New-GitHubVariableOnOwner -Owner 'octocat' -Name 'HOST_NAME' -Value 'github.com' -Context $GitHubContext + + Creates a new organization variable named `HOST_NAME` with the value `github.com` in the specified organization. + + .LINK + [Create an organization variable](https://docs.github.com/rest/actions/variables#create-an-organization-variable) + #> + [OutputType([void])] + [CmdletBinding(SupportsShouldProcess)] + param( + [Parameter(Mandatory)] + [string] $Owner, + + # The name of the variable. + [Parameter(Mandatory)] + [string] $Name, + + # The value of the variable. + [Parameter(Mandatory)] + [string] $Value, + + # The visibility of the variable. Can be `private`, `selected`, or `all`. + # `private` - The variable is only available to the organization. + # `selected` - The variable is available to selected repositories. + # `all` - The variable is available to all repositories in the organization. + [Parameter()] + [ValidateSet('private', 'selected', 'all')] + [string] $Visibility = 'private', + + # The IDs of the repositories to which the variable is available. + # This parameter is only used when the `-Visibility` parameter is set to `selected`. + # The IDs can be obtained from the `Get-GitHubRepository` function. + [Parameter()] + [UInt64[]] $SelectedRepository, + + # The context to run the command in. Used to get the details for the API call. + # Can be either a string or a GitHubContext object. + [Parameter(Mandatory)] + [object] $Context + ) + + begin { + $stackPath = Get-PSCallStackPath + Write-Debug "[$stackPath] - Start" + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + } + + process { + $body = @{ + name = $Name + value = $Value + visibility = $Visibility + } + + if ($Visibility -eq 'selected') { + if (-not $SelectedRepository) { + throw 'You must specify the -SelectedRepository parameter when using the -Visibility selected switch.' + } + $body['selected_repository_ids'] = $SelectedRepository + } + + $inputObject = @{ + Method = 'POST' + APIEndpoint = "/orgs/$Owner/actions/variables" + Body = $body + Context = $Context + } + + if ($PSCmdlet.ShouldProcess("variable [$Name] on [$Owner]", 'Create')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } + } + + end { + Write-Debug "[$stackPath] - End" + } +} diff --git a/src/functions/private/Variables/New-GitHubVariableOnRepository.ps1 b/src/functions/private/Variables/New-GitHubVariableOnRepository.ps1 new file mode 100644 index 000000000..48c1d7eec --- /dev/null +++ b/src/functions/private/Variables/New-GitHubVariableOnRepository.ps1 @@ -0,0 +1,73 @@ +function New-GitHubVariableOnRepository { + <# + .SYNOPSIS + Create a repository variable. + + .DESCRIPTION + Creates a repository variable that you can reference in a GitHub Actions workflow. + Authenticated users must have collaborator access to a repository to create, update, or read variables. + OAuth tokens and personal access tokens (classic) need the `repo` scope to use this endpoint. + + .EXAMPLE + New-GitHubVariableOnRepository -Owner 'octocat' -Repository 'Hello-World' -Name 'HOST_NAME' -Value 'github.com' -Context $GitHubContext + + Creates a new repository variable named `HOST_NAME` with the value `github.com` in the specified repository. + + .LINK + [Create a repository variable](https://docs.github.com/rest/actions/variables#create-a-repository-variable) + #> + [OutputType([void])] + [CmdletBinding(SupportsShouldProcess)] + param( + # The account owner of the repository. The name is not case sensitive. + [Parameter(Mandatory)] + [string] $Owner, + + # The name of the repository. The name is not case sensitive. + [Parameter(Mandatory)] + [string] $Repository, + + # The name of the variable. + [Parameter(Mandatory)] + [string] $Name, + + # The value of the variable. + [Parameter(Mandatory)] + [string] $Value, + + # The context to run the command in. Used to get the details for the API call. + # Can be either a string or a GitHubContext object. + [Parameter(Mandatory)] + [object] $Context + ) + + begin { + $stackPath = Get-PSCallStackPath + Write-Debug "[$stackPath] - Start" + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + } + + process { + $body = @{ + name = $Name + value = $Value + } + + $inputObject = @{ + Method = 'POST' + APIEndpoint = "/repos/$Owner/$Repository/actions/variables" + Body = $body + Context = $Context + } + + if ($PSCmdlet.ShouldProcess("variable [$Name] on [$Owner/$Repository]", 'Create')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } + } + + end { + Write-Debug "[$stackPath] - End" + } +} diff --git a/src/functions/public/Variables/Get-GitHubVariable.ps1 b/src/functions/public/Variables/Get-GitHubVariable.ps1 index ce0c0101d..efca564ad 100644 --- a/src/functions/public/Variables/Get-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Get-GitHubVariable.ps1 @@ -126,7 +126,7 @@ function Get-GitHubVariable { [CmdletBinding()] param( # The account owner of the repository. The name is not case sensitive. - [Parameter(Mandatory, ParameterSetName = 'Owner')] + [Parameter(Mandatory, ParameterSetName = 'Organization')] [Parameter(Mandatory, ParameterSetName = 'Repository')] [Parameter(Mandatory, ParameterSetName = 'Environment')] [Alias('Organization', 'User')] @@ -160,7 +160,7 @@ function Get-GitHubVariable { process { switch ($PSCmdlet.ParameterSetName) { - 'Owner' { + 'Organization' { if ($Name) { Get-GitHubVariableOwnerByName -Owner $Owner -Name $Name -Context $Context } else { diff --git a/src/functions/public/Variables/New-GitHubVariable.ps1 b/src/functions/public/Variables/New-GitHubVariable.ps1 new file mode 100644 index 000000000..fe6a1b5f8 --- /dev/null +++ b/src/functions/public/Variables/New-GitHubVariable.ps1 @@ -0,0 +1,98 @@ +function New-GitHubVariable { + <# + + #> + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSUseShouldProcessForStateChangingFunctions', '', + Scope = 'Function', Justification = 'This check is performed in the private functions.' + )] + [OutputType([void])] + [CmdletBinding()] + param( + # The account owner of the repository. The name is not case sensitive. + [Parameter(Mandatory, ParameterSetName = 'Organization')] + [Parameter(Mandatory, ParameterSetName = 'Repository')] + [Parameter(Mandatory, ParameterSetName = 'Environment')] + [Alias('Organization', 'User')] + [string] $Owner, + + # The name of the repository. The name is not case sensitive. + [Parameter(Mandatory, ParameterSetName = 'Repository')] + [Parameter(Mandatory, ParameterSetName = 'Environment')] + [string] $Repository, + + # The name of the repository environment. + [Parameter(Mandatory, ParameterSetName = 'Environment')] + [string] $Environment, + + # The name of the variable. + [Parameter(Mandatory)] + [string] $Name, + + [Parameter(Mandatory)] + [string] $Value, + + [Parameter(ParameterSetName = 'Organization')] + [ValidateSet('private', 'selected', 'all')] + [string] $Visibility = 'private', + + [Parameter(ParameterSetName = 'Organization')] + [UInt64[]] $SelectedRepository, + + # The context to run the command in. Used to get the details for the API call. + # Can be either a string or a GitHubContext object. + [Parameter()] + [object] $Context = (Get-GitHubContext) + ) + + begin { + $stackPath = Get-PSCallStackPath + Write-Debug "[$stackPath] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + } + + process { + switch ($PSCmdlet.ParameterSetName) { + 'Organization' { + $params = @{ + Owner = $Owner + Name = $Name + Value = $Value + Visibility = $Visibility + SelectedRepository = $SelectedRepository + Context = $Context + } + New-GitHubVariableOnOwner @params + break + } + 'Repository' { + $params = @{ + Owner = $Owner + Repository = $Repository + Name = $Name + Value = $Value + Context = $Context + } + New-GitHubVariableOnRepository @params + break + } + 'Environment' { + $params = @{ + Owner = $Owner + Repository = $Repository + Environment = $Environment + Name = $Name + Value = $Value + Context = $Context + } + New-GitHubVariableOnEnvironment @params + break + } + } + } + + end { + Write-Debug "[$stackPath] - End" + } +} From 51b68a0e2896ac7a62246246491c4df09cc935a9 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions@users.noreply.github.com> Date: Mon, 17 Mar 2025 14:46:25 +0000 Subject: [PATCH 08/85] Auto-generated changes --- Coverage.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Coverage.md b/Coverage.md index 5910c644e..ba714a3f1 100644 --- a/Coverage.md +++ b/Coverage.md @@ -9,15 +9,15 @@ Covered functions - 173 + 177 Missing functions - 846 + 842 Coverage - 16.98% + 17.37% @@ -132,8 +132,8 @@ | `/orgs/{org}/actions/secrets/{secret_name}/repositories` | | :x: | | | :x: | | `/orgs/{org}/actions/secrets/{secret_name}/repositories/{repository_id}` | :x: | | | | :x: | | `/orgs/{org}/actions/variables` | | :white_check_mark: | | :white_check_mark: | | -| `/orgs/{org}/actions/variables/{name}` | :white_check_mark: | :x: | :x: | | | -| `/orgs/{org}/actions/variables/{name}/repositories` | | :x: | | | :x: | +| `/orgs/{org}/actions/variables/{name}` | :white_check_mark: | :white_check_mark: | :x: | | | +| `/orgs/{org}/actions/variables/{name}/repositories` | | :white_check_mark: | | | :x: | | `/orgs/{org}/actions/variables/{name}/repositories/{repository_id}` | :x: | | | | :x: | | `/orgs/{org}/attestations/{subject_digest}` | | :x: | | | | | `/orgs/{org}/blocks` | | :white_check_mark: | | | | @@ -330,7 +330,7 @@ | `/repos/{owner}/{repo}/actions/secrets/public-key` | | :x: | | | | | `/repos/{owner}/{repo}/actions/secrets/{secret_name}` | :x: | :x: | | | :x: | | `/repos/{owner}/{repo}/actions/variables` | | :white_check_mark: | | :white_check_mark: | | -| `/repos/{owner}/{repo}/actions/variables/{name}` | :white_check_mark: | :x: | :x: | | | +| `/repos/{owner}/{repo}/actions/variables/{name}` | :white_check_mark: | :white_check_mark: | :x: | | | | `/repos/{owner}/{repo}/actions/workflows` | | :white_check_mark: | | | | | `/repos/{owner}/{repo}/actions/workflows/{workflow_id}` | | :white_check_mark: | | | | | `/repos/{owner}/{repo}/actions/workflows/{workflow_id}/disable` | | | | | :white_check_mark: | @@ -437,7 +437,7 @@ | `/repos/{owner}/{repo}/environments/{environment_name}/secrets/public-key` | | :x: | | | | | `/repos/{owner}/{repo}/environments/{environment_name}/secrets/{secret_name}` | :x: | :x: | | | :x: | | `/repos/{owner}/{repo}/environments/{environment_name}/variables` | | :white_check_mark: | | :white_check_mark: | | -| `/repos/{owner}/{repo}/environments/{environment_name}/variables/{name}` | :white_check_mark: | :x: | :x: | | | +| `/repos/{owner}/{repo}/environments/{environment_name}/variables/{name}` | :white_check_mark: | :white_check_mark: | :x: | | | | `/repos/{owner}/{repo}/events` | | :x: | | | | | `/repos/{owner}/{repo}/forks` | | :white_check_mark: | | :white_check_mark: | | | `/repos/{owner}/{repo}/git/blobs` | | | | :x: | | From 83e1ec5f4e899d583d78ba22915677eed9bb7837 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 17 Mar 2025 16:08:20 +0100 Subject: [PATCH 09/85] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Add=20functions?= =?UTF-8?q?=20to=20remove=20GitHub=20variables=20from=20environments,=20re?= =?UTF-8?q?positories,=20and=20organizations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Remove-GitHubVariableOnEnvironment.ps1 | 61 +++++++++++++ .../Remove-GitHubVariableOnOwner.ps1 | 53 ++++++++++++ .../Remove-GitHubVariableOnRepository.ps1 | 57 ++++++++++++ .../public/Variables/New-GitHubVariable.ps1 | 6 +- .../Variables/Remove-GitHubVariable.ps1 | 86 +++++-------------- 5 files changed, 197 insertions(+), 66 deletions(-) create mode 100644 src/functions/private/Variables/Remove-GitHubVariableOnEnvironment.ps1 create mode 100644 src/functions/private/Variables/Remove-GitHubVariableOnOwner.ps1 create mode 100644 src/functions/private/Variables/Remove-GitHubVariableOnRepository.ps1 diff --git a/src/functions/private/Variables/Remove-GitHubVariableOnEnvironment.ps1 b/src/functions/private/Variables/Remove-GitHubVariableOnEnvironment.ps1 new file mode 100644 index 000000000..f81f609c1 --- /dev/null +++ b/src/functions/private/Variables/Remove-GitHubVariableOnEnvironment.ps1 @@ -0,0 +1,61 @@ +function Remove-GitHubVariableOnEnvironment { + <# + .SYNOPSIS + + .DESCRIPTION + + .EXAMPLE + + .LINK + []() + #> + [OutputType([void])] + [CmdletBinding(SupportsShouldProcess)] + param( + # The account owner of the repository. The name is not case sensitive. + [Parameter(Mandatory)] + [string] $Owner, + + # The name of the repository. The name is not case sensitive. + [Parameter(Mandatory)] + [string] $Repository, + + # The name of the repository environment. + [Parameter(Mandatory)] + [string] $Environment, + + # The name of the variable. + [Parameter(Mandatory)] + [string] $Name, + + # The context to run the command in. Used to get the details for the API call. + # Can be either a string or a GitHubContext object. + [Parameter(Mandatory)] + [object] $Context + ) + + begin { + $stackPath = Get-PSCallStackPath + Write-Debug "[$stackPath] - Start" + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + } + + process { + $inputObject = @{ + Method = 'DELETE' + APIEndpoint = "/repos/$Owner/$Repository/environments/$Environment/variables/$Name" + Context = $Context + } + + if ($PSCmdlet.ShouldProcess("variable [$Name] on [$Owner/$Repository/$Environment]", 'Delete')) { + Invoke-GitHubAPI @inputObject + # Invoke-GitHubAPI @inputObject | ForeEach-Object { + # Write-Output $_.Response + # } + } + } + + end { + Write-Debug "[$stackPath] - End" + } +} diff --git a/src/functions/private/Variables/Remove-GitHubVariableOnOwner.ps1 b/src/functions/private/Variables/Remove-GitHubVariableOnOwner.ps1 new file mode 100644 index 000000000..24cf9c3b7 --- /dev/null +++ b/src/functions/private/Variables/Remove-GitHubVariableOnOwner.ps1 @@ -0,0 +1,53 @@ +function Remove-GitHubVariableOnOwner { + <# + .SYNOPSIS + + .DESCRIPTION + + .EXAMPLE + + .LINK + []() + #> + [OutputType([void])] + [CmdletBinding(SupportsShouldProcess)] + param( + # The account owner of the repository. The name is not case sensitive. + [Parameter(Mandatory)] + [string] $Owner, + + # The name of the variable. + [Parameter(Mandatory)] + [string] $Name, + + # The context to run the command in. Used to get the details for the API call. + # Can be either a string or a GitHubContext object. + [Parameter(Mandatory)] + [object] $Context + ) + + begin { + $stackPath = Get-PSCallStackPath + Write-Debug "[$stackPath] - Start" + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + } + + process { + $inputObject = @{ + Method = 'DELETE' + APIEndpoint = "/orgs/$Owner/actions/variables/$Name" + Context = $Context + } + + if ($PSCmdlet.ShouldProcess("variable [$Name] on [$Owner]", 'Delete')) { + Invoke-GitHubAPI @inputObject + # Invoke-GitHubAPI @inputObject | ForeEach-Object { + # Write-Output $_.Response + # } + } + } + + end { + Write-Debug "[$stackPath] - End" + } +} diff --git a/src/functions/private/Variables/Remove-GitHubVariableOnRepository.ps1 b/src/functions/private/Variables/Remove-GitHubVariableOnRepository.ps1 new file mode 100644 index 000000000..19c4459be --- /dev/null +++ b/src/functions/private/Variables/Remove-GitHubVariableOnRepository.ps1 @@ -0,0 +1,57 @@ +function Remove-GitHubVariableOnRepository { + <# + .SYNOPSIS + + .DESCRIPTION + + .EXAMPLE + + .LINK + []() + #> + [OutputType([void])] + [CmdletBinding(SupportsShouldProcess)] + param( + # The account owner of the repository. The name is not case sensitive. + [Parameter(Mandatory)] + [string] $Owner, + + # The name of the repository. The name is not case sensitive. + [Parameter(Mandatory)] + [string] $Repository, + + # The name of the variable. + [Parameter(Mandatory)] + [string] $Name, + + # The context to run the command in. Used to get the details for the API call. + # Can be either a string or a GitHubContext object. + [Parameter(Mandatory)] + [object] $Context + ) + + begin { + $stackPath = Get-PSCallStackPath + Write-Debug "[$stackPath] - Start" + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + } + + process { + $inputObject = @{ + Method = 'DELETE' + APIEndpoint = "/repos/$Owner/$Repository/actions/variables/$Name" + Context = $Context + } + + if ($PSCmdlet.ShouldProcess("variable [$Name] on [$Owner/$Repository]", 'Delete')) { + Invoke-GitHubAPI @inputObject + # Invoke-GitHubAPI @inputObject | ForeEach-Object { + # Write-Output $_.Response + # } + } + } + + end { + Write-Debug "[$stackPath] - End" + } +} diff --git a/src/functions/public/Variables/New-GitHubVariable.ps1 b/src/functions/public/Variables/New-GitHubVariable.ps1 index fe6a1b5f8..bc0a89f6c 100644 --- a/src/functions/public/Variables/New-GitHubVariable.ps1 +++ b/src/functions/public/Variables/New-GitHubVariable.ps1 @@ -3,11 +3,11 @@ function New-GitHubVariable { #> [Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSUseShouldProcessForStateChangingFunctions', '', - Scope = 'Function', Justification = 'This check is performed in the private functions.' + 'PSShouldProcess', '', Scope = 'Function', + Justification = 'This check is performed in the private functions.' )] [OutputType([void])] - [CmdletBinding()] + [CmdletBinding(SupportsShouldProcess)] param( # The account owner of the repository. The name is not case sensitive. [Parameter(Mandatory, ParameterSetName = 'Organization')] diff --git a/src/functions/public/Variables/Remove-GitHubVariable.ps1 b/src/functions/public/Variables/Remove-GitHubVariable.ps1 index e722dae03..408770f36 100644 --- a/src/functions/public/Variables/Remove-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Remove-GitHubVariable.ps1 @@ -1,62 +1,32 @@ function Remove-GitHubVariable { <# - .SYNOPSIS - Removes a GitHub variable from an Organisation, Repository or Environment. - .DESCRIPTION - Removes a GitHub variable from an Organisation, Repository or Environment. - - .PARAMETER Owner - The account owner of the repository. The name is not case-sensitive. - - .PARAMETER Repository - The name of the repository. The name is not case-sensitive. - - .PARAMETER Environment - The name of the repository environment. - - .PARAMETER Name - The name of the variable. - - .PARAMETER Context - The context to run the command in. Used to get the details for the API call. - - .EXAMPLE - Remove-GitHubVariable -Owner "octocat" -Repository "Hello-World" -Environment "dev" -Name "myVariable" - Remove-GitHubVariable -Owner "octocat" -Repository "Hello-World" -Name "myVariable" - Remove-GitHubVariable -Owner "octocat" -Name "myVariable" - - .NOTES - [Delete an Organisation Variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#delete-an-organization-variable) - [Delete a Repository Variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#delete-a-repository-variable) - [Delete an Environment Variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#delete-an-environment-variable) - - .OUTPUTS - psobject[] #> + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSShouldProcess', '', Scope = 'Function', + Justification = 'This check is performed in the private functions.' + )] [OutputType([psobject[]])] [CmdletBinding(SupportsShouldProcess)] param( - [Parameter(ParameterSetName = 'Organization', Mandatory)] - [Parameter(ParameterSetName = 'Repository', Mandatory)] - [Parameter(ParameterSetName = 'Environment', Mandatory)] + # The account owner of the repository. The name is not case sensitive. + [Parameter(Mandatory, ParameterSetName = 'Organization')] + [Parameter(Mandatory, ParameterSetName = 'Repository')] + [Parameter(Mandatory, ParameterSetName = 'Environment')] [Alias('Organization', 'User')] [string] $Owner, # The name of the repository. The name is not case sensitive. - [Parameter(ParameterSetName = 'Repository', Mandatory)] - [Parameter(ParameterSetName = 'Environment', Mandatory)] + [Parameter(Mandatory, ParameterSetName = 'Repository')] + [Parameter(Mandatory, ParameterSetName = 'Environment')] [string] $Repository, # The name of the repository environment. - [Parameter(ParameterSetName = 'Environment', Mandatory)] + [Parameter(Mandatory, ParameterSetName = 'Environment')] [string] $Environment, # The name of the variable. - - [Parameter(ParameterSetName = 'Organization', Mandatory)] - [Parameter(ParameterSetName = 'Repository', Mandatory)] - [Parameter(ParameterSetName = 'Environment', Mandatory)] + [Parameter(Mandatory)] [string] $Name, # The context to run the command in. Used to get the details for the API call. @@ -73,28 +43,18 @@ function Remove-GitHubVariable { } process { - $inputObject = @{ - Method = 'DELETE' - APIEndpoint = switch ($PSCmdlet.ParameterSetName) { - 'Environment' { - "/repos/$Owner/$Repository/environments/$Environment/variables/$Name" - break - } - 'Repository' { - "/repos/$Owner/$Repository/actions/variables/$Name" - break - } - 'Organization' { - "/orgs/$Owner/actions/variables/$Name" - break - } + switch ($PSCmdlet.ParameterSetName) { + 'Organization' { + Remove-GitHubVariableOnOwner -Owner $Owner -Name $Name -Context $Context + break } - Context = $Context - } - - if ($PSCmdlet.ShouldProcess("Variable [$Name]", 'DELETE')) { - Invoke-GitHubAPI @inputObject | ForeEach-Object { - Write-Output $_.Response + 'Repository' { + Remove-GitHubVariableOnRepository -Owner $Owner -Repository $Repository -Name $Name -Context $Context + break + } + 'Environment' { + Remove-GitHubVariableOnEnvironment -Owner $Owner -Repository $Repository -Environment $Environment -Name $Name -Context $Context + break } } } From 7c906a5524a80183ad18d1b47c0b23e5fe996cea Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 17 Mar 2025 16:54:10 +0100 Subject: [PATCH 10/85] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Enhance=20docum?= =?UTF-8?q?entation=20for=20variable=20removal=20functions=20and=20improve?= =?UTF-8?q?=20parameter=20handling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Remove-GitHubVariableOnEnvironment.ps1 | 16 +++++-- .../Remove-GitHubVariableOnOwner.ps1 | 16 +++++-- .../Remove-GitHubVariableOnRepository.ps1 | 15 ++++-- .../Variables/Remove-GitHubVariable.ps1 | 46 ++++++++++++++++--- 4 files changed, 73 insertions(+), 20 deletions(-) diff --git a/src/functions/private/Variables/Remove-GitHubVariableOnEnvironment.ps1 b/src/functions/private/Variables/Remove-GitHubVariableOnEnvironment.ps1 index f81f609c1..9bd0c484d 100644 --- a/src/functions/private/Variables/Remove-GitHubVariableOnEnvironment.ps1 +++ b/src/functions/private/Variables/Remove-GitHubVariableOnEnvironment.ps1 @@ -1,13 +1,20 @@ function Remove-GitHubVariableOnEnvironment { <# .SYNOPSIS + Delete an environment variable. .DESCRIPTION + Deletes an environment variable using the variable name. + Authenticated users must have collaborator access to a repository to create, update, or read variables. + OAuth tokens and personal access tokens (classic) need the `repo` scope to use this endpoint. .EXAMPLE + Remove-GitHubVariableOnEnvironment -Owner 'octocat' -Repository 'Hello-World' -Environment 'dev' -Name 'HOST_NAME' -Context $GitHubContext + + Deletes the specified variable from the specified environment. .LINK - []() + [Delete an environment variable](https://docs.github.com/rest/actions/variables#delete-an-environment-variable) #> [OutputType([void])] [CmdletBinding(SupportsShouldProcess)] @@ -48,10 +55,9 @@ function Remove-GitHubVariableOnEnvironment { } if ($PSCmdlet.ShouldProcess("variable [$Name] on [$Owner/$Repository/$Environment]", 'Delete')) { - Invoke-GitHubAPI @inputObject - # Invoke-GitHubAPI @inputObject | ForeEach-Object { - # Write-Output $_.Response - # } + Invoke-GitHubAPI @inputObject | ForeEach-Object { + Write-Output $_.Response + } } } diff --git a/src/functions/private/Variables/Remove-GitHubVariableOnOwner.ps1 b/src/functions/private/Variables/Remove-GitHubVariableOnOwner.ps1 index 24cf9c3b7..4785c978e 100644 --- a/src/functions/private/Variables/Remove-GitHubVariableOnOwner.ps1 +++ b/src/functions/private/Variables/Remove-GitHubVariableOnOwner.ps1 @@ -1,13 +1,21 @@ function Remove-GitHubVariableOnOwner { <# .SYNOPSIS + Delete an organization variable. .DESCRIPTION + Deletes an organization variable using the variable name. + Authenticated users must have collaborator access to a repository to create, update, or read variables. + OAuth tokens and personal access tokens (classic) need the`admin:org` scope to use this endpoint. If the repository is private, + OAuth tokens and personal access tokens (classic) need the `repo` scope to use this endpoint. .EXAMPLE + Remove-GitHubVariableOnOwner -Owner 'octocat' -Name 'HOST_NAME' -Context $GitHubContext + + Deletes the specified variable from the specified organization. .LINK - []() + [Delete an organization variable](https://docs.github.com/rest/actions/variables#delete-an-organization-variable) #> [OutputType([void])] [CmdletBinding(SupportsShouldProcess)] @@ -41,9 +49,9 @@ function Remove-GitHubVariableOnOwner { if ($PSCmdlet.ShouldProcess("variable [$Name] on [$Owner]", 'Delete')) { Invoke-GitHubAPI @inputObject - # Invoke-GitHubAPI @inputObject | ForeEach-Object { - # Write-Output $_.Response - # } + Invoke-GitHubAPI @inputObject | ForeEach-Object { + Write-Output $_.Response + } } } diff --git a/src/functions/private/Variables/Remove-GitHubVariableOnRepository.ps1 b/src/functions/private/Variables/Remove-GitHubVariableOnRepository.ps1 index 19c4459be..5ec72507e 100644 --- a/src/functions/private/Variables/Remove-GitHubVariableOnRepository.ps1 +++ b/src/functions/private/Variables/Remove-GitHubVariableOnRepository.ps1 @@ -1,13 +1,20 @@ function Remove-GitHubVariableOnRepository { <# .SYNOPSIS + Delete a repository variable. .DESCRIPTION + Deletes a repository variable using the variable name. + Authenticated users must have collaborator access to a repository to create, update, or read variables. + OAuth tokens and personal access tokens (classic) need the `repo` scope to use this endpoint. .EXAMPLE + Remove-GitHubVariableOnRepository -Owner 'octocat' -Repository 'Hello-World' -Name 'HOST_NAME' -Context $GitHubContext + + Deletes the specified variable from the specified repository. .LINK - []() + [Delete a repository variable](https://docs.github.com/rest/actions/variables#delete-a-repository-variable) #> [OutputType([void])] [CmdletBinding(SupportsShouldProcess)] @@ -45,9 +52,9 @@ function Remove-GitHubVariableOnRepository { if ($PSCmdlet.ShouldProcess("variable [$Name] on [$Owner/$Repository]", 'Delete')) { Invoke-GitHubAPI @inputObject - # Invoke-GitHubAPI @inputObject | ForeEach-Object { - # Write-Output $_.Response - # } + Invoke-GitHubAPI @inputObject | ForeEach-Object { + Write-Output $_.Response + } } } diff --git a/src/functions/public/Variables/Remove-GitHubVariable.ps1 b/src/functions/public/Variables/Remove-GitHubVariable.ps1 index 408770f36..b95994d54 100644 --- a/src/functions/public/Variables/Remove-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Remove-GitHubVariable.ps1 @@ -1,6 +1,38 @@ function Remove-GitHubVariable { <# + .SYNOPSIS + Deletes a GitHub variable from an organization, repository, or environment. + .DESCRIPTION + Deletes a GitHub variable based on the provided scope (organization, repository, or environment). + + This function routes the request to the appropriate private function based on the provided parameters. + + Authenticated users must have collaborator access to a repository to manage variables. + OAuth tokens and personal access tokens (classic) require specific scopes: + - `admin:org` for organization-level variables. + - `repo` for repository and environment-level variables. + + .EXAMPLE + Remove-GitHubVariable -Owner 'octocat' -Name 'HOST_NAME' -Context $GitHubContext + + Deletes the specified variable from the specified organization. + + .EXAMPLE + Remove-GitHubVariable -Owner 'octocat' -Repository 'Hello-World' -Name 'HOST_NAME' -Context $GitHubContext + + Deletes the specified variable from the specified repository. + + .EXAMPLE + Remove-GitHubVariable -Owner 'octocat' -Repository 'Hello-World' -Environment 'dev' -Name 'HOST_NAME' -Context $GitHubContext + + Deletes the specified variable from the specified environment. + + .OUTPUTS + void + + .LINK + https://psmodule.io/GitHub/Functions/Variables/Remove-GitHubVariable/ #> [Diagnostics.CodeAnalysis.SuppressMessageAttribute( 'PSShouldProcess', '', Scope = 'Function', @@ -10,23 +42,23 @@ function Remove-GitHubVariable { [CmdletBinding(SupportsShouldProcess)] param( # The account owner of the repository. The name is not case sensitive. - [Parameter(Mandatory, ParameterSetName = 'Organization')] - [Parameter(Mandatory, ParameterSetName = 'Repository')] - [Parameter(Mandatory, ParameterSetName = 'Environment')] + [Parameter(Mandatory, ParameterSetName = 'Organization', ValueFromPipelineByPropertyName)] + [Parameter(Mandatory, ParameterSetName = 'Repository', ValueFromPipelineByPropertyName)] + [Parameter(Mandatory, ParameterSetName = 'Environment', ValueFromPipelineByPropertyName)] [Alias('Organization', 'User')] [string] $Owner, # The name of the repository. The name is not case sensitive. - [Parameter(Mandatory, ParameterSetName = 'Repository')] - [Parameter(Mandatory, ParameterSetName = 'Environment')] + [Parameter(Mandatory, ParameterSetName = 'Repository', ValueFromPipelineByPropertyName)] + [Parameter(Mandatory, ParameterSetName = 'Environment', ValueFromPipelineByPropertyName)] [string] $Repository, # The name of the repository environment. - [Parameter(Mandatory, ParameterSetName = 'Environment')] + [Parameter(Mandatory, ParameterSetName = 'Environment', ValueFromPipelineByPropertyName)] [string] $Environment, # The name of the variable. - [Parameter(Mandatory)] + [Parameter(Mandatory, ValueFromPipelineByPropertyName)] [string] $Name, # The context to run the command in. Used to get the details for the API call. From a6818fad36c56487ad3a5f2ee8926a27f3a4e829 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 17 Mar 2025 17:06:41 +0100 Subject: [PATCH 11/85] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Enhance=20Remov?= =?UTF-8?q?e-GitHubVariable=20function=20to=20support=20array=20input=20an?= =?UTF-8?q?d=20improve=20parameter=20handling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Variables/Remove-GitHubVariable.ps1 | 87 ++++++++++++++----- 1 file changed, 65 insertions(+), 22 deletions(-) diff --git a/src/functions/public/Variables/Remove-GitHubVariable.ps1 b/src/functions/public/Variables/Remove-GitHubVariable.ps1 index b95994d54..776e84f4a 100644 --- a/src/functions/public/Variables/Remove-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Remove-GitHubVariable.ps1 @@ -6,7 +6,7 @@ function Remove-GitHubVariable { .DESCRIPTION Deletes a GitHub variable based on the provided scope (organization, repository, or environment). - This function routes the request to the appropriate private function based on the provided parameters. + Supports pipeline input from Get-GitHubVariable or direct array input. Authenticated users must have collaborator access to a repository to manage variables. OAuth tokens and personal access tokens (classic) require specific scopes: @@ -14,19 +14,22 @@ function Remove-GitHubVariable { - `repo` for repository and environment-level variables. .EXAMPLE - Remove-GitHubVariable -Owner 'octocat' -Name 'HOST_NAME' -Context $GitHubContext + Get-GitHubVariable -Owner 'octocat' -Repository 'Hello-World' | Remove-GitHubVariable - Deletes the specified variable from the specified organization. + Removes all variables retrieved from the specified repository. .EXAMPLE - Remove-GitHubVariable -Owner 'octocat' -Repository 'Hello-World' -Name 'HOST_NAME' -Context $GitHubContext + Remove-GitHubVariable -Owner 'octocat' -Name 'HOST_NAME' -Context $GitHubContext - Deletes the specified variable from the specified repository. + Deletes the specified variable from the specified organization. .EXAMPLE - Remove-GitHubVariable -Owner 'octocat' -Repository 'Hello-World' -Environment 'dev' -Name 'HOST_NAME' -Context $GitHubContext + Remove-GitHubVariable -Variable $variablesArray - Deletes the specified variable from the specified environment. + Removes all variables provided in the array. + + .INPUTS + GitHubVariable .OUTPUTS void @@ -38,33 +41,29 @@ function Remove-GitHubVariable { 'PSShouldProcess', '', Scope = 'Function', Justification = 'This check is performed in the private functions.' )] - [OutputType([psobject[]])] [CmdletBinding(SupportsShouldProcess)] param( - # The account owner of the repository. The name is not case sensitive. [Parameter(Mandatory, ParameterSetName = 'Organization', ValueFromPipelineByPropertyName)] [Parameter(Mandatory, ParameterSetName = 'Repository', ValueFromPipelineByPropertyName)] [Parameter(Mandatory, ParameterSetName = 'Environment', ValueFromPipelineByPropertyName)] [Alias('Organization', 'User')] [string] $Owner, - # The name of the repository. The name is not case sensitive. [Parameter(Mandatory, ParameterSetName = 'Repository', ValueFromPipelineByPropertyName)] [Parameter(Mandatory, ParameterSetName = 'Environment', ValueFromPipelineByPropertyName)] [string] $Repository, - # The name of the repository environment. [Parameter(Mandatory, ParameterSetName = 'Environment', ValueFromPipelineByPropertyName)] [string] $Environment, - # The name of the variable. [Parameter(Mandatory, ValueFromPipelineByPropertyName)] [string] $Name, - # The context to run the command in. Used to get the details for the API call. - # Can be either a string or a GitHubContext object. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(ValueFromPipelineByPropertyName)] + [object] $Context = (Get-GitHubContext), + + [Parameter(Mandatory, ParameterSetName = 'ArrayInput')] + [GitHubVariable[]] $InputObject ) begin { @@ -76,17 +75,61 @@ function Remove-GitHubVariable { process { switch ($PSCmdlet.ParameterSetName) { + 'ArrayInput' { + foreach ($item in $InputObject) { + if ($item.Environment) { + $params = @{ + Owner = $item.Owner + Repository = $item.Repository + Environment = $item.Environment + Name = $item.Name + Context = $Context + } + Remove-GitHubVariableOnEnvironment @params + } elseif ($item.Repository) { + $params = @{ + Owner = $item.Owner + Repository = $item.Repository + Name = $item.Name + Context = $Context + } + Remove-GitHubVariableOnRepository @params + } else { + $params = @{ + Owner = $item.Owner + Name = $item.Name + Context = $Context + } + Remove-GitHubVariableOnOwner @params + } + } + } 'Organization' { - Remove-GitHubVariableOnOwner -Owner $Owner -Name $Name -Context $Context - break + $params = @{ + Owner = $Owner + Name = $Name + Context = $Context + } + Remove-GitHubVariableOnOwner @params } 'Repository' { - Remove-GitHubVariableOnRepository -Owner $Owner -Repository $Repository -Name $Name -Context $Context - break + $params = @{ + Owner = $Owner + Repository = $Repository + Name = $Name + Context = $Context + } + Remove-GitHubVariableOnRepository @params } 'Environment' { - Remove-GitHubVariableOnEnvironment -Owner $Owner -Repository $Repository -Environment $Environment -Name $Name -Context $Context - break + $params = @{ + Owner = $Owner + Repository = $Repository + Environment = $Environment + Name = $Name + Context = $Context + } + Remove-GitHubVariableOnEnvironment @params } } } From a7506b1ac88a6861d4ec61c0323621a47aa418a5 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 17 Mar 2025 17:08:01 +0100 Subject: [PATCH 12/85] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20Remove?= =?UTF-8?q?-GitHubVariable=20to=20allow=20pipeline=20input=20for=20array?= =?UTF-8?q?=20parameters?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/functions/public/Variables/Remove-GitHubVariable.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions/public/Variables/Remove-GitHubVariable.ps1 b/src/functions/public/Variables/Remove-GitHubVariable.ps1 index 776e84f4a..2435f22e8 100644 --- a/src/functions/public/Variables/Remove-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Remove-GitHubVariable.ps1 @@ -62,7 +62,7 @@ function Remove-GitHubVariable { [Parameter(ValueFromPipelineByPropertyName)] [object] $Context = (Get-GitHubContext), - [Parameter(Mandatory, ParameterSetName = 'ArrayInput')] + [Parameter(Mandatory, ParameterSetName = 'ArrayInput', ValueFromPipeline)] [GitHubVariable[]] $InputObject ) From c8df89a5f38e65aea8d0bdd524b508dd4ba39c09 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 17 Mar 2025 17:16:02 +0100 Subject: [PATCH 13/85] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Refactor=20vari?= =?UTF-8?q?able=20removal=20functions=20to=20use=20ForEach-Object=20consis?= =?UTF-8?q?tently=20for=20improved=20readability?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../private/Variables/Remove-GitHubVariableOnEnvironment.ps1 | 2 +- .../private/Variables/Remove-GitHubVariableOnOwner.ps1 | 3 +-- .../private/Variables/Remove-GitHubVariableOnRepository.ps1 | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/functions/private/Variables/Remove-GitHubVariableOnEnvironment.ps1 b/src/functions/private/Variables/Remove-GitHubVariableOnEnvironment.ps1 index 9bd0c484d..3ae29bba2 100644 --- a/src/functions/private/Variables/Remove-GitHubVariableOnEnvironment.ps1 +++ b/src/functions/private/Variables/Remove-GitHubVariableOnEnvironment.ps1 @@ -55,7 +55,7 @@ function Remove-GitHubVariableOnEnvironment { } if ($PSCmdlet.ShouldProcess("variable [$Name] on [$Owner/$Repository/$Environment]", 'Delete')) { - Invoke-GitHubAPI @inputObject | ForeEach-Object { + Invoke-GitHubAPI @inputObject | ForEach-Object { Write-Output $_.Response } } diff --git a/src/functions/private/Variables/Remove-GitHubVariableOnOwner.ps1 b/src/functions/private/Variables/Remove-GitHubVariableOnOwner.ps1 index 4785c978e..2433555fc 100644 --- a/src/functions/private/Variables/Remove-GitHubVariableOnOwner.ps1 +++ b/src/functions/private/Variables/Remove-GitHubVariableOnOwner.ps1 @@ -48,8 +48,7 @@ function Remove-GitHubVariableOnOwner { } if ($PSCmdlet.ShouldProcess("variable [$Name] on [$Owner]", 'Delete')) { - Invoke-GitHubAPI @inputObject - Invoke-GitHubAPI @inputObject | ForeEach-Object { + Invoke-GitHubAPI @inputObject | ForEach-Object { Write-Output $_.Response } } diff --git a/src/functions/private/Variables/Remove-GitHubVariableOnRepository.ps1 b/src/functions/private/Variables/Remove-GitHubVariableOnRepository.ps1 index 5ec72507e..9970eb133 100644 --- a/src/functions/private/Variables/Remove-GitHubVariableOnRepository.ps1 +++ b/src/functions/private/Variables/Remove-GitHubVariableOnRepository.ps1 @@ -51,8 +51,7 @@ function Remove-GitHubVariableOnRepository { } if ($PSCmdlet.ShouldProcess("variable [$Name] on [$Owner/$Repository]", 'Delete')) { - Invoke-GitHubAPI @inputObject - Invoke-GitHubAPI @inputObject | ForeEach-Object { + Invoke-GitHubAPI @inputObject | ForEach-Object { Write-Output $_.Response } } From e18b4a26d659575dc194aac35392b4470fbb10c4 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 17 Mar 2025 20:46:53 +0100 Subject: [PATCH 14/85] cleanup --- src/formats/GitHubContext.Format.ps1xml | 3 --- src/formats/GitHubWebhook.Format.ps1xml | 3 --- src/formats/GitHubWebhookRedelivery.Format.ps1xml | 3 --- 3 files changed, 9 deletions(-) diff --git a/src/formats/GitHubContext.Format.ps1xml b/src/formats/GitHubContext.Format.ps1xml index 5897f2b75..824682b99 100644 --- a/src/formats/GitHubContext.Format.ps1xml +++ b/src/formats/GitHubContext.Format.ps1xml @@ -1,7 +1,6 @@ - GitHubContextTableView @@ -42,8 +41,6 @@ - - GitHubContextListView diff --git a/src/formats/GitHubWebhook.Format.ps1xml b/src/formats/GitHubWebhook.Format.ps1xml index c5b96100e..d8e2eed0d 100644 --- a/src/formats/GitHubWebhook.Format.ps1xml +++ b/src/formats/GitHubWebhook.Format.ps1xml @@ -1,7 +1,6 @@ - GitHubWebhookTable @@ -79,8 +78,6 @@ - - GitHubWebhookList diff --git a/src/formats/GitHubWebhookRedelivery.Format.ps1xml b/src/formats/GitHubWebhookRedelivery.Format.ps1xml index dab55ba4c..1e87f79c2 100644 --- a/src/formats/GitHubWebhookRedelivery.Format.ps1xml +++ b/src/formats/GitHubWebhookRedelivery.Format.ps1xml @@ -1,7 +1,6 @@ - GitHubWebhookRedeliveryTable @@ -60,8 +59,6 @@ - - GitHubWebhookRedeliveryList From 6ce319aa0053e337a54c0663e889c264b6f4e49d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 17 Mar 2025 21:43:13 +0100 Subject: [PATCH 15/85] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Rename=20Select?= =?UTF-8?q?edRepository=20parameter=20to=20SelectedRepositories=20for=20co?= =?UTF-8?q?nsistency=20and=20clarity;=20add=20Update-GitHubVariableOnRepos?= =?UTF-8?q?itory=20and=20Update-GitHubVariableOnEnvironment=20functions=20?= =?UTF-8?q?for=20managing=20GitHub=20variables.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Variables/New-GitHubVariableOnOwner.ps1 | 8 +- .../Update-GitHubVariableOnEnvironment.ps1 | 93 ++++++++++++ .../Update-GitHubVariableOnOwner.ps1 | 104 ++++++++++++++ .../Update-GitHubVariableOnRepository.ps1 | 80 +++++++++++ .../public/Variables/New-GitHubVariable.ps1 | 50 ++++++- .../Variables/Update-GitHubVariable.ps1 | 132 ++++++++++++++++++ 6 files changed, 456 insertions(+), 11 deletions(-) create mode 100644 src/functions/private/Variables/Update-GitHubVariableOnEnvironment.ps1 create mode 100644 src/functions/private/Variables/Update-GitHubVariableOnOwner.ps1 create mode 100644 src/functions/private/Variables/Update-GitHubVariableOnRepository.ps1 create mode 100644 src/functions/public/Variables/Update-GitHubVariable.ps1 diff --git a/src/functions/private/Variables/New-GitHubVariableOnOwner.ps1 b/src/functions/private/Variables/New-GitHubVariableOnOwner.ps1 index 8a396f1f1..3a5f28c18 100644 --- a/src/functions/private/Variables/New-GitHubVariableOnOwner.ps1 +++ b/src/functions/private/Variables/New-GitHubVariableOnOwner.ps1 @@ -43,7 +43,7 @@ function New-GitHubVariableOnOwner { # This parameter is only used when the `-Visibility` parameter is set to `selected`. # The IDs can be obtained from the `Get-GitHubRepository` function. [Parameter()] - [UInt64[]] $SelectedRepository, + [UInt64[]] $SelectedRepositories, # The context to run the command in. Used to get the details for the API call. # Can be either a string or a GitHubContext object. @@ -65,10 +65,10 @@ function New-GitHubVariableOnOwner { } if ($Visibility -eq 'selected') { - if (-not $SelectedRepository) { - throw 'You must specify the -SelectedRepository parameter when using the -Visibility selected switch.' + if (-not $SelectedRepositories) { + throw 'You must specify the -SelectedRepositories parameter when using the -Visibility selected switch.' } - $body['selected_repository_ids'] = $SelectedRepository + $body['selected_repository_ids'] = $SelectedRepositories } $inputObject = @{ diff --git a/src/functions/private/Variables/Update-GitHubVariableOnEnvironment.ps1 b/src/functions/private/Variables/Update-GitHubVariableOnEnvironment.ps1 new file mode 100644 index 000000000..ace54f70e --- /dev/null +++ b/src/functions/private/Variables/Update-GitHubVariableOnEnvironment.ps1 @@ -0,0 +1,93 @@ +function Update-GitHubVariableOnEnvironment { + <# + .SYNOPSIS + Update an environment variable. + + .DESCRIPTION + Updates an environment variable that you can reference in a GitHub Actions workflow. + Authenticated users must have collaborator access to a repository to create, update, or read variables. + OAuth app tokens and personal access tokens (classic) need the `repo` scope to use this endpoint. + + + .EXAMPLE + $params = @{ + Owner = 'octocat' + Repository = 'Hello-World' + Environment = 'dev' + Name = 'HOST_NAME' + Value = 'github.com' + Context = $GitHubContext + } + Update-GitHubVariableOnEnvironment @params + + Updates the environment variable named `HOST_NAME` with the value `github.com` in the specified environment. + + .LINK + [Update an environment variable](https://docs.github.com/rest/actions/variables#update-an-environment-variable) + #> + [OutputType([void])] + [CmdletBinding(SupportsShouldProcess)] + param( + # The account owner of the repository. The name is not case sensitive. + [Parameter(Mandatory)] + [string] $Owner, + + # The name of the repository. The name is not case sensitive. + [Parameter(Mandatory)] + [string] $Repository, + + # The name of the repository environment. + [Parameter(Mandatory)] + [string] $Environment, + + # The name of the variable. + [Parameter(Mandatory)] + [string] $Name, + + # The new name of the variable. + [Parameter()] + [string] $NewName, + + # The value of the variable. + [Parameter()] + [string] $Value, + + # The context to run the command in. Used to get the details for the API call. + # Can be either a string or a GitHubContext object. + [Parameter(Mandatory)] + [object] $Context + ) + + begin { + $stackPath = Get-PSCallStackPath + Write-Debug "[$stackPath] - Start" + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + } + + process { + $body = @{} + if ($PSBoundParameters.ContainsKey('NewName')) { + $body.name = $NewName + } + if ($PSBoundParameters.ContainsKey('Value')) { + $body.value = $Value + } + + $inputObject = @{ + Method = 'PATCH' + APIEndpoint = "/repos/$Owner/$Repository/environments/$Environment/variables/$Name" + Body = $body + Context = $Context + } + + if ($PSCmdlet.ShouldProcess("variable [$Name] on [$Owner/$Repository/$Environment]", 'Update')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } + } + + end { + Write-Debug "[$stackPath] - End" + } +} diff --git a/src/functions/private/Variables/Update-GitHubVariableOnOwner.ps1 b/src/functions/private/Variables/Update-GitHubVariableOnOwner.ps1 new file mode 100644 index 000000000..5c7fd9984 --- /dev/null +++ b/src/functions/private/Variables/Update-GitHubVariableOnOwner.ps1 @@ -0,0 +1,104 @@ +function Update-GitHubVariableOnOwner { + <# + .SYNOPSIS + Update an organization variable. + + .DESCRIPTION + Updates an organization variable that you can reference in a GitHub Actions workflow. + Authenticated users must have collaborator access to a repository to create, update, or read variables. + OAuth app tokens and personal access tokens (classic) need the `admin:org` scope to use this endpoint. If the repository is private, + the `repo` scope is also required. + + .EXAMPLE + Update-GitHubVariableOnOwner -Owner 'octocat' -Name 'HOST_NAME' -Value 'github.com' -Context $GitHubContext + + Updates the organization variable named `HOST_NAME` with the value `github.com` in the specified organization. + + .LINK + [Update an organization variable](https://docs.github.com/rest/actions/variables#update-an-organization-variable) + #> + [OutputType([void])] + [CmdletBinding(SupportsShouldProcess)] + param( + # The account owner of the repository. The name is not case sensitive. + [Parameter(Mandatory)] + [string] $Owner, + + # The name of the variable. + [Parameter(Mandatory)] + [string] $Name, + + # The new name of the variable. + [Parameter()] + [string] $NewName, + + # The value of the variable. + [Parameter(Mandatory)] + [string] $Value, + + # The visibility of the variable. Can be `private`, `selected`, or `all`. + # `private` - The variable is only available to the organization. + # `selected` - The variable is available to selected repositories. + # `all` - The variable is available to all repositories in the organization. + [Parameter()] + [ValidateSet('private', 'selected', 'all')] + [string] $Visibility, + + # The IDs of the repositories to which the variable is available. + # This parameter is only used when the `-Visibility` parameter is set to `selected`. + # The IDs can be obtained from the `Get-GitHubRepository` function. + [Parameter()] + [UInt64[]] $SelectedRepositories, + + # The context to run the command in. Used to get the details for the API call. + # Can be either a string or a GitHubContext object. + [Parameter(Mandatory)] + [object] $Context + ) + + begin { + $stackPath = Get-PSCallStackPath + Write-Debug "[$stackPath] - Start" + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + } + + process { + $body = @{} + if ($PSBoundParameters.ContainsKey('NewName')) { + $body.name = $NewName + } + if ($PSBoundParameters.ContainsKey('Value')) { + $body.value = $Value + } + if ($PSBoundParameters.ContainsKey('Visibility')) { + $body.visibility = $Visibility + } + if ($PSBoundParameters.ContainsKey('SelectedRepositories')) { + $body.selected_repository_ids = $SelectedRepositories + } + + if ($Visibility -eq 'selected') { + if (-not $SelectedRepositories) { + throw 'You must specify the -SelectedRepositories parameter when using the -Visibility selected switch.' + } + $body['selected_repository_ids'] = $SelectedRepositories + } + + $inputObject = @{ + Method = 'PATCH' + APIEndpoint = "/orgs/$Owner/actions/variables/$Name" + Body = $body + Context = $Context + } + + if ($PSCmdlet.ShouldProcess("variable [$Name] on [$Owner]", 'Update')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } + } + + end { + Write-Debug "[$stackPath] - End" + } +} diff --git a/src/functions/private/Variables/Update-GitHubVariableOnRepository.ps1 b/src/functions/private/Variables/Update-GitHubVariableOnRepository.ps1 new file mode 100644 index 000000000..47e6bce5e --- /dev/null +++ b/src/functions/private/Variables/Update-GitHubVariableOnRepository.ps1 @@ -0,0 +1,80 @@ +function Update-GitHubVariableOnRepository { + <# + .SYNOPSIS + Update a repository variable. + + .DESCRIPTION + Updates a repository variable that you can reference in a GitHub Actions workflow. + Authenticated users must have collaborator access to a repository to create, update, or read variables. + OAuth app tokens and personal access tokens (classic) need the `repo` scope to use this endpoint. + + .EXAMPLE + Update-GitHubVariableOnRepository -Owner 'octocat' -Repository 'Hello-World' -Name 'HOST_NAME' -Value 'github.com' -Context $GitHubContext + + Updates the repository variable named `HOST_NAME` with the value `github.com` in the specified repository. + + .LINK + [Update a repository variable](https://docs.github.com/rest/actions/variables#update-a-repository-variable) + #> + [OutputType([void])] + [CmdletBinding(SupportsShouldProcess)] + param( + # The account owner of the repository. The name is not case sensitive. + [Parameter(Mandatory)] + [string] $Owner, + + # The name of the repository. The name is not case sensitive. + [Parameter(Mandatory)] + [string] $Repository, + + # The name of the variable. + [Parameter(Mandatory)] + [string] $Name, + + # The new name of the variable. + [Parameter()] + [string] $NewName, + + # The value of the variable. + [Parameter()] + [string] $Value, + + # The context to run the command in. Used to get the details for the API call. + # Can be either a string or a GitHubContext object. + [Parameter(Mandatory)] + [object] $Context + ) + + begin { + $stackPath = Get-PSCallStackPath + Write-Debug "[$stackPath] - Start" + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + } + + process { + $body = @{} + if ($PSBoundParameters.ContainsKey('NewName')) { + $body.name = $NewName + } + if ($PSBoundParameters.ContainsKey('Value')) { + $body.value = $Value + } + + $inputObject = @{ + Method = 'PATCH' + APIEndpoint = "/repos/$Owner/$Repository/actions/variables" + Body = $body + Context = $Context + } + + if ($PSCmdlet.ShouldProcess("variable [$Name] on [$Owner/$Repository]", 'Update')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } + } + + end { + Write-Debug "[$stackPath] - End" + } +} diff --git a/src/functions/public/Variables/New-GitHubVariable.ps1 b/src/functions/public/Variables/New-GitHubVariable.ps1 index bc0a89f6c..1aed0f45c 100644 --- a/src/functions/public/Variables/New-GitHubVariable.ps1 +++ b/src/functions/public/Variables/New-GitHubVariable.ps1 @@ -1,6 +1,35 @@ function New-GitHubVariable { <# + .SYNOPSIS + Creates a GitHub Actions variable at the organization, repository, or environment level. + .DESCRIPTION + This function creates a GitHub Actions variable that can be referenced in a workflow. The variable can be scoped to an organization, + repository, or environment. + + - Organization-level variables require the `admin:org` scope for OAuth tokens and personal access tokens (classic). If the repository is + private, the `repo` scope is also required. + - Repository-level variables require the `repo` scope. + - Environment-level variables require collaborator access to the repository. + + .EXAMPLE + New-GitHubVariable -Owner 'octocat' -Repository 'Hello-World' -Name 'HOST_NAME' -Value 'github.com' -Context $GitHubContext + + Creates a new repository variable named `HOST_NAME` with the value `github.com` in the specified repository. + + .EXAMPLE + New-GitHubVariable -Owner 'octocat' -Name 'HOST_NAME' -Value 'github.com' -Visibility 'all' -Context $GitHubContext + + Creates a new organization variable named `HOST_NAME` with the value `github.com` and + makes it available to all repositories in the organization. + + .EXAMPLE + New-GitHubVariable -Owner 'octocat' -Repository 'Hello-World' -Environment 'dev' -Name 'HOST_NAME' -Value 'github.com' -Context $GitHubContext + + Creates a new environment variable named `HOST_NAME` with the value `github.com` in the specified environment. + + .LINK + https://psmodule.io/GitHub/Functions/Variables/New-GitHubVariable/ #> [Diagnostics.CodeAnalysis.SuppressMessageAttribute( 'PSShouldProcess', '', Scope = 'Function', @@ -29,15 +58,22 @@ function New-GitHubVariable { [Parameter(Mandatory)] [string] $Name, + # The value of the variable. [Parameter(Mandatory)] [string] $Value, + # The visibility of the variable. Can be `private`, `selected`, or `all`. + # `private` - The variable is only available to the organization. + # `selected` - The variable is available to selected repositories. + # `all` - The variable is available to all repositories in the organization. [Parameter(ParameterSetName = 'Organization')] [ValidateSet('private', 'selected', 'all')] [string] $Visibility = 'private', + # The IDs of the repositories to which the variable is available. + # This parameter is only used when the `-Visibility` parameter is set to `selected`. [Parameter(ParameterSetName = 'Organization')] - [UInt64[]] $SelectedRepository, + [UInt64[]] $SelectedRepositories, # The context to run the command in. Used to get the details for the API call. # Can be either a string or a GitHubContext object. @@ -56,12 +92,12 @@ function New-GitHubVariable { switch ($PSCmdlet.ParameterSetName) { 'Organization' { $params = @{ - Owner = $Owner - Name = $Name - Value = $Value - Visibility = $Visibility - SelectedRepository = $SelectedRepository - Context = $Context + Owner = $Owner + Name = $Name + Value = $Value + Visibility = $Visibility + SelectedRepositories = $SelectedRepositories + Context = $Context } New-GitHubVariableOnOwner @params break diff --git a/src/functions/public/Variables/Update-GitHubVariable.ps1 b/src/functions/public/Variables/Update-GitHubVariable.ps1 new file mode 100644 index 000000000..1356956dd --- /dev/null +++ b/src/functions/public/Variables/Update-GitHubVariable.ps1 @@ -0,0 +1,132 @@ +function Update-GitHubVariable { + <# + .SYNOPSIS + Update a GitHub variable at the organization, repository, or environment level. + + .DESCRIPTION + Updates a GitHub Actions variable that can be referenced in workflows. This function supports updating variables + at different levels: organization, repository, or environment. It delegates the update process to the appropriate + private function based on the specified parameters. + + To modify an organization variable, users must have `admin:org` scope. Repository variables require `repo` scope, + and environment variables require collaborator access. + + .EXAMPLE + Update-GitHubVariable -Owner 'octocat' -Repository 'Hello-World' -Name 'HOST_NAME' -Value 'github.com' + + Updates the repository variable named `HOST_NAME` with the value `github.com` in the specified repository. + + .EXAMPLE + Update-GitHubVariable -Owner 'octocat' -Name 'HOST_NAME' -Value 'github.com' -Visibility 'private' + + Updates the organization variable named `HOST_NAME` with the value `github.com`, making it private. + + .EXAMPLE + Update-GitHubVariable -Owner 'octocat' -Repository 'Hello-World' -Environment 'dev' -Name 'HOST_NAME' -Value 'github.com' + + Updates the environment variable named `HOST_NAME` with the value `github.com` in the specified environment. + + .LINK + https://psmodule.io/GitHub/Functions/Variables/Update-GitHubVariable/ + #> + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSShouldProcess', '', Scope = 'Function', + Justification = 'This check is performed in the private functions.' + )] + [OutputType([void])] + [CmdletBinding(SupportsShouldProcess)] + param( + # The account owner of the repository. The name is not case sensitive. + [Parameter(Mandatory, ParameterSetName = 'Organization')] + [Parameter(Mandatory, ParameterSetName = 'Repository')] + [Parameter(Mandatory, ParameterSetName = 'Environment')] + [Alias('Organization', 'User')] + [string] $Owner, + + # The name of the repository. The name is not case sensitive. + [Parameter(Mandatory, ParameterSetName = 'Repository')] + [Parameter(Mandatory, ParameterSetName = 'Environment')] + [string] $Repository, + + # The name of the repository environment. + [Parameter(Mandatory, ParameterSetName = 'Environment')] + [string] $Environment, + + # The name of the variable. + [Parameter(Mandatory)] + [string] $Name, + + # The new name of the variable. + [Parameter()] + [string] $NewName, + + # The value of the variable. + [Parameter()] + [string] $Value, + + # The visibility of the variable when updating an organization variable. + # Can be `private`, `selected`, or `all`. + [Parameter(ParameterSetName = 'Organization')] + [ValidateSet('private', 'selected', 'all')] + [string] $Visibility = 'private', + + # The IDs of the repositories to which the variable is available. + # Used only when the `-Visibility` parameter is set to `selected`. + [Parameter(ParameterSetName = 'Organization')] + [UInt64[]] $SelectedRepositories, + + # The context to run the command in. Can be either a string or a GitHubContext object. + [Parameter()] + [object] $Context = (Get-GitHubContext) + ) + + begin { + $stackPath = Get-PSCallStackPath + Write-Debug "[$stackPath] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + } + + process { + $params = @{ + Owner = $Owner + Name = $Name + NewName = $NewName + Value = $Value + Context = $Context + } + if ($PSBoundParameters.ContainsKey('NewName')) { + $params['NewName'] = $NewName + } + if ($PSBoundParameters.ContainsKey('Value')) { + $params['Value'] = $Value + } + switch ($PSCmdlet.ParameterSetName) { + 'Organization' { + if ($PSBoundParameters.ContainsKey('Visibility')) { + $params['Visibility'] = $Visibility + } + if ($PSBoundParameters.ContainsKey('SelectedRepositories')) { + $params['SelectedRepositories'] = $SelectedRepositories + } + Update-GitHubVariableOnOwner @params + break + } + 'Repository' { + $params['Repository'] = $Repository + Update-GitHubVariableOnRepository @params + break + } + 'Environment' { + $params['Repository'] = $Repository + $params['Environment'] = $Environment + Update-GitHubVariableOnEnvironment @params + break + } + } + } + + end { + Write-Debug "[$stackPath] - End" + } +} From 576827451777a549ad20913d2f602421fd384da3 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions@users.noreply.github.com> Date: Mon, 17 Mar 2025 20:44:40 +0000 Subject: [PATCH 16/85] Auto-generated changes --- Coverage.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Coverage.md b/Coverage.md index ba714a3f1..ef93b0af3 100644 --- a/Coverage.md +++ b/Coverage.md @@ -9,15 +9,15 @@ Covered functions - 177 + 179 Missing functions - 842 + 840 Coverage - 17.37% + 17.57% @@ -132,7 +132,7 @@ | `/orgs/{org}/actions/secrets/{secret_name}/repositories` | | :x: | | | :x: | | `/orgs/{org}/actions/secrets/{secret_name}/repositories/{repository_id}` | :x: | | | | :x: | | `/orgs/{org}/actions/variables` | | :white_check_mark: | | :white_check_mark: | | -| `/orgs/{org}/actions/variables/{name}` | :white_check_mark: | :white_check_mark: | :x: | | | +| `/orgs/{org}/actions/variables/{name}` | :white_check_mark: | :white_check_mark: | :white_check_mark: | | | | `/orgs/{org}/actions/variables/{name}/repositories` | | :white_check_mark: | | | :x: | | `/orgs/{org}/actions/variables/{name}/repositories/{repository_id}` | :x: | | | | :x: | | `/orgs/{org}/attestations/{subject_digest}` | | :x: | | | | @@ -437,7 +437,7 @@ | `/repos/{owner}/{repo}/environments/{environment_name}/secrets/public-key` | | :x: | | | | | `/repos/{owner}/{repo}/environments/{environment_name}/secrets/{secret_name}` | :x: | :x: | | | :x: | | `/repos/{owner}/{repo}/environments/{environment_name}/variables` | | :white_check_mark: | | :white_check_mark: | | -| `/repos/{owner}/{repo}/environments/{environment_name}/variables/{name}` | :white_check_mark: | :white_check_mark: | :x: | | | +| `/repos/{owner}/{repo}/environments/{environment_name}/variables/{name}` | :white_check_mark: | :white_check_mark: | :white_check_mark: | | | | `/repos/{owner}/{repo}/events` | | :x: | | | | | `/repos/{owner}/{repo}/forks` | | :white_check_mark: | | :white_check_mark: | | | `/repos/{owner}/{repo}/git/blobs` | | | | :x: | | From 5549f8710dcbd81640f4448091350e237524499d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 17 Mar 2025 21:50:39 +0100 Subject: [PATCH 17/85] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Remove=20unused?= =?UTF-8?q?=20NewName=20parameter=20from=20Update-GitHubVariable=20functio?= =?UTF-8?q?n=20for=20improved=20clarity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/functions/public/Variables/Update-GitHubVariable.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/src/functions/public/Variables/Update-GitHubVariable.ps1 b/src/functions/public/Variables/Update-GitHubVariable.ps1 index 1356956dd..0c58e2959 100644 --- a/src/functions/public/Variables/Update-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Update-GitHubVariable.ps1 @@ -91,7 +91,6 @@ function Update-GitHubVariable { $params = @{ Owner = $Owner Name = $Name - NewName = $NewName Value = $Value Context = $Context } From b9c00fa6e6072087c976dc3547686003a7247f01 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 17 Mar 2025 21:55:24 +0100 Subject: [PATCH 18/85] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Remove=20Value?= =?UTF-8?q?=20parameter=20from=20Update-GitHubVariable=20function=20for=20?= =?UTF-8?q?improved=20clarity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/functions/public/Variables/Update-GitHubVariable.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/src/functions/public/Variables/Update-GitHubVariable.ps1 b/src/functions/public/Variables/Update-GitHubVariable.ps1 index 0c58e2959..b2e924ffc 100644 --- a/src/functions/public/Variables/Update-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Update-GitHubVariable.ps1 @@ -91,7 +91,6 @@ function Update-GitHubVariable { $params = @{ Owner = $Owner Name = $Name - Value = $Value Context = $Context } if ($PSBoundParameters.ContainsKey('NewName')) { From bc7090ad2f17a368eac3c7513f0bb365c64c784c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 17 Mar 2025 21:59:28 +0100 Subject: [PATCH 19/85] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Remove=20mandat?= =?UTF-8?q?ory=20requirement=20for=20Value=20parameter=20in=20Update-GitHu?= =?UTF-8?q?bVariableOnOwner=20function=20for=20improved=20flexibility?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../private/Variables/Update-GitHubVariableOnOwner.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions/private/Variables/Update-GitHubVariableOnOwner.ps1 b/src/functions/private/Variables/Update-GitHubVariableOnOwner.ps1 index 5c7fd9984..387f7a76b 100644 --- a/src/functions/private/Variables/Update-GitHubVariableOnOwner.ps1 +++ b/src/functions/private/Variables/Update-GitHubVariableOnOwner.ps1 @@ -33,7 +33,7 @@ function Update-GitHubVariableOnOwner { [string] $NewName, # The value of the variable. - [Parameter(Mandatory)] + [Parameter()] [string] $Value, # The visibility of the variable. Can be `private`, `selected`, or `all`. From 9d2a8a8fec26b4c8573e993a7c2752cb8601ac5f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 17 Mar 2025 22:10:32 +0100 Subject: [PATCH 20/85] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20APIEnd?= =?UTF-8?q?point=20in=20Update-GitHubVariableOnRepository=20function=20to?= =?UTF-8?q?=20include=20variable=20name=20for=20precise=20targeting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../private/Variables/Update-GitHubVariableOnRepository.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions/private/Variables/Update-GitHubVariableOnRepository.ps1 b/src/functions/private/Variables/Update-GitHubVariableOnRepository.ps1 index 47e6bce5e..72f434d29 100644 --- a/src/functions/private/Variables/Update-GitHubVariableOnRepository.ps1 +++ b/src/functions/private/Variables/Update-GitHubVariableOnRepository.ps1 @@ -62,7 +62,7 @@ function Update-GitHubVariableOnRepository { $inputObject = @{ Method = 'PATCH' - APIEndpoint = "/repos/$Owner/$Repository/actions/variables" + APIEndpoint = "/repos/$Owner/$Repository/actions/variables/$Name" Body = $body Context = $Context } From 58b71110313c5775eb5977f066e9b836db2d9638 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions@users.noreply.github.com> Date: Mon, 17 Mar 2025 21:11:49 +0000 Subject: [PATCH 21/85] Auto-generated changes --- Coverage.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Coverage.md b/Coverage.md index ef93b0af3..9d21c5923 100644 --- a/Coverage.md +++ b/Coverage.md @@ -9,15 +9,15 @@ Covered functions - 179 + 180 Missing functions - 840 + 839 Coverage - 17.57% + 17.66% @@ -330,7 +330,7 @@ | `/repos/{owner}/{repo}/actions/secrets/public-key` | | :x: | | | | | `/repos/{owner}/{repo}/actions/secrets/{secret_name}` | :x: | :x: | | | :x: | | `/repos/{owner}/{repo}/actions/variables` | | :white_check_mark: | | :white_check_mark: | | -| `/repos/{owner}/{repo}/actions/variables/{name}` | :white_check_mark: | :white_check_mark: | :x: | | | +| `/repos/{owner}/{repo}/actions/variables/{name}` | :white_check_mark: | :white_check_mark: | :white_check_mark: | | | | `/repos/{owner}/{repo}/actions/workflows` | | :white_check_mark: | | | | | `/repos/{owner}/{repo}/actions/workflows/{workflow_id}` | | :white_check_mark: | | | | | `/repos/{owner}/{repo}/actions/workflows/{workflow_id}/disable` | | | | | :white_check_mark: | From 3dd6b5574cad8e4402597197583674aa3ee2dd89 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 17 Mar 2025 22:24:06 +0100 Subject: [PATCH 22/85] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Add=20PassThru?= =?UTF-8?q?=20parameter=20to=20New-GitHubVariable=20and=20Update-GitHubVar?= =?UTF-8?q?iable=20functions=20for=20optional=20return=20of=20updated=20va?= =?UTF-8?q?riable=20object?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../public/Variables/New-GitHubVariable.ps1 | 49 ++++++++++--------- .../Variables/Update-GitHubVariable.ps1 | 43 +++++++++------- 2 files changed, 51 insertions(+), 41 deletions(-) diff --git a/src/functions/public/Variables/New-GitHubVariable.ps1 b/src/functions/public/Variables/New-GitHubVariable.ps1 index 1aed0f45c..9577fca37 100644 --- a/src/functions/public/Variables/New-GitHubVariable.ps1 +++ b/src/functions/public/Variables/New-GitHubVariable.ps1 @@ -75,6 +75,10 @@ function New-GitHubVariable { [Parameter(ParameterSetName = 'Organization')] [UInt64[]] $SelectedRepositories, + # If specified, the function will return the updated variable object. + [Parameter()] + [switch] $PassThru, + # The context to run the command in. Used to get the details for the API call. # Can be either a string or a GitHubContext object. [Parameter()] @@ -89,43 +93,42 @@ function New-GitHubVariable { } process { + $params = @{ + Owner = $Owner + Repository = $Repository + Environment = $Environment + Name = $Name + Value = $Value + Visibility = $Visibility + SelectedRepositories = $SelectedRepositories + Context = $Context + } + $params | Remove-HashtableEntry -NullOrEmptyValues switch ($PSCmdlet.ParameterSetName) { 'Organization' { - $params = @{ - Owner = $Owner - Name = $Name - Value = $Value - Visibility = $Visibility - SelectedRepositories = $SelectedRepositories - Context = $Context - } New-GitHubVariableOnOwner @params break } 'Repository' { - $params = @{ - Owner = $Owner - Repository = $Repository - Name = $Name - Value = $Value - Context = $Context - } New-GitHubVariableOnRepository @params break } 'Environment' { - $params = @{ - Owner = $Owner - Repository = $Repository - Environment = $Environment - Name = $Name - Value = $Value - Context = $Context - } New-GitHubVariableOnEnvironment @params break } } + if ($PassThru) { + $params = @{ + Owner = $Owner + Repository = $Repository + Environment = $Environment + Name = $Name + Context = $Context + } + $params | Remove-HashtableEntry -NullOrEmptyValues + Get-GitHubVariable @params + } } end { diff --git a/src/functions/public/Variables/Update-GitHubVariable.ps1 b/src/functions/public/Variables/Update-GitHubVariable.ps1 index b2e924ffc..b8d4c33f7 100644 --- a/src/functions/public/Variables/Update-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Update-GitHubVariable.ps1 @@ -75,6 +75,10 @@ function Update-GitHubVariable { [Parameter(ParameterSetName = 'Organization')] [UInt64[]] $SelectedRepositories, + # If specified, the function will return the updated variable object. + [Parameter()] + [switch] $PassThru, + # The context to run the command in. Can be either a string or a GitHubContext object. [Parameter()] [object] $Context = (Get-GitHubContext) @@ -89,39 +93,42 @@ function Update-GitHubVariable { process { $params = @{ - Owner = $Owner - Name = $Name - Context = $Context - } - if ($PSBoundParameters.ContainsKey('NewName')) { - $params['NewName'] = $NewName - } - if ($PSBoundParameters.ContainsKey('Value')) { - $params['Value'] = $Value + Owner = $Owner + Repository = $Repository + Environment = $Environment + Name = $Name + Context = $Context + NewName = $NewName + Value = $Value + Visibility = $Visibility + SelectedRepositories = $SelectedRepositories } + $params | Remove-HashtableEntry -NullOrEmptyValues switch ($PSCmdlet.ParameterSetName) { 'Organization' { - if ($PSBoundParameters.ContainsKey('Visibility')) { - $params['Visibility'] = $Visibility - } - if ($PSBoundParameters.ContainsKey('SelectedRepositories')) { - $params['SelectedRepositories'] = $SelectedRepositories - } Update-GitHubVariableOnOwner @params break } 'Repository' { - $params['Repository'] = $Repository Update-GitHubVariableOnRepository @params break } 'Environment' { - $params['Repository'] = $Repository - $params['Environment'] = $Environment Update-GitHubVariableOnEnvironment @params break } } + if ($PassThru) { + $params = @{ + Owner = $Owner + Repository = $Repository + Environment = $Environment + Name = $Name + Context = $Context + } + $params | Remove-HashtableEntry -NullOrEmptyValues + Get-GitHubVariable @params + } } end { From 850a6e11e4cfa52c6dc1cb662b5c927c5b1a0448 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions@users.noreply.github.com> Date: Mon, 17 Mar 2025 21:25:21 +0000 Subject: [PATCH 23/85] Auto-generated changes --- Coverage.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Coverage.md b/Coverage.md index 9d21c5923..8c6493d70 100644 --- a/Coverage.md +++ b/Coverage.md @@ -5,7 +5,7 @@ - + @@ -13,11 +13,11 @@ - + - +
Available functions10191023
Covered functions
Missing functions839843
Coverage17.66%17.6%
@@ -191,6 +191,8 @@ | `/orgs/{org}/invitations` | | :white_check_mark: | | :white_check_mark: | | | `/orgs/{org}/invitations/{invitation_id}` | :white_check_mark: | | | | | | `/orgs/{org}/invitations/{invitation_id}/teams` | | :x: | | | | +| `/orgs/{org}/issue-types` | | :x: | | :x: | | +| `/orgs/{org}/issue-types/{issue_type_id}` | :x: | | | | :x: | | `/orgs/{org}/issues` | | :x: | | | | | `/orgs/{org}/members` | | :white_check_mark: | | | | | `/orgs/{org}/members/{username}` | :x: | :x: | | | | From 321a5c2851a86e0031c5a358ef480f5f8cf06e44 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 17 Mar 2025 22:44:04 +0100 Subject: [PATCH 24/85] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Simplify=20API?= =?UTF-8?q?=20invocation=20in=20variable=20update=20functions=20and=20add?= =?UTF-8?q?=20ErrorAction=20parameter=20for=20improved=20error=20handling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../private/Variables/Update-GitHubVariableOnEnvironment.ps1 | 4 +--- .../private/Variables/Update-GitHubVariableOnOwner.ps1 | 4 +--- .../private/Variables/Update-GitHubVariableOnRepository.ps1 | 4 +--- src/functions/public/Variables/New-GitHubVariable.ps1 | 1 + src/functions/public/Variables/Update-GitHubVariable.ps1 | 1 + 5 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/functions/private/Variables/Update-GitHubVariableOnEnvironment.ps1 b/src/functions/private/Variables/Update-GitHubVariableOnEnvironment.ps1 index ace54f70e..80877c33b 100644 --- a/src/functions/private/Variables/Update-GitHubVariableOnEnvironment.ps1 +++ b/src/functions/private/Variables/Update-GitHubVariableOnEnvironment.ps1 @@ -81,9 +81,7 @@ function Update-GitHubVariableOnEnvironment { } if ($PSCmdlet.ShouldProcess("variable [$Name] on [$Owner/$Repository/$Environment]", 'Update')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + $null = Invoke-GitHubAPI @inputObject } } diff --git a/src/functions/private/Variables/Update-GitHubVariableOnOwner.ps1 b/src/functions/private/Variables/Update-GitHubVariableOnOwner.ps1 index 387f7a76b..086fbd013 100644 --- a/src/functions/private/Variables/Update-GitHubVariableOnOwner.ps1 +++ b/src/functions/private/Variables/Update-GitHubVariableOnOwner.ps1 @@ -92,9 +92,7 @@ function Update-GitHubVariableOnOwner { } if ($PSCmdlet.ShouldProcess("variable [$Name] on [$Owner]", 'Update')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + $null = Invoke-GitHubAPI @inputObject } } diff --git a/src/functions/private/Variables/Update-GitHubVariableOnRepository.ps1 b/src/functions/private/Variables/Update-GitHubVariableOnRepository.ps1 index 72f434d29..ba97a4952 100644 --- a/src/functions/private/Variables/Update-GitHubVariableOnRepository.ps1 +++ b/src/functions/private/Variables/Update-GitHubVariableOnRepository.ps1 @@ -68,9 +68,7 @@ function Update-GitHubVariableOnRepository { } if ($PSCmdlet.ShouldProcess("variable [$Name] on [$Owner/$Repository]", 'Update')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + $null = Invoke-GitHubAPI @inputObject } } diff --git a/src/functions/public/Variables/New-GitHubVariable.ps1 b/src/functions/public/Variables/New-GitHubVariable.ps1 index 9577fca37..c94d670ac 100644 --- a/src/functions/public/Variables/New-GitHubVariable.ps1 +++ b/src/functions/public/Variables/New-GitHubVariable.ps1 @@ -102,6 +102,7 @@ function New-GitHubVariable { Visibility = $Visibility SelectedRepositories = $SelectedRepositories Context = $Context + ErrorAction = 'Stop' } $params | Remove-HashtableEntry -NullOrEmptyValues switch ($PSCmdlet.ParameterSetName) { diff --git a/src/functions/public/Variables/Update-GitHubVariable.ps1 b/src/functions/public/Variables/Update-GitHubVariable.ps1 index b8d4c33f7..2e4c3af66 100644 --- a/src/functions/public/Variables/Update-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Update-GitHubVariable.ps1 @@ -102,6 +102,7 @@ function Update-GitHubVariable { Value = $Value Visibility = $Visibility SelectedRepositories = $SelectedRepositories + ErrorAction = 'Stop' } $params | Remove-HashtableEntry -NullOrEmptyValues switch ($PSCmdlet.ParameterSetName) { From 813846946f9bdb3091091d0419d942abfcf18448 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 17 Mar 2025 23:07:29 +0100 Subject: [PATCH 25/85] Add retry config --- src/classes/public/Config/GitHubConfig.ps1 | 6 ++++++ src/functions/public/API/Invoke-GitHubAPI.ps1 | 10 +++++++++- src/variables/private/GitHub.ps1 | 2 ++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/classes/public/Config/GitHubConfig.ps1 b/src/classes/public/Config/GitHubConfig.ps1 index 32a7b5bfc..fbd86f1ae 100644 --- a/src/classes/public/Config/GitHubConfig.ps1 +++ b/src/classes/public/Config/GitHubConfig.ps1 @@ -26,6 +26,12 @@ # The default value for the 'per_page' API parameter used in 'GET' functions that support paging. [int] $PerPage + # The default value for retry count. + [int] $RetryCount + + # The default value for retry interval in seconds. + [int] $RetryInterval + # Simple parameterless constructor GitHubConfig() {} diff --git a/src/functions/public/API/Invoke-GitHubAPI.ps1 b/src/functions/public/API/Invoke-GitHubAPI.ps1 index 1a0450a4e..ff6c526a4 100644 --- a/src/functions/public/API/Invoke-GitHubAPI.ps1 +++ b/src/functions/public/API/Invoke-GitHubAPI.ps1 @@ -81,6 +81,14 @@ filter Invoke-GitHubAPI { [Parameter()] [string] $ApiVersion, + # Specifies how many times PowerShell retries a connection when a failure code between 400 and 599, inclusive or 304 is received. + [int] $RetryCount = $script:GitHub.Config.RetryCount, + + # Specifies the interval between retries for the connection when a failure code between 400 and 599, inclusive or 304 is received. + # When the failure code is 429 and the response includes the Retry-After property in its headers, the cmdlet uses that value for the retry + # interval, even if this parameter is specified. + [int] $RetryInterval = $script:GitHub.Config.RetryInterval, + # The context to run the command in. Used to get the details for the API call. # Can be either a string or a GitHubContext object. [Parameter()] @@ -180,7 +188,7 @@ filter Invoke-GitHubAPI { } } } - $response = Invoke-WebRequest @APICall + $response = Invoke-WebRequest @APICall -MaximumRetryCount $RetryCount -RetryIntervalSec $RetryInterval $headers = @{} foreach ($item in $response.Headers.GetEnumerator()) { diff --git a/src/variables/private/GitHub.ps1 b/src/variables/private/GitHub.ps1 index 9ca9b6847..519c14ad6 100644 --- a/src/variables/private/GitHub.ps1 +++ b/src/variables/private/GitHub.ps1 @@ -17,6 +17,8 @@ ApiVersion = '2022-11-28' HttpVersion = '2.0' PerPage = 100 + RetryCount = 10 + RetryInterval = 1 } Config = $null Event = $null From 0f51cb041dbaccb846a9a8da91d86e12742d38ce Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 17 Mar 2025 23:20:59 +0100 Subject: [PATCH 26/85] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Add=20RetryCoun?= =?UTF-8?q?t=20and=20RetryInterval=20parameters=20to=20Invoke-GitHubAPI=20?= =?UTF-8?q?for=20enhanced=20retry=20control?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/functions/public/API/Invoke-GitHubAPI.ps1 | 24 +++++++++++-------- src/variables/private/GitHub.ps1 | 2 +- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/functions/public/API/Invoke-GitHubAPI.ps1 b/src/functions/public/API/Invoke-GitHubAPI.ps1 index ff6c526a4..467e32da6 100644 --- a/src/functions/public/API/Invoke-GitHubAPI.ps1 +++ b/src/functions/public/API/Invoke-GitHubAPI.ps1 @@ -82,11 +82,13 @@ filter Invoke-GitHubAPI { [string] $ApiVersion, # Specifies how many times PowerShell retries a connection when a failure code between 400 and 599, inclusive or 304 is received. + [Parameter()] [int] $RetryCount = $script:GitHub.Config.RetryCount, # Specifies the interval between retries for the connection when a failure code between 400 and 599, inclusive or 304 is received. # When the failure code is 429 and the response includes the Retry-After property in its headers, the cmdlet uses that value for the retry # interval, even if this parameter is specified. + [Parameter()] [int] $RetryInterval = $script:GitHub.Config.RetryInterval, # The context to run the command in. Used to get the details for the API call. @@ -139,15 +141,17 @@ filter Invoke-GitHubAPI { } $APICall = @{ - Uri = $Uri - Method = [string]$Method - Headers = $Headers - Authentication = 'Bearer' - Token = $Token - ContentType = $ContentType - InFile = $UploadFilePath - OutFile = $DownloadFilePath - HttpVersion = [string]$HttpVersion + Uri = $Uri + Method = [string]$Method + Headers = $Headers + Authentication = 'Bearer' + Token = $Token + ContentType = $ContentType + InFile = $UploadFilePath + OutFile = $DownloadFilePath + HttpVersion = [string]$HttpVersion + MaximumRetryCount = $RetryCount + RetryIntervalSec = $RetryInterval } $APICall | Remove-HashtableEntry -NullOrEmptyValues @@ -188,7 +192,7 @@ filter Invoke-GitHubAPI { } } } - $response = Invoke-WebRequest @APICall -MaximumRetryCount $RetryCount -RetryIntervalSec $RetryInterval + $response = Invoke-WebRequest @APICall $headers = @{} foreach ($item in $response.Headers.GetEnumerator()) { diff --git a/src/variables/private/GitHub.ps1 b/src/variables/private/GitHub.ps1 index 519c14ad6..8b9b77b19 100644 --- a/src/variables/private/GitHub.ps1 +++ b/src/variables/private/GitHub.ps1 @@ -17,7 +17,7 @@ ApiVersion = '2022-11-28' HttpVersion = '2.0' PerPage = 100 - RetryCount = 10 + RetryCount = 0 RetryInterval = 1 } Config = $null From ea00ed42b04d5616a1620b1d6e2e05ac6381e0ff Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 17 Mar 2025 23:39:13 +0100 Subject: [PATCH 27/85] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Refactor=20New-?= =?UTF-8?q?GitHubVariable=20and=20Update-GitHubVariable=20functions=20to?= =?UTF-8?q?=20temporarily=20set=20RetryCount=20for=20API=20calls?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../public/Variables/New-GitHubVariable.ps1 | 21 ++++++++++--------- .../Variables/Update-GitHubVariable.ps1 | 3 +++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/functions/public/Variables/New-GitHubVariable.ps1 b/src/functions/public/Variables/New-GitHubVariable.ps1 index c94d670ac..611333b8f 100644 --- a/src/functions/public/Variables/New-GitHubVariable.ps1 +++ b/src/functions/public/Variables/New-GitHubVariable.ps1 @@ -119,17 +119,18 @@ function New-GitHubVariable { break } } - if ($PassThru) { - $params = @{ - Owner = $Owner - Repository = $Repository - Environment = $Environment - Name = $Name - Context = $Context - } - $params | Remove-HashtableEntry -NullOrEmptyValues - Get-GitHubVariable @params + $params = @{ + Owner = $Owner + Repository = $Repository + Environment = $Environment + Name = $Name + Context = $Context } + $params | Remove-HashtableEntry -NullOrEmptyValues + $tmp = $script:GitHub.Config.RetryCount + $script:GitHub.Config.RetryCount = 5 + Get-GitHubVariable @params + $script:GitHub.Config.RetryCount = $tmp } end { diff --git a/src/functions/public/Variables/Update-GitHubVariable.ps1 b/src/functions/public/Variables/Update-GitHubVariable.ps1 index 2e4c3af66..996d3ebe3 100644 --- a/src/functions/public/Variables/Update-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Update-GitHubVariable.ps1 @@ -128,7 +128,10 @@ function Update-GitHubVariable { Context = $Context } $params | Remove-HashtableEntry -NullOrEmptyValues + $tmp = $script:GitHub.Config.RetryCount + $script:GitHub.Config.RetryCount = 5 Get-GitHubVariable @params + $script:GitHub.Config.RetryCount = $tmp } } From bcb57317223079c9053df38dc733545a64f30d87 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 17 Mar 2025 23:50:17 +0100 Subject: [PATCH 28/85] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Add=20AllowNull?= =?UTF-8?q?=20attribute=20to=20Context=20parameter=20in=20Resolve-GitHubCo?= =?UTF-8?q?ntext=20function=20for=20improved=20null=20handling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/functions/private/Auth/Context/Resolve-GitHubContext.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/src/functions/private/Auth/Context/Resolve-GitHubContext.ps1 b/src/functions/private/Auth/Context/Resolve-GitHubContext.ps1 index 60f1b3158..5593f4906 100644 --- a/src/functions/private/Auth/Context/Resolve-GitHubContext.ps1 +++ b/src/functions/private/Auth/Context/Resolve-GitHubContext.ps1 @@ -29,6 +29,7 @@ Mandatory, ValueFromPipeline )] + [AllowNull()] [object] $Context ) From 557ab9f0bb06b6755a7a0fd28a7982987ad6b074 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 00:03:15 +0100 Subject: [PATCH 29/85] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Remove=20unused?= =?UTF-8?q?=20PassThru=20parameter=20from=20New-GitHubVariable=20function?= =?UTF-8?q?=20for=20cleaner=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/functions/public/Variables/New-GitHubVariable.ps1 | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/functions/public/Variables/New-GitHubVariable.ps1 b/src/functions/public/Variables/New-GitHubVariable.ps1 index 611333b8f..92cd5ae8f 100644 --- a/src/functions/public/Variables/New-GitHubVariable.ps1 +++ b/src/functions/public/Variables/New-GitHubVariable.ps1 @@ -75,10 +75,6 @@ function New-GitHubVariable { [Parameter(ParameterSetName = 'Organization')] [UInt64[]] $SelectedRepositories, - # If specified, the function will return the updated variable object. - [Parameter()] - [switch] $PassThru, - # The context to run the command in. Used to get the details for the API call. # Can be either a string or a GitHubContext object. [Parameter()] From 83cb08f5b3341a286ee5c4d4e23ebcb5dc2d7cf7 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 00:10:07 +0100 Subject: [PATCH 30/85] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20Update?= =?UTF-8?q?-GitHubVariable=20function=20to=20conditionally=20use=20NewName?= =?UTF-8?q?=20parameter=20for=20improved=20flexibility?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/functions/public/Variables/Update-GitHubVariable.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions/public/Variables/Update-GitHubVariable.ps1 b/src/functions/public/Variables/Update-GitHubVariable.ps1 index 996d3ebe3..f74137ada 100644 --- a/src/functions/public/Variables/Update-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Update-GitHubVariable.ps1 @@ -124,7 +124,7 @@ function Update-GitHubVariable { Owner = $Owner Repository = $Repository Environment = $Environment - Name = $Name + Name = $PSBoundParameters.ContainsKey('NewName') ? $NewName : $Name Context = $Context } $params | Remove-HashtableEntry -NullOrEmptyValues From c83eb67d366befe143336408d5532714aef7ec2e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 00:22:15 +0100 Subject: [PATCH 31/85] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Restore=20Visib?= =?UTF-8?q?ility=20parameter=20in=20New-GitHubVariable=20and=20Update-GitH?= =?UTF-8?q?ubVariable=20functions=20for=20improved=20functionality?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/functions/public/Variables/New-GitHubVariable.ps1 | 2 +- src/functions/public/Variables/Update-GitHubVariable.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/functions/public/Variables/New-GitHubVariable.ps1 b/src/functions/public/Variables/New-GitHubVariable.ps1 index 92cd5ae8f..ae75a1c24 100644 --- a/src/functions/public/Variables/New-GitHubVariable.ps1 +++ b/src/functions/public/Variables/New-GitHubVariable.ps1 @@ -95,7 +95,6 @@ function New-GitHubVariable { Environment = $Environment Name = $Name Value = $Value - Visibility = $Visibility SelectedRepositories = $SelectedRepositories Context = $Context ErrorAction = 'Stop' @@ -103,6 +102,7 @@ function New-GitHubVariable { $params | Remove-HashtableEntry -NullOrEmptyValues switch ($PSCmdlet.ParameterSetName) { 'Organization' { + $params.Visibility = $Visibility New-GitHubVariableOnOwner @params break } diff --git a/src/functions/public/Variables/Update-GitHubVariable.ps1 b/src/functions/public/Variables/Update-GitHubVariable.ps1 index f74137ada..d9f8e6465 100644 --- a/src/functions/public/Variables/Update-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Update-GitHubVariable.ps1 @@ -100,13 +100,13 @@ function Update-GitHubVariable { Context = $Context NewName = $NewName Value = $Value - Visibility = $Visibility SelectedRepositories = $SelectedRepositories ErrorAction = 'Stop' } $params | Remove-HashtableEntry -NullOrEmptyValues switch ($PSCmdlet.ParameterSetName) { 'Organization' { + $params.Visibility = $Visibility Update-GitHubVariableOnOwner @params break } From bccba763f26580b55743b92bd75ddb7e5714a87b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 00:52:20 +0100 Subject: [PATCH 32/85] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20Output?= =?UTF-8?q?Type=20for=20New-GitHubVariable,=20Remove-GitHubVariable,=20Set?= =?UTF-8?q?-GitHubVariable,=20and=20Update-GitHubVariable=20functions=20fo?= =?UTF-8?q?r=20improved=20type=20clarity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../public/Variables/New-GitHubVariable.ps1 | 2 +- .../Variables/Remove-GitHubVariable.ps1 | 1 + .../public/Variables/Set-GitHubVariable.ps1 | 166 +++++++----------- .../Variables/Update-GitHubVariable.ps1 | 2 +- 4 files changed, 68 insertions(+), 103 deletions(-) diff --git a/src/functions/public/Variables/New-GitHubVariable.ps1 b/src/functions/public/Variables/New-GitHubVariable.ps1 index ae75a1c24..c348a9b0c 100644 --- a/src/functions/public/Variables/New-GitHubVariable.ps1 +++ b/src/functions/public/Variables/New-GitHubVariable.ps1 @@ -35,7 +35,7 @@ function New-GitHubVariable { 'PSShouldProcess', '', Scope = 'Function', Justification = 'This check is performed in the private functions.' )] - [OutputType([void])] + [OutputType([GitHubVariable])] [CmdletBinding(SupportsShouldProcess)] param( # The account owner of the repository. The name is not case sensitive. diff --git a/src/functions/public/Variables/Remove-GitHubVariable.ps1 b/src/functions/public/Variables/Remove-GitHubVariable.ps1 index 2435f22e8..e43773e6a 100644 --- a/src/functions/public/Variables/Remove-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Remove-GitHubVariable.ps1 @@ -41,6 +41,7 @@ function Remove-GitHubVariable { 'PSShouldProcess', '', Scope = 'Function', Justification = 'This check is performed in the private functions.' )] + [OutputType([void])] [CmdletBinding(SupportsShouldProcess)] param( [Parameter(Mandatory, ParameterSetName = 'Organization', ValueFromPipelineByPropertyName)] diff --git a/src/functions/public/Variables/Set-GitHubVariable.ps1 b/src/functions/public/Variables/Set-GitHubVariable.ps1 index 4ed662ed3..495e4fe88 100644 --- a/src/functions/public/Variables/Set-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Set-GitHubVariable.ps1 @@ -1,99 +1,79 @@ function Set-GitHubVariable { <# .SYNOPSIS - Creates/Updates a GitHub variable for a Organisation, Repository or Environment. + Creates or updates a GitHub Actions variable at the organization, repository, or environment level. .DESCRIPTION - Creates/Updates a GitHub variable for a Organisation, Repository or Environment. + This function checks if a GitHub Actions variable exists at the specified level (organization, repository, or environment). + If the variable exists, it updates it with the new value. If it does not exist, it creates a new variable. - .PARAMETER Owner - The account owner of the repository. The name is not case-sensitive. + - Organization-level variables require the `admin:org` scope for OAuth tokens and personal access tokens (classic). If the repository is + private, the `repo` scope is also required. + - Repository-level variables require the `repo` scope. + - Environment-level variables require collaborator access to the repository. - .PARAMETER Repository - The name of the repository. The name is not case-sensitive. - - .PARAMETER Environment - The name of the repository environment. - - .PARAMETER Name - The name of the variable. - - .PARAMETER Value - The value of the variable. - - .PARAMETER Private - Set visibility to private (only applicable at the organization level). - - .PARAMETER SelectedRepositoryIds - List of numeric repository IDs where the variable should be visible (only applicable at the organization level). + .EXAMPLE + Set-GitHubVariable -Owner 'octocat' -Repository 'Hello-World' -Name 'HOST_NAME' -Value 'github.com' -Context $GitHubContext - .PARAMETER Context - The context to run the command in. Used to get the details for the API call. + Creates or updates a repository variable named `HOST_NAME` with the value `github.com` in the specified repository. .EXAMPLE - Sets a variable in an environment. - Set-GitHubVariable -Owner "octocat" -Repository "Hello-World" -Environment "dev" -Name "myVariable" -Value "myValue" + Set-GitHubVariable -Owner 'octocat' -Name 'HOST_NAME' -Value 'github.com' -Visibility 'all' -Context $GitHubContext - .EXAMPLE - Sets a variable in a repository. - Set-GitHubVariable -Owner "octocat" -Repository "Hello-World" -Name "myVariable" -Value "myValue" + Creates or updates an organization variable named `HOST_NAME` with the value `github.com` and + makes it available to all repositories in the organization. .EXAMPLE - Sets a variable in an organisation. - Set-GitHubVariable -Owner "octocat" -Name "myVariable" -Value "myValue" + Set-GitHubVariable -Owner 'octocat' -Repository 'Hello-World' -Environment 'dev' -Name 'HOST_NAME' -Value 'github.com' -Context $GitHubContext - .EXAMPLE - Sets a variable in an organisation with visibility set to private. - Set-GitHubVariable -Owner "octocat" -Name "myVariable" -Value "myValue" -Private + Creates or updates an environment variable named `HOST_NAME` with the value `github.com` in the specified environment. - .EXAMPLE - Sets a variable in an organisation with visibility set to selected repositories. - Set-GitHubVariable -Owner "octocat" -Name "myVariable" -Value "myValue" -SelectedRepositoryIds 123456, 654362 - - .NOTES - [Create an organization variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#create-an-organization-variable) - [Create a repository variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#create-a-repository-variable) - [Create an environment variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#create-an-environment-variable) - [Update an organization variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#update-an-organization-variable) - [Update a repository variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#update-a-repository-variable) - [Update an environment variable](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#update-an-environment-variable) - - .OUTPUTS - psobject[] + .LINK + https://psmodule.io/GitHub/Functions/Variables/Set-GitHubVariable/ #> - [OutputType([psobject[]])] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSShouldProcess', '', Scope = 'Function', + Justification = 'This check is performed in the private functions.' + )] + [OutputType([GitHubVariable])] [CmdletBinding(SupportsShouldProcess)] param( - [Parameter(ParameterSetName = 'Environment', Mandatory)] - [Parameter(ParameterSetName = 'Organization', Mandatory)] - [Parameter(ParameterSetName = 'Repository', Mandatory)] + # The account owner of the repository. The name is not case sensitive. + [Parameter(Mandatory, ParameterSetName = 'Organization')] + [Parameter(Mandatory, ParameterSetName = 'Repository')] + [Parameter(Mandatory, ParameterSetName = 'Environment')] [Alias('Organization', 'User')] [string] $Owner, # The name of the repository. The name is not case sensitive. - [Parameter(ParameterSetName = 'Environment', Mandatory)] - [Parameter(ParameterSetName = 'Repository', Mandatory)] + [Parameter(Mandatory, ParameterSetName = 'Repository')] + [Parameter(Mandatory, ParameterSetName = 'Environment')] [string] $Repository, # The name of the repository environment. - [Parameter(ParameterSetName = 'Environment', Mandatory)] + [Parameter(Mandatory, ParameterSetName = 'Environment')] [string] $Environment, # The name of the variable. [Parameter(Mandatory)] [string] $Name, - [Parameter(Mandatory)] + # The value of the variable. + [Parameter()] [string] $Value, + # The visibility of the variable when updating an organization variable. + # Can be `private`, `selected`, or `all`. [Parameter(ParameterSetName = 'Organization')] - [switch] $Private, + [ValidateSet('private', 'selected', 'all')] + [string] $Visibility = 'private', + # The IDs of the repositories to which the variable is available. + # Used only when the `-Visibility` parameter is set to `selected`. [Parameter(ParameterSetName = 'Organization')] - [int[]] $SelectedRepositoryIDs, + [UInt64[]] $SelectedRepositories, - # The context to run the command in. Used to get the details for the API call. - # Can be either a string or a GitHubContext object. + # The context to run the command in. Can be either a string or a GitHubContext object. [Parameter()] [object] $Context = (Get-GitHubContext) ) @@ -106,55 +86,39 @@ function Set-GitHubVariable { } process { - $getParams = $PSBoundParameters - $getParams | Remove-HashtableEntry -NullOrEmptyValues -RemoveNames 'Value', 'Private', 'SelectedRepositoryIDs', 'Context' - $variableFound = Get-GitHubVariable @getParams -Name $Name - - $body = @{ - name = $Name - value = $Value + $getParams = @{ + Owner = $Owner + Repository = $Repository + Environment = $Environment + Name = $Name + Context = $Context + } + $getParams | Remove-HashtableEntry -NullOrEmptyValues + + $params = @{ + Owner = $Owner + Repository = $Repository + Environment = $Environment + Name = $Name + Value = $Value + SelectedRepositories = $SelectedRepositories + Context = $Context + ErrorAction = 'Stop' } - if ($PSCmdlet.ParameterSetName -eq 'Organization') { - if ($PSBoundParameters.ContainsKey('SelectedRepositoryIDs')) { - $body['selected_repository_ids'] = @($SelectedRepositoryIDs) - $body['visibility'] = 'selected' - } elseif ($Private) { - $body['visibility'] = 'private' - } else { - $body['visibility'] = 'all' - } + $params.Visibility = $Visibility } + $params | Remove-HashtableEntry -NullOrEmptyValues - $inputObject = @{ - Method = 'Post' - APIEndpoint = switch ($PSCmdlet.ParameterSetName) { - 'Environment' { - "/repos/$Owner/$Repository/environments/$Environment/variables" - break - } - 'Repository' { - "/repos/$Owner/$Repository/actions/variables" - break - } - 'Organization' { - "/orgs/$Owner/actions/variables" - break - } - } - Body = $body - Context = $Context - } + $variable = Get-GitHubVariable @getParams -ErrorAction SilentlyContinue - if ($variableFound) { - $inputObject.Method = 'PATCH' - $inputObject.APIEndpoint = $inputObject.APIEndpoint + "/$Name" + if ($variable) { + $null = Update-GitHubVariable @params + } else { + $null = New-GitHubVariable @params } - if ($PSCmdlet.ShouldProcess("Variable [$Name]", 'CREATE/UPDATE')) { - $result = Invoke-GitHubAPI @inputObject - Write-Output $result.Response - } + Get-GitHubVariable @getParams } end { diff --git a/src/functions/public/Variables/Update-GitHubVariable.ps1 b/src/functions/public/Variables/Update-GitHubVariable.ps1 index d9f8e6465..b0c0b6a50 100644 --- a/src/functions/public/Variables/Update-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Update-GitHubVariable.ps1 @@ -33,7 +33,7 @@ function Update-GitHubVariable { 'PSShouldProcess', '', Scope = 'Function', Justification = 'This check is performed in the private functions.' )] - [OutputType([void])] + [OutputType([GitHubVariable])] [CmdletBinding(SupportsShouldProcess)] param( # The account owner of the repository. The name is not case sensitive. From 63466e07fdf9f7494f8d9169227cc71a6e727764 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 01:00:39 +0100 Subject: [PATCH 33/85] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Refactor=20Set-?= =?UTF-8?q?GitHubVariable=20function=20to=20filter=20Get-GitHubVariable=20?= =?UTF-8?q?results=20by=20Name=20for=20improved=20accuracy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/functions/public/Variables/Set-GitHubVariable.ps1 | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/functions/public/Variables/Set-GitHubVariable.ps1 b/src/functions/public/Variables/Set-GitHubVariable.ps1 index 495e4fe88..c893271f1 100644 --- a/src/functions/public/Variables/Set-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Set-GitHubVariable.ps1 @@ -90,7 +90,6 @@ function Set-GitHubVariable { Owner = $Owner Repository = $Repository Environment = $Environment - Name = $Name Context = $Context } $getParams | Remove-HashtableEntry -NullOrEmptyValues @@ -110,7 +109,7 @@ function Set-GitHubVariable { } $params | Remove-HashtableEntry -NullOrEmptyValues - $variable = Get-GitHubVariable @getParams -ErrorAction SilentlyContinue + $variable = Get-GitHubVariable @getParams | Where-Object { $_.Name -eq $Name } if ($variable) { $null = Update-GitHubVariable @params @@ -118,7 +117,7 @@ function Set-GitHubVariable { $null = New-GitHubVariable @params } - Get-GitHubVariable @getParams + Get-GitHubVariable @getParams -Name $Name } end { From 82d778d559724f7ff3524edd1071117378ea1916 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 01:36:47 +0100 Subject: [PATCH 34/85] =?UTF-8?q?=F0=9F=A9=B9=20[Test]:=20Add=20Pester=20t?= =?UTF-8?q?ests=20for=20Set-GitHubVariable=20function=20across=20user=20an?= =?UTF-8?q?d=20organization=20accounts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 252 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 252 insertions(+) create mode 100644 tests/Variables.Tests.ps1 diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 new file mode 100644 index 000000000..7b02487e4 --- /dev/null +++ b/tests/Variables.Tests.ps1 @@ -0,0 +1,252 @@ +#Requires -Modules @{ ModuleName = 'Pester'; RequiredVersion = '5.7.1' } + +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSUseDeclaredVarsMoreThanAssignments', '', + Justification = 'Pester grouping syntax: known issue.' +)] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidUsingConvertToSecureStringWithPlainText', '', + Justification = 'Used to create a secure string for testing.' +)] +[CmdletBinding()] +param() + +BeforeAll { + $repoSuffix = 'VariableTest' + $environmentName = 'production' +} + +Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT)' { + BeforeAll { + Connect-GitHubAccount -Token $env:TEST_USER_USER_FG_PAT + $owner = 'psmodule-user' + $guid = [guid]::NewGuid().ToString() + $repo = "$repoSuffix-$guid" + New-GitHubRepository -Name $repo -AllowSquashMerge + Set-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName + } + AfterAll { + Remove-GitHubRepository -Owner $owner -Name $repo -Confirm:$false + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount + } + Context 'Variables' { + It 'Set-GitHubVariable - Repository' { + $param = @{ + Name = 'TestVariable' + Value = 'TestValue' + } + $result = Set-GitHubVariable @param -Owner $owner -Repository $repo + $result | Should -Not -BeNullOrEmpty + + $result | Remove-GitHubVariable + } + + It 'Set-GitHubVariable - Environment' { + $param = @{ + Name = 'TestVariable' + Value = 'TestValue' + } + $result = Set-GitHubVariable @param -Owner $owner -Repository $repo -Environment $environmentName + $result | Should -Not -BeNullOrEmpty + + $result | Remove-GitHubVariable + } + } +} + +Describe 'As a user - Fine-grained PAT token - organization account access (ORG_FG_PAT)' { + BeforeAll { + Connect-GitHubAccount -Token $env:TEST_USER_ORG_FG_PAT + $owner = 'psmodule-test-org2' + $guid = [guid]::NewGuid().ToString() + $repo = "$repoSuffix-$guid" + New-GitHubRepository -Owner $owner -Name $repo -AllowSquashMerge + Set-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName + } + AfterAll { + Remove-GitHubRepository -Owner $owner -Name $repo -Confirm:$false + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount + } + Context 'Variables' { + It 'Set-GitHubVariable - Organization' { + $param = @{ + Name = 'TestVariable' + Value = 'TestValue' + } + $result = Set-GitHubVariable @param -Owner $owner + $result | Should -Not -BeNullOrEmpty + + $result | Remove-GitHubVariable + } + + It 'Set-GitHubVariable - Repository' { + $param = @{ + Name = 'TestVariable' + Value = 'TestValue' + } + $result = Set-GitHubVariable @param -Owner $owner -Repository $repo + $result | Should -Not -BeNullOrEmpty + + $result | Remove-GitHubVariable + } + + It 'Set-GitHubVariable - Environment' { + $param = @{ + Name = 'TestVariable' + Value = 'TestValue' + } + $result = Set-GitHubVariable @param -Owner $owner -Repository $repo -Environment $environmentName + $result | Should -Not -BeNullOrEmpty + + $result | Remove-GitHubVariable + } + } +} + +Describe 'As a user - Classic PAT token (PAT)' { + BeforeAll { + Connect-GitHubAccount -Token $env:TEST_USER_PAT + $owner = 'psmodule-test-org2' + $guid = [guid]::NewGuid().ToString() + $repo = "$repoSuffix-$guid" + New-GitHubRepository -Owner $owner -Name $repo -AllowSquashMerge + Set-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName + } + AfterAll { + Remove-GitHubRepository -Owner $owner -Name $repo -Confirm:$false + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount + } + Context 'Variables' { + It 'Set-GitHubVariable - Repository' { + $param = @{ + Name = 'TestVariable' + Value = 'TestValue' + } + $result = Set-GitHubVariable @param -Owner $owner -Repository $repo + $result | Should -Not -BeNullOrEmpty + + $result | Remove-GitHubVariable + } + + It 'Set-GitHubVariable - Environment' { + $param = @{ + Name = 'TestVariable' + Value = 'TestValue' + } + $result = Set-GitHubVariable @param -Owner $owner -Repository $repo -Environment $environmentName + $result | Should -Not -BeNullOrEmpty + + $result | Remove-GitHubVariable + } + } +} + +Describe 'As GitHub Actions (GHA)' { + BeforeAll { + Connect-GitHubAccount + } + AfterAll { + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount + } + Context 'Variables' { + + } +} + +Describe 'As a GitHub App - Enterprise (APP_ENT)' { + BeforeAll { + Connect-GitHubAccount -ClientID $env:TEST_APP_ENT_CLIENT_ID -PrivateKey $env:TEST_APP_ENT_PRIVATE_KEY + $owner = 'psmodule-test-org3' + $guid = [guid]::NewGuid().ToString() + $repo = "$repoSuffix-$guid" + Connect-GitHubApp -Organization $owner -Default + New-GitHubRepository -Owner $owner -Name $repo -AllowSquashMerge + } + AfterAll { + Remove-GitHubRepository -Owner $owner -Name $repo -Confirm:$false + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount + } + Context 'Variables' { + It 'Set-GitHubVariable - Organization' { + $param = @{ + Name = 'TestVariable' + Value = 'TestValue' + } + $result = Set-GitHubVariable @param -Owner $owner + $result | Should -Not -BeNullOrEmpty + + $result | Remove-GitHubVariable + } + + It 'Set-GitHubVariable - Repository' { + $param = @{ + Name = 'TestVariable' + Value = 'TestValue' + } + $result = Set-GitHubVariable @param -Owner $owner -Repository $repo + $result | Should -Not -BeNullOrEmpty + + $result | Remove-GitHubVariable + } + + It 'Set-GitHubVariable - Environment' { + $param = @{ + Name = 'TestVariable' + Value = 'TestValue' + } + $result = Set-GitHubVariable @param -Owner $owner -Repository $repo -Environment $environmentName + $result | Should -Not -BeNullOrEmpty + + $result | Remove-GitHubVariable + } + } +} + +Describe 'As a GitHub App - Organization (APP_ORG)' { + BeforeAll { + Connect-GitHubAccount -ClientID $env:TEST_APP_ORG_CLIENT_ID -PrivateKey $env:TEST_APP_ORG_PRIVATE_KEY + $owner = 'psmodule-test-org' + $guid = [guid]::NewGuid().ToString() + $repo = "$repoSuffix-$guid" + Connect-GitHubApp -Organization $owner -Default + New-GitHubRepository -Owner $owner -Name $repo -AllowSquashMerge + } + AfterAll { + Remove-GitHubRepository -Owner $owner -Name $repo -Confirm:$false + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount + } + Context 'Variables' { + It 'Set-GitHubVariable - Organization' { + $param = @{ + Name = 'TestVariable' + Value = 'TestValue' + } + $result = Set-GitHubVariable @param -Owner $owner + $result | Should -Not -BeNullOrEmpty + + $result | Remove-GitHubVariable + } + + It 'Set-GitHubVariable - Repository' { + $param = @{ + Name = 'TestVariable' + Value = 'TestValue' + } + $result = Set-GitHubVariable @param -Owner $owner -Repository $repo + $result | Should -Not -BeNullOrEmpty + + $result | Remove-GitHubVariable + } + + It 'Set-GitHubVariable - Environment' { + $param = @{ + Name = 'TestVariable' + Value = 'TestValue' + } + $result = Set-GitHubVariable @param -Owner $owner -Repository $repo -Environment $environmentName + $result | Should -Not -BeNullOrEmpty + + $result | Remove-GitHubVariable + } + } +} From 3f17c5001f51ebc5f52cbdfdc7d318d87d3c7c1b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 01:44:23 +0100 Subject: [PATCH 35/85] =?UTF-8?q?=F0=9F=A9=B9=20[Test]:=20Add=20Set-GitHub?= =?UTF-8?q?Environment=20calls=20in=20repository=20tests=20for=20improved?= =?UTF-8?q?=20environment=20setup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 7b02487e4..d2afc9358 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -161,6 +161,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { $repo = "$repoSuffix-$guid" Connect-GitHubApp -Organization $owner -Default New-GitHubRepository -Owner $owner -Name $repo -AllowSquashMerge + Set-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName } AfterAll { Remove-GitHubRepository -Owner $owner -Name $repo -Confirm:$false @@ -210,6 +211,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { $repo = "$repoSuffix-$guid" Connect-GitHubApp -Organization $owner -Default New-GitHubRepository -Owner $owner -Name $repo -AllowSquashMerge + Set-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName } AfterAll { Remove-GitHubRepository -Owner $owner -Name $repo -Confirm:$false From d8f6f80cf997241966e01a113622fb05acb497e4 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 01:59:37 +0100 Subject: [PATCH 36/85] =?UTF-8?q?=F0=9F=A9=B9=20[Test]:=20Refactor=20and?= =?UTF-8?q?=20enhance=20Set-GitHubVariable=20tests=20for=20user=20and=20or?= =?UTF-8?q?ganization=20accounts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 127 ++++++++++++++++++++++++++------------ 1 file changed, 89 insertions(+), 38 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index d2afc9358..6d345564e 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -30,26 +30,32 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } Context 'Variables' { - It 'Set-GitHubVariable - Repository' { - $param = @{ - Name = 'TestVariable' - Value = 'TestValue' - } - $result = Set-GitHubVariable @param -Owner $owner -Repository $repo - $result | Should -Not -BeNullOrEmpty + Context 'Repository' { + It 'Set-GitHubVariable' { + $param = @{ + Name = 'TestVariable' + Value = 'TestValue' + } + $result = Set-GitHubVariable @param -Owner $owner -Repository $repo + $result = Set-GitHubVariable @param -Owner $owner -Repository $repo + $result | Should -Not -BeNullOrEmpty - $result | Remove-GitHubVariable + $result | Remove-GitHubVariable + } } - It 'Set-GitHubVariable - Environment' { - $param = @{ - Name = 'TestVariable' - Value = 'TestValue' - } - $result = Set-GitHubVariable @param -Owner $owner -Repository $repo -Environment $environmentName - $result | Should -Not -BeNullOrEmpty + Context 'Environment' { + It 'Set-GitHubVariable' { + $param = @{ + Name = 'TestVariable' + Value = 'TestValue' + } + $result = Set-GitHubVariable @param -Owner $owner -Repository $repo -Environment $environmentName + $result = Set-GitHubVariable @param -Owner $owner -Repository $repo -Environment $environmentName + $result | Should -Not -BeNullOrEmpty - $result | Remove-GitHubVariable + $result | Remove-GitHubVariable + } } } } @@ -68,38 +74,75 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } Context 'Variables' { - It 'Set-GitHubVariable - Organization' { - $param = @{ - Name = 'TestVariable' - Value = 'TestValue' + Context 'Organization' { + It 'Set-GitHubVariable' { + $param = @{ + Name = 'TestVariable' + Value = 'TestValue' + } + $result = Set-GitHubVariable @param -Owner $owner + $result = Set-GitHubVariable @param -Owner $owner + $result | Should -Not -BeNullOrEmpty } - $result = Set-GitHubVariable @param -Owner $owner - $result | Should -Not -BeNullOrEmpty - $result | Remove-GitHubVariable - } + It 'Update-GitHubVariable' { + $param = @{ + Name = 'TestVariable' + Value = 'TestValue123' + Visibility = 'all' + } + $result = Update-GitHubVariable @param -Owner $owner + $result | Should -Not -BeNullOrEmpty + } - It 'Set-GitHubVariable - Repository' { - $param = @{ - Name = 'TestVariable' - Value = 'TestValue' + It 'New-GitHubVariable' { + $param = @{ + Name = 'TestVariable2' + Value = 'TestValue123' + } + $result = New-GitHubVariable @param -Owner $owner + $result | Should -Not -BeNullOrEmpty } - $result = Set-GitHubVariable @param -Owner $owner -Repository $repo - $result | Should -Not -BeNullOrEmpty - $result | Remove-GitHubVariable + It 'Get-GitHubVariable' { + $result = Get-GitHubVariable -Owner $owner + $result | Should -Not -BeNullOrEmpty + } + + It 'Remove-GitHubVariable' { + Get-GitHubVariable -Owner $owner | Remove-GitHubVariable + Get-GitHubVariable -Owner $owner | Should -BeNullOrEmpty + } } - It 'Set-GitHubVariable - Environment' { - $param = @{ - Name = 'TestVariable' - Value = 'TestValue' + Context 'Repository' { + It 'Set-GitHubVariable' { + $param = @{ + Name = 'TestVariable' + Value = 'TestValue' + } + $result = Set-GitHubVariable @param -Owner $owner -Repository $repo + $result = Set-GitHubVariable @param -Owner $owner -Repository $repo + $result | Should -Not -BeNullOrEmpty + + $result | Remove-GitHubVariable } - $result = Set-GitHubVariable @param -Owner $owner -Repository $repo -Environment $environmentName - $result | Should -Not -BeNullOrEmpty + } + Context 'Environment' { + It 'Set-GitHubVariable' { + $param = @{ + Name = 'TestVariable' + Value = 'TestValue' + } + $result = Set-GitHubVariable @param -Owner $owner -Repository $repo -Environment $environmentName + $result = Set-GitHubVariable @param -Owner $owner -Repository $repo -Environment $environmentName + $result | Should -Not -BeNullOrEmpty - $result | Remove-GitHubVariable + $result | Remove-GitHubVariable + } } + + } } @@ -123,6 +166,7 @@ Describe 'As a user - Classic PAT token (PAT)' { Value = 'TestValue' } $result = Set-GitHubVariable @param -Owner $owner -Repository $repo + $result = Set-GitHubVariable @param -Owner $owner -Repository $repo $result | Should -Not -BeNullOrEmpty $result | Remove-GitHubVariable @@ -134,6 +178,7 @@ Describe 'As a user - Classic PAT token (PAT)' { Value = 'TestValue' } $result = Set-GitHubVariable @param -Owner $owner -Repository $repo -Environment $environmentName + $result = Set-GitHubVariable @param -Owner $owner -Repository $repo -Environment $environmentName $result | Should -Not -BeNullOrEmpty $result | Remove-GitHubVariable @@ -174,6 +219,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { Value = 'TestValue' } $result = Set-GitHubVariable @param -Owner $owner + $result = Set-GitHubVariable @param -Owner $owner $result | Should -Not -BeNullOrEmpty $result | Remove-GitHubVariable @@ -185,6 +231,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { Value = 'TestValue' } $result = Set-GitHubVariable @param -Owner $owner -Repository $repo + $result = Set-GitHubVariable @param -Owner $owner -Repository $repo $result | Should -Not -BeNullOrEmpty $result | Remove-GitHubVariable @@ -196,6 +243,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { Value = 'TestValue' } $result = Set-GitHubVariable @param -Owner $owner -Repository $repo -Environment $environmentName + $result = Set-GitHubVariable @param -Owner $owner -Repository $repo -Environment $environmentName $result | Should -Not -BeNullOrEmpty $result | Remove-GitHubVariable @@ -224,6 +272,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { Value = 'TestValue' } $result = Set-GitHubVariable @param -Owner $owner + $result = Set-GitHubVariable @param -Owner $owner $result | Should -Not -BeNullOrEmpty $result | Remove-GitHubVariable @@ -235,6 +284,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { Value = 'TestValue' } $result = Set-GitHubVariable @param -Owner $owner -Repository $repo + $result = Set-GitHubVariable @param -Owner $owner -Repository $repo $result | Should -Not -BeNullOrEmpty $result | Remove-GitHubVariable @@ -246,6 +296,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { Value = 'TestValue' } $result = Set-GitHubVariable @param -Owner $owner -Repository $repo -Environment $environmentName + $result = Set-GitHubVariable @param -Owner $owner -Repository $repo -Environment $environmentName $result | Should -Not -BeNullOrEmpty $result | Remove-GitHubVariable From 5b12cc839a1566fc46dd75d53345af498f85d223 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 09:37:02 +0100 Subject: [PATCH 37/85] Send exception to throw --- src/functions/public/API/Invoke-GitHubAPI.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/functions/public/API/Invoke-GitHubAPI.ps1 b/src/functions/public/API/Invoke-GitHubAPI.ps1 index 467e32da6..ec723d8be 100644 --- a/src/functions/public/API/Invoke-GitHubAPI.ps1 +++ b/src/functions/public/API/Invoke-GitHubAPI.ps1 @@ -300,7 +300,7 @@ filter Invoke-GitHubAPI { $APICall.Headers = $APICall.Headers | ConvertTo-Json $APICall.Method = $APICall.Method.ToString() - Write-Warning @" + $exception = @" ---------------------------------- Error details: @@ -311,7 +311,7 @@ $($errorResult | Format-List | Out-String -Stream | ForEach-Object { " $_`n" $PSCmdlet.ThrowTerminatingError( [System.Management.Automation.ErrorRecord]::new( - [System.Exception]::new('GitHub API call failed. See error details above.'), + [System.Exception]::new($exception), 'GitHubAPIError', [System.Management.Automation.ErrorCategory]::InvalidOperation, $errorResult From 2ae757af362d6fefe992d7a33045778bbe7a6239 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 09:37:32 +0100 Subject: [PATCH 38/85] Set a prefix for tests to avoid clobbering from other tests --- tests/Variables.Tests.ps1 | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 6d345564e..3d168cd5f 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -64,6 +64,8 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ BeforeAll { Connect-GitHubAccount -Token $env:TEST_USER_ORG_FG_PAT $owner = 'psmodule-test-org2' + $os = Get-GitHubRunnerData | Select-Object -ExpandProperty OS + $prefix = $os + 'ORG_FG_PAT' $guid = [guid]::NewGuid().ToString() $repo = "$repoSuffix-$guid" New-GitHubRepository -Owner $owner -Name $repo -AllowSquashMerge @@ -77,7 +79,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ Context 'Organization' { It 'Set-GitHubVariable' { $param = @{ - Name = 'TestVariable' + Name = "$prefix`TestVariable" Value = 'TestValue' } $result = Set-GitHubVariable @param -Owner $owner @@ -87,7 +89,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ It 'Update-GitHubVariable' { $param = @{ - Name = 'TestVariable' + Name = "$prefix`TestVariable" Value = 'TestValue123' Visibility = 'all' } @@ -97,7 +99,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ It 'New-GitHubVariable' { $param = @{ - Name = 'TestVariable2' + Name = "$prefix`TestVariable2" Value = 'TestValue123' } $result = New-GitHubVariable @param -Owner $owner @@ -118,7 +120,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ Context 'Repository' { It 'Set-GitHubVariable' { $param = @{ - Name = 'TestVariable' + Name = "$prefix`TestVariable" Value = 'TestValue' } $result = Set-GitHubVariable @param -Owner $owner -Repository $repo @@ -131,7 +133,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ Context 'Environment' { It 'Set-GitHubVariable' { $param = @{ - Name = 'TestVariable' + Name = "$prefix`TestVariable" Value = 'TestValue' } $result = Set-GitHubVariable @param -Owner $owner -Repository $repo -Environment $environmentName From 24a7735aea84ee94189b88bff159297e82c688cd Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 10:06:13 +0100 Subject: [PATCH 39/85] =?UTF-8?q?=F0=9F=A9=B9=20[Test]:=20Add=20Connect-Gi?= =?UTF-8?q?tHubApp=20calls=20for=20organization=20tests=20to=20improve=20s?= =?UTF-8?q?etup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/TEMPLATE.ps1 | 2 + tests/Variables.Tests.ps1 | 686 +++++++++++++++++++++++++++++++------- 2 files changed, 568 insertions(+), 120 deletions(-) diff --git a/tests/TEMPLATE.ps1 b/tests/TEMPLATE.ps1 index 087ab37d6..f9d18a136 100644 --- a/tests/TEMPLATE.ps1 +++ b/tests/TEMPLATE.ps1 @@ -71,6 +71,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { BeforeAll { Connect-GitHubAccount -ClientID $env:TEST_APP_ENT_CLIENT_ID -PrivateKey $env:TEST_APP_ENT_PRIVATE_KEY $owner = 'psmodule-test-org3' + Connect-GitHubApp -Organization $owner -Default } AfterAll { Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount @@ -84,6 +85,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { BeforeAll { Connect-GitHubAccount -ClientID $env:TEST_APP_ORG_CLIENT_ID -PrivateKey $env:TEST_APP_ORG_PRIVATE_KEY $owner = 'psmodule-test-org' + Connect-GitHubApp -Organization $owner -Default } AfterAll { Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 3d168cd5f..ffbb1b8a3 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -14,6 +14,8 @@ param() BeforeAll { $repoSuffix = 'VariableTest' $environmentName = 'production' + $os = Get-GitHubRunnerData | Select-Object -ExpandProperty OS + $prefix = $os + 'ORG_FG_PAT' } Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT)' { @@ -22,40 +24,104 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) $owner = 'psmodule-user' $guid = [guid]::NewGuid().ToString() $repo = "$repoSuffix-$guid" - New-GitHubRepository -Name $repo -AllowSquashMerge + New-GitHubRepository -Owner $owner -Name $repo -AllowSquashMerge Set-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName } AfterAll { Remove-GitHubRepository -Owner $owner -Name $repo -Confirm:$false Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } - Context 'Variables' { - Context 'Repository' { - It 'Set-GitHubVariable' { - $param = @{ - Name = 'TestVariable' - Value = 'TestValue' - } - $result = Set-GitHubVariable @param -Owner $owner -Repository $repo - $result = Set-GitHubVariable @param -Owner $owner -Repository $repo - $result | Should -Not -BeNullOrEmpty + Context 'Repository' { + BeforeAll { + $scope = @{ + Owner = $owner + Repository = $repo + } + } + It 'Set-GitHubVariable' { + $param = @{ + Name = "$prefix`TestVariable" + Value = 'TestValue' + } + $result = Set-GitHubVariable @param @scope + $result = Set-GitHubVariable @param @scope + $result | Should -Not -BeNullOrEmpty + } + + It 'Update-GitHubVariable' { + $param = @{ + Name = "$prefix`TestVariable" + Value = 'TestValue123' + Visibility = 'all' + } + $result = Update-GitHubVariable @param @scope -PassThru + $result | Should -Not -BeNullOrEmpty + } - $result | Remove-GitHubVariable + It 'New-GitHubVariable' { + $param = @{ + Name = "$prefix`TestVariable2" + Value = 'TestValue123' } + $result = New-GitHubVariable @param @scope + $result | Should -Not -BeNullOrEmpty } - Context 'Environment' { - It 'Set-GitHubVariable' { - $param = @{ - Name = 'TestVariable' - Value = 'TestValue' - } - $result = Set-GitHubVariable @param -Owner $owner -Repository $repo -Environment $environmentName - $result = Set-GitHubVariable @param -Owner $owner -Repository $repo -Environment $environmentName - $result | Should -Not -BeNullOrEmpty + It 'Get-GitHubVariable' { + $result = Get-GitHubVariable @scope + $result | Should -Not -BeNullOrEmpty + } + + It 'Remove-GitHubVariable' { + Get-GitHubVariable @scope | Remove-GitHubVariable + Get-GitHubVariable @scope | Should -BeNullOrEmpty + } + } + Context 'Environment' { + BeforeAll { + $scope = @{ + Owner = $owner + Repository = $repo + Environment = $environmentName + } + } + It 'Set-GitHubVariable' { + $param = @{ + Name = "$prefix`TestVariable" + Value = 'TestValue' + } + $result = Set-GitHubVariable @param @scope + $result = Set-GitHubVariable @param @scope + $result | Should -Not -BeNullOrEmpty + } + + It 'Update-GitHubVariable' { + $param = @{ + Name = "$prefix`TestVariable" + Value = 'TestValue123' + Visibility = 'all' + } + $result = Update-GitHubVariable @param @scope -PassThru + $result | Should -Not -BeNullOrEmpty + } - $result | Remove-GitHubVariable + It 'New-GitHubVariable' { + $param = @{ + Name = "$prefix`TestVariable2" + Value = 'TestValue123' } + $result = New-GitHubVariable @param @scope + $result | Should -Not -BeNullOrEmpty + } + + It 'Get-GitHubVariable' { + $result = Get-GitHubVariable @scope + $result | Should -Not -BeNullOrEmpty + } + + It 'Remove-GitHubVariable' { + Get-GitHubVariable @scope | Remove-GitHubVariable + Get-GitHubVariable @scope | Should -BeNullOrEmpty } } } @@ -64,8 +130,6 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ BeforeAll { Connect-GitHubAccount -Token $env:TEST_USER_ORG_FG_PAT $owner = 'psmodule-test-org2' - $os = Get-GitHubRunnerData | Select-Object -ExpandProperty OS - $prefix = $os + 'ORG_FG_PAT' $guid = [guid]::NewGuid().ToString() $repo = "$repoSuffix-$guid" New-GitHubRepository -Owner $owner -Name $repo -AllowSquashMerge @@ -75,76 +139,143 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ Remove-GitHubRepository -Owner $owner -Name $repo -Confirm:$false Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } - Context 'Variables' { - Context 'Organization' { - It 'Set-GitHubVariable' { - $param = @{ - Name = "$prefix`TestVariable" - Value = 'TestValue' - } - $result = Set-GitHubVariable @param -Owner $owner - $result = Set-GitHubVariable @param -Owner $owner - $result | Should -Not -BeNullOrEmpty + Context 'Organization' { + BeforeAll { + $scope = @{ + Owner = $owner + } + } + It 'Set-GitHubVariable' { + $param = @{ + Name = "$prefix`TestVariable" + Value = 'TestValue' } + $result = Set-GitHubVariable @param @scope + $result = Set-GitHubVariable @param @scope + $result | Should -Not -BeNullOrEmpty + } - It 'Update-GitHubVariable' { - $param = @{ - Name = "$prefix`TestVariable" - Value = 'TestValue123' - Visibility = 'all' - } - $result = Update-GitHubVariable @param -Owner $owner - $result | Should -Not -BeNullOrEmpty + It 'Update-GitHubVariable' { + $param = @{ + Name = "$prefix`TestVariable" + Value = 'TestValue123' + Visibility = 'all' + } + $result = Update-GitHubVariable @param @scope -PassThru + $result | Should -Not -BeNullOrEmpty + } + + It 'New-GitHubVariable' { + $param = @{ + Name = "$prefix`TestVariable2" + Value = 'TestValue123' } + $result = New-GitHubVariable @param @scope + $result | Should -Not -BeNullOrEmpty + } - It 'New-GitHubVariable' { - $param = @{ - Name = "$prefix`TestVariable2" - Value = 'TestValue123' - } - $result = New-GitHubVariable @param -Owner $owner - $result | Should -Not -BeNullOrEmpty + It 'Get-GitHubVariable' { + $result = Get-GitHubVariable @scope + $result | Should -Not -BeNullOrEmpty + } + + It 'Remove-GitHubVariable' { + Get-GitHubVariable @scope | Remove-GitHubVariable + Get-GitHubVariable @scope | Should -BeNullOrEmpty + } + } + Context 'Repository' { + BeforeAll { + $scope = @{ + Owner = $owner + Repository = $repo + } + } + It 'Set-GitHubVariable' { + $param = @{ + Name = "$prefix`TestVariable" + Value = 'TestValue' } + $result = Set-GitHubVariable @param @scope + $result = Set-GitHubVariable @param @scope + $result | Should -Not -BeNullOrEmpty + } - It 'Get-GitHubVariable' { - $result = Get-GitHubVariable -Owner $owner - $result | Should -Not -BeNullOrEmpty + It 'Update-GitHubVariable' { + $param = @{ + Name = "$prefix`TestVariable" + Value = 'TestValue123' + Visibility = 'all' } + $result = Update-GitHubVariable @param @scope -PassThru + $result | Should -Not -BeNullOrEmpty + } - It 'Remove-GitHubVariable' { - Get-GitHubVariable -Owner $owner | Remove-GitHubVariable - Get-GitHubVariable -Owner $owner | Should -BeNullOrEmpty + It 'New-GitHubVariable' { + $param = @{ + Name = "$prefix`TestVariable2" + Value = 'TestValue123' } + $result = New-GitHubVariable @param @scope + $result | Should -Not -BeNullOrEmpty } - Context 'Repository' { - It 'Set-GitHubVariable' { - $param = @{ - Name = "$prefix`TestVariable" - Value = 'TestValue' - } - $result = Set-GitHubVariable @param -Owner $owner -Repository $repo - $result = Set-GitHubVariable @param -Owner $owner -Repository $repo - $result | Should -Not -BeNullOrEmpty + It 'Get-GitHubVariable' { + $result = Get-GitHubVariable @scope + $result | Should -Not -BeNullOrEmpty + } - $result | Remove-GitHubVariable + It 'Remove-GitHubVariable' { + Get-GitHubVariable @scope | Remove-GitHubVariable + Get-GitHubVariable @scope | Should -BeNullOrEmpty + } + } + Context 'Environment' { + BeforeAll { + $scope = @{ + Owner = $owner + Repository = $repo + Environment = $environmentName } } - Context 'Environment' { - It 'Set-GitHubVariable' { - $param = @{ - Name = "$prefix`TestVariable" - Value = 'TestValue' - } - $result = Set-GitHubVariable @param -Owner $owner -Repository $repo -Environment $environmentName - $result = Set-GitHubVariable @param -Owner $owner -Repository $repo -Environment $environmentName - $result | Should -Not -BeNullOrEmpty + It 'Set-GitHubVariable' { + $param = @{ + Name = "$prefix`TestVariable" + Value = 'TestValue' + } + $result = Set-GitHubVariable @param @scope + $result = Set-GitHubVariable @param @scope + $result | Should -Not -BeNullOrEmpty + } - $result | Remove-GitHubVariable + It 'Update-GitHubVariable' { + $param = @{ + Name = "$prefix`TestVariable" + Value = 'TestValue123' + Visibility = 'all' } + $result = Update-GitHubVariable @param @scope -PassThru + $result | Should -Not -BeNullOrEmpty } + It 'New-GitHubVariable' { + $param = @{ + Name = "$prefix`TestVariable2" + Value = 'TestValue123' + } + $result = New-GitHubVariable @param @scope + $result | Should -Not -BeNullOrEmpty + } + It 'Get-GitHubVariable' { + $result = Get-GitHubVariable @scope + $result | Should -Not -BeNullOrEmpty + } + + It 'Remove-GitHubVariable' { + Get-GitHubVariable @scope | Remove-GitHubVariable + Get-GitHubVariable @scope | Should -BeNullOrEmpty + } } } @@ -161,29 +292,142 @@ Describe 'As a user - Classic PAT token (PAT)' { Remove-GitHubRepository -Owner $owner -Name $repo -Confirm:$false Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } - Context 'Variables' { - It 'Set-GitHubVariable - Repository' { + Context 'Organization' { + BeforeAll { + $scope = @{ + Owner = $owner + } + } + It 'Set-GitHubVariable' { $param = @{ - Name = 'TestVariable' + Name = "$prefix`TestVariable" Value = 'TestValue' } - $result = Set-GitHubVariable @param -Owner $owner -Repository $repo - $result = Set-GitHubVariable @param -Owner $owner -Repository $repo + $result = Set-GitHubVariable @param @scope + $result = Set-GitHubVariable @param @scope + $result | Should -Not -BeNullOrEmpty + } + + It 'Update-GitHubVariable' { + $param = @{ + Name = "$prefix`TestVariable" + Value = 'TestValue123' + Visibility = 'all' + } + $result = Update-GitHubVariable @param @scope -PassThru + $result | Should -Not -BeNullOrEmpty + } + + It 'New-GitHubVariable' { + $param = @{ + Name = "$prefix`TestVariable2" + Value = 'TestValue123' + } + $result = New-GitHubVariable @param @scope + $result | Should -Not -BeNullOrEmpty + } + + It 'Get-GitHubVariable' { + $result = Get-GitHubVariable @scope + $result | Should -Not -BeNullOrEmpty + } + + It 'Remove-GitHubVariable' { + Get-GitHubVariable @scope | Remove-GitHubVariable + Get-GitHubVariable @scope | Should -BeNullOrEmpty + } + } + Context 'Repository' { + BeforeAll { + $scope = @{ + Owner = $owner + Repository = $repo + } + } + It 'Set-GitHubVariable' { + $param = @{ + Name = "$prefix`TestVariable" + Value = 'TestValue' + } + $result = Set-GitHubVariable @param @scope + $result = Set-GitHubVariable @param @scope + $result | Should -Not -BeNullOrEmpty + } + + It 'Update-GitHubVariable' { + $param = @{ + Name = "$prefix`TestVariable" + Value = 'TestValue123' + Visibility = 'all' + } + $result = Update-GitHubVariable @param @scope -PassThru + $result | Should -Not -BeNullOrEmpty + } + + It 'New-GitHubVariable' { + $param = @{ + Name = "$prefix`TestVariable2" + Value = 'TestValue123' + } + $result = New-GitHubVariable @param @scope $result | Should -Not -BeNullOrEmpty + } - $result | Remove-GitHubVariable + It 'Get-GitHubVariable' { + $result = Get-GitHubVariable @scope + $result | Should -Not -BeNullOrEmpty } - It 'Set-GitHubVariable - Environment' { + It 'Remove-GitHubVariable' { + Get-GitHubVariable @scope | Remove-GitHubVariable + Get-GitHubVariable @scope | Should -BeNullOrEmpty + } + } + Context 'Environment' { + BeforeAll { + $scope = @{ + Owner = $owner + Repository = $repo + Environment = $environmentName + } + } + It 'Set-GitHubVariable' { $param = @{ - Name = 'TestVariable' + Name = "$prefix`TestVariable" Value = 'TestValue' } - $result = Set-GitHubVariable @param -Owner $owner -Repository $repo -Environment $environmentName - $result = Set-GitHubVariable @param -Owner $owner -Repository $repo -Environment $environmentName + $result = Set-GitHubVariable @param @scope + $result = Set-GitHubVariable @param @scope $result | Should -Not -BeNullOrEmpty + } - $result | Remove-GitHubVariable + It 'Update-GitHubVariable' { + $param = @{ + Name = "$prefix`TestVariable" + Value = 'TestValue123' + Visibility = 'all' + } + $result = Update-GitHubVariable @param @scope -PassThru + $result | Should -Not -BeNullOrEmpty + } + + It 'New-GitHubVariable' { + $param = @{ + Name = "$prefix`TestVariable2" + Value = 'TestValue123' + } + $result = New-GitHubVariable @param @scope + $result | Should -Not -BeNullOrEmpty + } + + It 'Get-GitHubVariable' { + $result = Get-GitHubVariable @scope + $result | Should -Not -BeNullOrEmpty + } + + It 'Remove-GitHubVariable' { + Get-GitHubVariable @scope | Remove-GitHubVariable + Get-GitHubVariable @scope | Should -BeNullOrEmpty } } } @@ -204,9 +448,9 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { BeforeAll { Connect-GitHubAccount -ClientID $env:TEST_APP_ENT_CLIENT_ID -PrivateKey $env:TEST_APP_ENT_PRIVATE_KEY $owner = 'psmodule-test-org3' + Connect-GitHubApp -Organization $owner -Default $guid = [guid]::NewGuid().ToString() $repo = "$repoSuffix-$guid" - Connect-GitHubApp -Organization $owner -Default New-GitHubRepository -Owner $owner -Name $repo -AllowSquashMerge Set-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName } @@ -214,41 +458,142 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { Remove-GitHubRepository -Owner $owner -Name $repo -Confirm:$false Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } - Context 'Variables' { - It 'Set-GitHubVariable - Organization' { + Context 'Organization' { + BeforeAll { + $scope = @{ + Owner = $owner + } + } + It 'Set-GitHubVariable' { $param = @{ - Name = 'TestVariable' + Name = "$prefix`TestVariable" Value = 'TestValue' } - $result = Set-GitHubVariable @param -Owner $owner - $result = Set-GitHubVariable @param -Owner $owner + $result = Set-GitHubVariable @param @scope + $result = Set-GitHubVariable @param @scope + $result | Should -Not -BeNullOrEmpty + } + + It 'Update-GitHubVariable' { + $param = @{ + Name = "$prefix`TestVariable" + Value = 'TestValue123' + Visibility = 'all' + } + $result = Update-GitHubVariable @param @scope -PassThru + $result | Should -Not -BeNullOrEmpty + } + + It 'New-GitHubVariable' { + $param = @{ + Name = "$prefix`TestVariable2" + Value = 'TestValue123' + } + $result = New-GitHubVariable @param @scope $result | Should -Not -BeNullOrEmpty + } - $result | Remove-GitHubVariable + It 'Get-GitHubVariable' { + $result = Get-GitHubVariable @scope + $result | Should -Not -BeNullOrEmpty } - It 'Set-GitHubVariable - Repository' { + It 'Remove-GitHubVariable' { + Get-GitHubVariable @scope | Remove-GitHubVariable + Get-GitHubVariable @scope | Should -BeNullOrEmpty + } + } + Context 'Repository' { + BeforeAll { + $scope = @{ + Owner = $owner + Repository = $repo + } + } + It 'Set-GitHubVariable' { $param = @{ - Name = 'TestVariable' + Name = "$prefix`TestVariable" Value = 'TestValue' } - $result = Set-GitHubVariable @param -Owner $owner -Repository $repo - $result = Set-GitHubVariable @param -Owner $owner -Repository $repo + $result = Set-GitHubVariable @param @scope + $result = Set-GitHubVariable @param @scope $result | Should -Not -BeNullOrEmpty + } - $result | Remove-GitHubVariable + It 'Update-GitHubVariable' { + $param = @{ + Name = "$prefix`TestVariable" + Value = 'TestValue123' + Visibility = 'all' + } + $result = Update-GitHubVariable @param @scope -PassThru + $result | Should -Not -BeNullOrEmpty } - It 'Set-GitHubVariable - Environment' { + It 'New-GitHubVariable' { $param = @{ - Name = 'TestVariable' + Name = "$prefix`TestVariable2" + Value = 'TestValue123' + } + $result = New-GitHubVariable @param @scope + $result | Should -Not -BeNullOrEmpty + } + + It 'Get-GitHubVariable' { + $result = Get-GitHubVariable @scope + $result | Should -Not -BeNullOrEmpty + } + + It 'Remove-GitHubVariable' { + Get-GitHubVariable @scope | Remove-GitHubVariable + Get-GitHubVariable @scope | Should -BeNullOrEmpty + } + } + Context 'Environment' { + BeforeAll { + $scope = @{ + Owner = $owner + Repository = $repo + Environment = $environmentName + } + } + It 'Set-GitHubVariable' { + $param = @{ + Name = "$prefix`TestVariable" Value = 'TestValue' } - $result = Set-GitHubVariable @param -Owner $owner -Repository $repo -Environment $environmentName - $result = Set-GitHubVariable @param -Owner $owner -Repository $repo -Environment $environmentName + $result = Set-GitHubVariable @param @scope + $result = Set-GitHubVariable @param @scope + $result | Should -Not -BeNullOrEmpty + } + + It 'Update-GitHubVariable' { + $param = @{ + Name = "$prefix`TestVariable" + Value = 'TestValue123' + Visibility = 'all' + } + $result = Update-GitHubVariable @param @scope -PassThru + $result | Should -Not -BeNullOrEmpty + } + + It 'New-GitHubVariable' { + $param = @{ + Name = "$prefix`TestVariable2" + Value = 'TestValue123' + } + $result = New-GitHubVariable @param @scope + $result | Should -Not -BeNullOrEmpty + } + + It 'Get-GitHubVariable' { + $result = Get-GitHubVariable @scope $result | Should -Not -BeNullOrEmpty + } - $result | Remove-GitHubVariable + It 'Remove-GitHubVariable' { + Get-GitHubVariable @scope | Remove-GitHubVariable + Get-GitHubVariable @scope | Should -BeNullOrEmpty } } } @@ -257,9 +602,9 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { BeforeAll { Connect-GitHubAccount -ClientID $env:TEST_APP_ORG_CLIENT_ID -PrivateKey $env:TEST_APP_ORG_PRIVATE_KEY $owner = 'psmodule-test-org' + Connect-GitHubApp -Organization $owner -Default $guid = [guid]::NewGuid().ToString() $repo = "$repoSuffix-$guid" - Connect-GitHubApp -Organization $owner -Default New-GitHubRepository -Owner $owner -Name $repo -AllowSquashMerge Set-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName } @@ -267,41 +612,142 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { Remove-GitHubRepository -Owner $owner -Name $repo -Confirm:$false Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } - Context 'Variables' { - It 'Set-GitHubVariable - Organization' { + Context 'Organization' { + BeforeAll { + $scope = @{ + Owner = $owner + } + } + It 'Set-GitHubVariable' { $param = @{ - Name = 'TestVariable' + Name = "$prefix`TestVariable" Value = 'TestValue' } - $result = Set-GitHubVariable @param -Owner $owner - $result = Set-GitHubVariable @param -Owner $owner + $result = Set-GitHubVariable @param @scope + $result = Set-GitHubVariable @param @scope $result | Should -Not -BeNullOrEmpty + } - $result | Remove-GitHubVariable + It 'Update-GitHubVariable' { + $param = @{ + Name = "$prefix`TestVariable" + Value = 'TestValue123' + Visibility = 'all' + } + $result = Update-GitHubVariable @param @scope -PassThru + $result | Should -Not -BeNullOrEmpty } - It 'Set-GitHubVariable - Repository' { + It 'New-GitHubVariable' { + $param = @{ + Name = "$prefix`TestVariable2" + Value = 'TestValue123' + } + $result = New-GitHubVariable @param @scope + $result | Should -Not -BeNullOrEmpty + } + + It 'Get-GitHubVariable' { + $result = Get-GitHubVariable @scope + $result | Should -Not -BeNullOrEmpty + } + + It 'Remove-GitHubVariable' { + Get-GitHubVariable @scope | Remove-GitHubVariable + Get-GitHubVariable @scope | Should -BeNullOrEmpty + } + } + Context 'Repository' { + BeforeAll { + $scope = @{ + Owner = $owner + Repository = $repo + } + } + It 'Set-GitHubVariable' { $param = @{ - Name = 'TestVariable' + Name = "$prefix`TestVariable" Value = 'TestValue' } - $result = Set-GitHubVariable @param -Owner $owner -Repository $repo - $result = Set-GitHubVariable @param -Owner $owner -Repository $repo + $result = Set-GitHubVariable @param @scope + $result = Set-GitHubVariable @param @scope $result | Should -Not -BeNullOrEmpty + } - $result | Remove-GitHubVariable + It 'Update-GitHubVariable' { + $param = @{ + Name = "$prefix`TestVariable" + Value = 'TestValue123' + Visibility = 'all' + } + $result = Update-GitHubVariable @param @scope -PassThru + $result | Should -Not -BeNullOrEmpty } - It 'Set-GitHubVariable - Environment' { + It 'New-GitHubVariable' { $param = @{ - Name = 'TestVariable' + Name = "$prefix`TestVariable2" + Value = 'TestValue123' + } + $result = New-GitHubVariable @param @scope + $result | Should -Not -BeNullOrEmpty + } + + It 'Get-GitHubVariable' { + $result = Get-GitHubVariable @scope + $result | Should -Not -BeNullOrEmpty + } + + It 'Remove-GitHubVariable' { + Get-GitHubVariable @scope | Remove-GitHubVariable + Get-GitHubVariable @scope | Should -BeNullOrEmpty + } + } + Context 'Environment' { + BeforeAll { + $scope = @{ + Owner = $owner + Repository = $repo + Environment = $environmentName + } + } + It 'Set-GitHubVariable' { + $param = @{ + Name = "$prefix`TestVariable" Value = 'TestValue' } - $result = Set-GitHubVariable @param -Owner $owner -Repository $repo -Environment $environmentName - $result = Set-GitHubVariable @param -Owner $owner -Repository $repo -Environment $environmentName + $result = Set-GitHubVariable @param @scope + $result = Set-GitHubVariable @param @scope + $result | Should -Not -BeNullOrEmpty + } + + It 'Update-GitHubVariable' { + $param = @{ + Name = "$prefix`TestVariable" + Value = 'TestValue123' + Visibility = 'all' + } + $result = Update-GitHubVariable @param @scope -PassThru $result | Should -Not -BeNullOrEmpty + } + + It 'New-GitHubVariable' { + $param = @{ + Name = "$prefix`TestVariable2" + Value = 'TestValue123' + } + $result = New-GitHubVariable @param @scope + $result | Should -Not -BeNullOrEmpty + } + + It 'Get-GitHubVariable' { + $result = Get-GitHubVariable @scope + $result | Should -Not -BeNullOrEmpty + } - $result | Remove-GitHubVariable + It 'Remove-GitHubVariable' { + Get-GitHubVariable @scope | Remove-GitHubVariable + Get-GitHubVariable @scope | Should -BeNullOrEmpty } } } From a600c45bd02177d34b9a14e170c1b77de4fbbe55 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 11:50:11 +0100 Subject: [PATCH 40/85] =?UTF-8?q?=F0=9F=A9=B9=20[Test]:=20Update=20test=20?= =?UTF-8?q?variable=20values=20for=20consistency=20across=20user=20and=20o?= =?UTF-8?q?rganization=20account=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 40 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index ffbb1b8a3..2116e1930 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -24,7 +24,7 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) $owner = 'psmodule-user' $guid = [guid]::NewGuid().ToString() $repo = "$repoSuffix-$guid" - New-GitHubRepository -Owner $owner -Name $repo -AllowSquashMerge + New-GitHubRepository -Name $repo -AllowSquashMerge Set-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName } AfterAll { @@ -51,8 +51,7 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) It 'Update-GitHubVariable' { $param = @{ Name = "$prefix`TestVariable" - Value = 'TestValue123' - Visibility = 'all' + Value = 'TestValue1234' } $result = Update-GitHubVariable @param @scope -PassThru $result | Should -Not -BeNullOrEmpty @@ -98,8 +97,7 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) It 'Update-GitHubVariable' { $param = @{ Name = "$prefix`TestVariable" - Value = 'TestValue123' - Visibility = 'all' + Value = 'TestValue1234' } $result = Update-GitHubVariable @param @scope -PassThru $result | Should -Not -BeNullOrEmpty @@ -158,7 +156,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ It 'Update-GitHubVariable' { $param = @{ Name = "$prefix`TestVariable" - Value = 'TestValue123' + Value = 'TestValue1234' Visibility = 'all' } $result = Update-GitHubVariable @param @scope -PassThru @@ -204,8 +202,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ It 'Update-GitHubVariable' { $param = @{ Name = "$prefix`TestVariable" - Value = 'TestValue123' - Visibility = 'all' + Value = 'TestValue1234' } $result = Update-GitHubVariable @param @scope -PassThru $result | Should -Not -BeNullOrEmpty @@ -251,8 +248,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ It 'Update-GitHubVariable' { $param = @{ Name = "$prefix`TestVariable" - Value = 'TestValue123' - Visibility = 'all' + Value = 'TestValue1234' } $result = Update-GitHubVariable @param @scope -PassThru $result | Should -Not -BeNullOrEmpty @@ -311,7 +307,7 @@ Describe 'As a user - Classic PAT token (PAT)' { It 'Update-GitHubVariable' { $param = @{ Name = "$prefix`TestVariable" - Value = 'TestValue123' + Value = 'TestValue1234' Visibility = 'all' } $result = Update-GitHubVariable @param @scope -PassThru @@ -357,8 +353,7 @@ Describe 'As a user - Classic PAT token (PAT)' { It 'Update-GitHubVariable' { $param = @{ Name = "$prefix`TestVariable" - Value = 'TestValue123' - Visibility = 'all' + Value = 'TestValue1234' } $result = Update-GitHubVariable @param @scope -PassThru $result | Should -Not -BeNullOrEmpty @@ -404,8 +399,7 @@ Describe 'As a user - Classic PAT token (PAT)' { It 'Update-GitHubVariable' { $param = @{ Name = "$prefix`TestVariable" - Value = 'TestValue123' - Visibility = 'all' + Value = 'TestValue1234' } $result = Update-GitHubVariable @param @scope -PassThru $result | Should -Not -BeNullOrEmpty @@ -477,7 +471,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { It 'Update-GitHubVariable' { $param = @{ Name = "$prefix`TestVariable" - Value = 'TestValue123' + Value = 'TestValue1234' Visibility = 'all' } $result = Update-GitHubVariable @param @scope -PassThru @@ -523,8 +517,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { It 'Update-GitHubVariable' { $param = @{ Name = "$prefix`TestVariable" - Value = 'TestValue123' - Visibility = 'all' + Value = 'TestValue1234' } $result = Update-GitHubVariable @param @scope -PassThru $result | Should -Not -BeNullOrEmpty @@ -570,8 +563,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { It 'Update-GitHubVariable' { $param = @{ Name = "$prefix`TestVariable" - Value = 'TestValue123' - Visibility = 'all' + Value = 'TestValue1234' } $result = Update-GitHubVariable @param @scope -PassThru $result | Should -Not -BeNullOrEmpty @@ -631,7 +623,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { It 'Update-GitHubVariable' { $param = @{ Name = "$prefix`TestVariable" - Value = 'TestValue123' + Value = 'TestValue1234' Visibility = 'all' } $result = Update-GitHubVariable @param @scope -PassThru @@ -677,8 +669,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { It 'Update-GitHubVariable' { $param = @{ Name = "$prefix`TestVariable" - Value = 'TestValue123' - Visibility = 'all' + Value = 'TestValue1234' } $result = Update-GitHubVariable @param @scope -PassThru $result | Should -Not -BeNullOrEmpty @@ -724,8 +715,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { It 'Update-GitHubVariable' { $param = @{ Name = "$prefix`TestVariable" - Value = 'TestValue123' - Visibility = 'all' + Value = 'TestValue1234' } $result = Update-GitHubVariable @param @scope -PassThru $result | Should -Not -BeNullOrEmpty From 64fe4a687910b2f68968e7d0ef5ac7375b6239d5 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 12:42:55 +0100 Subject: [PATCH 41/85] =?UTF-8?q?=F0=9F=A9=B9=20[Test]:=20Add=20delay=20in?= =?UTF-8?q?=20Remove-GitHubVariable=20tests=20to=20ensure=20proper=20clean?= =?UTF-8?q?up?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 2116e1930..2b3ecfa65 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -73,6 +73,7 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) It 'Remove-GitHubVariable' { Get-GitHubVariable @scope | Remove-GitHubVariable + Start-Sleep -Seconds 5 Get-GitHubVariable @scope | Should -BeNullOrEmpty } } @@ -119,6 +120,7 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) It 'Remove-GitHubVariable' { Get-GitHubVariable @scope | Remove-GitHubVariable + Start-Sleep -Seconds 5 Get-GitHubVariable @scope | Should -BeNullOrEmpty } } @@ -179,6 +181,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ It 'Remove-GitHubVariable' { Get-GitHubVariable @scope | Remove-GitHubVariable + Start-Sleep -Seconds 5 Get-GitHubVariable @scope | Should -BeNullOrEmpty } } @@ -224,6 +227,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ It 'Remove-GitHubVariable' { Get-GitHubVariable @scope | Remove-GitHubVariable + Start-Sleep -Seconds 5 Get-GitHubVariable @scope | Should -BeNullOrEmpty } } @@ -270,6 +274,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ It 'Remove-GitHubVariable' { Get-GitHubVariable @scope | Remove-GitHubVariable + Start-Sleep -Seconds 5 Get-GitHubVariable @scope | Should -BeNullOrEmpty } } @@ -330,6 +335,7 @@ Describe 'As a user - Classic PAT token (PAT)' { It 'Remove-GitHubVariable' { Get-GitHubVariable @scope | Remove-GitHubVariable + Start-Sleep -Seconds 5 Get-GitHubVariable @scope | Should -BeNullOrEmpty } } @@ -375,6 +381,7 @@ Describe 'As a user - Classic PAT token (PAT)' { It 'Remove-GitHubVariable' { Get-GitHubVariable @scope | Remove-GitHubVariable + Start-Sleep -Seconds 5 Get-GitHubVariable @scope | Should -BeNullOrEmpty } } @@ -421,6 +428,7 @@ Describe 'As a user - Classic PAT token (PAT)' { It 'Remove-GitHubVariable' { Get-GitHubVariable @scope | Remove-GitHubVariable + Start-Sleep -Seconds 5 Get-GitHubVariable @scope | Should -BeNullOrEmpty } } @@ -494,6 +502,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { It 'Remove-GitHubVariable' { Get-GitHubVariable @scope | Remove-GitHubVariable + Start-Sleep -Seconds 5 Get-GitHubVariable @scope | Should -BeNullOrEmpty } } @@ -539,6 +548,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { It 'Remove-GitHubVariable' { Get-GitHubVariable @scope | Remove-GitHubVariable + Start-Sleep -Seconds 5 Get-GitHubVariable @scope | Should -BeNullOrEmpty } } @@ -585,6 +595,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { It 'Remove-GitHubVariable' { Get-GitHubVariable @scope | Remove-GitHubVariable + Start-Sleep -Seconds 5 Get-GitHubVariable @scope | Should -BeNullOrEmpty } } @@ -646,6 +657,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { It 'Remove-GitHubVariable' { Get-GitHubVariable @scope | Remove-GitHubVariable + Start-Sleep -Seconds 5 Get-GitHubVariable @scope | Should -BeNullOrEmpty } } @@ -691,6 +703,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { It 'Remove-GitHubVariable' { Get-GitHubVariable @scope | Remove-GitHubVariable + Start-Sleep -Seconds 5 Get-GitHubVariable @scope | Should -BeNullOrEmpty } } @@ -737,6 +750,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { It 'Remove-GitHubVariable' { Get-GitHubVariable @scope | Remove-GitHubVariable + Start-Sleep -Seconds 5 Get-GitHubVariable @scope | Should -BeNullOrEmpty } } From cc28c93d73fb802f2a4e5b14cd9069731277ca0b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 12:52:24 +0100 Subject: [PATCH 42/85] =?UTF-8?q?=F0=9F=A9=B9=20[Test]:=20Replace=20Start-?= =?UTF-8?q?Sleep=20with=20Write-Verbose=20for=20improved=20variable=20clea?= =?UTF-8?q?nup=20logging=20in=20Remove-GitHubVariable=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 2b3ecfa65..2e9dec3ec 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -73,7 +73,7 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) It 'Remove-GitHubVariable' { Get-GitHubVariable @scope | Remove-GitHubVariable - Start-Sleep -Seconds 5 + Write-Verbose (Get-GitHubVariable @scope) -Verbose Get-GitHubVariable @scope | Should -BeNullOrEmpty } } @@ -120,7 +120,7 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) It 'Remove-GitHubVariable' { Get-GitHubVariable @scope | Remove-GitHubVariable - Start-Sleep -Seconds 5 + Write-Verbose (Get-GitHubVariable @scope) -Verbose Get-GitHubVariable @scope | Should -BeNullOrEmpty } } @@ -181,7 +181,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ It 'Remove-GitHubVariable' { Get-GitHubVariable @scope | Remove-GitHubVariable - Start-Sleep -Seconds 5 + Write-Verbose (Get-GitHubVariable @scope) -Verbose Get-GitHubVariable @scope | Should -BeNullOrEmpty } } @@ -227,7 +227,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ It 'Remove-GitHubVariable' { Get-GitHubVariable @scope | Remove-GitHubVariable - Start-Sleep -Seconds 5 + Write-Verbose (Get-GitHubVariable @scope) -Verbose Get-GitHubVariable @scope | Should -BeNullOrEmpty } } @@ -274,7 +274,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ It 'Remove-GitHubVariable' { Get-GitHubVariable @scope | Remove-GitHubVariable - Start-Sleep -Seconds 5 + Write-Verbose (Get-GitHubVariable @scope) -Verbose Get-GitHubVariable @scope | Should -BeNullOrEmpty } } @@ -335,7 +335,7 @@ Describe 'As a user - Classic PAT token (PAT)' { It 'Remove-GitHubVariable' { Get-GitHubVariable @scope | Remove-GitHubVariable - Start-Sleep -Seconds 5 + Write-Verbose (Get-GitHubVariable @scope) -Verbose Get-GitHubVariable @scope | Should -BeNullOrEmpty } } @@ -381,7 +381,7 @@ Describe 'As a user - Classic PAT token (PAT)' { It 'Remove-GitHubVariable' { Get-GitHubVariable @scope | Remove-GitHubVariable - Start-Sleep -Seconds 5 + Write-Verbose (Get-GitHubVariable @scope) -Verbose Get-GitHubVariable @scope | Should -BeNullOrEmpty } } @@ -428,7 +428,7 @@ Describe 'As a user - Classic PAT token (PAT)' { It 'Remove-GitHubVariable' { Get-GitHubVariable @scope | Remove-GitHubVariable - Start-Sleep -Seconds 5 + Write-Verbose (Get-GitHubVariable @scope) -Verbose Get-GitHubVariable @scope | Should -BeNullOrEmpty } } @@ -502,7 +502,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { It 'Remove-GitHubVariable' { Get-GitHubVariable @scope | Remove-GitHubVariable - Start-Sleep -Seconds 5 + Write-Verbose (Get-GitHubVariable @scope) -Verbose Get-GitHubVariable @scope | Should -BeNullOrEmpty } } @@ -548,7 +548,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { It 'Remove-GitHubVariable' { Get-GitHubVariable @scope | Remove-GitHubVariable - Start-Sleep -Seconds 5 + Write-Verbose (Get-GitHubVariable @scope) -Verbose Get-GitHubVariable @scope | Should -BeNullOrEmpty } } @@ -595,7 +595,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { It 'Remove-GitHubVariable' { Get-GitHubVariable @scope | Remove-GitHubVariable - Start-Sleep -Seconds 5 + Write-Verbose (Get-GitHubVariable @scope) -Verbose Get-GitHubVariable @scope | Should -BeNullOrEmpty } } @@ -657,7 +657,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { It 'Remove-GitHubVariable' { Get-GitHubVariable @scope | Remove-GitHubVariable - Start-Sleep -Seconds 5 + Write-Verbose (Get-GitHubVariable @scope) -Verbose Get-GitHubVariable @scope | Should -BeNullOrEmpty } } @@ -703,7 +703,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { It 'Remove-GitHubVariable' { Get-GitHubVariable @scope | Remove-GitHubVariable - Start-Sleep -Seconds 5 + Write-Verbose (Get-GitHubVariable @scope) -Verbose Get-GitHubVariable @scope | Should -BeNullOrEmpty } } @@ -750,7 +750,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { It 'Remove-GitHubVariable' { Get-GitHubVariable @scope | Remove-GitHubVariable - Start-Sleep -Seconds 5 + Write-Verbose (Get-GitHubVariable @scope) -Verbose Get-GitHubVariable @scope | Should -BeNullOrEmpty } } From 7d96cce59cbfbea31430150878315b14175e54ad Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 12:57:34 +0100 Subject: [PATCH 43/85] =?UTF-8?q?=F0=9F=A9=B9=20[Test]:=20Simplify=20asser?= =?UTF-8?q?tions=20in=20Remove-GitHubVariable=20tests=20by=20checking=20co?= =?UTF-8?q?unt=20directly?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 42 +++++++++++++-------------------------- 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 2e9dec3ec..68fb1d414 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -73,8 +73,7 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) It 'Remove-GitHubVariable' { Get-GitHubVariable @scope | Remove-GitHubVariable - Write-Verbose (Get-GitHubVariable @scope) -Verbose - Get-GitHubVariable @scope | Should -BeNullOrEmpty + (Get-GitHubVariable @scope).Count | Should -Be 0 } } Context 'Environment' { @@ -120,8 +119,7 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) It 'Remove-GitHubVariable' { Get-GitHubVariable @scope | Remove-GitHubVariable - Write-Verbose (Get-GitHubVariable @scope) -Verbose - Get-GitHubVariable @scope | Should -BeNullOrEmpty + (Get-GitHubVariable @scope).Count | Should -Be 0 } } } @@ -181,8 +179,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ It 'Remove-GitHubVariable' { Get-GitHubVariable @scope | Remove-GitHubVariable - Write-Verbose (Get-GitHubVariable @scope) -Verbose - Get-GitHubVariable @scope | Should -BeNullOrEmpty + (Get-GitHubVariable @scope).Count | Should -Be 0 } } Context 'Repository' { @@ -227,8 +224,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ It 'Remove-GitHubVariable' { Get-GitHubVariable @scope | Remove-GitHubVariable - Write-Verbose (Get-GitHubVariable @scope) -Verbose - Get-GitHubVariable @scope | Should -BeNullOrEmpty + (Get-GitHubVariable @scope).Count | Should -Be 0 } } Context 'Environment' { @@ -274,8 +270,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ It 'Remove-GitHubVariable' { Get-GitHubVariable @scope | Remove-GitHubVariable - Write-Verbose (Get-GitHubVariable @scope) -Verbose - Get-GitHubVariable @scope | Should -BeNullOrEmpty + (Get-GitHubVariable @scope).Count | Should -Be 0 } } } @@ -335,8 +330,7 @@ Describe 'As a user - Classic PAT token (PAT)' { It 'Remove-GitHubVariable' { Get-GitHubVariable @scope | Remove-GitHubVariable - Write-Verbose (Get-GitHubVariable @scope) -Verbose - Get-GitHubVariable @scope | Should -BeNullOrEmpty + (Get-GitHubVariable @scope).Count | Should -Be 0 } } Context 'Repository' { @@ -381,8 +375,7 @@ Describe 'As a user - Classic PAT token (PAT)' { It 'Remove-GitHubVariable' { Get-GitHubVariable @scope | Remove-GitHubVariable - Write-Verbose (Get-GitHubVariable @scope) -Verbose - Get-GitHubVariable @scope | Should -BeNullOrEmpty + (Get-GitHubVariable @scope).Count | Should -Be 0 } } Context 'Environment' { @@ -428,8 +421,7 @@ Describe 'As a user - Classic PAT token (PAT)' { It 'Remove-GitHubVariable' { Get-GitHubVariable @scope | Remove-GitHubVariable - Write-Verbose (Get-GitHubVariable @scope) -Verbose - Get-GitHubVariable @scope | Should -BeNullOrEmpty + (Get-GitHubVariable @scope).Count | Should -Be 0 } } } @@ -502,8 +494,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { It 'Remove-GitHubVariable' { Get-GitHubVariable @scope | Remove-GitHubVariable - Write-Verbose (Get-GitHubVariable @scope) -Verbose - Get-GitHubVariable @scope | Should -BeNullOrEmpty + (Get-GitHubVariable @scope).Count | Should -Be 0 } } Context 'Repository' { @@ -548,8 +539,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { It 'Remove-GitHubVariable' { Get-GitHubVariable @scope | Remove-GitHubVariable - Write-Verbose (Get-GitHubVariable @scope) -Verbose - Get-GitHubVariable @scope | Should -BeNullOrEmpty + (Get-GitHubVariable @scope).Count | Should -Be 0 } } Context 'Environment' { @@ -595,8 +585,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { It 'Remove-GitHubVariable' { Get-GitHubVariable @scope | Remove-GitHubVariable - Write-Verbose (Get-GitHubVariable @scope) -Verbose - Get-GitHubVariable @scope | Should -BeNullOrEmpty + (Get-GitHubVariable @scope).Count | Should -Be 0 } } } @@ -657,8 +646,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { It 'Remove-GitHubVariable' { Get-GitHubVariable @scope | Remove-GitHubVariable - Write-Verbose (Get-GitHubVariable @scope) -Verbose - Get-GitHubVariable @scope | Should -BeNullOrEmpty + (Get-GitHubVariable @scope).Count | Should -Be 0 } } Context 'Repository' { @@ -703,8 +691,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { It 'Remove-GitHubVariable' { Get-GitHubVariable @scope | Remove-GitHubVariable - Write-Verbose (Get-GitHubVariable @scope) -Verbose - Get-GitHubVariable @scope | Should -BeNullOrEmpty + (Get-GitHubVariable @scope).Count | Should -Be 0 } } Context 'Environment' { @@ -750,8 +737,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { It 'Remove-GitHubVariable' { Get-GitHubVariable @scope | Remove-GitHubVariable - Write-Verbose (Get-GitHubVariable @scope) -Verbose - Get-GitHubVariable @scope | Should -BeNullOrEmpty + (Get-GitHubVariable @scope).Count | Should -Be 0 } } } From e84412717ca58224e701bb3a362bb0641e860f2d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 13:12:19 +0100 Subject: [PATCH 44/85] =?UTF-8?q?=F0=9F=A9=B9=20[Fix]:=20Improve=20variabl?= =?UTF-8?q?e=20cleanup=20in=20Remove-GitHubVariable=20by=20adding=20delay?= =?UTF-8?q?=20and=20null=20value=20removal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Variables/Remove-GitHubVariable.ps1 | 22 ++++++++++ tests/Variables.Tests.ps1 | 40 +++++++++---------- 2 files changed, 42 insertions(+), 20 deletions(-) diff --git a/src/functions/public/Variables/Remove-GitHubVariable.ps1 b/src/functions/public/Variables/Remove-GitHubVariable.ps1 index e43773e6a..a1e9176c6 100644 --- a/src/functions/public/Variables/Remove-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Remove-GitHubVariable.ps1 @@ -103,6 +103,17 @@ function Remove-GitHubVariable { } Remove-GitHubVariableOnOwner @params } + $scopeParam = @{ + Owner = $Owner + Repository = $Repository + Environment = $Environment + } + $scopeParam | Remove-HashtableEntry -NullOrEmptyValues + for ($i = 0; ($i -le 10); $i++) { + Start-Sleep -Seconds 1 + $variable = Get-GitHubVariable @scopeParam | Where-Object { $_.Name -eq $Name } + if (-not $variable) { break } + } } } 'Organization' { @@ -133,6 +144,17 @@ function Remove-GitHubVariable { Remove-GitHubVariableOnEnvironment @params } } + $scopeParam = @{ + Owner = $Owner + Repository = $Repository + Environment = $Environment + } + $scopeParam | Remove-HashtableEntry -NullOrEmptyValues + for ($i = 0; ($i -le 10); $i++) { + Start-Sleep -Seconds 1 + $variable = Get-GitHubVariable @scopeParam | Where-Object { $_.Name -eq $Name } + if (-not $variable) { break } + } } end { diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 68fb1d414..13c353c4a 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -50,8 +50,8 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) It 'Update-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable" - Value = 'TestValue1234' + Name = "$prefix`TestVariable" + Value = 'TestValue1234' } $result = Update-GitHubVariable @param @scope -PassThru $result | Should -Not -BeNullOrEmpty @@ -96,8 +96,8 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) It 'Update-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable" - Value = 'TestValue1234' + Name = "$prefix`TestVariable" + Value = 'TestValue1234' } $result = Update-GitHubVariable @param @scope -PassThru $result | Should -Not -BeNullOrEmpty @@ -201,8 +201,8 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ It 'Update-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable" - Value = 'TestValue1234' + Name = "$prefix`TestVariable" + Value = 'TestValue1234' } $result = Update-GitHubVariable @param @scope -PassThru $result | Should -Not -BeNullOrEmpty @@ -247,8 +247,8 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ It 'Update-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable" - Value = 'TestValue1234' + Name = "$prefix`TestVariable" + Value = 'TestValue1234' } $result = Update-GitHubVariable @param @scope -PassThru $result | Should -Not -BeNullOrEmpty @@ -352,8 +352,8 @@ Describe 'As a user - Classic PAT token (PAT)' { It 'Update-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable" - Value = 'TestValue1234' + Name = "$prefix`TestVariable" + Value = 'TestValue1234' } $result = Update-GitHubVariable @param @scope -PassThru $result | Should -Not -BeNullOrEmpty @@ -398,8 +398,8 @@ Describe 'As a user - Classic PAT token (PAT)' { It 'Update-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable" - Value = 'TestValue1234' + Name = "$prefix`TestVariable" + Value = 'TestValue1234' } $result = Update-GitHubVariable @param @scope -PassThru $result | Should -Not -BeNullOrEmpty @@ -516,8 +516,8 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { It 'Update-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable" - Value = 'TestValue1234' + Name = "$prefix`TestVariable" + Value = 'TestValue1234' } $result = Update-GitHubVariable @param @scope -PassThru $result | Should -Not -BeNullOrEmpty @@ -562,8 +562,8 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { It 'Update-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable" - Value = 'TestValue1234' + Name = "$prefix`TestVariable" + Value = 'TestValue1234' } $result = Update-GitHubVariable @param @scope -PassThru $result | Should -Not -BeNullOrEmpty @@ -668,8 +668,8 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { It 'Update-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable" - Value = 'TestValue1234' + Name = "$prefix`TestVariable" + Value = 'TestValue1234' } $result = Update-GitHubVariable @param @scope -PassThru $result | Should -Not -BeNullOrEmpty @@ -714,8 +714,8 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { It 'Update-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable" - Value = 'TestValue1234' + Name = "$prefix`TestVariable" + Value = 'TestValue1234' } $result = Update-GitHubVariable @param @scope -PassThru $result | Should -Not -BeNullOrEmpty From 357b5f0abe8d4d57b3d1f29da13442e8e00b0885 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 13:21:41 +0100 Subject: [PATCH 45/85] =?UTF-8?q?=F0=9F=A9=B9=20[Fix]:=20Enhance=20error?= =?UTF-8?q?=20logging=20in=20Connect-GithubCli=20and=20streamline=20parame?= =?UTF-8?q?ter=20handling=20in=20Remove-GitHubVariable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/functions/private/Auth/Cli/Connect-GithubCli.ps1 | 3 +-- src/functions/public/Variables/Remove-GitHubVariable.ps1 | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/functions/private/Auth/Cli/Connect-GithubCli.ps1 b/src/functions/private/Auth/Cli/Connect-GithubCli.ps1 index ccba21046..dda0be192 100644 --- a/src/functions/private/Auth/Cli/Connect-GithubCli.ps1 +++ b/src/functions/private/Auth/Cli/Connect-GithubCli.ps1 @@ -44,10 +44,9 @@ process { $Context.Token | ConvertFrom-SecureString -AsPlainText | gh auth login --with-token --hostname $Context.HostName if ($LASTEXITCODE -ne 0) { - Write-Warning 'Unable to log on with the GitHub Cli.' + Write-Warning "Unable to log on with the GitHub Cli. ($LASTEXITCODE)" $Global:LASTEXITCODE = 0 Write-Debug "Resetting LASTEXITCODE: $LASTEXITCODE" - return } } diff --git a/src/functions/public/Variables/Remove-GitHubVariable.ps1 b/src/functions/public/Variables/Remove-GitHubVariable.ps1 index a1e9176c6..71b996f06 100644 --- a/src/functions/public/Variables/Remove-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Remove-GitHubVariable.ps1 @@ -104,9 +104,9 @@ function Remove-GitHubVariable { Remove-GitHubVariableOnOwner @params } $scopeParam = @{ - Owner = $Owner - Repository = $Repository - Environment = $Environment + Owner = $item.Owner + Repository = $item.Repository + Environment = $item.Environment } $scopeParam | Remove-HashtableEntry -NullOrEmptyValues for ($i = 0; ($i -le 10); $i++) { From 048c26a6d69f9b56e1f73c6c7f277d84d8496925 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 13:38:34 +0100 Subject: [PATCH 46/85] =?UTF-8?q?=F0=9F=A9=B9=20[Fix]:=20Improve=20error?= =?UTF-8?q?=20handling=20in=20Connect-GithubCli=20and=20enhance=20logging?= =?UTF-8?q?=20in=20Remove-GitHubVariable=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../private/Auth/Cli/Connect-GithubCli.ps1 | 3 ++- tests/Variables.Tests.ps1 | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/functions/private/Auth/Cli/Connect-GithubCli.ps1 b/src/functions/private/Auth/Cli/Connect-GithubCli.ps1 index dda0be192..93cf67820 100644 --- a/src/functions/private/Auth/Cli/Connect-GithubCli.ps1 +++ b/src/functions/private/Auth/Cli/Connect-GithubCli.ps1 @@ -42,8 +42,9 @@ } process { - $Context.Token | ConvertFrom-SecureString -AsPlainText | gh auth login --with-token --hostname $Context.HostName + $return = $Context.Token | ConvertFrom-SecureString -AsPlainText | gh auth login --with-token --hostname $Context.HostName if ($LASTEXITCODE -ne 0) { + Write-Warning $return Write-Warning "Unable to log on with the GitHub Cli. ($LASTEXITCODE)" $Global:LASTEXITCODE = 0 Write-Debug "Resetting LASTEXITCODE: $LASTEXITCODE" diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 13c353c4a..62f6a913a 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -72,6 +72,7 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) } It 'Remove-GitHubVariable' { + Write-Verbose "$(Get-GitHubVariable @scope)" -Verbose Get-GitHubVariable @scope | Remove-GitHubVariable (Get-GitHubVariable @scope).Count | Should -Be 0 } @@ -118,6 +119,7 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) } It 'Remove-GitHubVariable' { + Write-Verbose "$(Get-GitHubVariable @scope)" -Verbose Get-GitHubVariable @scope | Remove-GitHubVariable (Get-GitHubVariable @scope).Count | Should -Be 0 } @@ -178,6 +180,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ } It 'Remove-GitHubVariable' { + Write-Verbose "$(Get-GitHubVariable @scope)" -Verbose Get-GitHubVariable @scope | Remove-GitHubVariable (Get-GitHubVariable @scope).Count | Should -Be 0 } @@ -223,6 +226,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ } It 'Remove-GitHubVariable' { + Write-Verbose "$(Get-GitHubVariable @scope)" -Verbose Get-GitHubVariable @scope | Remove-GitHubVariable (Get-GitHubVariable @scope).Count | Should -Be 0 } @@ -269,6 +273,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ } It 'Remove-GitHubVariable' { + Write-Verbose "$(Get-GitHubVariable @scope)" -Verbose Get-GitHubVariable @scope | Remove-GitHubVariable (Get-GitHubVariable @scope).Count | Should -Be 0 } @@ -329,6 +334,7 @@ Describe 'As a user - Classic PAT token (PAT)' { } It 'Remove-GitHubVariable' { + Write-Verbose "$(Get-GitHubVariable @scope)" -Verbose Get-GitHubVariable @scope | Remove-GitHubVariable (Get-GitHubVariable @scope).Count | Should -Be 0 } @@ -374,6 +380,7 @@ Describe 'As a user - Classic PAT token (PAT)' { } It 'Remove-GitHubVariable' { + Write-Verbose "$(Get-GitHubVariable @scope)" -Verbose Get-GitHubVariable @scope | Remove-GitHubVariable (Get-GitHubVariable @scope).Count | Should -Be 0 } @@ -420,6 +427,7 @@ Describe 'As a user - Classic PAT token (PAT)' { } It 'Remove-GitHubVariable' { + Write-Verbose "$(Get-GitHubVariable @scope)" -Verbose Get-GitHubVariable @scope | Remove-GitHubVariable (Get-GitHubVariable @scope).Count | Should -Be 0 } @@ -493,6 +501,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { } It 'Remove-GitHubVariable' { + Write-Verbose "$(Get-GitHubVariable @scope)" -Verbose Get-GitHubVariable @scope | Remove-GitHubVariable (Get-GitHubVariable @scope).Count | Should -Be 0 } @@ -538,6 +547,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { } It 'Remove-GitHubVariable' { + Write-Verbose "$(Get-GitHubVariable @scope)" -Verbose Get-GitHubVariable @scope | Remove-GitHubVariable (Get-GitHubVariable @scope).Count | Should -Be 0 } @@ -584,6 +594,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { } It 'Remove-GitHubVariable' { + Write-Verbose "$(Get-GitHubVariable @scope)" -Verbose Get-GitHubVariable @scope | Remove-GitHubVariable (Get-GitHubVariable @scope).Count | Should -Be 0 } @@ -645,6 +656,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { } It 'Remove-GitHubVariable' { + Write-Verbose "$(Get-GitHubVariable @scope)" -Verbose Get-GitHubVariable @scope | Remove-GitHubVariable (Get-GitHubVariable @scope).Count | Should -Be 0 } @@ -690,6 +702,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { } It 'Remove-GitHubVariable' { + Write-Verbose "$(Get-GitHubVariable @scope)" -Verbose Get-GitHubVariable @scope | Remove-GitHubVariable (Get-GitHubVariable @scope).Count | Should -Be 0 } @@ -736,6 +749,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { } It 'Remove-GitHubVariable' { + Write-Verbose "$(Get-GitHubVariable @scope)" -Verbose Get-GitHubVariable @scope | Remove-GitHubVariable (Get-GitHubVariable @scope).Count | Should -Be 0 } From f225f4bce0c7145469ca60531c3678d253646a36 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 13:56:56 +0100 Subject: [PATCH 47/85] =?UTF-8?q?=F0=9F=A9=B9=20[Fix]:=20Enhance=20error?= =?UTF-8?q?=20handling=20in=20Connect-GithubCli=20by=20capturing=20command?= =?UTF-8?q?=20output=20and=20logging=20warnings=20on=20failure?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/functions/private/Auth/Cli/Connect-GithubCli.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/functions/private/Auth/Cli/Connect-GithubCli.ps1 b/src/functions/private/Auth/Cli/Connect-GithubCli.ps1 index 93cf67820..3bcbd3cb8 100644 --- a/src/functions/private/Auth/Cli/Connect-GithubCli.ps1 +++ b/src/functions/private/Auth/Cli/Connect-GithubCli.ps1 @@ -42,7 +42,8 @@ } process { - $return = $Context.Token | ConvertFrom-SecureString -AsPlainText | gh auth login --with-token --hostname $Context.HostName + $return = ($Context.Token | ConvertFrom-SecureString -AsPlainText | gh auth login --with-token --hostname $Context.HostName) 2>&1 + if ($LASTEXITCODE -ne 0) { Write-Warning $return Write-Warning "Unable to log on with the GitHub Cli. ($LASTEXITCODE)" From 79425804cb4fed9473ecc7dd216df6a8b9f5a0fe Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 14:01:40 +0100 Subject: [PATCH 48/85] =?UTF-8?q?=F0=9F=A9=B9=20[Fix]:=20Improve=20warning?= =?UTF-8?q?=20output=20formatting=20in=20Connect-GithubCli=20and=20ensure?= =?UTF-8?q?=20early=20returns=20in=20Remove-GitHubVariable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/functions/private/Auth/Cli/Connect-GithubCli.ps1 | 2 +- src/functions/public/Variables/Remove-GitHubVariable.ps1 | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/functions/private/Auth/Cli/Connect-GithubCli.ps1 b/src/functions/private/Auth/Cli/Connect-GithubCli.ps1 index 3bcbd3cb8..676c55d06 100644 --- a/src/functions/private/Auth/Cli/Connect-GithubCli.ps1 +++ b/src/functions/private/Auth/Cli/Connect-GithubCli.ps1 @@ -45,7 +45,7 @@ $return = ($Context.Token | ConvertFrom-SecureString -AsPlainText | gh auth login --with-token --hostname $Context.HostName) 2>&1 if ($LASTEXITCODE -ne 0) { - Write-Warning $return + Write-Warning "$($return -join '`n')" Write-Warning "Unable to log on with the GitHub Cli. ($LASTEXITCODE)" $Global:LASTEXITCODE = 0 Write-Debug "Resetting LASTEXITCODE: $LASTEXITCODE" diff --git a/src/functions/public/Variables/Remove-GitHubVariable.ps1 b/src/functions/public/Variables/Remove-GitHubVariable.ps1 index 71b996f06..454b682a4 100644 --- a/src/functions/public/Variables/Remove-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Remove-GitHubVariable.ps1 @@ -115,6 +115,7 @@ function Remove-GitHubVariable { if (-not $variable) { break } } } + return } 'Organization' { $params = @{ @@ -123,6 +124,7 @@ function Remove-GitHubVariable { Context = $Context } Remove-GitHubVariableOnOwner @params + break } 'Repository' { $params = @{ @@ -132,6 +134,7 @@ function Remove-GitHubVariable { Context = $Context } Remove-GitHubVariableOnRepository @params + break } 'Environment' { $params = @{ @@ -142,8 +145,10 @@ function Remove-GitHubVariable { Context = $Context } Remove-GitHubVariableOnEnvironment @params + break } } + $scopeParam = @{ Owner = $Owner Repository = $Repository From 2a42ef9c7d5ef23d4929cf720dcc5a7864aa199b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 14:09:51 +0100 Subject: [PATCH 49/85] =?UTF-8?q?=F0=9F=A9=B9=20[Fix]:=20Improve=20warning?= =?UTF-8?q?=20output=20and=20debug=20logging=20in=20Connect-GithubCli=20fo?= =?UTF-8?q?r=20better=20authentication=20error=20handling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/functions/private/Auth/Cli/Connect-GithubCli.ps1 | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/functions/private/Auth/Cli/Connect-GithubCli.ps1 b/src/functions/private/Auth/Cli/Connect-GithubCli.ps1 index 676c55d06..57c5ac4e2 100644 --- a/src/functions/private/Auth/Cli/Connect-GithubCli.ps1 +++ b/src/functions/private/Auth/Cli/Connect-GithubCli.ps1 @@ -43,10 +43,13 @@ process { $return = ($Context.Token | ConvertFrom-SecureString -AsPlainText | gh auth login --with-token --hostname $Context.HostName) 2>&1 - + $return = $return -join [System.Environment]::NewLine if ($LASTEXITCODE -ne 0) { - Write-Warning "$($return -join '`n')" - Write-Warning "Unable to log on with the GitHub Cli. ($LASTEXITCODE)" + if ($return.Contains('GITHUB_TOKEN environment variable is being used for authentication')) { + Write-Debug $return + } else { + Write-Warning "Unable to log on with the GitHub Cli. ($LASTEXITCODE)" + } $Global:LASTEXITCODE = 0 Write-Debug "Resetting LASTEXITCODE: $LASTEXITCODE" } From 03e6685243b3f65b0761b85db31912bc8be44b90 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 14:12:24 +0100 Subject: [PATCH 50/85] =?UTF-8?q?=F0=9F=A9=B9=20[Fix]:=20Simplify=20loop?= =?UTF-8?q?=20syntax=20in=20Remove-GitHubVariable=20for=20improved=20reada?= =?UTF-8?q?bility?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/functions/public/Variables/Remove-GitHubVariable.ps1 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/functions/public/Variables/Remove-GitHubVariable.ps1 b/src/functions/public/Variables/Remove-GitHubVariable.ps1 index 454b682a4..39fdfe50a 100644 --- a/src/functions/public/Variables/Remove-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Remove-GitHubVariable.ps1 @@ -107,9 +107,10 @@ function Remove-GitHubVariable { Owner = $item.Owner Repository = $item.Repository Environment = $item.Environment + Context = $Context } $scopeParam | Remove-HashtableEntry -NullOrEmptyValues - for ($i = 0; ($i -le 10); $i++) { + for ($i = 0; $i -le 10; $i++) { Start-Sleep -Seconds 1 $variable = Get-GitHubVariable @scopeParam | Where-Object { $_.Name -eq $Name } if (-not $variable) { break } @@ -155,7 +156,7 @@ function Remove-GitHubVariable { Environment = $Environment } $scopeParam | Remove-HashtableEntry -NullOrEmptyValues - for ($i = 0; ($i -le 10); $i++) { + for ($i = 0; $i -le 10; $i++) { Start-Sleep -Seconds 1 $variable = Get-GitHubVariable @scopeParam | Where-Object { $_.Name -eq $Name } if (-not $variable) { break } From a04421e6489850e7be50850b89616d2de725b333 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 14:22:21 +0100 Subject: [PATCH 51/85] =?UTF-8?q?=F0=9F=A9=B9=20[Fix]:=20Replace=20Write-V?= =?UTF-8?q?erbose=20with=20Write-Host=20in=20Remove-GitHubVariable=20tests?= =?UTF-8?q?=20for=20improved=20output=20clarity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 62f6a913a..516c7bac7 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -72,7 +72,7 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) } It 'Remove-GitHubVariable' { - Write-Verbose "$(Get-GitHubVariable @scope)" -Verbose + Write-Host "$(Get-GitHubVariable @scope)" Get-GitHubVariable @scope | Remove-GitHubVariable (Get-GitHubVariable @scope).Count | Should -Be 0 } @@ -119,7 +119,7 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) } It 'Remove-GitHubVariable' { - Write-Verbose "$(Get-GitHubVariable @scope)" -Verbose + Write-Host "$(Get-GitHubVariable @scope)" Get-GitHubVariable @scope | Remove-GitHubVariable (Get-GitHubVariable @scope).Count | Should -Be 0 } @@ -180,7 +180,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ } It 'Remove-GitHubVariable' { - Write-Verbose "$(Get-GitHubVariable @scope)" -Verbose + Write-Host "$(Get-GitHubVariable @scope)" Get-GitHubVariable @scope | Remove-GitHubVariable (Get-GitHubVariable @scope).Count | Should -Be 0 } @@ -226,7 +226,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ } It 'Remove-GitHubVariable' { - Write-Verbose "$(Get-GitHubVariable @scope)" -Verbose + Write-Host "$(Get-GitHubVariable @scope)" Get-GitHubVariable @scope | Remove-GitHubVariable (Get-GitHubVariable @scope).Count | Should -Be 0 } @@ -273,7 +273,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ } It 'Remove-GitHubVariable' { - Write-Verbose "$(Get-GitHubVariable @scope)" -Verbose + Write-Host "$(Get-GitHubVariable @scope)" Get-GitHubVariable @scope | Remove-GitHubVariable (Get-GitHubVariable @scope).Count | Should -Be 0 } @@ -334,7 +334,7 @@ Describe 'As a user - Classic PAT token (PAT)' { } It 'Remove-GitHubVariable' { - Write-Verbose "$(Get-GitHubVariable @scope)" -Verbose + Write-Host "$(Get-GitHubVariable @scope)" Get-GitHubVariable @scope | Remove-GitHubVariable (Get-GitHubVariable @scope).Count | Should -Be 0 } @@ -380,7 +380,7 @@ Describe 'As a user - Classic PAT token (PAT)' { } It 'Remove-GitHubVariable' { - Write-Verbose "$(Get-GitHubVariable @scope)" -Verbose + Write-Host "$(Get-GitHubVariable @scope)" Get-GitHubVariable @scope | Remove-GitHubVariable (Get-GitHubVariable @scope).Count | Should -Be 0 } @@ -427,7 +427,7 @@ Describe 'As a user - Classic PAT token (PAT)' { } It 'Remove-GitHubVariable' { - Write-Verbose "$(Get-GitHubVariable @scope)" -Verbose + Write-Host "$(Get-GitHubVariable @scope)" Get-GitHubVariable @scope | Remove-GitHubVariable (Get-GitHubVariable @scope).Count | Should -Be 0 } @@ -501,7 +501,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { } It 'Remove-GitHubVariable' { - Write-Verbose "$(Get-GitHubVariable @scope)" -Verbose + Write-Host "$(Get-GitHubVariable @scope)" Get-GitHubVariable @scope | Remove-GitHubVariable (Get-GitHubVariable @scope).Count | Should -Be 0 } @@ -547,7 +547,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { } It 'Remove-GitHubVariable' { - Write-Verbose "$(Get-GitHubVariable @scope)" -Verbose + Write-Host "$(Get-GitHubVariable @scope)" Get-GitHubVariable @scope | Remove-GitHubVariable (Get-GitHubVariable @scope).Count | Should -Be 0 } @@ -594,7 +594,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { } It 'Remove-GitHubVariable' { - Write-Verbose "$(Get-GitHubVariable @scope)" -Verbose + Write-Host "$(Get-GitHubVariable @scope)" Get-GitHubVariable @scope | Remove-GitHubVariable (Get-GitHubVariable @scope).Count | Should -Be 0 } @@ -656,7 +656,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { } It 'Remove-GitHubVariable' { - Write-Verbose "$(Get-GitHubVariable @scope)" -Verbose + Write-Host "$(Get-GitHubVariable @scope)" Get-GitHubVariable @scope | Remove-GitHubVariable (Get-GitHubVariable @scope).Count | Should -Be 0 } @@ -702,7 +702,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { } It 'Remove-GitHubVariable' { - Write-Verbose "$(Get-GitHubVariable @scope)" -Verbose + Write-Host "$(Get-GitHubVariable @scope)" Get-GitHubVariable @scope | Remove-GitHubVariable (Get-GitHubVariable @scope).Count | Should -Be 0 } @@ -749,7 +749,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { } It 'Remove-GitHubVariable' { - Write-Verbose "$(Get-GitHubVariable @scope)" -Verbose + Write-Host "$(Get-GitHubVariable @scope)" Get-GitHubVariable @scope | Remove-GitHubVariable (Get-GitHubVariable @scope).Count | Should -Be 0 } From 20e7ca276de870029317062cb18969e934757edf Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 15:52:54 +0100 Subject: [PATCH 52/85] =?UTF-8?q?=F0=9F=A9=B9=20[Refactor]:=20Migrate=20te?= =?UTF-8?q?st=20files=20to=20new=20directory=20structure=20and=20update=20?= =?UTF-8?q?README=20for=20clarity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 42 ++++++++++++++++-------- {tests => tests2}/API.Tests.ps1 | 0 {tests => tests2}/Apps.Tests.ps1 | 0 {tests => tests2}/Auth.Tests.ps1 | 0 {tests => tests2}/Emojis.Tests.ps1 | 0 {tests => tests2}/Environments.Tests.ps1 | 0 {tests => tests2}/GitHub.Tests.ps1 | 0 {tests => tests2}/IssueForm.md | 0 {tests => tests2}/Organization.Tests.ps1 | 0 {tests => tests2}/README.md | 0 {tests => tests2}/TEMPLATE.ps1 | 0 {tests => tests2}/User.Tests.ps1 | 0 12 files changed, 28 insertions(+), 14 deletions(-) rename {tests => tests2}/API.Tests.ps1 (100%) rename {tests => tests2}/Apps.Tests.ps1 (100%) rename {tests => tests2}/Auth.Tests.ps1 (100%) rename {tests => tests2}/Emojis.Tests.ps1 (100%) rename {tests => tests2}/Environments.Tests.ps1 (100%) rename {tests => tests2}/GitHub.Tests.ps1 (100%) rename {tests => tests2}/IssueForm.md (100%) rename {tests => tests2}/Organization.Tests.ps1 (100%) rename {tests => tests2}/README.md (100%) rename {tests => tests2}/TEMPLATE.ps1 (100%) rename {tests => tests2}/User.Tests.ps1 (100%) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 516c7bac7..d5944e6f2 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -72,8 +72,9 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) } It 'Remove-GitHubVariable' { - Write-Host "$(Get-GitHubVariable @scope)" + Write-Host "$(Get-GitHubVariable @scope | Out-String)" Get-GitHubVariable @scope | Remove-GitHubVariable + Write-Host "$(Get-GitHubVariable @scope | Out-String)" (Get-GitHubVariable @scope).Count | Should -Be 0 } } @@ -119,8 +120,9 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) } It 'Remove-GitHubVariable' { - Write-Host "$(Get-GitHubVariable @scope)" + Write-Host "$(Get-GitHubVariable @scope | Out-String)" Get-GitHubVariable @scope | Remove-GitHubVariable + Write-Host "$(Get-GitHubVariable @scope | Out-String)" (Get-GitHubVariable @scope).Count | Should -Be 0 } } @@ -180,8 +182,9 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ } It 'Remove-GitHubVariable' { - Write-Host "$(Get-GitHubVariable @scope)" + Write-Host "$(Get-GitHubVariable @scope | Out-String)" Get-GitHubVariable @scope | Remove-GitHubVariable + Write-Host "$(Get-GitHubVariable @scope | Out-String)" (Get-GitHubVariable @scope).Count | Should -Be 0 } } @@ -226,8 +229,9 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ } It 'Remove-GitHubVariable' { - Write-Host "$(Get-GitHubVariable @scope)" + Write-Host "$(Get-GitHubVariable @scope | Out-String)" Get-GitHubVariable @scope | Remove-GitHubVariable + Write-Host "$(Get-GitHubVariable @scope | Out-String)" (Get-GitHubVariable @scope).Count | Should -Be 0 } } @@ -273,8 +277,9 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ } It 'Remove-GitHubVariable' { - Write-Host "$(Get-GitHubVariable @scope)" + Write-Host "$(Get-GitHubVariable @scope | Out-String)" Get-GitHubVariable @scope | Remove-GitHubVariable + Write-Host "$(Get-GitHubVariable @scope | Out-String)" (Get-GitHubVariable @scope).Count | Should -Be 0 } } @@ -334,8 +339,9 @@ Describe 'As a user - Classic PAT token (PAT)' { } It 'Remove-GitHubVariable' { - Write-Host "$(Get-GitHubVariable @scope)" + Write-Host "$(Get-GitHubVariable @scope | Out-String)" Get-GitHubVariable @scope | Remove-GitHubVariable + Write-Host "$(Get-GitHubVariable @scope | Out-String)" (Get-GitHubVariable @scope).Count | Should -Be 0 } } @@ -380,8 +386,9 @@ Describe 'As a user - Classic PAT token (PAT)' { } It 'Remove-GitHubVariable' { - Write-Host "$(Get-GitHubVariable @scope)" + Write-Host "$(Get-GitHubVariable @scope | Out-String)" Get-GitHubVariable @scope | Remove-GitHubVariable + Write-Host "$(Get-GitHubVariable @scope | Out-String)" (Get-GitHubVariable @scope).Count | Should -Be 0 } } @@ -427,8 +434,9 @@ Describe 'As a user - Classic PAT token (PAT)' { } It 'Remove-GitHubVariable' { - Write-Host "$(Get-GitHubVariable @scope)" + Write-Host "$(Get-GitHubVariable @scope | Out-String)" Get-GitHubVariable @scope | Remove-GitHubVariable + Write-Host "$(Get-GitHubVariable @scope | Out-String)" (Get-GitHubVariable @scope).Count | Should -Be 0 } } @@ -501,8 +509,9 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { } It 'Remove-GitHubVariable' { - Write-Host "$(Get-GitHubVariable @scope)" + Write-Host "$(Get-GitHubVariable @scope | Out-String)" Get-GitHubVariable @scope | Remove-GitHubVariable + Write-Host "$(Get-GitHubVariable @scope | Out-String)" (Get-GitHubVariable @scope).Count | Should -Be 0 } } @@ -547,8 +556,9 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { } It 'Remove-GitHubVariable' { - Write-Host "$(Get-GitHubVariable @scope)" + Write-Host "$(Get-GitHubVariable @scope | Out-String)" Get-GitHubVariable @scope | Remove-GitHubVariable + Write-Host "$(Get-GitHubVariable @scope | Out-String)" (Get-GitHubVariable @scope).Count | Should -Be 0 } } @@ -594,8 +604,9 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { } It 'Remove-GitHubVariable' { - Write-Host "$(Get-GitHubVariable @scope)" + Write-Host "$(Get-GitHubVariable @scope | Out-String)" Get-GitHubVariable @scope | Remove-GitHubVariable + Write-Host "$(Get-GitHubVariable @scope | Out-String)" (Get-GitHubVariable @scope).Count | Should -Be 0 } } @@ -656,8 +667,9 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { } It 'Remove-GitHubVariable' { - Write-Host "$(Get-GitHubVariable @scope)" + Write-Host "$(Get-GitHubVariable @scope | Out-String)" Get-GitHubVariable @scope | Remove-GitHubVariable + Write-Host "$(Get-GitHubVariable @scope | Out-String)" (Get-GitHubVariable @scope).Count | Should -Be 0 } } @@ -702,8 +714,9 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { } It 'Remove-GitHubVariable' { - Write-Host "$(Get-GitHubVariable @scope)" + Write-Host "$(Get-GitHubVariable @scope | Out-String)" Get-GitHubVariable @scope | Remove-GitHubVariable + Write-Host "$(Get-GitHubVariable @scope | Out-String)" (Get-GitHubVariable @scope).Count | Should -Be 0 } } @@ -749,8 +762,9 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { } It 'Remove-GitHubVariable' { - Write-Host "$(Get-GitHubVariable @scope)" + Write-Host "$(Get-GitHubVariable @scope | Out-String)" Get-GitHubVariable @scope | Remove-GitHubVariable + Write-Host "$(Get-GitHubVariable @scope | Out-String)" (Get-GitHubVariable @scope).Count | Should -Be 0 } } diff --git a/tests/API.Tests.ps1 b/tests2/API.Tests.ps1 similarity index 100% rename from tests/API.Tests.ps1 rename to tests2/API.Tests.ps1 diff --git a/tests/Apps.Tests.ps1 b/tests2/Apps.Tests.ps1 similarity index 100% rename from tests/Apps.Tests.ps1 rename to tests2/Apps.Tests.ps1 diff --git a/tests/Auth.Tests.ps1 b/tests2/Auth.Tests.ps1 similarity index 100% rename from tests/Auth.Tests.ps1 rename to tests2/Auth.Tests.ps1 diff --git a/tests/Emojis.Tests.ps1 b/tests2/Emojis.Tests.ps1 similarity index 100% rename from tests/Emojis.Tests.ps1 rename to tests2/Emojis.Tests.ps1 diff --git a/tests/Environments.Tests.ps1 b/tests2/Environments.Tests.ps1 similarity index 100% rename from tests/Environments.Tests.ps1 rename to tests2/Environments.Tests.ps1 diff --git a/tests/GitHub.Tests.ps1 b/tests2/GitHub.Tests.ps1 similarity index 100% rename from tests/GitHub.Tests.ps1 rename to tests2/GitHub.Tests.ps1 diff --git a/tests/IssueForm.md b/tests2/IssueForm.md similarity index 100% rename from tests/IssueForm.md rename to tests2/IssueForm.md diff --git a/tests/Organization.Tests.ps1 b/tests2/Organization.Tests.ps1 similarity index 100% rename from tests/Organization.Tests.ps1 rename to tests2/Organization.Tests.ps1 diff --git a/tests/README.md b/tests2/README.md similarity index 100% rename from tests/README.md rename to tests2/README.md diff --git a/tests/TEMPLATE.ps1 b/tests2/TEMPLATE.ps1 similarity index 100% rename from tests/TEMPLATE.ps1 rename to tests2/TEMPLATE.ps1 diff --git a/tests/User.Tests.ps1 b/tests2/User.Tests.ps1 similarity index 100% rename from tests/User.Tests.ps1 rename to tests2/User.Tests.ps1 From b89a68686a0d4e86c4653a3d2a2de98cc2029f40 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 16:04:23 +0100 Subject: [PATCH 53/85] --- {tests2 => tests}/API.Tests.ps1 | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {tests2 => tests}/API.Tests.ps1 (100%) diff --git a/tests2/API.Tests.ps1 b/tests/API.Tests.ps1 similarity index 100% rename from tests2/API.Tests.ps1 rename to tests/API.Tests.ps1 From 1434f7902d1a7eac8a61a8e014915873db3418be Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 16:05:32 +0100 Subject: [PATCH 54/85] =?UTF-8?q?=F0=9F=A9=B9=20[Refactor]:=20Move=20repos?= =?UTF-8?q?itory=20tests=20to=20a=20new=20directory=20and=20restructure=20?= =?UTF-8?q?for=20improved=20organization?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- {tests => tests2}/API.Tests.ps1 | 0 {tests => tests2}/Repositories.Tests.ps1 | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename {tests => tests2}/API.Tests.ps1 (100%) rename {tests => tests2}/Repositories.Tests.ps1 (100%) diff --git a/tests/API.Tests.ps1 b/tests2/API.Tests.ps1 similarity index 100% rename from tests/API.Tests.ps1 rename to tests2/API.Tests.ps1 diff --git a/tests/Repositories.Tests.ps1 b/tests2/Repositories.Tests.ps1 similarity index 100% rename from tests/Repositories.Tests.ps1 rename to tests2/Repositories.Tests.ps1 From 4980908299d562406fc6fe984639702501c8255f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 16:56:33 +0100 Subject: [PATCH 55/85] Refactor: Update test structure and enhance documentation for better clarity --- tests/Variables.Tests.ps1 | 168 ++++++++++++++++++++------------------ 1 file changed, 88 insertions(+), 80 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index d5944e6f2..a7b389e5a 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -12,35 +12,35 @@ param() BeforeAll { - $repoSuffix = 'VariableTest' - $environmentName = 'production' + $testName = 'VariableTest' $os = Get-GitHubRunnerData | Select-Object -ExpandProperty OS - $prefix = $os + 'ORG_FG_PAT' } Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT)' { BeforeAll { Connect-GitHubAccount -Token $env:TEST_USER_USER_FG_PAT $owner = 'psmodule-user' - $guid = [guid]::NewGuid().ToString() - $repo = "$repoSuffix-$guid" - New-GitHubRepository -Name $repo -AllowSquashMerge - Set-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName + $testType = 'USER_FG_PAT' + $repoName = "$testName-$os-$testType" + $variablePrefix = "$testName`_$os`_$testType`_" + $environmentName = "$testName-$os-$testType" + New-GitHubRepository -Name $repoName -AllowSquashMerge + Set-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName } AfterAll { - Remove-GitHubRepository -Owner $owner -Name $repo -Confirm:$false + Remove-GitHubRepository -Owner $owner -Name $repoName -Confirm:$false Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } Context 'Repository' { BeforeAll { $scope = @{ Owner = $owner - Repository = $repo + Repository = $repoName } } It 'Set-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable" + Name = "$variablePrefix`TestVariable" Value = 'TestValue' } $result = Set-GitHubVariable @param @scope @@ -50,7 +50,7 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) It 'Update-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable" + Name = "$variablePrefix`TestVariable" Value = 'TestValue1234' } $result = Update-GitHubVariable @param @scope -PassThru @@ -59,7 +59,7 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) It 'New-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable2" + Name = "$variablePrefix`TestVariable2" Value = 'TestValue123' } $result = New-GitHubVariable @param @scope @@ -82,13 +82,13 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) BeforeAll { $scope = @{ Owner = $owner - Repository = $repo + Repository = $repoName Environment = $environmentName } } It 'Set-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable" + Name = "$variablePrefix`TestVariable" Value = 'TestValue' } $result = Set-GitHubVariable @param @scope @@ -98,7 +98,7 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) It 'Update-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable" + Name = "$variablePrefix`TestVariable" Value = 'TestValue1234' } $result = Update-GitHubVariable @param @scope -PassThru @@ -107,7 +107,7 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) It 'New-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable2" + Name = "$variablePrefix`TestVariable2" Value = 'TestValue123' } $result = New-GitHubVariable @param @scope @@ -132,13 +132,15 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ BeforeAll { Connect-GitHubAccount -Token $env:TEST_USER_ORG_FG_PAT $owner = 'psmodule-test-org2' - $guid = [guid]::NewGuid().ToString() - $repo = "$repoSuffix-$guid" - New-GitHubRepository -Owner $owner -Name $repo -AllowSquashMerge - Set-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName + $testType = 'ORG_FG_PAT' + $repoName = "$testName-$os-$testType" + $variablePrefix = "$testName`_$os`_$testType`_" + $environmentName = "$testName-$os-$testType" + New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge + Set-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName } AfterAll { - Remove-GitHubRepository -Owner $owner -Name $repo -Confirm:$false + Remove-GitHubRepository -Owner $owner -Name $repoName -Confirm:$false Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } Context 'Organization' { @@ -149,7 +151,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ } It 'Set-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable" + Name = "$variablePrefix`TestVariable" Value = 'TestValue' } $result = Set-GitHubVariable @param @scope @@ -159,7 +161,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ It 'Update-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable" + Name = "$variablePrefix`TestVariable" Value = 'TestValue1234' Visibility = 'all' } @@ -169,7 +171,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ It 'New-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable2" + Name = "$variablePrefix`TestVariable2" Value = 'TestValue123' } $result = New-GitHubVariable @param @scope @@ -192,12 +194,12 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ BeforeAll { $scope = @{ Owner = $owner - Repository = $repo + Repository = $repoName } } It 'Set-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable" + Name = "$variablePrefix`TestVariable" Value = 'TestValue' } $result = Set-GitHubVariable @param @scope @@ -207,7 +209,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ It 'Update-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable" + Name = "$variablePrefix`TestVariable" Value = 'TestValue1234' } $result = Update-GitHubVariable @param @scope -PassThru @@ -216,7 +218,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ It 'New-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable2" + Name = "$variablePrefix`TestVariable2" Value = 'TestValue123' } $result = New-GitHubVariable @param @scope @@ -239,13 +241,13 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ BeforeAll { $scope = @{ Owner = $owner - Repository = $repo + Repository = $repoName Environment = $environmentName } } It 'Set-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable" + Name = "$variablePrefix`TestVariable" Value = 'TestValue' } $result = Set-GitHubVariable @param @scope @@ -255,7 +257,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ It 'Update-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable" + Name = "$variablePrefix`TestVariable" Value = 'TestValue1234' } $result = Update-GitHubVariable @param @scope -PassThru @@ -264,7 +266,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ It 'New-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable2" + Name = "$variablePrefix`TestVariable2" Value = 'TestValue123' } $result = New-GitHubVariable @param @scope @@ -289,13 +291,15 @@ Describe 'As a user - Classic PAT token (PAT)' { BeforeAll { Connect-GitHubAccount -Token $env:TEST_USER_PAT $owner = 'psmodule-test-org2' - $guid = [guid]::NewGuid().ToString() - $repo = "$repoSuffix-$guid" - New-GitHubRepository -Owner $owner -Name $repo -AllowSquashMerge - Set-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName + $testType = 'PAT' + $repoName = "$testName-$os-$testType" + $variablePrefix = "$testName`_$os`_$testType`_" + $environmentName = "$testName-$os-$testType" + New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge + Set-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName } AfterAll { - Remove-GitHubRepository -Owner $owner -Name $repo -Confirm:$false + Remove-GitHubRepository -Owner $owner -Name $repoName -Confirm:$false Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } Context 'Organization' { @@ -306,7 +310,7 @@ Describe 'As a user - Classic PAT token (PAT)' { } It 'Set-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable" + Name = "$variablePrefix`TestVariable" Value = 'TestValue' } $result = Set-GitHubVariable @param @scope @@ -316,7 +320,7 @@ Describe 'As a user - Classic PAT token (PAT)' { It 'Update-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable" + Name = "$variablePrefix`TestVariable" Value = 'TestValue1234' Visibility = 'all' } @@ -326,7 +330,7 @@ Describe 'As a user - Classic PAT token (PAT)' { It 'New-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable2" + Name = "$variablePrefix`TestVariable2" Value = 'TestValue123' } $result = New-GitHubVariable @param @scope @@ -349,12 +353,12 @@ Describe 'As a user - Classic PAT token (PAT)' { BeforeAll { $scope = @{ Owner = $owner - Repository = $repo + Repository = $repoName } } It 'Set-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable" + Name = "$variablePrefix`TestVariable" Value = 'TestValue' } $result = Set-GitHubVariable @param @scope @@ -364,7 +368,7 @@ Describe 'As a user - Classic PAT token (PAT)' { It 'Update-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable" + Name = "$variablePrefix`TestVariable" Value = 'TestValue1234' } $result = Update-GitHubVariable @param @scope -PassThru @@ -373,7 +377,7 @@ Describe 'As a user - Classic PAT token (PAT)' { It 'New-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable2" + Name = "$variablePrefix`TestVariable2" Value = 'TestValue123' } $result = New-GitHubVariable @param @scope @@ -396,13 +400,13 @@ Describe 'As a user - Classic PAT token (PAT)' { BeforeAll { $scope = @{ Owner = $owner - Repository = $repo + Repository = $repoName Environment = $environmentName } } It 'Set-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable" + Name = "$variablePrefix`TestVariable" Value = 'TestValue' } $result = Set-GitHubVariable @param @scope @@ -412,7 +416,7 @@ Describe 'As a user - Classic PAT token (PAT)' { It 'Update-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable" + Name = "$variablePrefix`TestVariable" Value = 'TestValue1234' } $result = Update-GitHubVariable @param @scope -PassThru @@ -421,7 +425,7 @@ Describe 'As a user - Classic PAT token (PAT)' { It 'New-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable2" + Name = "$variablePrefix`TestVariable2" Value = 'TestValue123' } $result = New-GitHubVariable @param @scope @@ -459,13 +463,15 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { Connect-GitHubAccount -ClientID $env:TEST_APP_ENT_CLIENT_ID -PrivateKey $env:TEST_APP_ENT_PRIVATE_KEY $owner = 'psmodule-test-org3' Connect-GitHubApp -Organization $owner -Default - $guid = [guid]::NewGuid().ToString() - $repo = "$repoSuffix-$guid" - New-GitHubRepository -Owner $owner -Name $repo -AllowSquashMerge - Set-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName + $testType = 'APP_ENT' + $repoName = "$testName-$os-$testType" + $variablePrefix = "$testName`_$os`_$testType`_" + $environmentName = "$testName-$os-$testType" + New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge + Set-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName } AfterAll { - Remove-GitHubRepository -Owner $owner -Name $repo -Confirm:$false + Remove-GitHubRepository -Owner $owner -Name $repoName -Confirm:$false Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } Context 'Organization' { @@ -476,7 +482,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { } It 'Set-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable" + Name = "$variablePrefix`TestVariable" Value = 'TestValue' } $result = Set-GitHubVariable @param @scope @@ -486,7 +492,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { It 'Update-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable" + Name = "$variablePrefix`TestVariable" Value = 'TestValue1234' Visibility = 'all' } @@ -496,7 +502,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { It 'New-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable2" + Name = "$variablePrefix`TestVariable2" Value = 'TestValue123' } $result = New-GitHubVariable @param @scope @@ -519,12 +525,12 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { BeforeAll { $scope = @{ Owner = $owner - Repository = $repo + Repository = $repoName } } It 'Set-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable" + Name = "$variablePrefix`TestVariable" Value = 'TestValue' } $result = Set-GitHubVariable @param @scope @@ -534,7 +540,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { It 'Update-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable" + Name = "$variablePrefix`TestVariable" Value = 'TestValue1234' } $result = Update-GitHubVariable @param @scope -PassThru @@ -543,7 +549,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { It 'New-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable2" + Name = "$variablePrefix`TestVariable2" Value = 'TestValue123' } $result = New-GitHubVariable @param @scope @@ -566,13 +572,13 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { BeforeAll { $scope = @{ Owner = $owner - Repository = $repo + Repository = $repoName Environment = $environmentName } } It 'Set-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable" + Name = "$variablePrefix`TestVariable" Value = 'TestValue' } $result = Set-GitHubVariable @param @scope @@ -582,7 +588,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { It 'Update-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable" + Name = "$variablePrefix`TestVariable" Value = 'TestValue1234' } $result = Update-GitHubVariable @param @scope -PassThru @@ -591,7 +597,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { It 'New-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable2" + Name = "$variablePrefix`TestVariable2" Value = 'TestValue123' } $result = New-GitHubVariable @param @scope @@ -617,13 +623,15 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { Connect-GitHubAccount -ClientID $env:TEST_APP_ORG_CLIENT_ID -PrivateKey $env:TEST_APP_ORG_PRIVATE_KEY $owner = 'psmodule-test-org' Connect-GitHubApp -Organization $owner -Default - $guid = [guid]::NewGuid().ToString() - $repo = "$repoSuffix-$guid" - New-GitHubRepository -Owner $owner -Name $repo -AllowSquashMerge - Set-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName + $testType = 'APP_ORG' + $repoName = "$testName-$os-$testType" + $variablePrefix = "$testName`_$os`_$testType`_" + $environmentName = "$testName-$os-$testType" + New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge + Set-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName } AfterAll { - Remove-GitHubRepository -Owner $owner -Name $repo -Confirm:$false + Remove-GitHubRepository -Owner $owner -Name $repoName -Confirm:$false Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } Context 'Organization' { @@ -634,7 +642,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { } It 'Set-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable" + Name = "$variablePrefix`TestVariable" Value = 'TestValue' } $result = Set-GitHubVariable @param @scope @@ -644,7 +652,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { It 'Update-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable" + Name = "$variablePrefix`TestVariable" Value = 'TestValue1234' Visibility = 'all' } @@ -654,7 +662,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { It 'New-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable2" + Name = "$variablePrefix`TestVariable2" Value = 'TestValue123' } $result = New-GitHubVariable @param @scope @@ -677,12 +685,12 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { BeforeAll { $scope = @{ Owner = $owner - Repository = $repo + Repository = $repoName } } It 'Set-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable" + Name = "$variablePrefix`TestVariable" Value = 'TestValue' } $result = Set-GitHubVariable @param @scope @@ -692,7 +700,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { It 'Update-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable" + Name = "$variablePrefix`TestVariable" Value = 'TestValue1234' } $result = Update-GitHubVariable @param @scope -PassThru @@ -701,7 +709,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { It 'New-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable2" + Name = "$variablePrefix`TestVariable2" Value = 'TestValue123' } $result = New-GitHubVariable @param @scope @@ -724,13 +732,13 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { BeforeAll { $scope = @{ Owner = $owner - Repository = $repo + Repository = $repoName Environment = $environmentName } } It 'Set-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable" + Name = "$variablePrefix`TestVariable" Value = 'TestValue' } $result = Set-GitHubVariable @param @scope @@ -740,7 +748,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { It 'Update-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable" + Name = "$variablePrefix`TestVariable" Value = 'TestValue1234' } $result = Update-GitHubVariable @param @scope -PassThru @@ -749,7 +757,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { It 'New-GitHubVariable' { $param = @{ - Name = "$prefix`TestVariable2" + Name = "$variablePrefix`TestVariable2" Value = 'TestValue123' } $result = New-GitHubVariable @param @scope From 946be884a07abc8572b77e2c38b649dde81af190 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 17:09:28 +0100 Subject: [PATCH 56/85] Refactor: Organize test files into a dedicated directory and improve documentation --- tests/Variables.Tests.ps1 | 168 ++++++++++++++++++++++---------------- 1 file changed, 98 insertions(+), 70 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index a7b389e5a..3f7c7492f 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -67,15 +67,17 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) } It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope + $result = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } $result | Should -Not -BeNullOrEmpty } It 'Remove-GitHubVariable' { - Write-Host "$(Get-GitHubVariable @scope | Out-String)" - Get-GitHubVariable @scope | Remove-GitHubVariable - Write-Host "$(Get-GitHubVariable @scope | Out-String)" - (Get-GitHubVariable @scope).Count | Should -Be 0 + $before = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + Write-Host "$($before | Out-String)" + $before | Remove-GitHubVariable + $after = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + Write-Host "$($after | Out-String)" + $after.Count | Should -Be 0 } } Context 'Environment' { @@ -115,15 +117,17 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) } It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope + $result = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } $result | Should -Not -BeNullOrEmpty } It 'Remove-GitHubVariable' { - Write-Host "$(Get-GitHubVariable @scope | Out-String)" - Get-GitHubVariable @scope | Remove-GitHubVariable - Write-Host "$(Get-GitHubVariable @scope | Out-String)" - (Get-GitHubVariable @scope).Count | Should -Be 0 + $before = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + Write-Host "$($before | Out-String)" + $before | Remove-GitHubVariable + $after = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + Write-Host "$($after | Out-String)" + $after.Count | Should -Be 0 } } } @@ -179,15 +183,17 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ } It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope + $result = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } $result | Should -Not -BeNullOrEmpty } It 'Remove-GitHubVariable' { - Write-Host "$(Get-GitHubVariable @scope | Out-String)" - Get-GitHubVariable @scope | Remove-GitHubVariable - Write-Host "$(Get-GitHubVariable @scope | Out-String)" - (Get-GitHubVariable @scope).Count | Should -Be 0 + $before = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + Write-Host "$($before | Out-String)" + $before | Remove-GitHubVariable + $after = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + Write-Host "$($after | Out-String)" + $after.Count | Should -Be 0 } } Context 'Repository' { @@ -226,15 +232,17 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ } It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope + $result = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } $result | Should -Not -BeNullOrEmpty } It 'Remove-GitHubVariable' { - Write-Host "$(Get-GitHubVariable @scope | Out-String)" - Get-GitHubVariable @scope | Remove-GitHubVariable - Write-Host "$(Get-GitHubVariable @scope | Out-String)" - (Get-GitHubVariable @scope).Count | Should -Be 0 + $before = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + Write-Host "$($before | Out-String)" + $before | Remove-GitHubVariable + $after = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + Write-Host "$($after | Out-String)" + $after.Count | Should -Be 0 } } Context 'Environment' { @@ -274,15 +282,17 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ } It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope + $result = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } $result | Should -Not -BeNullOrEmpty } It 'Remove-GitHubVariable' { - Write-Host "$(Get-GitHubVariable @scope | Out-String)" - Get-GitHubVariable @scope | Remove-GitHubVariable - Write-Host "$(Get-GitHubVariable @scope | Out-String)" - (Get-GitHubVariable @scope).Count | Should -Be 0 + $before = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + Write-Host "$($before | Out-String)" + $before | Remove-GitHubVariable + $after = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + Write-Host "$($after | Out-String)" + $after.Count | Should -Be 0 } } } @@ -338,15 +348,17 @@ Describe 'As a user - Classic PAT token (PAT)' { } It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope + $result = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } $result | Should -Not -BeNullOrEmpty } It 'Remove-GitHubVariable' { - Write-Host "$(Get-GitHubVariable @scope | Out-String)" - Get-GitHubVariable @scope | Remove-GitHubVariable - Write-Host "$(Get-GitHubVariable @scope | Out-String)" - (Get-GitHubVariable @scope).Count | Should -Be 0 + $before = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + Write-Host "$($before | Out-String)" + $before | Remove-GitHubVariable + $after = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + Write-Host "$($after | Out-String)" + $after.Count | Should -Be 0 } } Context 'Repository' { @@ -385,15 +397,17 @@ Describe 'As a user - Classic PAT token (PAT)' { } It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope + $result = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } $result | Should -Not -BeNullOrEmpty } It 'Remove-GitHubVariable' { - Write-Host "$(Get-GitHubVariable @scope | Out-String)" - Get-GitHubVariable @scope | Remove-GitHubVariable - Write-Host "$(Get-GitHubVariable @scope | Out-String)" - (Get-GitHubVariable @scope).Count | Should -Be 0 + $before = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + Write-Host "$($before | Out-String)" + $before | Remove-GitHubVariable + $after = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + Write-Host "$($after | Out-String)" + $after.Count | Should -Be 0 } } Context 'Environment' { @@ -433,15 +447,17 @@ Describe 'As a user - Classic PAT token (PAT)' { } It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope + $result = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } $result | Should -Not -BeNullOrEmpty } It 'Remove-GitHubVariable' { - Write-Host "$(Get-GitHubVariable @scope | Out-String)" - Get-GitHubVariable @scope | Remove-GitHubVariable - Write-Host "$(Get-GitHubVariable @scope | Out-String)" - (Get-GitHubVariable @scope).Count | Should -Be 0 + $before = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + Write-Host "$($before | Out-String)" + $before | Remove-GitHubVariable + $after = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + Write-Host "$($after | Out-String)" + $after.Count | Should -Be 0 } } } @@ -510,15 +526,17 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { } It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope + $result = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } $result | Should -Not -BeNullOrEmpty } It 'Remove-GitHubVariable' { - Write-Host "$(Get-GitHubVariable @scope | Out-String)" - Get-GitHubVariable @scope | Remove-GitHubVariable - Write-Host "$(Get-GitHubVariable @scope | Out-String)" - (Get-GitHubVariable @scope).Count | Should -Be 0 + $before = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + Write-Host "$($before | Out-String)" + $before | Remove-GitHubVariable + $after = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + Write-Host "$($after | Out-String)" + $after.Count | Should -Be 0 } } Context 'Repository' { @@ -557,15 +575,17 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { } It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope + $result = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } $result | Should -Not -BeNullOrEmpty } It 'Remove-GitHubVariable' { - Write-Host "$(Get-GitHubVariable @scope | Out-String)" - Get-GitHubVariable @scope | Remove-GitHubVariable - Write-Host "$(Get-GitHubVariable @scope | Out-String)" - (Get-GitHubVariable @scope).Count | Should -Be 0 + $before = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + Write-Host "$($before | Out-String)" + $before | Remove-GitHubVariable + $after = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + Write-Host "$($after | Out-String)" + $after.Count | Should -Be 0 } } Context 'Environment' { @@ -605,15 +625,17 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { } It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope + $result = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } $result | Should -Not -BeNullOrEmpty } It 'Remove-GitHubVariable' { - Write-Host "$(Get-GitHubVariable @scope | Out-String)" - Get-GitHubVariable @scope | Remove-GitHubVariable - Write-Host "$(Get-GitHubVariable @scope | Out-String)" - (Get-GitHubVariable @scope).Count | Should -Be 0 + $before = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + Write-Host "$($before | Out-String)" + $before | Remove-GitHubVariable + $after = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + Write-Host "$($after | Out-String)" + $after.Count | Should -Be 0 } } } @@ -670,15 +692,17 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { } It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope + $result = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } $result | Should -Not -BeNullOrEmpty } It 'Remove-GitHubVariable' { - Write-Host "$(Get-GitHubVariable @scope | Out-String)" - Get-GitHubVariable @scope | Remove-GitHubVariable - Write-Host "$(Get-GitHubVariable @scope | Out-String)" - (Get-GitHubVariable @scope).Count | Should -Be 0 + $before = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + Write-Host "$($before | Out-String)" + $before | Remove-GitHubVariable + $after = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + Write-Host "$($after | Out-String)" + $after.Count | Should -Be 0 } } Context 'Repository' { @@ -717,15 +741,17 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { } It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope + $result = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } $result | Should -Not -BeNullOrEmpty } It 'Remove-GitHubVariable' { - Write-Host "$(Get-GitHubVariable @scope | Out-String)" - Get-GitHubVariable @scope | Remove-GitHubVariable - Write-Host "$(Get-GitHubVariable @scope | Out-String)" - (Get-GitHubVariable @scope).Count | Should -Be 0 + $before = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + Write-Host "$($before | Out-String)" + $before | Remove-GitHubVariable + $after = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + Write-Host "$($after | Out-String)" + $after.Count | Should -Be 0 } } Context 'Environment' { @@ -765,15 +791,17 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { } It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope + $result = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } $result | Should -Not -BeNullOrEmpty } It 'Remove-GitHubVariable' { - Write-Host "$(Get-GitHubVariable @scope | Out-String)" - Get-GitHubVariable @scope | Remove-GitHubVariable - Write-Host "$(Get-GitHubVariable @scope | Out-String)" - (Get-GitHubVariable @scope).Count | Should -Be 0 + $before = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + Write-Host "$($before | Out-String)" + $before | Remove-GitHubVariable + $after = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + Write-Host "$($after | Out-String)" + $after.Count | Should -Be 0 } } } From 1118bbd7b4cd7325e647f6510e3c7f73f74dce00 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 17:23:47 +0100 Subject: [PATCH 57/85] Add initial test files for GitHub API interactions and enhance documentation --- {tests2 => tests}/API.Tests.ps1 | 0 {tests2 => tests}/Apps.Tests.ps1 | 0 {tests2 => tests}/Auth.Tests.ps1 | 0 {tests2 => tests}/Emojis.Tests.ps1 | 0 {tests2 => tests}/Environments.Tests.ps1 | 0 {tests2 => tests}/GitHub.Tests.ps1 | 0 {tests2 => tests}/IssueForm.md | 0 {tests2 => tests}/Organization.Tests.ps1 | 0 {tests2 => tests}/README.md | 0 {tests2 => tests}/Repositories.Tests.ps1 | 0 {tests2 => tests}/TEMPLATE.ps1 | 0 {tests2 => tests}/User.Tests.ps1 | 0 12 files changed, 0 insertions(+), 0 deletions(-) rename {tests2 => tests}/API.Tests.ps1 (100%) rename {tests2 => tests}/Apps.Tests.ps1 (100%) rename {tests2 => tests}/Auth.Tests.ps1 (100%) rename {tests2 => tests}/Emojis.Tests.ps1 (100%) rename {tests2 => tests}/Environments.Tests.ps1 (100%) rename {tests2 => tests}/GitHub.Tests.ps1 (100%) rename {tests2 => tests}/IssueForm.md (100%) rename {tests2 => tests}/Organization.Tests.ps1 (100%) rename {tests2 => tests}/README.md (100%) rename {tests2 => tests}/Repositories.Tests.ps1 (100%) rename {tests2 => tests}/TEMPLATE.ps1 (100%) rename {tests2 => tests}/User.Tests.ps1 (100%) diff --git a/tests2/API.Tests.ps1 b/tests/API.Tests.ps1 similarity index 100% rename from tests2/API.Tests.ps1 rename to tests/API.Tests.ps1 diff --git a/tests2/Apps.Tests.ps1 b/tests/Apps.Tests.ps1 similarity index 100% rename from tests2/Apps.Tests.ps1 rename to tests/Apps.Tests.ps1 diff --git a/tests2/Auth.Tests.ps1 b/tests/Auth.Tests.ps1 similarity index 100% rename from tests2/Auth.Tests.ps1 rename to tests/Auth.Tests.ps1 diff --git a/tests2/Emojis.Tests.ps1 b/tests/Emojis.Tests.ps1 similarity index 100% rename from tests2/Emojis.Tests.ps1 rename to tests/Emojis.Tests.ps1 diff --git a/tests2/Environments.Tests.ps1 b/tests/Environments.Tests.ps1 similarity index 100% rename from tests2/Environments.Tests.ps1 rename to tests/Environments.Tests.ps1 diff --git a/tests2/GitHub.Tests.ps1 b/tests/GitHub.Tests.ps1 similarity index 100% rename from tests2/GitHub.Tests.ps1 rename to tests/GitHub.Tests.ps1 diff --git a/tests2/IssueForm.md b/tests/IssueForm.md similarity index 100% rename from tests2/IssueForm.md rename to tests/IssueForm.md diff --git a/tests2/Organization.Tests.ps1 b/tests/Organization.Tests.ps1 similarity index 100% rename from tests2/Organization.Tests.ps1 rename to tests/Organization.Tests.ps1 diff --git a/tests2/README.md b/tests/README.md similarity index 100% rename from tests2/README.md rename to tests/README.md diff --git a/tests2/Repositories.Tests.ps1 b/tests/Repositories.Tests.ps1 similarity index 100% rename from tests2/Repositories.Tests.ps1 rename to tests/Repositories.Tests.ps1 diff --git a/tests2/TEMPLATE.ps1 b/tests/TEMPLATE.ps1 similarity index 100% rename from tests2/TEMPLATE.ps1 rename to tests/TEMPLATE.ps1 diff --git a/tests2/User.Tests.ps1 b/tests/User.Tests.ps1 similarity index 100% rename from tests2/User.Tests.ps1 rename to tests/User.Tests.ps1 From 9112072929a8de625ebda1f715dd9dbe83b55c5b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 18:54:37 +0100 Subject: [PATCH 58/85] Add function to list organization variables and enhance Get-GitHubVariable for better variable retrieval --- .../Get-GitHubVariableFromOrganization.ps1 | 99 +++++++++++++++++++ .../public/Variables/Get-GitHubVariable.ps1 | 30 +++--- 2 files changed, 115 insertions(+), 14 deletions(-) create mode 100644 src/functions/private/Variables/Get-GitHubVariableFromOrganization.ps1 diff --git a/src/functions/private/Variables/Get-GitHubVariableFromOrganization.ps1 b/src/functions/private/Variables/Get-GitHubVariableFromOrganization.ps1 new file mode 100644 index 000000000..4a13d7ba2 --- /dev/null +++ b/src/functions/private/Variables/Get-GitHubVariableFromOrganization.ps1 @@ -0,0 +1,99 @@ +function Get-GitHubVariableFromOrganization { + <# + .SYNOPSIS + List repository organization variables. + + .DESCRIPTION + Lists all organization variables shared with a repository. + Authenticated users must have collaborator access to a repository to create, update, or read variables. + OAuth app tokens and personal access tokens (classic) need the `repo` scope to use this endpoint. + + .EXAMPLE + Get-GitHubVariableFromOrganization -Owner 'PSModule' -Repository 'GitHub' -Context (Get-GitHubContext) + + Output: + ```powershell + Name : AVAILVAR + Value : ValueVar + Owner : PSModule + Repository : + Environment : + CreatedAt : 3/17/2025 10:56:22 AM + UpdatedAt : 3/17/2025 10:56:22 AM + Visibility : + SelectedRepositories : + + Name : SELECTEDVAR + Value : Varselected + Owner : PSModule + Repository : + Environment : + CreatedAt : 3/17/2025 10:56:39 AM + UpdatedAt : 3/17/2025 10:56:39 AM + Visibility : + SelectedRepositories : + + Name : TESTVAR + Value : VarTest + Owner : PSModule + Repository : + Environment : + CreatedAt : 3/17/2025 10:56:05 AM + UpdatedAt : 3/17/2025 10:56:05 AM + Visibility : + SelectedRepositories : + ``` + + Lists the variables visible from 'PSModule' to the 'GitHub' repository. + + .LINK + [List repository organization variables](https://docs.github.com/rest/actions/variables#list-repository-organization-variables) + #> + [OutputType([GitHubVariable[]])] + [CmdletBinding()] + 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] $Repository, + + # The context to run the command in. Used to get the details for the API call. + # Can be either a string or a GitHubContext object. + [Parameter(Mandatory)] + [object] $Context + ) + + begin { + $stackPath = Get-PSCallStackPath + Write-Debug "[$stackPath] - Start" + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + } + + process { + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/repos/$Owner/$Repository/actions/organization-variables" + Context = $Context + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + $_.Response.variables | ForEach-Object { + [GitHubVariable]@{ + Name = $_.name + Value = $_.value + CreatedAt = $_.created_at + UpdatedAt = $_.updated_at + Owner = $Owner + Visibility = $_.visibility + } + } + } + } + + end { + Write-Debug "[$stackPath] - End" + } +} diff --git a/src/functions/public/Variables/Get-GitHubVariable.ps1 b/src/functions/public/Variables/Get-GitHubVariable.ps1 index efca564ad..c026cb888 100644 --- a/src/functions/public/Variables/Get-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Get-GitHubVariable.ps1 @@ -143,7 +143,12 @@ function Get-GitHubVariable { # The name of the variable. [Parameter()] - [string] $Name, + [SupportsWildcards()] + [string] $Name = '*', + + # List all variables that are inherited. + [Parameter()] + [switch] $All, # The context to run the command in. Used to get the details for the API call. # Can be either a string or a GitHubContext object. @@ -159,32 +164,29 @@ function Get-GitHubVariable { } process { + $variables = @() switch ($PSCmdlet.ParameterSetName) { 'Organization' { - if ($Name) { - Get-GitHubVariableOwnerByName -Owner $Owner -Name $Name -Context $Context - } else { - Get-GitHubVariableOwnerList -Owner $Owner -Context $Context - } + $variables += Get-GitHubVariableOwnerList -Owner $Owner -Context $Context break } 'Repository' { - if ($Name) { - Get-GitHubVariableRepositoryByName -Owner $Owner -Repository $Repository -Name $Name -Context $Context - } else { - Get-GitHubVariableRepositoryList -Owner $Owner -Repository $Repository -Context $Context + if ($All) { + $variables += Get-GitHubVariableFromOrganization -Owner $Owner -Context $Context } + $variables += Get-GitHubVariableRepositoryList -Owner $Owner -Repository $Repository -Context $Context break } 'Environment' { - if ($Name) { - Get-GitHubVariableEnvironmentByName -Owner $Owner -Repository $Repository -Environment $Environment -Name $Name -Context $Context - } else { - Get-GitHubVariableEnvironmentList -Owner $Owner -Repository $Repository -Environment $Environment -Context $Context + if ($All) { + $variables += Get-GitHubVariableFromOrganization -Owner $Owner -Context $Context + $variables += Get-GitHubVariableRepositoryList -Owner $Owner -Repository $Repository -Context } + $variables += Get-GitHubVariableEnvironmentList -Owner $Owner -Repository $Repository -Environment $Environment -Context $Context break } } + $variables | Where-Object { $_.Name -like $Name } } end { From e193d9c39ed9b63ceab51f1a4b83141e892a06ee Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions@users.noreply.github.com> Date: Tue, 18 Mar 2025 17:56:08 +0000 Subject: [PATCH 59/85] Auto-generated changes --- Coverage.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Coverage.md b/Coverage.md index 8c6493d70..2c1293386 100644 --- a/Coverage.md +++ b/Coverage.md @@ -9,15 +9,15 @@ Covered functions - 180 + 181 Missing functions - 843 + 842 Coverage - 17.6% + 17.69% @@ -298,7 +298,7 @@ | `/repos/{owner}/{repo}/actions/jobs/{job_id}/rerun` | | | | :x: | | | `/repos/{owner}/{repo}/actions/oidc/customization/sub` | | :x: | | | :x: | | `/repos/{owner}/{repo}/actions/organization-secrets` | | :x: | | | | -| `/repos/{owner}/{repo}/actions/organization-variables` | | :x: | | | | +| `/repos/{owner}/{repo}/actions/organization-variables` | | :white_check_mark: | | | | | `/repos/{owner}/{repo}/actions/permissions` | | :x: | | | :x: | | `/repos/{owner}/{repo}/actions/permissions/access` | | :x: | | | :x: | | `/repos/{owner}/{repo}/actions/permissions/selected-actions` | | :x: | | | :x: | From 53479515de2c60c3096b40307631603f78297e9b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 19:09:29 +0100 Subject: [PATCH 60/85] Refactor: Improve formatting and readability in Get-GitHubVariableFromOrganization function --- .../Get-GitHubVariableFromOrganization.ps1 | 14 +-- tests/Variables.Tests.ps1 | 88 ++++++++++--------- 2 files changed, 53 insertions(+), 49 deletions(-) diff --git a/src/functions/private/Variables/Get-GitHubVariableFromOrganization.ps1 b/src/functions/private/Variables/Get-GitHubVariableFromOrganization.ps1 index 4a13d7ba2..e67eccf14 100644 --- a/src/functions/private/Variables/Get-GitHubVariableFromOrganization.ps1 +++ b/src/functions/private/Variables/Get-GitHubVariableFromOrganization.ps1 @@ -40,7 +40,7 @@ function Get-GitHubVariableFromOrganization { Environment : CreatedAt : 3/17/2025 10:56:05 AM UpdatedAt : 3/17/2025 10:56:05 AM - Visibility : + Visibility : SelectedRepositories : ``` @@ -82,12 +82,12 @@ function Get-GitHubVariableFromOrganization { Invoke-GitHubAPI @inputObject | ForEach-Object { $_.Response.variables | ForEach-Object { [GitHubVariable]@{ - Name = $_.name - Value = $_.value - CreatedAt = $_.created_at - UpdatedAt = $_.updated_at - Owner = $Owner - Visibility = $_.visibility + Name = $_.name + Value = $_.value + CreatedAt = $_.created_at + UpdatedAt = $_.updated_at + Owner = $Owner + Visibility = $_.visibility } } } diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 3f7c7492f..eb0adfd50 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -8,6 +8,10 @@ 'PSAvoidUsingConvertToSecureStringWithPlainText', '', Justification = 'Used to create a secure string for testing.' )] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidUsingWriteHost', '', + Justification = 'Outputs into logs from the tests.' +)] [CmdletBinding()] param() @@ -67,15 +71,15 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) } It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + $result = Get-GitHubVariable @scope -Name "*$os*" $result | Should -Not -BeNullOrEmpty } It 'Remove-GitHubVariable' { - $before = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + $before = Get-GitHubVariable @scope -Name "*$os*" Write-Host "$($before | Out-String)" $before | Remove-GitHubVariable - $after = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + $after = Get-GitHubVariable @scope -Name "*$os*" Write-Host "$($after | Out-String)" $after.Count | Should -Be 0 } @@ -117,15 +121,15 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) } It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + $result = Get-GitHubVariable @scope -Name "*$os*" $result | Should -Not -BeNullOrEmpty } It 'Remove-GitHubVariable' { - $before = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + $before = Get-GitHubVariable @scope -Name "*$os*" Write-Host "$($before | Out-String)" $before | Remove-GitHubVariable - $after = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + $after = Get-GitHubVariable @scope -Name "*$os*" Write-Host "$($after | Out-String)" $after.Count | Should -Be 0 } @@ -183,15 +187,15 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ } It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + $result = Get-GitHubVariable @scope -Name "*$os*" $result | Should -Not -BeNullOrEmpty } It 'Remove-GitHubVariable' { - $before = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + $before = Get-GitHubVariable @scope -Name "*$os*" Write-Host "$($before | Out-String)" $before | Remove-GitHubVariable - $after = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + $after = Get-GitHubVariable @scope -Name "*$os*" Write-Host "$($after | Out-String)" $after.Count | Should -Be 0 } @@ -232,15 +236,15 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ } It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + $result = Get-GitHubVariable @scope -Name "*$os*" $result | Should -Not -BeNullOrEmpty } It 'Remove-GitHubVariable' { - $before = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + $before = Get-GitHubVariable @scope -Name "*$os*" Write-Host "$($before | Out-String)" $before | Remove-GitHubVariable - $after = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + $after = Get-GitHubVariable @scope -Name "*$os*" Write-Host "$($after | Out-String)" $after.Count | Should -Be 0 } @@ -282,15 +286,15 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ } It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + $result = Get-GitHubVariable @scope -Name "*$os*" $result | Should -Not -BeNullOrEmpty } It 'Remove-GitHubVariable' { - $before = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + $before = Get-GitHubVariable @scope -Name "*$os*" Write-Host "$($before | Out-String)" $before | Remove-GitHubVariable - $after = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + $after = Get-GitHubVariable @scope -Name "*$os*" Write-Host "$($after | Out-String)" $after.Count | Should -Be 0 } @@ -348,15 +352,15 @@ Describe 'As a user - Classic PAT token (PAT)' { } It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + $result = Get-GitHubVariable @scope -Name "*$os*" $result | Should -Not -BeNullOrEmpty } It 'Remove-GitHubVariable' { - $before = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + $before = Get-GitHubVariable @scope -Name "*$os*" Write-Host "$($before | Out-String)" $before | Remove-GitHubVariable - $after = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + $after = Get-GitHubVariable @scope -Name "*$os*" Write-Host "$($after | Out-String)" $after.Count | Should -Be 0 } @@ -397,15 +401,15 @@ Describe 'As a user - Classic PAT token (PAT)' { } It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + $result = Get-GitHubVariable @scope -Name "*$os*" $result | Should -Not -BeNullOrEmpty } It 'Remove-GitHubVariable' { - $before = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + $before = Get-GitHubVariable @scope -Name "*$os*" Write-Host "$($before | Out-String)" $before | Remove-GitHubVariable - $after = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + $after = Get-GitHubVariable @scope -Name "*$os*" Write-Host "$($after | Out-String)" $after.Count | Should -Be 0 } @@ -447,15 +451,15 @@ Describe 'As a user - Classic PAT token (PAT)' { } It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + $result = Get-GitHubVariable @scope -Name "*$os*" $result | Should -Not -BeNullOrEmpty } It 'Remove-GitHubVariable' { - $before = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + $before = Get-GitHubVariable @scope -Name "*$os*" Write-Host "$($before | Out-String)" $before | Remove-GitHubVariable - $after = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + $after = Get-GitHubVariable @scope -Name "*$os*" Write-Host "$($after | Out-String)" $after.Count | Should -Be 0 } @@ -526,15 +530,15 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { } It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + $result = Get-GitHubVariable @scope -Name "*$os*" $result | Should -Not -BeNullOrEmpty } It 'Remove-GitHubVariable' { - $before = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + $before = Get-GitHubVariable @scope -Name "*$os*" Write-Host "$($before | Out-String)" $before | Remove-GitHubVariable - $after = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + $after = Get-GitHubVariable @scope -Name "*$os*" Write-Host "$($after | Out-String)" $after.Count | Should -Be 0 } @@ -575,15 +579,15 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { } It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + $result = Get-GitHubVariable @scope -Name "*$os*" $result | Should -Not -BeNullOrEmpty } It 'Remove-GitHubVariable' { - $before = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + $before = Get-GitHubVariable @scope -Name "*$os*" Write-Host "$($before | Out-String)" $before | Remove-GitHubVariable - $after = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + $after = Get-GitHubVariable @scope -Name "*$os*" Write-Host "$($after | Out-String)" $after.Count | Should -Be 0 } @@ -625,15 +629,15 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { } It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + $result = Get-GitHubVariable @scope -Name "*$os*" $result | Should -Not -BeNullOrEmpty } It 'Remove-GitHubVariable' { - $before = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + $before = Get-GitHubVariable @scope -Name "*$os*" Write-Host "$($before | Out-String)" $before | Remove-GitHubVariable - $after = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + $after = Get-GitHubVariable @scope -Name "*$os*" Write-Host "$($after | Out-String)" $after.Count | Should -Be 0 } @@ -692,15 +696,15 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { } It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + $result = Get-GitHubVariable @scope -Name "*$os*" $result | Should -Not -BeNullOrEmpty } It 'Remove-GitHubVariable' { - $before = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + $before = Get-GitHubVariable @scope -Name "*$os*" Write-Host "$($before | Out-String)" $before | Remove-GitHubVariable - $after = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + $after = Get-GitHubVariable @scope -Name "*$os*" Write-Host "$($after | Out-String)" $after.Count | Should -Be 0 } @@ -741,15 +745,15 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { } It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + $result = Get-GitHubVariable @scope -Name "*$os*" $result | Should -Not -BeNullOrEmpty } It 'Remove-GitHubVariable' { - $before = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + $before = Get-GitHubVariable @scope -Name "*$os*" Write-Host "$($before | Out-String)" $before | Remove-GitHubVariable - $after = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + $after = Get-GitHubVariable @scope -Name "*$os*" Write-Host "$($after | Out-String)" $after.Count | Should -Be 0 } @@ -791,15 +795,15 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { } It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + $result = Get-GitHubVariable @scope -Name "*$os*" $result | Should -Not -BeNullOrEmpty } It 'Remove-GitHubVariable' { - $before = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + $before = Get-GitHubVariable @scope -Name "*$os*" Write-Host "$($before | Out-String)" $before | Remove-GitHubVariable - $after = Get-GitHubVariable @scope | Where-Object { $_.Name -Like "*$os*" } + $after = Get-GitHubVariable @scope -Name "*$os*" Write-Host "$($after | Out-String)" $after.Count | Should -Be 0 } From 843ee5336f239a7682bbb6c3aa4e7933319dedf0 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 20:42:28 +0100 Subject: [PATCH 61/85] Add testing framework files and documentation for GitHub API interactions --- .github/workflows/Process-PSModule.yml | 2 ++ tests/Variables.Tests.ps1 | 38 +++++++++++++++++------- {tests => tests2}/API.Tests.ps1 | 0 {tests => tests2}/Apps.Tests.ps1 | 0 {tests => tests2}/Auth.Tests.ps1 | 0 {tests => tests2}/Emojis.Tests.ps1 | 0 {tests => tests2}/Environments.Tests.ps1 | 0 {tests => tests2}/GitHub.Tests.ps1 | 0 {tests => tests2}/IssueForm.md | 0 {tests => tests2}/Organization.Tests.ps1 | 0 {tests => tests2}/README.md | 0 {tests => tests2}/Repositories.Tests.ps1 | 0 {tests => tests2}/TEMPLATE.ps1 | 0 {tests => tests2}/User.Tests.ps1 | 0 14 files changed, 30 insertions(+), 10 deletions(-) rename {tests => tests2}/API.Tests.ps1 (100%) rename {tests => tests2}/Apps.Tests.ps1 (100%) rename {tests => tests2}/Auth.Tests.ps1 (100%) rename {tests => tests2}/Emojis.Tests.ps1 (100%) rename {tests => tests2}/Environments.Tests.ps1 (100%) rename {tests => tests2}/GitHub.Tests.ps1 (100%) rename {tests => tests2}/IssueForm.md (100%) rename {tests => tests2}/Organization.Tests.ps1 (100%) rename {tests => tests2}/README.md (100%) rename {tests => tests2}/Repositories.Tests.ps1 (100%) rename {tests => tests2}/TEMPLATE.ps1 (100%) rename {tests => tests2}/User.Tests.ps1 (100%) diff --git a/.github/workflows/Process-PSModule.yml b/.github/workflows/Process-PSModule.yml index 2fdfe0422..0e06d4b96 100644 --- a/.github/workflows/Process-PSModule.yml +++ b/.github/workflows/Process-PSModule.yml @@ -36,3 +36,5 @@ jobs: TEST_USER_ORG_FG_PAT: ${{ secrets.TEST_USER_ORG_FG_PAT }} TEST_USER_USER_FG_PAT: ${{ secrets.TEST_USER_USER_FG_PAT }} TEST_USER_PAT: ${{ secrets.TEST_USER_PAT }} + with: + SkipTests: SourceCode diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index eb0adfd50..bd6ee6edf 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -28,8 +28,7 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) $repoName = "$testName-$os-$testType" $variablePrefix = "$testName`_$os`_$testType`_" $environmentName = "$testName-$os-$testType" - New-GitHubRepository -Name $repoName -AllowSquashMerge - Set-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName + $repo = New-GitHubRepository -Name $repoName -AllowSquashMerge } AfterAll { Remove-GitHubRepository -Owner $owner -Name $repoName -Confirm:$false @@ -41,6 +40,7 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) Owner = $owner Repository = $repoName } + Set-GitHubVariable -Owner $owner -Repository $repoName -Name $os -Value 'repository' } It 'Set-GitHubVariable' { $param = @{ @@ -91,6 +91,8 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) Repository = $repoName Environment = $environmentName } + Set-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName + Set-GitHubVariable @scope -Name $os -Value 'environment' } It 'Set-GitHubVariable' { $param = @{ @@ -144,11 +146,11 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ $repoName = "$testName-$os-$testType" $variablePrefix = "$testName`_$os`_$testType`_" $environmentName = "$testName-$os-$testType" - New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge - Set-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName + $repo = New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge } AfterAll { Remove-GitHubRepository -Owner $owner -Name $repoName -Confirm:$false + Get-GitHubVariable -Owner $owner -Name "*$os*" | Remove-GitHubVariable Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } Context 'Organization' { @@ -156,6 +158,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ $scope = @{ Owner = $owner } + Set-GitHubVariable -Owner $owner -Name $os -Value 'organization' -Visibility selected -SelectedRepositories $repo.id } It 'Set-GitHubVariable' { $param = @{ @@ -206,6 +209,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ Owner = $owner Repository = $repoName } + Set-GitHubVariable -Owner $owner -Repository $repoName -Name $os -Value 'repository' } It 'Set-GitHubVariable' { $param = @{ @@ -256,6 +260,8 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ Repository = $repoName Environment = $environmentName } + Set-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName + Set-GitHubVariable @scope -Name $os -Value 'environment' } It 'Set-GitHubVariable' { $param = @{ @@ -309,11 +315,11 @@ Describe 'As a user - Classic PAT token (PAT)' { $repoName = "$testName-$os-$testType" $variablePrefix = "$testName`_$os`_$testType`_" $environmentName = "$testName-$os-$testType" - New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge - Set-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName + $repo = New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge } AfterAll { Remove-GitHubRepository -Owner $owner -Name $repoName -Confirm:$false + Get-GitHubVariable -Owner $owner -Name "*$os*" | Remove-GitHubVariable Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } Context 'Organization' { @@ -321,6 +327,7 @@ Describe 'As a user - Classic PAT token (PAT)' { $scope = @{ Owner = $owner } + Set-GitHubVariable @scope -Name $os -Value 'organization' -Visibility selected -SelectedRepositories $repo.id } It 'Set-GitHubVariable' { $param = @{ @@ -371,6 +378,7 @@ Describe 'As a user - Classic PAT token (PAT)' { Owner = $owner Repository = $repoName } + Set-GitHubVariable @scope -Name $os -Value 'repository' } It 'Set-GitHubVariable' { $param = @{ @@ -421,6 +429,8 @@ Describe 'As a user - Classic PAT token (PAT)' { Repository = $repoName Environment = $environmentName } + Set-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName + Set-GitHubVariable @scope -Name $os -Value 'environment' } It 'Set-GitHubVariable' { $param = @{ @@ -487,11 +497,11 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { $repoName = "$testName-$os-$testType" $variablePrefix = "$testName`_$os`_$testType`_" $environmentName = "$testName-$os-$testType" - New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge - Set-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName + $repo = New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge } AfterAll { Remove-GitHubRepository -Owner $owner -Name $repoName -Confirm:$false + Get-GitHubVariable -Owner $owner -Name "*$os*" | Remove-GitHubVariable Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } Context 'Organization' { @@ -499,6 +509,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { $scope = @{ Owner = $owner } + Set-GitHubVariable @scope -Name $os -Value 'organization' -Visibility selected -SelectedRepositories $repo.id } It 'Set-GitHubVariable' { $param = @{ @@ -549,6 +560,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { Owner = $owner Repository = $repoName } + Set-GitHubVariable @scope -Name $os -Value 'repository' } It 'Set-GitHubVariable' { $param = @{ @@ -599,6 +611,8 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { Repository = $repoName Environment = $environmentName } + Set-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName + Set-GitHubVariable @scope -Name $os -Value 'environment' } It 'Set-GitHubVariable' { $param = @{ @@ -653,11 +667,11 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { $repoName = "$testName-$os-$testType" $variablePrefix = "$testName`_$os`_$testType`_" $environmentName = "$testName-$os-$testType" - New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge - Set-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName + $repo = New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge } AfterAll { Remove-GitHubRepository -Owner $owner -Name $repoName -Confirm:$false + Get-GitHubVariable -Owner $owner -Name "*$os*" | Remove-GitHubVariable Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } Context 'Organization' { @@ -665,6 +679,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { $scope = @{ Owner = $owner } + Set-GitHubVariable @scope -Name $os -Value 'organization' -Visibility selected -SelectedRepositories $repo.id } It 'Set-GitHubVariable' { $param = @{ @@ -715,6 +730,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { Owner = $owner Repository = $repoName } + Set-GitHubVariable @scope -Name $os -Value 'repository' } It 'Set-GitHubVariable' { $param = @{ @@ -765,6 +781,8 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { Repository = $repoName Environment = $environmentName } + Set-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName + Set-GitHubVariable @scope -Name $os -Value 'environment' } It 'Set-GitHubVariable' { $param = @{ diff --git a/tests/API.Tests.ps1 b/tests2/API.Tests.ps1 similarity index 100% rename from tests/API.Tests.ps1 rename to tests2/API.Tests.ps1 diff --git a/tests/Apps.Tests.ps1 b/tests2/Apps.Tests.ps1 similarity index 100% rename from tests/Apps.Tests.ps1 rename to tests2/Apps.Tests.ps1 diff --git a/tests/Auth.Tests.ps1 b/tests2/Auth.Tests.ps1 similarity index 100% rename from tests/Auth.Tests.ps1 rename to tests2/Auth.Tests.ps1 diff --git a/tests/Emojis.Tests.ps1 b/tests2/Emojis.Tests.ps1 similarity index 100% rename from tests/Emojis.Tests.ps1 rename to tests2/Emojis.Tests.ps1 diff --git a/tests/Environments.Tests.ps1 b/tests2/Environments.Tests.ps1 similarity index 100% rename from tests/Environments.Tests.ps1 rename to tests2/Environments.Tests.ps1 diff --git a/tests/GitHub.Tests.ps1 b/tests2/GitHub.Tests.ps1 similarity index 100% rename from tests/GitHub.Tests.ps1 rename to tests2/GitHub.Tests.ps1 diff --git a/tests/IssueForm.md b/tests2/IssueForm.md similarity index 100% rename from tests/IssueForm.md rename to tests2/IssueForm.md diff --git a/tests/Organization.Tests.ps1 b/tests2/Organization.Tests.ps1 similarity index 100% rename from tests/Organization.Tests.ps1 rename to tests2/Organization.Tests.ps1 diff --git a/tests/README.md b/tests2/README.md similarity index 100% rename from tests/README.md rename to tests2/README.md diff --git a/tests/Repositories.Tests.ps1 b/tests2/Repositories.Tests.ps1 similarity index 100% rename from tests/Repositories.Tests.ps1 rename to tests2/Repositories.Tests.ps1 diff --git a/tests/TEMPLATE.ps1 b/tests2/TEMPLATE.ps1 similarity index 100% rename from tests/TEMPLATE.ps1 rename to tests2/TEMPLATE.ps1 diff --git a/tests/User.Tests.ps1 b/tests2/User.Tests.ps1 similarity index 100% rename from tests/User.Tests.ps1 rename to tests2/User.Tests.ps1 From 24f621b83ffd6341b473db99dd4a092b570c1627 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 21:06:14 +0100 Subject: [PATCH 62/85] Refactor: Update Set-GitHubVariable calls to use repoName for improved clarity and consistency --- tests/Variables.Tests.ps1 | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index bd6ee6edf..253720793 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -40,7 +40,7 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) Owner = $owner Repository = $repoName } - Set-GitHubVariable -Owner $owner -Repository $repoName -Name $os -Value 'repository' + Set-GitHubVariable @scope -Name $repoName -Value 'repository' } It 'Set-GitHubVariable' { $param = @{ @@ -92,7 +92,7 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) Environment = $environmentName } Set-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName - Set-GitHubVariable @scope -Name $os -Value 'environment' + Set-GitHubVariable @scope -Name $repoName -Value 'environment' } It 'Set-GitHubVariable' { $param = @{ @@ -158,7 +158,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ $scope = @{ Owner = $owner } - Set-GitHubVariable -Owner $owner -Name $os -Value 'organization' -Visibility selected -SelectedRepositories $repo.id + Set-GitHubVariable @scope -Name $repoName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id } It 'Set-GitHubVariable' { $param = @{ @@ -209,7 +209,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ Owner = $owner Repository = $repoName } - Set-GitHubVariable -Owner $owner -Repository $repoName -Name $os -Value 'repository' + Set-GitHubVariable @scope -Name $repoName -Value 'repository' } It 'Set-GitHubVariable' { $param = @{ @@ -261,7 +261,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ Environment = $environmentName } Set-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName - Set-GitHubVariable @scope -Name $os -Value 'environment' + Set-GitHubVariable @scope -Name $repoName -Value 'environment' } It 'Set-GitHubVariable' { $param = @{ @@ -327,7 +327,7 @@ Describe 'As a user - Classic PAT token (PAT)' { $scope = @{ Owner = $owner } - Set-GitHubVariable @scope -Name $os -Value 'organization' -Visibility selected -SelectedRepositories $repo.id + Set-GitHubVariable @scope -Name $repoName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id } It 'Set-GitHubVariable' { $param = @{ @@ -378,7 +378,7 @@ Describe 'As a user - Classic PAT token (PAT)' { Owner = $owner Repository = $repoName } - Set-GitHubVariable @scope -Name $os -Value 'repository' + Set-GitHubVariable @scope -Name $repoName -Value 'repository' } It 'Set-GitHubVariable' { $param = @{ @@ -430,7 +430,7 @@ Describe 'As a user - Classic PAT token (PAT)' { Environment = $environmentName } Set-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName - Set-GitHubVariable @scope -Name $os -Value 'environment' + Set-GitHubVariable @scope -Name $repoName -Value 'environment' } It 'Set-GitHubVariable' { $param = @{ @@ -509,7 +509,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { $scope = @{ Owner = $owner } - Set-GitHubVariable @scope -Name $os -Value 'organization' -Visibility selected -SelectedRepositories $repo.id + Set-GitHubVariable @scope -Name $repoName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id } It 'Set-GitHubVariable' { $param = @{ @@ -560,7 +560,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { Owner = $owner Repository = $repoName } - Set-GitHubVariable @scope -Name $os -Value 'repository' + Set-GitHubVariable @scope -Name $repoName -Value 'repository' } It 'Set-GitHubVariable' { $param = @{ @@ -612,7 +612,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { Environment = $environmentName } Set-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName - Set-GitHubVariable @scope -Name $os -Value 'environment' + Set-GitHubVariable @scope -Name $repoName -Value 'environment' } It 'Set-GitHubVariable' { $param = @{ @@ -679,7 +679,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { $scope = @{ Owner = $owner } - Set-GitHubVariable @scope -Name $os -Value 'organization' -Visibility selected -SelectedRepositories $repo.id + Set-GitHubVariable @scope -Name $repoName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id } It 'Set-GitHubVariable' { $param = @{ @@ -730,7 +730,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { Owner = $owner Repository = $repoName } - Set-GitHubVariable @scope -Name $os -Value 'repository' + Set-GitHubVariable @scope -Name $repoName -Value 'repository' } It 'Set-GitHubVariable' { $param = @{ @@ -782,7 +782,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { Environment = $environmentName } Set-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName - Set-GitHubVariable @scope -Name $os -Value 'environment' + Set-GitHubVariable @scope -Name $repoName -Value 'environment' } It 'Set-GitHubVariable' { $param = @{ From 526b045bcc9ab83065dcf26bd5b874dfb7234581 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 21:17:59 +0100 Subject: [PATCH 63/85] Refactor: Update variable naming in tests for consistency and clarity --- tests/Variables.Tests.ps1 | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 253720793..187342f40 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -26,7 +26,8 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) $owner = 'psmodule-user' $testType = 'USER_FG_PAT' $repoName = "$testName-$os-$testType" - $variablePrefix = "$testName`_$os`_$testType`_" + $varName = "$testName`_$os`_$testType" + $variablePrefix = "$varName`_" $environmentName = "$testName-$os-$testType" $repo = New-GitHubRepository -Name $repoName -AllowSquashMerge } @@ -40,7 +41,7 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) Owner = $owner Repository = $repoName } - Set-GitHubVariable @scope -Name $repoName -Value 'repository' + Set-GitHubVariable @scope -Name $varName -Value 'repository' } It 'Set-GitHubVariable' { $param = @{ @@ -92,7 +93,7 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) Environment = $environmentName } Set-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName - Set-GitHubVariable @scope -Name $repoName -Value 'environment' + Set-GitHubVariable @scope -Name $varName -Value 'environment' } It 'Set-GitHubVariable' { $param = @{ @@ -158,7 +159,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ $scope = @{ Owner = $owner } - Set-GitHubVariable @scope -Name $repoName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id + Set-GitHubVariable @scope -Name $varName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id } It 'Set-GitHubVariable' { $param = @{ @@ -209,7 +210,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ Owner = $owner Repository = $repoName } - Set-GitHubVariable @scope -Name $repoName -Value 'repository' + Set-GitHubVariable @scope -Name $varName -Value 'repository' } It 'Set-GitHubVariable' { $param = @{ @@ -261,7 +262,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ Environment = $environmentName } Set-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName - Set-GitHubVariable @scope -Name $repoName -Value 'environment' + Set-GitHubVariable @scope -Name $varName -Value 'environment' } It 'Set-GitHubVariable' { $param = @{ @@ -327,7 +328,7 @@ Describe 'As a user - Classic PAT token (PAT)' { $scope = @{ Owner = $owner } - Set-GitHubVariable @scope -Name $repoName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id + Set-GitHubVariable @scope -Name $varName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id } It 'Set-GitHubVariable' { $param = @{ @@ -378,7 +379,7 @@ Describe 'As a user - Classic PAT token (PAT)' { Owner = $owner Repository = $repoName } - Set-GitHubVariable @scope -Name $repoName -Value 'repository' + Set-GitHubVariable @scope -Name $varName -Value 'repository' } It 'Set-GitHubVariable' { $param = @{ @@ -430,7 +431,7 @@ Describe 'As a user - Classic PAT token (PAT)' { Environment = $environmentName } Set-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName - Set-GitHubVariable @scope -Name $repoName -Value 'environment' + Set-GitHubVariable @scope -Name $varName -Value 'environment' } It 'Set-GitHubVariable' { $param = @{ @@ -509,7 +510,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { $scope = @{ Owner = $owner } - Set-GitHubVariable @scope -Name $repoName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id + Set-GitHubVariable @scope -Name $varName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id } It 'Set-GitHubVariable' { $param = @{ @@ -560,7 +561,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { Owner = $owner Repository = $repoName } - Set-GitHubVariable @scope -Name $repoName -Value 'repository' + Set-GitHubVariable @scope -Name $varName -Value 'repository' } It 'Set-GitHubVariable' { $param = @{ @@ -612,7 +613,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { Environment = $environmentName } Set-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName - Set-GitHubVariable @scope -Name $repoName -Value 'environment' + Set-GitHubVariable @scope -Name $varName -Value 'environment' } It 'Set-GitHubVariable' { $param = @{ @@ -679,7 +680,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { $scope = @{ Owner = $owner } - Set-GitHubVariable @scope -Name $repoName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id + Set-GitHubVariable @scope -Name $varName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id } It 'Set-GitHubVariable' { $param = @{ @@ -730,7 +731,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { Owner = $owner Repository = $repoName } - Set-GitHubVariable @scope -Name $repoName -Value 'repository' + Set-GitHubVariable @scope -Name $varName -Value 'repository' } It 'Set-GitHubVariable' { $param = @{ @@ -782,7 +783,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { Environment = $environmentName } Set-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName - Set-GitHubVariable @scope -Name $repoName -Value 'environment' + Set-GitHubVariable @scope -Name $varName -Value 'environment' } It 'Set-GitHubVariable' { $param = @{ From 5b0c646f89f46841de3e24c78cb5e499c5648c2f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 21:23:04 +0100 Subject: [PATCH 64/85] Refactor: Update variable naming for clarity in Variables.Tests.ps1 --- tests/Variables.Tests.ps1 | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 187342f40..70dbe1b30 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -145,7 +145,8 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ $owner = 'psmodule-test-org2' $testType = 'ORG_FG_PAT' $repoName = "$testName-$os-$testType" - $variablePrefix = "$testName`_$os`_$testType`_" + $varName = "$testName`_$os`_$testType" + $variablePrefix = "$varName`_" $environmentName = "$testName-$os-$testType" $repo = New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge } @@ -314,7 +315,8 @@ Describe 'As a user - Classic PAT token (PAT)' { $owner = 'psmodule-test-org2' $testType = 'PAT' $repoName = "$testName-$os-$testType" - $variablePrefix = "$testName`_$os`_$testType`_" + $varName = "$testName`_$os`_$testType" + $variablePrefix = "$varName`_" $environmentName = "$testName-$os-$testType" $repo = New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge } @@ -496,7 +498,8 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { Connect-GitHubApp -Organization $owner -Default $testType = 'APP_ENT' $repoName = "$testName-$os-$testType" - $variablePrefix = "$testName`_$os`_$testType`_" + $varName = "$testName`_$os`_$testType" + $variablePrefix = "$varName`_" $environmentName = "$testName-$os-$testType" $repo = New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge } @@ -666,7 +669,8 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { Connect-GitHubApp -Organization $owner -Default $testType = 'APP_ORG' $repoName = "$testName-$os-$testType" - $variablePrefix = "$testName`_$os`_$testType`_" + $varName = "$testName`_$os`_$testType" + $variablePrefix = "$varName`_" $environmentName = "$testName-$os-$testType" $repo = New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge } From 2dce32c9d2ef85977266fd3ceed9f764baeb5aac Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 22:04:09 +0100 Subject: [PATCH 65/85] Add tests for Get-GitHubVariable and Get-GitHubVariable -All with output validation --- tests/Variables.Tests.ps1 | 98 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 70dbe1b30..bedccfb82 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -73,6 +73,13 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) It 'Get-GitHubVariable' { $result = Get-GitHubVariable @scope -Name "*$os*" + Write-Host "$($result | Out-String)" + $result | Should -Not -BeNullOrEmpty + } + + It 'Get-GitHubVariable -All' { + $result = Get-GitHubVariable @scope -Name "*$os*" -All + Write-Host "$($result | Out-String)" $result | Should -Not -BeNullOrEmpty } @@ -125,6 +132,13 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) It 'Get-GitHubVariable' { $result = Get-GitHubVariable @scope -Name "*$os*" + Write-Host "$($result | Out-String)" + $result | Should -Not -BeNullOrEmpty + } + + It 'Get-GitHubVariable -All' { + $result = Get-GitHubVariable @scope -Name "*$os*" -All + Write-Host "$($result | Out-String)" $result | Should -Not -BeNullOrEmpty } @@ -193,6 +207,13 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ It 'Get-GitHubVariable' { $result = Get-GitHubVariable @scope -Name "*$os*" + Write-Host "$($result | Out-String)" + $result | Should -Not -BeNullOrEmpty + } + + It 'Get-GitHubVariable -All' { + $result = Get-GitHubVariable @scope -Name "*$os*" -All + Write-Host "$($result | Out-String)" $result | Should -Not -BeNullOrEmpty } @@ -243,6 +264,13 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ It 'Get-GitHubVariable' { $result = Get-GitHubVariable @scope -Name "*$os*" + Write-Host "$($result | Out-String)" + $result | Should -Not -BeNullOrEmpty + } + + It 'Get-GitHubVariable -All' { + $result = Get-GitHubVariable @scope -Name "*$os*" -All + Write-Host "$($result | Out-String)" $result | Should -Not -BeNullOrEmpty } @@ -295,6 +323,13 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ It 'Get-GitHubVariable' { $result = Get-GitHubVariable @scope -Name "*$os*" + Write-Host "$($result | Out-String)" + $result | Should -Not -BeNullOrEmpty + } + + It 'Get-GitHubVariable -All' { + $result = Get-GitHubVariable @scope -Name "*$os*" -All + Write-Host "$($result | Out-String)" $result | Should -Not -BeNullOrEmpty } @@ -363,6 +398,13 @@ Describe 'As a user - Classic PAT token (PAT)' { It 'Get-GitHubVariable' { $result = Get-GitHubVariable @scope -Name "*$os*" + Write-Host "$($result | Out-String)" + $result | Should -Not -BeNullOrEmpty + } + + It 'Get-GitHubVariable -All' { + $result = Get-GitHubVariable @scope -Name "*$os*" -All + Write-Host "$($result | Out-String)" $result | Should -Not -BeNullOrEmpty } @@ -413,6 +455,13 @@ Describe 'As a user - Classic PAT token (PAT)' { It 'Get-GitHubVariable' { $result = Get-GitHubVariable @scope -Name "*$os*" + Write-Host "$($result | Out-String)" + $result | Should -Not -BeNullOrEmpty + } + + It 'Get-GitHubVariable -All' { + $result = Get-GitHubVariable @scope -Name "*$os*" -All + Write-Host "$($result | Out-String)" $result | Should -Not -BeNullOrEmpty } @@ -465,6 +514,13 @@ Describe 'As a user - Classic PAT token (PAT)' { It 'Get-GitHubVariable' { $result = Get-GitHubVariable @scope -Name "*$os*" + Write-Host "$($result | Out-String)" + $result | Should -Not -BeNullOrEmpty + } + + It 'Get-GitHubVariable -All' { + $result = Get-GitHubVariable @scope -Name "*$os*" -All + Write-Host "$($result | Out-String)" $result | Should -Not -BeNullOrEmpty } @@ -546,6 +602,13 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { It 'Get-GitHubVariable' { $result = Get-GitHubVariable @scope -Name "*$os*" + Write-Host "$($result | Out-String)" + $result | Should -Not -BeNullOrEmpty + } + + It 'Get-GitHubVariable -All' { + $result = Get-GitHubVariable @scope -Name "*$os*" -All + Write-Host "$($result | Out-String)" $result | Should -Not -BeNullOrEmpty } @@ -596,6 +659,13 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { It 'Get-GitHubVariable' { $result = Get-GitHubVariable @scope -Name "*$os*" + Write-Host "$($result | Out-String)" + $result | Should -Not -BeNullOrEmpty + } + + It 'Get-GitHubVariable -All' { + $result = Get-GitHubVariable @scope -Name "*$os*" -All + Write-Host "$($result | Out-String)" $result | Should -Not -BeNullOrEmpty } @@ -648,6 +718,13 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { It 'Get-GitHubVariable' { $result = Get-GitHubVariable @scope -Name "*$os*" + Write-Host "$($result | Out-String)" + $result | Should -Not -BeNullOrEmpty + } + + It 'Get-GitHubVariable -All' { + $result = Get-GitHubVariable @scope -Name "*$os*" -All + Write-Host "$($result | Out-String)" $result | Should -Not -BeNullOrEmpty } @@ -717,6 +794,13 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { It 'Get-GitHubVariable' { $result = Get-GitHubVariable @scope -Name "*$os*" + Write-Host "$($result | Out-String)" + $result | Should -Not -BeNullOrEmpty + } + + It 'Get-GitHubVariable -All' { + $result = Get-GitHubVariable @scope -Name "*$os*" -All + Write-Host "$($result | Out-String)" $result | Should -Not -BeNullOrEmpty } @@ -767,6 +851,13 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { It 'Get-GitHubVariable' { $result = Get-GitHubVariable @scope -Name "*$os*" + Write-Host "$($result | Out-String)" + $result | Should -Not -BeNullOrEmpty + } + + It 'Get-GitHubVariable -All' { + $result = Get-GitHubVariable @scope -Name "*$os*" -All + Write-Host "$($result | Out-String)" $result | Should -Not -BeNullOrEmpty } @@ -819,6 +910,13 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { It 'Get-GitHubVariable' { $result = Get-GitHubVariable @scope -Name "*$os*" + Write-Host "$($result | Out-String)" + $result | Should -Not -BeNullOrEmpty + } + + It 'Get-GitHubVariable -All' { + $result = Get-GitHubVariable @scope -Name "*$os*" -All + Write-Host "$($result | Out-String)" $result | Should -Not -BeNullOrEmpty } From 0af6958c88be50d44466942e0986219685b69bfd Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 22:12:08 +0100 Subject: [PATCH 66/85] Refactor: Update Get-GitHubVariable to include Repository parameter for organization variable retrieval --- src/functions/public/Variables/Get-GitHubVariable.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/functions/public/Variables/Get-GitHubVariable.ps1 b/src/functions/public/Variables/Get-GitHubVariable.ps1 index c026cb888..f452d3c80 100644 --- a/src/functions/public/Variables/Get-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Get-GitHubVariable.ps1 @@ -172,14 +172,14 @@ function Get-GitHubVariable { } 'Repository' { if ($All) { - $variables += Get-GitHubVariableFromOrganization -Owner $Owner -Context $Context + $variables += Get-GitHubVariableFromOrganization -Owner $Owner -Repository $Repository -Context $Context } $variables += Get-GitHubVariableRepositoryList -Owner $Owner -Repository $Repository -Context $Context break } 'Environment' { if ($All) { - $variables += Get-GitHubVariableFromOrganization -Owner $Owner -Context $Context + $variables += Get-GitHubVariableFromOrganization -Owner $Owner -Repository $Repository -Context $Context $variables += Get-GitHubVariableRepositoryList -Owner $Owner -Repository $Repository -Context } $variables += Get-GitHubVariableEnvironmentList -Owner $Owner -Repository $Repository -Environment $Environment -Context $Context From 89b75d3ca583a5d89f5f59468da15e0f1f93f434 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 22:24:30 +0100 Subject: [PATCH 67/85] Enhance Get-GitHubVariable functions to include pagination in organization variable retrieval --- .../private/Variables/Get-GitHubVariableFromOrganization.ps1 | 3 +++ src/functions/public/Variables/Get-GitHubVariable.ps1 | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/functions/private/Variables/Get-GitHubVariableFromOrganization.ps1 b/src/functions/private/Variables/Get-GitHubVariableFromOrganization.ps1 index e67eccf14..2c22cf0ae 100644 --- a/src/functions/private/Variables/Get-GitHubVariableFromOrganization.ps1 +++ b/src/functions/private/Variables/Get-GitHubVariableFromOrganization.ps1 @@ -76,6 +76,9 @@ function Get-GitHubVariableFromOrganization { $inputObject = @{ Method = 'GET' APIEndpoint = "/repos/$Owner/$Repository/actions/organization-variables" + Body = @{ + per_page = 30 + } Context = $Context } diff --git a/src/functions/public/Variables/Get-GitHubVariable.ps1 b/src/functions/public/Variables/Get-GitHubVariable.ps1 index f452d3c80..4b22b2261 100644 --- a/src/functions/public/Variables/Get-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Get-GitHubVariable.ps1 @@ -180,7 +180,7 @@ function Get-GitHubVariable { 'Environment' { if ($All) { $variables += Get-GitHubVariableFromOrganization -Owner $Owner -Repository $Repository -Context $Context - $variables += Get-GitHubVariableRepositoryList -Owner $Owner -Repository $Repository -Context + $variables += Get-GitHubVariableRepositoryList -Owner $Owner -Repository $Repository -Context $Context } $variables += Get-GitHubVariableEnvironmentList -Owner $Owner -Repository $Repository -Environment $Environment -Context $Context break From 29d029368f33dd550c0bf13b1d566d670cf6d66a Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 22:33:20 +0100 Subject: [PATCH 68/85] Implement retry logic in New-GitHubVariable for improved variable retrieval reliability --- .../public/Variables/New-GitHubVariable.ps1 | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/functions/public/Variables/New-GitHubVariable.ps1 b/src/functions/public/Variables/New-GitHubVariable.ps1 index c348a9b0c..77700b9dc 100644 --- a/src/functions/public/Variables/New-GitHubVariable.ps1 +++ b/src/functions/public/Variables/New-GitHubVariable.ps1 @@ -123,10 +123,16 @@ function New-GitHubVariable { Context = $Context } $params | Remove-HashtableEntry -NullOrEmptyValues - $tmp = $script:GitHub.Config.RetryCount - $script:GitHub.Config.RetryCount = 5 - Get-GitHubVariable @params - $script:GitHub.Config.RetryCount = $tmp + + for ($i = 0; $i -le 5; $i++) { + Start-Sleep -Seconds 1 + $tmp = $script:GitHub.Config.RetryCount + $script:GitHub.Config.RetryCount = 5 + $result = Get-GitHubVariable @params + $script:GitHub.Config.RetryCount = $tmp + if ($result) { break } + } + $result } end { From dbe1363cc03445d1a8f7bd1e22c38e5a0834b8bb Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 22:59:13 +0100 Subject: [PATCH 69/85] Remove unnecessary variable cleanup for contextData in Connect-GitHubAccount function --- src/functions/public/Auth/Connect-GitHubAccount.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/src/functions/public/Auth/Connect-GitHubAccount.ps1 b/src/functions/public/Auth/Connect-GitHubAccount.ps1 index 99ce6bd02..8390f272a 100644 --- a/src/functions/public/Auth/Connect-GitHubAccount.ps1 +++ b/src/functions/public/Auth/Connect-GitHubAccount.ps1 @@ -320,7 +320,6 @@ clean { Remove-Variable -Name tokenResponse -ErrorAction SilentlyContinue Remove-Variable -Name context -ErrorAction SilentlyContinue - Remove-Variable -Name contextData -ErrorAction SilentlyContinue Remove-Variable -Name Token -ErrorAction SilentlyContinue [System.GC]::Collect() } From 561cf27e2390ede85d48d5fcc7d63ec38acae87e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 23:10:03 +0100 Subject: [PATCH 70/85] Add check for context type in Get-GitHubVariableFromOrganization to prevent execution for non-user contexts --- .../private/Variables/Get-GitHubVariableFromOrganization.ps1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/functions/private/Variables/Get-GitHubVariableFromOrganization.ps1 b/src/functions/private/Variables/Get-GitHubVariableFromOrganization.ps1 index 2c22cf0ae..aea7f1aa4 100644 --- a/src/functions/private/Variables/Get-GitHubVariableFromOrganization.ps1 +++ b/src/functions/private/Variables/Get-GitHubVariableFromOrganization.ps1 @@ -73,6 +73,9 @@ function Get-GitHubVariableFromOrganization { } process { + if ($Context.Type -ne 'User') { + return + } $inputObject = @{ Method = 'GET' APIEndpoint = "/repos/$Owner/$Repository/actions/organization-variables" From 50d933df906ac5e1d27609caa5fcdffa109bbd40 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 23:16:59 +0100 Subject: [PATCH 71/85] Implement error handling in Get-GitHubVariableFromOrganization to improve robustness --- tests/Variables.Tests.ps1 | 128 +++++++++++++++++++------------------- 1 file changed, 64 insertions(+), 64 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index bedccfb82..3e7363413 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -22,7 +22,7 @@ BeforeAll { Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT)' { BeforeAll { - Connect-GitHubAccount -Token $env:TEST_USER_USER_FG_PAT + Connect-GitHubAccount -Token $env:TEST_USER_USER_FG_PAT -PassThru | Format-List $owner = 'psmodule-user' $testType = 'USER_FG_PAT' $repoName = "$testName-$os-$testType" @@ -73,22 +73,22 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) It 'Get-GitHubVariable' { $result = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($result | Out-String)" + Write-Host "$($result | Format-Table)" $result | Should -Not -BeNullOrEmpty } It 'Get-GitHubVariable -All' { $result = Get-GitHubVariable @scope -Name "*$os*" -All - Write-Host "$($result | Out-String)" + Write-Host "$($result | Format-Table)" $result | Should -Not -BeNullOrEmpty } It 'Remove-GitHubVariable' { $before = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($before | Out-String)" + Write-Host "$($before | Format-Table)" $before | Remove-GitHubVariable $after = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($after | Out-String)" + Write-Host "$($after | Format-Table)" $after.Count | Should -Be 0 } } @@ -132,22 +132,22 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) It 'Get-GitHubVariable' { $result = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($result | Out-String)" + Write-Host "$($result | Format-Table)" $result | Should -Not -BeNullOrEmpty } It 'Get-GitHubVariable -All' { $result = Get-GitHubVariable @scope -Name "*$os*" -All - Write-Host "$($result | Out-String)" + Write-Host "$($result | Format-Table)" $result | Should -Not -BeNullOrEmpty } It 'Remove-GitHubVariable' { $before = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($before | Out-String)" + Write-Host "$($before | Format-Table)" $before | Remove-GitHubVariable $after = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($after | Out-String)" + Write-Host "$($after | Format-Table)" $after.Count | Should -Be 0 } } @@ -155,7 +155,7 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) Describe 'As a user - Fine-grained PAT token - organization account access (ORG_FG_PAT)' { BeforeAll { - Connect-GitHubAccount -Token $env:TEST_USER_ORG_FG_PAT + Connect-GitHubAccount -Token $env:TEST_USER_ORG_FG_PAT -PassThru | Format-List $owner = 'psmodule-test-org2' $testType = 'ORG_FG_PAT' $repoName = "$testName-$os-$testType" @@ -207,22 +207,22 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ It 'Get-GitHubVariable' { $result = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($result | Out-String)" + Write-Host "$($result | Format-Table)" $result | Should -Not -BeNullOrEmpty } It 'Get-GitHubVariable -All' { $result = Get-GitHubVariable @scope -Name "*$os*" -All - Write-Host "$($result | Out-String)" + Write-Host "$($result | Format-Table)" $result | Should -Not -BeNullOrEmpty } It 'Remove-GitHubVariable' { $before = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($before | Out-String)" + Write-Host "$($before | Format-Table)" $before | Remove-GitHubVariable $after = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($after | Out-String)" + Write-Host "$($after | Format-Table)" $after.Count | Should -Be 0 } } @@ -264,22 +264,22 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ It 'Get-GitHubVariable' { $result = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($result | Out-String)" + Write-Host "$($result | Format-Table)" $result | Should -Not -BeNullOrEmpty } It 'Get-GitHubVariable -All' { $result = Get-GitHubVariable @scope -Name "*$os*" -All - Write-Host "$($result | Out-String)" + Write-Host "$($result | Format-Table)" $result | Should -Not -BeNullOrEmpty } It 'Remove-GitHubVariable' { $before = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($before | Out-String)" + Write-Host "$($before | Format-Table)" $before | Remove-GitHubVariable $after = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($after | Out-String)" + Write-Host "$($after | Format-Table)" $after.Count | Should -Be 0 } } @@ -323,22 +323,22 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ It 'Get-GitHubVariable' { $result = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($result | Out-String)" + Write-Host "$($result | Format-Table)" $result | Should -Not -BeNullOrEmpty } It 'Get-GitHubVariable -All' { $result = Get-GitHubVariable @scope -Name "*$os*" -All - Write-Host "$($result | Out-String)" + Write-Host "$($result | Format-Table)" $result | Should -Not -BeNullOrEmpty } It 'Remove-GitHubVariable' { $before = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($before | Out-String)" + Write-Host "$($before | Format-Table)" $before | Remove-GitHubVariable $after = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($after | Out-String)" + Write-Host "$($after | Format-Table)" $after.Count | Should -Be 0 } } @@ -346,7 +346,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ Describe 'As a user - Classic PAT token (PAT)' { BeforeAll { - Connect-GitHubAccount -Token $env:TEST_USER_PAT + Connect-GitHubAccount -Token $env:TEST_USER_PAT -PassThru | Format-List $owner = 'psmodule-test-org2' $testType = 'PAT' $repoName = "$testName-$os-$testType" @@ -398,22 +398,22 @@ Describe 'As a user - Classic PAT token (PAT)' { It 'Get-GitHubVariable' { $result = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($result | Out-String)" + Write-Host "$($result | Format-Table)" $result | Should -Not -BeNullOrEmpty } It 'Get-GitHubVariable -All' { $result = Get-GitHubVariable @scope -Name "*$os*" -All - Write-Host "$($result | Out-String)" + Write-Host "$($result | Format-Table)" $result | Should -Not -BeNullOrEmpty } It 'Remove-GitHubVariable' { $before = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($before | Out-String)" + Write-Host "$($before | Format-Table)" $before | Remove-GitHubVariable $after = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($after | Out-String)" + Write-Host "$($after | Format-Table)" $after.Count | Should -Be 0 } } @@ -455,22 +455,22 @@ Describe 'As a user - Classic PAT token (PAT)' { It 'Get-GitHubVariable' { $result = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($result | Out-String)" + Write-Host "$($result | Format-Table)" $result | Should -Not -BeNullOrEmpty } It 'Get-GitHubVariable -All' { $result = Get-GitHubVariable @scope -Name "*$os*" -All - Write-Host "$($result | Out-String)" + Write-Host "$($result | Format-Table)" $result | Should -Not -BeNullOrEmpty } It 'Remove-GitHubVariable' { $before = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($before | Out-String)" + Write-Host "$($before | Format-Table)" $before | Remove-GitHubVariable $after = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($after | Out-String)" + Write-Host "$($after | Format-Table)" $after.Count | Should -Be 0 } } @@ -514,22 +514,22 @@ Describe 'As a user - Classic PAT token (PAT)' { It 'Get-GitHubVariable' { $result = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($result | Out-String)" + Write-Host "$($result | Format-Table)" $result | Should -Not -BeNullOrEmpty } It 'Get-GitHubVariable -All' { $result = Get-GitHubVariable @scope -Name "*$os*" -All - Write-Host "$($result | Out-String)" + Write-Host "$($result | Format-Table)" $result | Should -Not -BeNullOrEmpty } It 'Remove-GitHubVariable' { $before = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($before | Out-String)" + Write-Host "$($before | Format-Table)" $before | Remove-GitHubVariable $after = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($after | Out-String)" + Write-Host "$($after | Format-Table)" $after.Count | Should -Be 0 } } @@ -537,7 +537,7 @@ Describe 'As a user - Classic PAT token (PAT)' { Describe 'As GitHub Actions (GHA)' { BeforeAll { - Connect-GitHubAccount + Connect-GitHubAccount -PassThru | Format-List } AfterAll { Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount @@ -549,9 +549,9 @@ Describe 'As GitHub Actions (GHA)' { Describe 'As a GitHub App - Enterprise (APP_ENT)' { BeforeAll { - Connect-GitHubAccount -ClientID $env:TEST_APP_ENT_CLIENT_ID -PrivateKey $env:TEST_APP_ENT_PRIVATE_KEY + Connect-GitHubAccount -ClientID $env:TEST_APP_ENT_CLIENT_ID -PrivateKey $env:TEST_APP_ENT_PRIVATE_KEY -PassThru | Format-List $owner = 'psmodule-test-org3' - Connect-GitHubApp -Organization $owner -Default + Connect-GitHubApp -Organization $owner -Default -PassThru | Format-List $testType = 'APP_ENT' $repoName = "$testName-$os-$testType" $varName = "$testName`_$os`_$testType" @@ -602,22 +602,22 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { It 'Get-GitHubVariable' { $result = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($result | Out-String)" + Write-Host "$($result | Format-Table)" $result | Should -Not -BeNullOrEmpty } It 'Get-GitHubVariable -All' { $result = Get-GitHubVariable @scope -Name "*$os*" -All - Write-Host "$($result | Out-String)" + Write-Host "$($result | Format-Table)" $result | Should -Not -BeNullOrEmpty } It 'Remove-GitHubVariable' { $before = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($before | Out-String)" + Write-Host "$($before | Format-Table)" $before | Remove-GitHubVariable $after = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($after | Out-String)" + Write-Host "$($after | Format-Table)" $after.Count | Should -Be 0 } } @@ -659,22 +659,22 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { It 'Get-GitHubVariable' { $result = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($result | Out-String)" + Write-Host "$($result | Format-Table)" $result | Should -Not -BeNullOrEmpty } It 'Get-GitHubVariable -All' { $result = Get-GitHubVariable @scope -Name "*$os*" -All - Write-Host "$($result | Out-String)" + Write-Host "$($result | Format-Table)" $result | Should -Not -BeNullOrEmpty } It 'Remove-GitHubVariable' { $before = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($before | Out-String)" + Write-Host "$($before | Format-Table)" $before | Remove-GitHubVariable $after = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($after | Out-String)" + Write-Host "$($after | Format-Table)" $after.Count | Should -Be 0 } } @@ -718,22 +718,22 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { It 'Get-GitHubVariable' { $result = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($result | Out-String)" + Write-Host "$($result | Format-Table)" $result | Should -Not -BeNullOrEmpty } It 'Get-GitHubVariable -All' { $result = Get-GitHubVariable @scope -Name "*$os*" -All - Write-Host "$($result | Out-String)" + Write-Host "$($result | Format-Table)" $result | Should -Not -BeNullOrEmpty } It 'Remove-GitHubVariable' { $before = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($before | Out-String)" + Write-Host "$($before | Format-Table)" $before | Remove-GitHubVariable $after = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($after | Out-String)" + Write-Host "$($after | Format-Table)" $after.Count | Should -Be 0 } } @@ -741,9 +741,9 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { Describe 'As a GitHub App - Organization (APP_ORG)' { BeforeAll { - Connect-GitHubAccount -ClientID $env:TEST_APP_ORG_CLIENT_ID -PrivateKey $env:TEST_APP_ORG_PRIVATE_KEY + Connect-GitHubAccount -ClientID $env:TEST_APP_ORG_CLIENT_ID -PrivateKey $env:TEST_APP_ORG_PRIVATE_KEY -PassThru | Format-List $owner = 'psmodule-test-org' - Connect-GitHubApp -Organization $owner -Default + Connect-GitHubApp -Organization $owner -Default -PassThru | Format-List $testType = 'APP_ORG' $repoName = "$testName-$os-$testType" $varName = "$testName`_$os`_$testType" @@ -794,22 +794,22 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { It 'Get-GitHubVariable' { $result = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($result | Out-String)" + Write-Host "$($result | Format-Table)" $result | Should -Not -BeNullOrEmpty } It 'Get-GitHubVariable -All' { $result = Get-GitHubVariable @scope -Name "*$os*" -All - Write-Host "$($result | Out-String)" + Write-Host "$($result | Format-Table)" $result | Should -Not -BeNullOrEmpty } It 'Remove-GitHubVariable' { $before = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($before | Out-String)" + Write-Host "$($before | Format-Table)" $before | Remove-GitHubVariable $after = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($after | Out-String)" + Write-Host "$($after | Format-Table)" $after.Count | Should -Be 0 } } @@ -851,22 +851,22 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { It 'Get-GitHubVariable' { $result = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($result | Out-String)" + Write-Host "$($result | Format-Table)" $result | Should -Not -BeNullOrEmpty } It 'Get-GitHubVariable -All' { $result = Get-GitHubVariable @scope -Name "*$os*" -All - Write-Host "$($result | Out-String)" + Write-Host "$($result | Format-Table)" $result | Should -Not -BeNullOrEmpty } It 'Remove-GitHubVariable' { $before = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($before | Out-String)" + Write-Host "$($before | Format-Table)" $before | Remove-GitHubVariable $after = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($after | Out-String)" + Write-Host "$($after | Format-Table)" $after.Count | Should -Be 0 } } @@ -910,22 +910,22 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { It 'Get-GitHubVariable' { $result = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($result | Out-String)" + Write-Host "$($result | Format-Table)" $result | Should -Not -BeNullOrEmpty } It 'Get-GitHubVariable -All' { $result = Get-GitHubVariable @scope -Name "*$os*" -All - Write-Host "$($result | Out-String)" + Write-Host "$($result | Format-Table)" $result | Should -Not -BeNullOrEmpty } It 'Remove-GitHubVariable' { $before = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($before | Out-String)" + Write-Host "$($before | Format-Table)" $before | Remove-GitHubVariable $after = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($after | Out-String)" + Write-Host "$($after | Format-Table)" $after.Count | Should -Be 0 } } From 72965bbe67527c402a2c7271b91a368664fcc8dc Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 23:26:10 +0100 Subject: [PATCH 72/85] Refactor Connect-GitHubAccount calls to remove unnecessary Format-List output and add Get-GitHubContext tests --- src/formats/GitHubVariable.Format.ps1xml | 1 - tests/Variables.Tests.ps1 | 35 ++++++++++++++++++------ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/formats/GitHubVariable.Format.ps1xml b/src/formats/GitHubVariable.Format.ps1xml index 9bb37b683..9b45857cf 100644 --- a/src/formats/GitHubVariable.Format.ps1xml +++ b/src/formats/GitHubVariable.Format.ps1xml @@ -7,7 +7,6 @@ GitHubVariable
- diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 3e7363413..65bef65fc 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -22,7 +22,7 @@ BeforeAll { Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT)' { BeforeAll { - Connect-GitHubAccount -Token $env:TEST_USER_USER_FG_PAT -PassThru | Format-List + Connect-GitHubAccount -Token $env:TEST_USER_USER_FG_PAT $owner = 'psmodule-user' $testType = 'USER_FG_PAT' $repoName = "$testName-$os-$testType" @@ -35,6 +35,9 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) Remove-GitHubRepository -Owner $owner -Name $repoName -Confirm:$false Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } + It 'Get-GitHubContext' { + Get-GitHubContext | Format-List + } Context 'Repository' { BeforeAll { $scope = @{ @@ -155,7 +158,7 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) Describe 'As a user - Fine-grained PAT token - organization account access (ORG_FG_PAT)' { BeforeAll { - Connect-GitHubAccount -Token $env:TEST_USER_ORG_FG_PAT -PassThru | Format-List + Connect-GitHubAccount -Token $env:TEST_USER_ORG_FG_PAT $owner = 'psmodule-test-org2' $testType = 'ORG_FG_PAT' $repoName = "$testName-$os-$testType" @@ -169,6 +172,9 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ Get-GitHubVariable -Owner $owner -Name "*$os*" | Remove-GitHubVariable Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } + It 'Get-GitHubContext' { + Get-GitHubContext | Format-List + } Context 'Organization' { BeforeAll { $scope = @{ @@ -346,7 +352,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ Describe 'As a user - Classic PAT token (PAT)' { BeforeAll { - Connect-GitHubAccount -Token $env:TEST_USER_PAT -PassThru | Format-List + Connect-GitHubAccount -Token $env:TEST_USER_PAT $owner = 'psmodule-test-org2' $testType = 'PAT' $repoName = "$testName-$os-$testType" @@ -360,6 +366,9 @@ Describe 'As a user - Classic PAT token (PAT)' { Get-GitHubVariable -Owner $owner -Name "*$os*" | Remove-GitHubVariable Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } + It 'Get-GitHubContext' { + Get-GitHubContext | Format-List + } Context 'Organization' { BeforeAll { $scope = @{ @@ -537,11 +546,14 @@ Describe 'As a user - Classic PAT token (PAT)' { Describe 'As GitHub Actions (GHA)' { BeforeAll { - Connect-GitHubAccount -PassThru | Format-List + Connect-GitHubAccount } AfterAll { Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } + It 'Get-GitHubContext' { + Get-GitHubContext | Format-List + } Context 'Variables' { } @@ -549,9 +561,9 @@ Describe 'As GitHub Actions (GHA)' { Describe 'As a GitHub App - Enterprise (APP_ENT)' { BeforeAll { - Connect-GitHubAccount -ClientID $env:TEST_APP_ENT_CLIENT_ID -PrivateKey $env:TEST_APP_ENT_PRIVATE_KEY -PassThru | Format-List + Connect-GitHubAccount -ClientID $env:TEST_APP_ENT_CLIENT_ID -PrivateKey $env:TEST_APP_ENT_PRIVATE_KEY $owner = 'psmodule-test-org3' - Connect-GitHubApp -Organization $owner -Default -PassThru | Format-List + Connect-GitHubApp -Organization $owner -Default $testType = 'APP_ENT' $repoName = "$testName-$os-$testType" $varName = "$testName`_$os`_$testType" @@ -564,6 +576,9 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { Get-GitHubVariable -Owner $owner -Name "*$os*" | Remove-GitHubVariable Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } + It 'Get-GitHubContext' { + Get-GitHubContext | Format-List + } Context 'Organization' { BeforeAll { $scope = @{ @@ -571,6 +586,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { } Set-GitHubVariable @scope -Name $varName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id } + It 'Set-GitHubVariable' { $param = @{ Name = "$variablePrefix`TestVariable" @@ -741,9 +757,9 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { Describe 'As a GitHub App - Organization (APP_ORG)' { BeforeAll { - Connect-GitHubAccount -ClientID $env:TEST_APP_ORG_CLIENT_ID -PrivateKey $env:TEST_APP_ORG_PRIVATE_KEY -PassThru | Format-List + Connect-GitHubAccount -ClientID $env:TEST_APP_ORG_CLIENT_ID -PrivateKey $env:TEST_APP_ORG_PRIVATE_KEY $owner = 'psmodule-test-org' - Connect-GitHubApp -Organization $owner -Default -PassThru | Format-List + Connect-GitHubApp -Organization $owner -Default $testType = 'APP_ORG' $repoName = "$testName-$os-$testType" $varName = "$testName`_$os`_$testType" @@ -756,6 +772,9 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { Get-GitHubVariable -Owner $owner -Name "*$os*" | Remove-GitHubVariable Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } + It 'Get-GitHubContext' { + Get-GitHubContext | Format-List + } Context 'Organization' { BeforeAll { $scope = @{ From 769b63a437f6b13238fd7fab95fc1204bdd342cc Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 23:29:48 +0100 Subject: [PATCH 73/85] Update Get-GitHubContext tests to use Write-Host for output display --- tests/Variables.Tests.ps1 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 65bef65fc..2f74dd051 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -36,7 +36,7 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } It 'Get-GitHubContext' { - Get-GitHubContext | Format-List + Write-Host "$(Get-GitHubContext | Format-List | Out-String)" } Context 'Repository' { BeforeAll { @@ -173,7 +173,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } It 'Get-GitHubContext' { - Get-GitHubContext | Format-List + Write-Host "$(Get-GitHubContext | Format-List | Out-String)" } Context 'Organization' { BeforeAll { @@ -367,7 +367,7 @@ Describe 'As a user - Classic PAT token (PAT)' { Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } It 'Get-GitHubContext' { - Get-GitHubContext | Format-List + Write-Host "$(Get-GitHubContext | Format-List | Out-String)" } Context 'Organization' { BeforeAll { @@ -552,7 +552,7 @@ Describe 'As GitHub Actions (GHA)' { Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } It 'Get-GitHubContext' { - Get-GitHubContext | Format-List + Write-Host "$(Get-GitHubContext | Format-List | Out-String)" } Context 'Variables' { @@ -577,7 +577,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } It 'Get-GitHubContext' { - Get-GitHubContext | Format-List + Write-Host "$(Get-GitHubContext | Format-List | Out-String)" } Context 'Organization' { BeforeAll { @@ -773,7 +773,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } It 'Get-GitHubContext' { - Get-GitHubContext | Format-List + Write-Host "$(Write-Host "$(Get-GitHubContext | Format-List | Out-String)" | Out-String)" } Context 'Organization' { BeforeAll { From a8aa0526eafebcaf3e1f018ac62c4b212d102d99 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 23:42:09 +0100 Subject: [PATCH 74/85] Remove unnecessary user context check in Get-GitHubVariableFromOrganization and update tests to streamline output display --- .../Get-GitHubVariableFromOrganization.ps1 | 3 --- tests/Variables.Tests.ps1 | 24 +++++-------------- 2 files changed, 6 insertions(+), 21 deletions(-) diff --git a/src/functions/private/Variables/Get-GitHubVariableFromOrganization.ps1 b/src/functions/private/Variables/Get-GitHubVariableFromOrganization.ps1 index aea7f1aa4..2c22cf0ae 100644 --- a/src/functions/private/Variables/Get-GitHubVariableFromOrganization.ps1 +++ b/src/functions/private/Variables/Get-GitHubVariableFromOrganization.ps1 @@ -73,9 +73,6 @@ function Get-GitHubVariableFromOrganization { } process { - if ($Context.Type -ne 'User') { - return - } $inputObject = @{ Method = 'GET' APIEndpoint = "/repos/$Owner/$Repository/actions/organization-variables" diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 2f74dd051..bf2743028 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -36,7 +36,7 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } It 'Get-GitHubContext' { - Write-Host "$(Get-GitHubContext | Format-List | Out-String)" + Write-Host "$(Get-GitHubContext | Format-List)" } Context 'Repository' { BeforeAll { @@ -80,12 +80,6 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) $result | Should -Not -BeNullOrEmpty } - It 'Get-GitHubVariable -All' { - $result = Get-GitHubVariable @scope -Name "*$os*" -All - Write-Host "$($result | Format-Table)" - $result | Should -Not -BeNullOrEmpty - } - It 'Remove-GitHubVariable' { $before = Get-GitHubVariable @scope -Name "*$os*" Write-Host "$($before | Format-Table)" @@ -139,12 +133,6 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) $result | Should -Not -BeNullOrEmpty } - It 'Get-GitHubVariable -All' { - $result = Get-GitHubVariable @scope -Name "*$os*" -All - Write-Host "$($result | Format-Table)" - $result | Should -Not -BeNullOrEmpty - } - It 'Remove-GitHubVariable' { $before = Get-GitHubVariable @scope -Name "*$os*" Write-Host "$($before | Format-Table)" @@ -173,7 +161,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } It 'Get-GitHubContext' { - Write-Host "$(Get-GitHubContext | Format-List | Out-String)" + Write-Host "$(Get-GitHubContext | Format-List)" } Context 'Organization' { BeforeAll { @@ -367,7 +355,7 @@ Describe 'As a user - Classic PAT token (PAT)' { Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } It 'Get-GitHubContext' { - Write-Host "$(Get-GitHubContext | Format-List | Out-String)" + Write-Host "$(Get-GitHubContext | Format-List)" } Context 'Organization' { BeforeAll { @@ -552,7 +540,7 @@ Describe 'As GitHub Actions (GHA)' { Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } It 'Get-GitHubContext' { - Write-Host "$(Get-GitHubContext | Format-List | Out-String)" + Write-Host "$(Get-GitHubContext | Format-List)" } Context 'Variables' { @@ -577,7 +565,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } It 'Get-GitHubContext' { - Write-Host "$(Get-GitHubContext | Format-List | Out-String)" + Write-Host "$(Get-GitHubContext | Format-List)" } Context 'Organization' { BeforeAll { @@ -773,7 +761,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } It 'Get-GitHubContext' { - Write-Host "$(Write-Host "$(Get-GitHubContext | Format-List | Out-String)" | Out-String)" + Write-Host "$(Write-Host "$(Get-GitHubContext | Format-List)")" } Context 'Organization' { BeforeAll { From 9d9f20c2c14f45054f18031a8b66aa60fbdb900b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 23:44:38 +0100 Subject: [PATCH 75/85] Remove GitHubVariable.Format.ps1xml file to simplify output formatting --- src/formats/GitHubVariable.Format.ps1xml | 92 ------------------------ 1 file changed, 92 deletions(-) delete mode 100644 src/formats/GitHubVariable.Format.ps1xml diff --git a/src/formats/GitHubVariable.Format.ps1xml b/src/formats/GitHubVariable.Format.ps1xml deleted file mode 100644 index 9b45857cf..000000000 --- a/src/formats/GitHubVariable.Format.ps1xml +++ /dev/null @@ -1,92 +0,0 @@ - - - - - GitHubVariableTable - - GitHubVariable - - - - - - - - - - - - - - - - - - - - - - - - Name - - - Value - - - Owner - - - Repository - - - Environment - - - - - - - - GitHubVariableList - - GitHubVariable - - - - - - - Name - - - Value - - - Owner - - - Repository - - - Environment - - - CreatedAt - - - UpdatedAt - - - Visibility - - - SelectedRepositories - - - - - - - - From 9b3d3f68b9adaba1c8c15cdc0eebfafa11f845ae Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 23:52:47 +0100 Subject: [PATCH 76/85] Refactor output handling in Get-GitHubVariableFromOrganization for improved clarity --- tests/Variables.Tests.ps1 | 78 +++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 44 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index bf2743028..b8f4b4886 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -23,6 +23,7 @@ BeforeAll { Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT)' { BeforeAll { Connect-GitHubAccount -Token $env:TEST_USER_USER_FG_PAT + LogGroup { Write-Host "$(Get-GitHubContext | Format-List)" } $owner = 'psmodule-user' $testType = 'USER_FG_PAT' $repoName = "$testName-$os-$testType" @@ -35,9 +36,6 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) Remove-GitHubRepository -Owner $owner -Name $repoName -Confirm:$false Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } - It 'Get-GitHubContext' { - Write-Host "$(Get-GitHubContext | Format-List)" - } Context 'Repository' { BeforeAll { $scope = @{ @@ -76,7 +74,7 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) It 'Get-GitHubVariable' { $result = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($result | Format-Table)" + Write-Host "$($result | Format-Table | Out-String)" $result | Should -Not -BeNullOrEmpty } @@ -129,7 +127,7 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) It 'Get-GitHubVariable' { $result = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($result | Format-Table)" + Write-Host "$($result | Format-Table | Out-String)" $result | Should -Not -BeNullOrEmpty } @@ -147,6 +145,7 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) Describe 'As a user - Fine-grained PAT token - organization account access (ORG_FG_PAT)' { BeforeAll { Connect-GitHubAccount -Token $env:TEST_USER_ORG_FG_PAT + LogGroup { Write-Host "$(Get-GitHubContext | Format-List)" } $owner = 'psmodule-test-org2' $testType = 'ORG_FG_PAT' $repoName = "$testName-$os-$testType" @@ -160,9 +159,6 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ Get-GitHubVariable -Owner $owner -Name "*$os*" | Remove-GitHubVariable Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } - It 'Get-GitHubContext' { - Write-Host "$(Get-GitHubContext | Format-List)" - } Context 'Organization' { BeforeAll { $scope = @{ @@ -201,13 +197,13 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ It 'Get-GitHubVariable' { $result = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($result | Format-Table)" + Write-Host "$($result | Format-Table | Out-String)" $result | Should -Not -BeNullOrEmpty } It 'Get-GitHubVariable -All' { $result = Get-GitHubVariable @scope -Name "*$os*" -All - Write-Host "$($result | Format-Table)" + Write-Host "$($result | Format-Table | Out-String)" $result | Should -Not -BeNullOrEmpty } @@ -258,13 +254,13 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ It 'Get-GitHubVariable' { $result = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($result | Format-Table)" + Write-Host "$($result | Format-Table | Out-String)" $result | Should -Not -BeNullOrEmpty } It 'Get-GitHubVariable -All' { $result = Get-GitHubVariable @scope -Name "*$os*" -All - Write-Host "$($result | Format-Table)" + Write-Host "$($result | Format-Table | Out-String)" $result | Should -Not -BeNullOrEmpty } @@ -317,13 +313,13 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ It 'Get-GitHubVariable' { $result = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($result | Format-Table)" + Write-Host "$($result | Format-Table | Out-String)" $result | Should -Not -BeNullOrEmpty } It 'Get-GitHubVariable -All' { $result = Get-GitHubVariable @scope -Name "*$os*" -All - Write-Host "$($result | Format-Table)" + Write-Host "$($result | Format-Table | Out-String)" $result | Should -Not -BeNullOrEmpty } @@ -341,6 +337,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ Describe 'As a user - Classic PAT token (PAT)' { BeforeAll { Connect-GitHubAccount -Token $env:TEST_USER_PAT + LogGroup { Write-Host "$(Get-GitHubContext | Format-List)" } $owner = 'psmodule-test-org2' $testType = 'PAT' $repoName = "$testName-$os-$testType" @@ -354,9 +351,6 @@ Describe 'As a user - Classic PAT token (PAT)' { Get-GitHubVariable -Owner $owner -Name "*$os*" | Remove-GitHubVariable Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } - It 'Get-GitHubContext' { - Write-Host "$(Get-GitHubContext | Format-List)" - } Context 'Organization' { BeforeAll { $scope = @{ @@ -395,13 +389,13 @@ Describe 'As a user - Classic PAT token (PAT)' { It 'Get-GitHubVariable' { $result = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($result | Format-Table)" + Write-Host "$($result | Format-Table | Out-String)" $result | Should -Not -BeNullOrEmpty } It 'Get-GitHubVariable -All' { $result = Get-GitHubVariable @scope -Name "*$os*" -All - Write-Host "$($result | Format-Table)" + Write-Host "$($result | Format-Table | Out-String)" $result | Should -Not -BeNullOrEmpty } @@ -452,13 +446,13 @@ Describe 'As a user - Classic PAT token (PAT)' { It 'Get-GitHubVariable' { $result = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($result | Format-Table)" + Write-Host "$($result | Format-Table | Out-String)" $result | Should -Not -BeNullOrEmpty } It 'Get-GitHubVariable -All' { $result = Get-GitHubVariable @scope -Name "*$os*" -All - Write-Host "$($result | Format-Table)" + Write-Host "$($result | Format-Table | Out-String)" $result | Should -Not -BeNullOrEmpty } @@ -511,13 +505,13 @@ Describe 'As a user - Classic PAT token (PAT)' { It 'Get-GitHubVariable' { $result = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($result | Format-Table)" + Write-Host "$($result | Format-Table | Out-String)" $result | Should -Not -BeNullOrEmpty } It 'Get-GitHubVariable -All' { $result = Get-GitHubVariable @scope -Name "*$os*" -All - Write-Host "$($result | Format-Table)" + Write-Host "$($result | Format-Table | Out-String)" $result | Should -Not -BeNullOrEmpty } @@ -535,13 +529,11 @@ Describe 'As a user - Classic PAT token (PAT)' { Describe 'As GitHub Actions (GHA)' { BeforeAll { Connect-GitHubAccount + LogGroup { Write-Host "$(Get-GitHubContext | Format-List)" } } AfterAll { Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } - It 'Get-GitHubContext' { - Write-Host "$(Get-GitHubContext | Format-List)" - } Context 'Variables' { } @@ -550,8 +542,10 @@ Describe 'As GitHub Actions (GHA)' { Describe 'As a GitHub App - Enterprise (APP_ENT)' { BeforeAll { Connect-GitHubAccount -ClientID $env:TEST_APP_ENT_CLIENT_ID -PrivateKey $env:TEST_APP_ENT_PRIVATE_KEY + LogGroup { Write-Host "$(Get-GitHubContext | Format-List)" } $owner = 'psmodule-test-org3' Connect-GitHubApp -Organization $owner -Default + LogGroup { Write-Host "$(Get-GitHubContext | Format-List)" } $testType = 'APP_ENT' $repoName = "$testName-$os-$testType" $varName = "$testName`_$os`_$testType" @@ -564,9 +558,6 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { Get-GitHubVariable -Owner $owner -Name "*$os*" | Remove-GitHubVariable Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } - It 'Get-GitHubContext' { - Write-Host "$(Get-GitHubContext | Format-List)" - } Context 'Organization' { BeforeAll { $scope = @{ @@ -606,13 +597,13 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { It 'Get-GitHubVariable' { $result = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($result | Format-Table)" + Write-Host "$($result | Format-Table | Out-String)" $result | Should -Not -BeNullOrEmpty } It 'Get-GitHubVariable -All' { $result = Get-GitHubVariable @scope -Name "*$os*" -All - Write-Host "$($result | Format-Table)" + Write-Host "$($result | Format-Table | Out-String)" $result | Should -Not -BeNullOrEmpty } @@ -663,13 +654,13 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { It 'Get-GitHubVariable' { $result = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($result | Format-Table)" + Write-Host "$($result | Format-Table | Out-String)" $result | Should -Not -BeNullOrEmpty } It 'Get-GitHubVariable -All' { $result = Get-GitHubVariable @scope -Name "*$os*" -All - Write-Host "$($result | Format-Table)" + Write-Host "$($result | Format-Table | Out-String)" $result | Should -Not -BeNullOrEmpty } @@ -722,13 +713,13 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { It 'Get-GitHubVariable' { $result = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($result | Format-Table)" + Write-Host "$($result | Format-Table | Out-String)" $result | Should -Not -BeNullOrEmpty } It 'Get-GitHubVariable -All' { $result = Get-GitHubVariable @scope -Name "*$os*" -All - Write-Host "$($result | Format-Table)" + Write-Host "$($result | Format-Table | Out-String)" $result | Should -Not -BeNullOrEmpty } @@ -746,8 +737,10 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { Describe 'As a GitHub App - Organization (APP_ORG)' { BeforeAll { Connect-GitHubAccount -ClientID $env:TEST_APP_ORG_CLIENT_ID -PrivateKey $env:TEST_APP_ORG_PRIVATE_KEY + LogGroup { Write-Host "$(Get-GitHubContext | Format-List)" } $owner = 'psmodule-test-org' Connect-GitHubApp -Organization $owner -Default + LogGroup { Write-Host "$(Get-GitHubContext | Format-List)" } $testType = 'APP_ORG' $repoName = "$testName-$os-$testType" $varName = "$testName`_$os`_$testType" @@ -760,9 +753,6 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { Get-GitHubVariable -Owner $owner -Name "*$os*" | Remove-GitHubVariable Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } - It 'Get-GitHubContext' { - Write-Host "$(Write-Host "$(Get-GitHubContext | Format-List)")" - } Context 'Organization' { BeforeAll { $scope = @{ @@ -801,13 +791,13 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { It 'Get-GitHubVariable' { $result = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($result | Format-Table)" + Write-Host "$($result | Format-Table | Out-String)" $result | Should -Not -BeNullOrEmpty } It 'Get-GitHubVariable -All' { $result = Get-GitHubVariable @scope -Name "*$os*" -All - Write-Host "$($result | Format-Table)" + Write-Host "$($result | Format-Table | Out-String)" $result | Should -Not -BeNullOrEmpty } @@ -858,13 +848,13 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { It 'Get-GitHubVariable' { $result = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($result | Format-Table)" + Write-Host "$($result | Format-Table | Out-String)" $result | Should -Not -BeNullOrEmpty } It 'Get-GitHubVariable -All' { $result = Get-GitHubVariable @scope -Name "*$os*" -All - Write-Host "$($result | Format-Table)" + Write-Host "$($result | Format-Table | Out-String)" $result | Should -Not -BeNullOrEmpty } @@ -917,13 +907,13 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { It 'Get-GitHubVariable' { $result = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($result | Format-Table)" + Write-Host "$($result | Format-Table | Out-String)" $result | Should -Not -BeNullOrEmpty } It 'Get-GitHubVariable -All' { $result = Get-GitHubVariable @scope -Name "*$os*" -All - Write-Host "$($result | Format-Table)" + Write-Host "$($result | Format-Table | Out-String)" $result | Should -Not -BeNullOrEmpty } From f9505bd7115f3744a2c2fee8b0a3b5e910e35a73 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 18 Mar 2025 23:56:18 +0100 Subject: [PATCH 77/85] Update LogGroup calls in Variables.Tests.ps1 to include 'Context' label for clarity --- tests/Variables.Tests.ps1 | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index b8f4b4886..0809c1122 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -23,7 +23,7 @@ BeforeAll { Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT)' { BeforeAll { Connect-GitHubAccount -Token $env:TEST_USER_USER_FG_PAT - LogGroup { Write-Host "$(Get-GitHubContext | Format-List)" } + LogGroup 'Context' { Write-Host "$(Get-GitHubContext | Format-List)" } $owner = 'psmodule-user' $testType = 'USER_FG_PAT' $repoName = "$testName-$os-$testType" @@ -145,7 +145,7 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) Describe 'As a user - Fine-grained PAT token - organization account access (ORG_FG_PAT)' { BeforeAll { Connect-GitHubAccount -Token $env:TEST_USER_ORG_FG_PAT - LogGroup { Write-Host "$(Get-GitHubContext | Format-List)" } + LogGroup 'Context' { Write-Host "$(Get-GitHubContext | Format-List)" } $owner = 'psmodule-test-org2' $testType = 'ORG_FG_PAT' $repoName = "$testName-$os-$testType" @@ -337,7 +337,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ Describe 'As a user - Classic PAT token (PAT)' { BeforeAll { Connect-GitHubAccount -Token $env:TEST_USER_PAT - LogGroup { Write-Host "$(Get-GitHubContext | Format-List)" } + LogGroup 'Context' { Write-Host "$(Get-GitHubContext | Format-List)" } $owner = 'psmodule-test-org2' $testType = 'PAT' $repoName = "$testName-$os-$testType" @@ -529,7 +529,7 @@ Describe 'As a user - Classic PAT token (PAT)' { Describe 'As GitHub Actions (GHA)' { BeforeAll { Connect-GitHubAccount - LogGroup { Write-Host "$(Get-GitHubContext | Format-List)" } + LogGroup 'Context' { Write-Host "$(Get-GitHubContext | Format-List)" } } AfterAll { Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount @@ -542,10 +542,10 @@ Describe 'As GitHub Actions (GHA)' { Describe 'As a GitHub App - Enterprise (APP_ENT)' { BeforeAll { Connect-GitHubAccount -ClientID $env:TEST_APP_ENT_CLIENT_ID -PrivateKey $env:TEST_APP_ENT_PRIVATE_KEY - LogGroup { Write-Host "$(Get-GitHubContext | Format-List)" } + LogGroup 'Context' { Write-Host "$(Get-GitHubContext | Format-List)" } $owner = 'psmodule-test-org3' Connect-GitHubApp -Organization $owner -Default - LogGroup { Write-Host "$(Get-GitHubContext | Format-List)" } + LogGroup 'Context' { Write-Host "$(Get-GitHubContext | Format-List)" } $testType = 'APP_ENT' $repoName = "$testName-$os-$testType" $varName = "$testName`_$os`_$testType" @@ -737,10 +737,10 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { Describe 'As a GitHub App - Organization (APP_ORG)' { BeforeAll { Connect-GitHubAccount -ClientID $env:TEST_APP_ORG_CLIENT_ID -PrivateKey $env:TEST_APP_ORG_PRIVATE_KEY - LogGroup { Write-Host "$(Get-GitHubContext | Format-List)" } + LogGroup 'Context' { Write-Host "$(Get-GitHubContext | Format-List)" } $owner = 'psmodule-test-org' Connect-GitHubApp -Organization $owner -Default - LogGroup { Write-Host "$(Get-GitHubContext | Format-List)" } + LogGroup 'Context' { Write-Host "$(Get-GitHubContext | Format-List)" } $testType = 'APP_ORG' $repoName = "$testName-$os-$testType" $varName = "$testName`_$os`_$testType" From 4e80ada1e43ce9286743ba425256f8f047a708fb Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 19 Mar 2025 00:01:16 +0100 Subject: [PATCH 78/85] Update LogGroup calls in Variables.Tests.ps1 to use Out-String for improved output formatting --- tests/Variables.Tests.ps1 | 72 +++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 0809c1122..3ff140046 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -23,7 +23,7 @@ BeforeAll { Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT)' { BeforeAll { Connect-GitHubAccount -Token $env:TEST_USER_USER_FG_PAT - LogGroup 'Context' { Write-Host "$(Get-GitHubContext | Format-List)" } + LogGroup 'Context' { Write-Host "$(Get-GitHubContext | Format-List | Out-String)" } $owner = 'psmodule-user' $testType = 'USER_FG_PAT' $repoName = "$testName-$os-$testType" @@ -80,10 +80,10 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) It 'Remove-GitHubVariable' { $before = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($before | Format-Table)" + Write-Host "$($before | Format-Table | Out-String)" $before | Remove-GitHubVariable $after = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($after | Format-Table)" + Write-Host "$($after | Format-Table | Out-String)" $after.Count | Should -Be 0 } } @@ -133,10 +133,10 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) It 'Remove-GitHubVariable' { $before = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($before | Format-Table)" + Write-Host "$($before | Format-Table | Out-String)" $before | Remove-GitHubVariable $after = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($after | Format-Table)" + Write-Host "$($after | Format-Table | Out-String)" $after.Count | Should -Be 0 } } @@ -145,7 +145,7 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) Describe 'As a user - Fine-grained PAT token - organization account access (ORG_FG_PAT)' { BeforeAll { Connect-GitHubAccount -Token $env:TEST_USER_ORG_FG_PAT - LogGroup 'Context' { Write-Host "$(Get-GitHubContext | Format-List)" } + LogGroup 'Context' { Write-Host "$(Get-GitHubContext | Format-List | Out-String)" } $owner = 'psmodule-test-org2' $testType = 'ORG_FG_PAT' $repoName = "$testName-$os-$testType" @@ -209,10 +209,10 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ It 'Remove-GitHubVariable' { $before = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($before | Format-Table)" + Write-Host "$($before | Format-Table | Out-String)" $before | Remove-GitHubVariable $after = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($after | Format-Table)" + Write-Host "$($after | Format-Table | Out-String)" $after.Count | Should -Be 0 } } @@ -266,10 +266,10 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ It 'Remove-GitHubVariable' { $before = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($before | Format-Table)" + Write-Host "$($before | Format-Table | Out-String)" $before | Remove-GitHubVariable $after = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($after | Format-Table)" + Write-Host "$($after | Format-Table | Out-String)" $after.Count | Should -Be 0 } } @@ -325,10 +325,10 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ It 'Remove-GitHubVariable' { $before = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($before | Format-Table)" + Write-Host "$($before | Format-Table | Out-String)" $before | Remove-GitHubVariable $after = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($after | Format-Table)" + Write-Host "$($after | Format-Table | Out-String)" $after.Count | Should -Be 0 } } @@ -337,7 +337,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ Describe 'As a user - Classic PAT token (PAT)' { BeforeAll { Connect-GitHubAccount -Token $env:TEST_USER_PAT - LogGroup 'Context' { Write-Host "$(Get-GitHubContext | Format-List)" } + LogGroup 'Context' { Write-Host "$(Get-GitHubContext | Format-List | Out-String)" } $owner = 'psmodule-test-org2' $testType = 'PAT' $repoName = "$testName-$os-$testType" @@ -401,10 +401,10 @@ Describe 'As a user - Classic PAT token (PAT)' { It 'Remove-GitHubVariable' { $before = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($before | Format-Table)" + Write-Host "$($before | Format-Table | Out-String)" $before | Remove-GitHubVariable $after = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($after | Format-Table)" + Write-Host "$($after | Format-Table | Out-String)" $after.Count | Should -Be 0 } } @@ -458,10 +458,10 @@ Describe 'As a user - Classic PAT token (PAT)' { It 'Remove-GitHubVariable' { $before = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($before | Format-Table)" + Write-Host "$($before | Format-Table | Out-String)" $before | Remove-GitHubVariable $after = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($after | Format-Table)" + Write-Host "$($after | Format-Table | Out-String)" $after.Count | Should -Be 0 } } @@ -517,10 +517,10 @@ Describe 'As a user - Classic PAT token (PAT)' { It 'Remove-GitHubVariable' { $before = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($before | Format-Table)" + Write-Host "$($before | Format-Table | Out-String)" $before | Remove-GitHubVariable $after = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($after | Format-Table)" + Write-Host "$($after | Format-Table | Out-String)" $after.Count | Should -Be 0 } } @@ -529,7 +529,7 @@ Describe 'As a user - Classic PAT token (PAT)' { Describe 'As GitHub Actions (GHA)' { BeforeAll { Connect-GitHubAccount - LogGroup 'Context' { Write-Host "$(Get-GitHubContext | Format-List)" } + LogGroup 'Context' { Write-Host "$(Get-GitHubContext | Format-List | Out-String)" } } AfterAll { Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount @@ -542,10 +542,10 @@ Describe 'As GitHub Actions (GHA)' { Describe 'As a GitHub App - Enterprise (APP_ENT)' { BeforeAll { Connect-GitHubAccount -ClientID $env:TEST_APP_ENT_CLIENT_ID -PrivateKey $env:TEST_APP_ENT_PRIVATE_KEY - LogGroup 'Context' { Write-Host "$(Get-GitHubContext | Format-List)" } + LogGroup 'Context' { Write-Host "$(Get-GitHubContext | Format-List | Out-String)" } $owner = 'psmodule-test-org3' Connect-GitHubApp -Organization $owner -Default - LogGroup 'Context' { Write-Host "$(Get-GitHubContext | Format-List)" } + LogGroup 'Context' { Write-Host "$(Get-GitHubContext | Format-List | Out-String)" } $testType = 'APP_ENT' $repoName = "$testName-$os-$testType" $varName = "$testName`_$os`_$testType" @@ -609,10 +609,10 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { It 'Remove-GitHubVariable' { $before = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($before | Format-Table)" + Write-Host "$($before | Format-Table | Out-String)" $before | Remove-GitHubVariable $after = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($after | Format-Table)" + Write-Host "$($after | Format-Table | Out-String)" $after.Count | Should -Be 0 } } @@ -666,10 +666,10 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { It 'Remove-GitHubVariable' { $before = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($before | Format-Table)" + Write-Host "$($before | Format-Table | Out-String)" $before | Remove-GitHubVariable $after = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($after | Format-Table)" + Write-Host "$($after | Format-Table | Out-String)" $after.Count | Should -Be 0 } } @@ -725,10 +725,10 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { It 'Remove-GitHubVariable' { $before = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($before | Format-Table)" + Write-Host "$($before | Format-Table | Out-String)" $before | Remove-GitHubVariable $after = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($after | Format-Table)" + Write-Host "$($after | Format-Table | Out-String)" $after.Count | Should -Be 0 } } @@ -737,10 +737,10 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { Describe 'As a GitHub App - Organization (APP_ORG)' { BeforeAll { Connect-GitHubAccount -ClientID $env:TEST_APP_ORG_CLIENT_ID -PrivateKey $env:TEST_APP_ORG_PRIVATE_KEY - LogGroup 'Context' { Write-Host "$(Get-GitHubContext | Format-List)" } + LogGroup 'Context' { Write-Host "$(Get-GitHubContext | Format-List | Out-String)" } $owner = 'psmodule-test-org' Connect-GitHubApp -Organization $owner -Default - LogGroup 'Context' { Write-Host "$(Get-GitHubContext | Format-List)" } + LogGroup 'Context' { Write-Host "$(Get-GitHubContext | Format-List | Out-String)" } $testType = 'APP_ORG' $repoName = "$testName-$os-$testType" $varName = "$testName`_$os`_$testType" @@ -803,10 +803,10 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { It 'Remove-GitHubVariable' { $before = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($before | Format-Table)" + Write-Host "$($before | Format-Table | Out-String)" $before | Remove-GitHubVariable $after = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($after | Format-Table)" + Write-Host "$($after | Format-Table | Out-String)" $after.Count | Should -Be 0 } } @@ -860,10 +860,10 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { It 'Remove-GitHubVariable' { $before = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($before | Format-Table)" + Write-Host "$($before | Format-Table | Out-String)" $before | Remove-GitHubVariable $after = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($after | Format-Table)" + Write-Host "$($after | Format-Table | Out-String)" $after.Count | Should -Be 0 } } @@ -919,10 +919,10 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { It 'Remove-GitHubVariable' { $before = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($before | Format-Table)" + Write-Host "$($before | Format-Table | Out-String)" $before | Remove-GitHubVariable $after = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($after | Format-Table)" + Write-Host "$($after | Format-Table | Out-String)" $after.Count | Should -Be 0 } } From 75a439de39a0b2e9aca86807d02652d078e5dd9b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 19 Mar 2025 00:18:28 +0100 Subject: [PATCH 79/85] Add GitHubVariable.Format.ps1xml for structured output formatting --- src/formats/GitHubVariable.Format.ps1xml | 92 ++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 src/formats/GitHubVariable.Format.ps1xml diff --git a/src/formats/GitHubVariable.Format.ps1xml b/src/formats/GitHubVariable.Format.ps1xml new file mode 100644 index 000000000..9b45857cf --- /dev/null +++ b/src/formats/GitHubVariable.Format.ps1xml @@ -0,0 +1,92 @@ + + + + + GitHubVariableTable + + GitHubVariable + + + + + + + + + + + + + + + + + + + + + + + + Name + + + Value + + + Owner + + + Repository + + + Environment + + + + + + + + GitHubVariableList + + GitHubVariable + + + + + + + Name + + + Value + + + Owner + + + Repository + + + Environment + + + CreatedAt + + + UpdatedAt + + + Visibility + + + SelectedRepositories + + + + + + + + From 411d5b2b8f381a82eb6e928dc5f037c42d7555c7 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 19 Mar 2025 08:15:37 +0100 Subject: [PATCH 80/85] Enable debug and verbose output preferences in Variables.Tests.ps1 for enhanced test visibility --- tests/Variables.Tests.ps1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 3ff140046..15d9db755 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -16,6 +16,8 @@ param() BeforeAll { + $DebugPreference = 'Continue' + $VerbosePreference = 'Continue' $testName = 'VariableTest' $os = Get-GitHubRunnerData | Select-Object -ExpandProperty OS } From 3b6ff831f104d200eb916ae3f4b1814f9d4d7dcb Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 19 Mar 2025 09:10:00 +0100 Subject: [PATCH 81/85] Add testing framework documentation and templates; enhance GitHub API invocation with pagination support --- .github/workflows/Process-PSModule.yml | 4 +- .../Context/Resolve-GitHubContextSetting.ps1 | 1 - src/functions/public/API/Invoke-GitHubAPI.ps1 | 47 ++++++++++++------- {tests2 => tests}/API.Tests.ps1 | 0 {tests2 => tests}/Apps.Tests.ps1 | 0 {tests2 => tests}/Auth.Tests.ps1 | 0 {tests2 => tests}/Emojis.Tests.ps1 | 0 {tests2 => tests}/Environments.Tests.ps1 | 0 {tests2 => tests}/GitHub.Tests.ps1 | 0 {tests2 => tests}/IssueForm.md | 0 {tests2 => tests}/Organization.Tests.ps1 | 0 {tests2 => tests}/README.md | 0 {tests2 => tests}/Repositories.Tests.ps1 | 0 {tests2 => tests}/TEMPLATE.ps1 | 0 {tests2 => tests}/User.Tests.ps1 | 0 15 files changed, 33 insertions(+), 19 deletions(-) rename {tests2 => tests}/API.Tests.ps1 (100%) rename {tests2 => tests}/Apps.Tests.ps1 (100%) rename {tests2 => tests}/Auth.Tests.ps1 (100%) rename {tests2 => tests}/Emojis.Tests.ps1 (100%) rename {tests2 => tests}/Environments.Tests.ps1 (100%) rename {tests2 => tests}/GitHub.Tests.ps1 (100%) rename {tests2 => tests}/IssueForm.md (100%) rename {tests2 => tests}/Organization.Tests.ps1 (100%) rename {tests2 => tests}/README.md (100%) rename {tests2 => tests}/Repositories.Tests.ps1 (100%) rename {tests2 => tests}/TEMPLATE.ps1 (100%) rename {tests2 => tests}/User.Tests.ps1 (100%) diff --git a/.github/workflows/Process-PSModule.yml b/.github/workflows/Process-PSModule.yml index 0e06d4b96..60e54d0db 100644 --- a/.github/workflows/Process-PSModule.yml +++ b/.github/workflows/Process-PSModule.yml @@ -36,5 +36,5 @@ jobs: TEST_USER_ORG_FG_PAT: ${{ secrets.TEST_USER_ORG_FG_PAT }} TEST_USER_USER_FG_PAT: ${{ secrets.TEST_USER_USER_FG_PAT }} TEST_USER_PAT: ${{ secrets.TEST_USER_PAT }} - with: - SkipTests: SourceCode + # with: + # SkipTests: SourceCode diff --git a/src/functions/private/Auth/Context/Resolve-GitHubContextSetting.ps1 b/src/functions/private/Auth/Context/Resolve-GitHubContextSetting.ps1 index 32f3868cb..4b8d8ec7b 100644 --- a/src/functions/private/Auth/Context/Resolve-GitHubContextSetting.ps1 +++ b/src/functions/private/Auth/Context/Resolve-GitHubContextSetting.ps1 @@ -41,6 +41,5 @@ if ([string]::IsNullOrEmpty($Value)) { $Value = $Context.$Name } - Write-Debug "$Name`: [$Value]" return $Value } diff --git a/src/functions/public/API/Invoke-GitHubAPI.ps1 b/src/functions/public/API/Invoke-GitHubAPI.ps1 index ec723d8be..62dcd9398 100644 --- a/src/functions/public/API/Invoke-GitHubAPI.ps1 +++ b/src/functions/public/API/Invoke-GitHubAPI.ps1 @@ -91,6 +91,10 @@ filter Invoke-GitHubAPI { [Parameter()] [int] $RetryInterval = $script:GitHub.Config.RetryInterval, + # The number of results per page for paginated GitHub API responses. + [Parameter()] + [int] $PerPage, + # The context to run the command in. Used to get the details for the API call. # Can be either a string or a GitHubContext object. [Parameter()] @@ -102,20 +106,26 @@ filter Invoke-GitHubAPI { Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Write-Debug 'Invoking GitHub API...' - Write-Debug 'Parameters:' - Get-FunctionParameter | Format-List | Out-String -Stream | ForEach-Object { Write-Debug $_ } Write-Debug 'Parent function parameters:' Get-FunctionParameter -Scope 1 | Format-List | Out-String -Stream | ForEach-Object { Write-Debug $_ } + Write-Debug 'Parameters:' + Get-FunctionParameter | Format-List | Out-String -Stream | ForEach-Object { Write-Debug $_ } } process { $Token = $Context.Token - Write-Debug "Token: [$Token]" $HttpVersion = Resolve-GitHubContextSetting -Name 'HttpVersion' -Value $HttpVersion -Context $Context $ApiBaseUri = Resolve-GitHubContextSetting -Name 'ApiBaseUri' -Value $ApiBaseUri -Context $Context $ApiVersion = Resolve-GitHubContextSetting -Name 'ApiVersion' -Value $ApiVersion -Context $Context $TokenType = Resolve-GitHubContextSetting -Name 'TokenType' -Value $TokenType -Context $Context + [pscustomobject]@{ + Token = $Token + HttpVersion = $HttpVersion + ApiBaseUri = $ApiBaseUri + ApiVersion = $ApiVersion + TokenType = $TokenType + } | Format-List | Out-String -Stream | ForEach-Object { Write-Debug $_ } $jwt = $null switch ($TokenType) { 'ghu' { @@ -155,20 +165,25 @@ filter Invoke-GitHubAPI { } $APICall | Remove-HashtableEntry -NullOrEmptyValues - if ($Body) { - # Use body to create the query string for certain situations - if ($Method -eq 'GET') { - # If body conatins 'per_page' and its is null, set it to $context.PerPage - if ($Body['per_page'] -eq 0) { - Write-Debug "Setting per_page to the default value in context [$($Context.PerPage)]." - $Body['per_page'] = $Context.PerPage - } - $APICall.Uri = New-Uri -BaseUri $Uri -Query $Body -AsString - } elseif ($Body -is [string]) { - # Use body to create the form data - $APICall.Body = $Body - } else { + if ($Method -eq 'GET') { + if (-not $Body) { + $Body = @{} + } + + if ($PSBoundParameters.ContainsKey('PerPage')) { + Write-Debug "Using provided PerPage parameter value [$PerPage]." + $Body['per_page'] = $PerPage + } elseif (-not $Body.ContainsKey('per_page') -or $Body['per_page'] -eq 0) { + Write-Debug "Setting per_page to the default value in context [$($Context.PerPage)]." + $Body['per_page'] = $Context.PerPage + } + + $APICall.Uri = New-Uri -BaseUri $Uri -Query $Body -AsString + } elseif ($Body) { + if ($Body -is [hashtable]) { $APICall.Body = $Body | ConvertTo-Json -Depth 100 + } else { + $APICall.Body = $Body } } diff --git a/tests2/API.Tests.ps1 b/tests/API.Tests.ps1 similarity index 100% rename from tests2/API.Tests.ps1 rename to tests/API.Tests.ps1 diff --git a/tests2/Apps.Tests.ps1 b/tests/Apps.Tests.ps1 similarity index 100% rename from tests2/Apps.Tests.ps1 rename to tests/Apps.Tests.ps1 diff --git a/tests2/Auth.Tests.ps1 b/tests/Auth.Tests.ps1 similarity index 100% rename from tests2/Auth.Tests.ps1 rename to tests/Auth.Tests.ps1 diff --git a/tests2/Emojis.Tests.ps1 b/tests/Emojis.Tests.ps1 similarity index 100% rename from tests2/Emojis.Tests.ps1 rename to tests/Emojis.Tests.ps1 diff --git a/tests2/Environments.Tests.ps1 b/tests/Environments.Tests.ps1 similarity index 100% rename from tests2/Environments.Tests.ps1 rename to tests/Environments.Tests.ps1 diff --git a/tests2/GitHub.Tests.ps1 b/tests/GitHub.Tests.ps1 similarity index 100% rename from tests2/GitHub.Tests.ps1 rename to tests/GitHub.Tests.ps1 diff --git a/tests2/IssueForm.md b/tests/IssueForm.md similarity index 100% rename from tests2/IssueForm.md rename to tests/IssueForm.md diff --git a/tests2/Organization.Tests.ps1 b/tests/Organization.Tests.ps1 similarity index 100% rename from tests2/Organization.Tests.ps1 rename to tests/Organization.Tests.ps1 diff --git a/tests2/README.md b/tests/README.md similarity index 100% rename from tests2/README.md rename to tests/README.md diff --git a/tests2/Repositories.Tests.ps1 b/tests/Repositories.Tests.ps1 similarity index 100% rename from tests2/Repositories.Tests.ps1 rename to tests/Repositories.Tests.ps1 diff --git a/tests2/TEMPLATE.ps1 b/tests/TEMPLATE.ps1 similarity index 100% rename from tests2/TEMPLATE.ps1 rename to tests/TEMPLATE.ps1 diff --git a/tests2/User.Tests.ps1 b/tests/User.Tests.ps1 similarity index 100% rename from tests2/User.Tests.ps1 rename to tests/User.Tests.ps1 From 08c6ff6445dd18cd358c20ef8f1fecf6762e7031 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 19 Mar 2025 15:23:19 +0100 Subject: [PATCH 82/85] Remove commented-out configuration for skipping tests in Process-PSModule.yml --- .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 60e54d0db..2fdfe0422 100644 --- a/.github/workflows/Process-PSModule.yml +++ b/.github/workflows/Process-PSModule.yml @@ -36,5 +36,3 @@ jobs: TEST_USER_ORG_FG_PAT: ${{ secrets.TEST_USER_ORG_FG_PAT }} TEST_USER_USER_FG_PAT: ${{ secrets.TEST_USER_USER_FG_PAT }} TEST_USER_PAT: ${{ secrets.TEST_USER_PAT }} - # with: - # SkipTests: SourceCode From f66cf49bdbcefaaefe2bb969d4eb74c249f58512 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 19 Mar 2025 15:27:47 +0100 Subject: [PATCH 83/85] Remove deprecated GitHubVariable and GitHubRepository classes; enhance warning output in Connect-GithubCli.ps1 --- .../public/Repositories/GitHubRepository.ps1 | 51 - .../public/Variables/GitHubVariable.ps1 | 45 - src/formats/GitHubVariable.Format.ps1xml | 92 -- .../private/Auth/Cli/Connect-GithubCli.ps1 | 1 + .../Get-GitHubVariableEnvironmentByName.ps1 | 89 -- .../Get-GitHubVariableEnvironmentList.ps1 | 90 -- .../Get-GitHubVariableFromOrganization.ps1 | 102 -- .../Get-GitHubVariableOwnerByName.ps1 | 85 -- .../Variables/Get-GitHubVariableOwnerList.ps1 | 101 -- .../Get-GitHubVariableRepositoryByName.ps1 | 77 -- .../Get-GitHubVariableRepositoryList.ps1 | 88 -- .../Get-GitHubVariableVisibilityList.ps1 | 93 -- .../New-GitHubVariableOnEnvironment.ps1 | 85 -- .../Variables/New-GitHubVariableOnOwner.ps1 | 91 -- .../New-GitHubVariableOnRepository.ps1 | 73 -- .../Remove-GitHubVariableOnEnvironment.ps1 | 67 -- .../Remove-GitHubVariableOnOwner.ps1 | 60 -- .../Remove-GitHubVariableOnRepository.ps1 | 63 -- .../Update-GitHubVariableOnEnvironment.ps1 | 91 -- .../Update-GitHubVariableOnOwner.ps1 | 102 -- .../Update-GitHubVariableOnRepository.ps1 | 78 -- .../public/Variables/Get-GitHubVariable.ps1 | 195 ---- .../public/Variables/New-GitHubVariable.ps1 | 141 --- .../Variables/Remove-GitHubVariable.ps1 | 169 ---- .../public/Variables/Set-GitHubVariable.ps1 | 126 --- .../Variables/Update-GitHubVariable.ps1 | 141 --- tests/Variables.Tests.ps1 | 931 ------------------ 27 files changed, 1 insertion(+), 3326 deletions(-) delete mode 100644 src/classes/public/Repositories/GitHubRepository.ps1 delete mode 100644 src/classes/public/Variables/GitHubVariable.ps1 delete mode 100644 src/formats/GitHubVariable.Format.ps1xml delete mode 100644 src/functions/private/Variables/Get-GitHubVariableEnvironmentByName.ps1 delete mode 100644 src/functions/private/Variables/Get-GitHubVariableEnvironmentList.ps1 delete mode 100644 src/functions/private/Variables/Get-GitHubVariableFromOrganization.ps1 delete mode 100644 src/functions/private/Variables/Get-GitHubVariableOwnerByName.ps1 delete mode 100644 src/functions/private/Variables/Get-GitHubVariableOwnerList.ps1 delete mode 100644 src/functions/private/Variables/Get-GitHubVariableRepositoryByName.ps1 delete mode 100644 src/functions/private/Variables/Get-GitHubVariableRepositoryList.ps1 delete mode 100644 src/functions/private/Variables/Get-GitHubVariableVisibilityList.ps1 delete mode 100644 src/functions/private/Variables/New-GitHubVariableOnEnvironment.ps1 delete mode 100644 src/functions/private/Variables/New-GitHubVariableOnOwner.ps1 delete mode 100644 src/functions/private/Variables/New-GitHubVariableOnRepository.ps1 delete mode 100644 src/functions/private/Variables/Remove-GitHubVariableOnEnvironment.ps1 delete mode 100644 src/functions/private/Variables/Remove-GitHubVariableOnOwner.ps1 delete mode 100644 src/functions/private/Variables/Remove-GitHubVariableOnRepository.ps1 delete mode 100644 src/functions/private/Variables/Update-GitHubVariableOnEnvironment.ps1 delete mode 100644 src/functions/private/Variables/Update-GitHubVariableOnOwner.ps1 delete mode 100644 src/functions/private/Variables/Update-GitHubVariableOnRepository.ps1 delete mode 100644 src/functions/public/Variables/Get-GitHubVariable.ps1 delete mode 100644 src/functions/public/Variables/New-GitHubVariable.ps1 delete mode 100644 src/functions/public/Variables/Remove-GitHubVariable.ps1 delete mode 100644 src/functions/public/Variables/Set-GitHubVariable.ps1 delete mode 100644 src/functions/public/Variables/Update-GitHubVariable.ps1 delete mode 100644 tests/Variables.Tests.ps1 diff --git a/src/classes/public/Repositories/GitHubRepository.ps1 b/src/classes/public/Repositories/GitHubRepository.ps1 deleted file mode 100644 index 5e7f12297..000000000 --- a/src/classes/public/Repositories/GitHubRepository.ps1 +++ /dev/null @@ -1,51 +0,0 @@ -class GitHubRepository { - # The name of the repository. - [string] $Name - - # The full name of the repository. - # This is the name of the repository including the owner. - # Example: "octocat/Hello-World". - [string] $FullName - - # The ID of the repository. - [string] $NodeID - - # The database ID of the repository. - [UInt64] $DatabaseID - - # The description of the repository. - [string] $Description - - # The owner of the repository. - [string] $Owner - - # The URL of the repository. - [string] $Url - - # The date and time the repository was created. - [System.Nullable[datetime]] $CreatedAt - - # The date and time the repository was last updated. - [System.Nullable[datetime]] $UpdatedAt - - # Simple parameterless constructor - GitHubRepository() {} - - # Creates a object from a hashtable of key-vaule pairs. - GitHubRepository([hashtable]$Properties) { - foreach ($Property in $Properties.Keys) { - $this.$Property = $Properties.$Property - } - } - - # Creates a object from a PSCustomObject. - GitHubRepository([PSCustomObject]$Object) { - $Object.PSObject.Properties | ForEach-Object { - $this.($_.Name) = $_.Value - } - } - - [string] ToString() { - return $this.Name - } -} diff --git a/src/classes/public/Variables/GitHubVariable.ps1 b/src/classes/public/Variables/GitHubVariable.ps1 deleted file mode 100644 index 67419e320..000000000 --- a/src/classes/public/Variables/GitHubVariable.ps1 +++ /dev/null @@ -1,45 +0,0 @@ -class GitHubVariable { - # The name of the variable. - [string] $Name - - # The value of the variable. - [string] $Value - - # The name of the organization or user the variable is associated with. - [string] $Owner - - # The name of the repository the variable is associated with. - [string] $Repository - - # The name of the environment the variable is associated with. - [string] $Environment - - # The date and time the variable was created. - [datetime] $CreatedAt - - # The date and time the variable was last updated. - [datetime] $UpdatedAt - - # The visibility of the variable. - [string] $Visibility - - # The ids of the repositories that the variable is visible to. - [GitHubRepository[]] $SelectedRepositories - - # Simple parameterless constructor - GitHubVariable() {} - - # Creates a object from a hashtable of key-vaule pairs. - GitHubVariable([hashtable]$Properties) { - foreach ($Property in $Properties.Keys) { - $this.$Property = $Properties.$Property - } - } - - # Creates a object from a PSCustomObject. - GitHubVariable([PSCustomObject]$Object) { - $Object.PSObject.Properties | ForEach-Object { - $this.($_.Name) = $_.Value - } - } -} diff --git a/src/formats/GitHubVariable.Format.ps1xml b/src/formats/GitHubVariable.Format.ps1xml deleted file mode 100644 index 9b45857cf..000000000 --- a/src/formats/GitHubVariable.Format.ps1xml +++ /dev/null @@ -1,92 +0,0 @@ - - - - - GitHubVariableTable - - GitHubVariable - - - - - - - - - - - - - - - - - - - - - - - - Name - - - Value - - - Owner - - - Repository - - - Environment - - - - - - - - GitHubVariableList - - GitHubVariable - - - - - - - Name - - - Value - - - Owner - - - Repository - - - Environment - - - CreatedAt - - - UpdatedAt - - - Visibility - - - SelectedRepositories - - - - - - - - diff --git a/src/functions/private/Auth/Cli/Connect-GithubCli.ps1 b/src/functions/private/Auth/Cli/Connect-GithubCli.ps1 index 57c5ac4e2..dd77bdf7d 100644 --- a/src/functions/private/Auth/Cli/Connect-GithubCli.ps1 +++ b/src/functions/private/Auth/Cli/Connect-GithubCli.ps1 @@ -49,6 +49,7 @@ Write-Debug $return } else { Write-Warning "Unable to log on with the GitHub Cli. ($LASTEXITCODE)" + Write-Warning "$($return)" } $Global:LASTEXITCODE = 0 Write-Debug "Resetting LASTEXITCODE: $LASTEXITCODE" diff --git a/src/functions/private/Variables/Get-GitHubVariableEnvironmentByName.ps1 b/src/functions/private/Variables/Get-GitHubVariableEnvironmentByName.ps1 deleted file mode 100644 index c4287f0d5..000000000 --- a/src/functions/private/Variables/Get-GitHubVariableEnvironmentByName.ps1 +++ /dev/null @@ -1,89 +0,0 @@ -function Get-GitHubVariableEnvironmentByName { - <# - .SYNOPSIS - Retrieves a specific variable from a GitHub repository. - - .DESCRIPTION - Gets a specific variable in an environment of a repository on GitHub. - Authenticated users must have collaborator access to a repository to create, update, or read variables. - OAuth tokens and personal access tokens (classic) need the `repo` scope to use this endpoint. - - .EXAMPLE - Get-GitHubVariableEnvironmentByName -Owner 'octocat' -Repository 'Hello-World' -Environment 'dev' -Name 'NAME' -Context $GitHubContext - - Output: - ```powershell - Name : NAME - Value : John Doe - Owner : octocat - Repository : Hello-World - Environment : dev - ``` - - Retrieves the specified variable from the specified environment. - - .OUTPUTS - GitHubVariable - - .NOTES - Returns an GitHubVariable object containing details about the environment variable, - including its name, value, associated repository, and environment details. - - .LINK - [Get an environment variable](https://docs.github.com/rest/actions/variables#get-an-environment-variable) - #> - [OutputType([GitHubVariable])] - [CmdletBinding()] - 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] $Repository, - - # The name of the environment. - [Parameter(Mandatory)] - [string] $Environment, - - # The name of the variable. - [Parameter(Mandatory)] - [string] $Name, - - # The context to run the command in. Used to get the details for the API call. - # Can be either a string or a GitHubContext object. - [Parameter(Mandatory)] - [object] $Context - ) - - begin { - $stackPath = Get-PSCallStackPath - Write-Debug "[$stackPath] - Start" - Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - } - - process { - $inputObject = @{ - Method = 'GET' - APIEndpoint = "/repos/$Owner/$Repository/environments/$Environment/variables/$Name" - Context = $Context - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - [GitHubVariable]@{ - Name = $_.Response.name - Value = $_.Response.value - CreatedAt = $_.Response.created_at - UpdatedAt = $_.Response.updated_at - Owner = $Owner - Repository = $Repository - Environment = $Environment - } - } - } - - end { - Write-Debug "[$stackPath] - End" - } -} diff --git a/src/functions/private/Variables/Get-GitHubVariableEnvironmentList.ps1 b/src/functions/private/Variables/Get-GitHubVariableEnvironmentList.ps1 deleted file mode 100644 index dea862f16..000000000 --- a/src/functions/private/Variables/Get-GitHubVariableEnvironmentList.ps1 +++ /dev/null @@ -1,90 +0,0 @@ -function Get-GitHubVariableEnvironmentList { - <# - .SYNOPSIS - Retrieves all variables for a specified environment in a GitHub repository. - - .DESCRIPTION - Lists all environment variables in a specified repository environment. - Authenticated users must have collaborator access to a repository to create, update, or read variables. - OAuth app tokens and personal access tokens (classic) need the `repo` scope to use this endpoint. - - .EXAMPLE - Get-GitHubVariableEnvironmentList -Owner 'octocat' -Repository 'Hello-World' -Environment 'dev' -Context $GitHubContext - - Output: - ```powershell - Name : NAME - Value : John Doe - Owner : octocat - Repository : Hello-World - Environment : dev - - Name : EMAIL - Value : John.Doe@example.com - Owner : octocat - Repository : Hello-World - Environment : dev - ``` - - Retrieves all variables for the specified environment. - - .OUTPUTS - GitHubVariable[]. An array of GitHubVariable objects representing the environment variables. - Each object contains Name, Value, CreatedAt, UpdatedAt, Owner, Repository, and Environment properties. - - .LINK - https://psmodule.io/GitHub/Functions/Get-GitHubVariableEnvironmentList - #> - [OutputType([GitHubVariable[]])] - [CmdletBinding()] - 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] $Repository, - - # The name of the environment. - [Parameter(Mandatory)] - [string] $Environment, - - # The context to run the command in. Used to get the details for the API call. - # Can be either a string or a GitHubContext object. - [Parameter(Mandatory)] - [object] $Context - ) - - begin { - $stackPath = Get-PSCallStackPath - Write-Debug "[$stackPath] - Start" - Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - } - - process { - $inputObject = @{ - Method = 'GET' - APIEndpoint = "/repos/$Owner/$Repository/environments/$Environment/variables" - Context = $Context - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - $_.Response.variables | ForEach-Object { - [GitHubVariable]@{ - Name = $_.name - Value = $_.value - CreatedAt = $_.created_at - UpdatedAt = $_.updated_at - Owner = $Owner - Repository = $Repository - Environment = $Environment - } - } - } - } - - end { - Write-Debug "[$stackPath] - End" - } -} diff --git a/src/functions/private/Variables/Get-GitHubVariableFromOrganization.ps1 b/src/functions/private/Variables/Get-GitHubVariableFromOrganization.ps1 deleted file mode 100644 index 2c22cf0ae..000000000 --- a/src/functions/private/Variables/Get-GitHubVariableFromOrganization.ps1 +++ /dev/null @@ -1,102 +0,0 @@ -function Get-GitHubVariableFromOrganization { - <# - .SYNOPSIS - List repository organization variables. - - .DESCRIPTION - Lists all organization variables shared with a repository. - Authenticated users must have collaborator access to a repository to create, update, or read variables. - OAuth app tokens and personal access tokens (classic) need the `repo` scope to use this endpoint. - - .EXAMPLE - Get-GitHubVariableFromOrganization -Owner 'PSModule' -Repository 'GitHub' -Context (Get-GitHubContext) - - Output: - ```powershell - Name : AVAILVAR - Value : ValueVar - Owner : PSModule - Repository : - Environment : - CreatedAt : 3/17/2025 10:56:22 AM - UpdatedAt : 3/17/2025 10:56:22 AM - Visibility : - SelectedRepositories : - - Name : SELECTEDVAR - Value : Varselected - Owner : PSModule - Repository : - Environment : - CreatedAt : 3/17/2025 10:56:39 AM - UpdatedAt : 3/17/2025 10:56:39 AM - Visibility : - SelectedRepositories : - - Name : TESTVAR - Value : VarTest - Owner : PSModule - Repository : - Environment : - CreatedAt : 3/17/2025 10:56:05 AM - UpdatedAt : 3/17/2025 10:56:05 AM - Visibility : - SelectedRepositories : - ``` - - Lists the variables visible from 'PSModule' to the 'GitHub' repository. - - .LINK - [List repository organization variables](https://docs.github.com/rest/actions/variables#list-repository-organization-variables) - #> - [OutputType([GitHubVariable[]])] - [CmdletBinding()] - 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] $Repository, - - # The context to run the command in. Used to get the details for the API call. - # Can be either a string or a GitHubContext object. - [Parameter(Mandatory)] - [object] $Context - ) - - begin { - $stackPath = Get-PSCallStackPath - Write-Debug "[$stackPath] - Start" - Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - } - - process { - $inputObject = @{ - Method = 'GET' - APIEndpoint = "/repos/$Owner/$Repository/actions/organization-variables" - Body = @{ - per_page = 30 - } - Context = $Context - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - $_.Response.variables | ForEach-Object { - [GitHubVariable]@{ - Name = $_.name - Value = $_.value - CreatedAt = $_.created_at - UpdatedAt = $_.updated_at - Owner = $Owner - Visibility = $_.visibility - } - } - } - } - - end { - Write-Debug "[$stackPath] - End" - } -} diff --git a/src/functions/private/Variables/Get-GitHubVariableOwnerByName.ps1 b/src/functions/private/Variables/Get-GitHubVariableOwnerByName.ps1 deleted file mode 100644 index 1645f3c3e..000000000 --- a/src/functions/private/Variables/Get-GitHubVariableOwnerByName.ps1 +++ /dev/null @@ -1,85 +0,0 @@ -function Get-GitHubVariableOwnerByName { - <# - .SYNOPSIS - Get an organization variable. - - .DESCRIPTION - Gets a specific variable in an organization. - The authenticated user must have collaborator access to a repository to create, update, or read variables. - OAuth tokens and personal access tokens (classic) need the`admin:org` scope to use this endpoint. If the repository is private, - OAuth tokens and personal access tokens (classic) need the `repo` scope to use this endpoint. - - .EXAMPLE - Get-GitHubVariableOwnerByName -Owner 'PSModule' -Name 'SELECTEDVAR' -Context (Get-GitHubContext) - - Output: - ```powershell - Name : SELECTEDVAR - Value : Varselected - Owner : PSModule - Repository : - Environment : - CreatedAt : 3/17/2025 10:56:39 AM - UpdatedAt : 3/17/2025 10:56:39 AM - Visibility : selected - SelectedRepositories : {Build-PSModule, Test-PSModule} - ``` - - Retrieves the specified variable from the specified organization. - - .LINK - [Get an organization variable](https://docs.github.com/rest/actions/variables#get-an-organization-variable) - #> - [OutputType([GitHubVariable])] - [CmdletBinding()] - param( - # The account owner of the repository. The name is not case sensitive. - [Parameter(Mandatory)] - [string] $Owner, - - # The name of the variable. - [Parameter(Mandatory)] - [string] $Name, - - # The context to run the command in. Used to get the details for the API call. - # Can be either a string or a GitHubContext object. - [Parameter(Mandatory)] - [object] $Context - ) - - begin { - $stackPath = Get-PSCallStackPath - Write-Debug "[$stackPath] - Start" - Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - } - - process { - $inputObject = @{ - Method = 'GET' - APIEndpoint = "/orgs/$Owner/actions/variables/$Name" - Context = $Context - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - $_.Response | ForEach-Object { - $selectedRepositories = @() - if ($_.visibility -eq 'selected') { - $selectedRepositories = Get-GitHubVariableVisibilityList -Owner $Owner -Name $_.name -Context $Context - } - [GitHubVariable]@{ - Name = $_.name - Value = $_.value - CreatedAt = $_.created_at - UpdatedAt = $_.updated_at - Owner = $Owner - Visibility = $_.visibility - SelectedRepositories = $selectedRepositories - } - } - } - } - - end { - Write-Debug "[$stackPath] - End" - } -} diff --git a/src/functions/private/Variables/Get-GitHubVariableOwnerList.ps1 b/src/functions/private/Variables/Get-GitHubVariableOwnerList.ps1 deleted file mode 100644 index 9ec90ba8c..000000000 --- a/src/functions/private/Variables/Get-GitHubVariableOwnerList.ps1 +++ /dev/null @@ -1,101 +0,0 @@ -function Get-GitHubVariableOwnerList { - <# - .SYNOPSIS - List organization variables - - .DESCRIPTION - Lists all organization variables. - Authenticated users must have collaborator access to a repository to create, update, or read variables. - OAuth app tokens and personal access tokens (classic) need the `admin:org` scope to use this endpoint. If the repository is private, - the `repo` scope is also required. - - .EXAMPLE - Get-GitHubVariableOwnerList -Owner 'PSModule' -Context (Get-GitHubContext) - - Output: - ```powershell - Name : AVAILVAR - Value : ValueVar - Owner : PSModule - Repository : - Environment : - CreatedAt : 3/17/2025 10:56:22 AM - UpdatedAt : 3/17/2025 10:56:22 AM - Visibility : all - SelectedRepositories : {} - - Name : SELECTEDVAR - Value : Varselected - Owner : PSModule - Repository : - Environment : - CreatedAt : 3/17/2025 10:56:39 AM - UpdatedAt : 3/17/2025 10:56:39 AM - Visibility : selected - SelectedRepositories : {Build-PSModule, Test-PSModule} - - Name : TESTVAR - Value : VarTest - Owner : PSModule - Repository : - Environment : - CreatedAt : 3/17/2025 10:56:05 AM - UpdatedAt : 3/17/2025 10:56:05 AM - Visibility : private - SelectedRepositories : {} - ``` - - Retrieves all variables from the specified organization. - - .LINK - List organization variables](https://docs.github.com/rest/actions/variables#list-organization-variables) - #> - [OutputType([GitHubVariable[]])] - [CmdletBinding()] - param( - # The account owner of the repository. The name is not case sensitive. - [Parameter(Mandatory)] - [string] $Owner, - - # The context to run the command in. Used to get the details for the API call. - # Can be either a string or a GitHubContext object. - [Parameter(Mandatory)] - [object] $Context - ) - - begin { - $stackPath = Get-PSCallStackPath - Write-Debug "[$stackPath] - Start" - Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - } - - process { - $inputObject = @{ - Method = 'GET' - APIEndpoint = "/orgs/$Owner/actions/variables" - Context = $Context - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - $_.Response.variables | ForEach-Object { - $selectedRepositories = @() - if ($_.visibility -eq 'selected') { - $selectedRepositories = Get-GitHubVariableVisibilityList -Owner $Owner -Name $_.name -Context $Context - } - [GitHubVariable]@{ - Name = $_.name - Value = $_.value - CreatedAt = $_.created_at - UpdatedAt = $_.updated_at - Owner = $Owner - Visibility = $_.visibility - SelectedRepositories = $selectedRepositories - } - } - } - } - - end { - Write-Debug "[$stackPath] - End" - } -} diff --git a/src/functions/private/Variables/Get-GitHubVariableRepositoryByName.ps1 b/src/functions/private/Variables/Get-GitHubVariableRepositoryByName.ps1 deleted file mode 100644 index 2b845a5bd..000000000 --- a/src/functions/private/Variables/Get-GitHubVariableRepositoryByName.ps1 +++ /dev/null @@ -1,77 +0,0 @@ -function Get-GitHubVariableRepositoryByName { - <# - .SYNOPSIS - Get a repository variable - - .DESCRIPTION - Gets a specific variable in a repository. - The authenticated user must have collaborator access to the repository to use this endpoint. - OAuth app tokens and personal access tokens (classic) need the `repo` scope to use this endpoint. - - .EXAMPLE - Get-GitHubVariableRepositoryByName -Owner 'PSModule' -Repository 'Hello-World' -Name 'EMAIL' -Context (Get-GitHubContext) - - Output: - ```powershell - Name : EMAIL - Value : John.Doe@example.com - Owner : octocat - Repository : Hello-World - Environment : - ``` - - Retrieves the specified variable from the specified repository. - - .LINK - [Get a repository variable](https://docs.github.com/rest/actions/variables#get-a-repository-variable) - #> - [OutputType([GitHubVariable])] - [CmdletBinding()] - 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] $Repository, - - # The name of the variable. - [Parameter(Mandatory)] - [string] $Name, - - # The context to run the command in. Used to get the details for the API call. - # Can be either a string or a GitHubContext object. - [Parameter(Mandatory)] - [object] $Context - ) - - begin { - $stackPath = Get-PSCallStackPath - Write-Debug "[$stackPath] - Start" - Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - } - - process { - $inputObject = @{ - Method = 'GET' - APIEndpoint = "/repos/$Owner/$Repository/actions/variables/$Name" - Context = $Context - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - [GitHubVariable]@{ - Name = $_.Response.name - Value = $_.Response.value - CreatedAt = $_.Response.created_at - UpdatedAt = $_.Response.updated_at - Owner = $Owner - Repository = $Repository - } - } - } - - end { - Write-Debug "[$stackPath] - End" - } -} diff --git a/src/functions/private/Variables/Get-GitHubVariableRepositoryList.ps1 b/src/functions/private/Variables/Get-GitHubVariableRepositoryList.ps1 deleted file mode 100644 index cad40d84e..000000000 --- a/src/functions/private/Variables/Get-GitHubVariableRepositoryList.ps1 +++ /dev/null @@ -1,88 +0,0 @@ -function Get-GitHubVariableRepositoryList { - <# - .SYNOPSIS - List repository variables. - - .DESCRIPTION - Lists all repository variables. - Authenticated users must have collaborator access to a repository to create, update, or read variables. - OAuth app tokens and personal access tokens (classic) need the `repo` scope to use this endpoint. - - .EXAMPLE - Get-GitHubVariableRepositoryList -Owner 'PSModule' -Repository 'Hello-World' -Context (Get-GitHubContext) - - Output: - ```powershell - Name : NAME - Value : John Doe - Owner : octocat - Repository : Hello-World - Environment : - - Name : EMAIL - Value : John.Doe@example.com - Owner : octocat - Repository : Hello-World - Environment : - ``` - - Retrieves all variables for the specified repository. - - .OUTPUTS - GitHubVariable - - .NOTES - Returns an GitHubVariable object containing details about the environment variable, - including its name, value, associated repository, and environment details. - - .LINK - [List repository variables](https://docs.github.com/rest/actions/variables#list-repository-variables) - #> - [OutputType([GitHubVariable[]])] - [CmdletBinding()] - 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] $Repository, - - # The context to run the command in. Used to get the details for the API call. - # Can be either a string or a GitHubContext object. - [Parameter(Mandatory)] - [object] $Context - ) - - begin { - $stackPath = Get-PSCallStackPath - Write-Debug "[$stackPath] - Start" - Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - } - - process { - $inputObject = @{ - Method = 'GET' - APIEndpoint = "/repos/$Owner/$Repository/actions/variables" - Context = $Context - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - $_.Response.variables | ForEach-Object { - [GitHubVariable]@{ - Name = $_.name - Value = $_.value - CreatedAt = $_.created_at - UpdatedAt = $_.updated_at - Owner = $Owner - Repository = $Repository - } - } - } - } - - end { - Write-Debug "[$stackPath] - End" - } -} diff --git a/src/functions/private/Variables/Get-GitHubVariableVisibilityList.ps1 b/src/functions/private/Variables/Get-GitHubVariableVisibilityList.ps1 deleted file mode 100644 index 3cf783c13..000000000 --- a/src/functions/private/Variables/Get-GitHubVariableVisibilityList.ps1 +++ /dev/null @@ -1,93 +0,0 @@ -function Get-GitHubVariableVisibilityList { - <# - .SYNOPSIS - List selected repositories for an organization variable. - - .DESCRIPTION - Lists all repositories that can access an organization variable that is available to selected repositories. - Authenticated users must have collaborator access to a repository to create, update, or read variables. - OAuth app tokens and personal access tokens (classic) need the `admin:org` scope to use this endpoint. If the repository is private, - the `repo` scope is also required. - - .EXAMPLE - Get-GitHubVariableVisibilityList -Owner 'PSModule' -Name 'SELECTEDVAR' -Context (Get-GitHubContext) - - .LINK - [List selected repositories for an organization variable](https://docs.github.com/rest/actions/variables#list-selected-repositories-for-an-organization-variable) - #> - [Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSAvoidLongLines', '', - Justification = 'Long links' - )] - [OutputType([pscustomobject])] - [CmdletBinding()] - param( - # The account owner of the repository. The name is not case sensitive. - [Parameter(Mandatory)] - [string] $Owner, - - # The name of the variable. - [Parameter(Mandatory)] - [string] $Name, - - # The context to run the command in. Used to get the details for the API call. - # Can be either a string or a GitHubContext object. - [Parameter(Mandatory)] - [object] $Context, - - [Parameter()] - [ValidateSet('json', 'pscustomobject', 'class', 'raw')] - [string] $Output = 'class' - ) - - begin { - # $stackPath = Get-PSCallStackPath - # Write-Debug "[$stackPath] - Start" - # Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - } - - process { - $inputObject = @{ - Method = 'GET' - APIEndpoint = "/orgs/$Owner/actions/variables/$Name/repositories" - Context = $Context - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - $apiReturn = $_ - $repositories = $apiReturn.Response.repositories - switch ($Output) { - 'raw' { - $apiReturn - break - } - 'json' { - $repositories | ConvertTo-Json -Depth 5 - break - } - 'pscustomobject' { - $repositories - break - } - 'class' { - $repositories | ForEach-Object { - [GitHubRepository]@{ - Name = $_.name - FullName = $_.full_name - NodeID = $_.node_id - DatabaseID = $_.id - Description = $_.description - Owner = $_.owner.login - URL = $_.html_url - } - } - break - } - } - } - } - - end { - Write-Debug "[$stackPath] - End" - } -} diff --git a/src/functions/private/Variables/New-GitHubVariableOnEnvironment.ps1 b/src/functions/private/Variables/New-GitHubVariableOnEnvironment.ps1 deleted file mode 100644 index d1cd48899..000000000 --- a/src/functions/private/Variables/New-GitHubVariableOnEnvironment.ps1 +++ /dev/null @@ -1,85 +0,0 @@ -function New-GitHubVariableOnEnvironment { - <# - .SYNOPSIS - Create an environment variable. - - .DESCRIPTION - Create an environment variable that you can reference in a GitHub Actions workflow. - Authenticated users must have collaborator access to a repository to create, update, or read variables. - OAuth tokens and personal access tokens (classic) need the `repo` scope to use this endpoint. - - .EXAMPLE - $params = @{ - Owner = 'octocat' - Repository = 'Hello-World' - Environment = 'dev' - Name = 'HOST_NAME' - Value = 'github.com' - Context = $GitHubContext - } - New-GitHubVariableOnEnvironment @params - - Creates a new environment variable named `HOST_NAME` with the value `github.com` in the specified environment. - - .LINK - [Create an environment variable](https://docs.github.com/rest/actions/variables#create-an-environment-variable) - #> - [OutputType([void])] - [CmdletBinding(SupportsShouldProcess)] - param( - # The account owner of the repository. The name is not case sensitive. - [Parameter(Mandatory)] - [string] $Owner, - - # The name of the repository. The name is not case sensitive. - [Parameter(Mandatory)] - [string] $Repository, - - # The name of the repository environment. - [Parameter(Mandatory)] - [string] $Environment, - - # The name of the variable. - [Parameter(Mandatory)] - [string] $Name, - - # The value of the variable. - [Parameter(Mandatory)] - [string] $Value, - - # The context to run the command in. Used to get the details for the API call. - # Can be either a string or a GitHubContext object. - [Parameter(Mandatory)] - [object] $Context - ) - - begin { - $stackPath = Get-PSCallStackPath - Write-Debug "[$stackPath] - Start" - Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - } - - process { - $body = @{ - name = $Name - value = $Value - } - - $inputObject = @{ - Method = 'POST' - APIEndpoint = "/repos/$Owner/$Repository/environments/$Environment/variables" - Body = $body - Context = $Context - } - - if ($PSCmdlet.ShouldProcess("variable [$Name] on [$Owner/$Repository/$Environment]", 'Create')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } - } - - end { - Write-Debug "[$stackPath] - End" - } -} diff --git a/src/functions/private/Variables/New-GitHubVariableOnOwner.ps1 b/src/functions/private/Variables/New-GitHubVariableOnOwner.ps1 deleted file mode 100644 index 3a5f28c18..000000000 --- a/src/functions/private/Variables/New-GitHubVariableOnOwner.ps1 +++ /dev/null @@ -1,91 +0,0 @@ -function New-GitHubVariableOnOwner { - <# - .SYNOPSIS - Create an organization variable. - - .DESCRIPTION - Creates an organization variable that you can reference in a GitHub Actions workflow. - Authenticated users must have collaborator access to a repository to create, update, or read variables. - OAuth tokens and personal access tokens (classic) need the`admin:org` scope to use this endpoint. If the repository is private, - OAuth tokens and personal access tokens (classic) need the `repo` scope to use this endpoint. - - .EXAMPLE - New-GitHubVariableOnOwner -Owner 'octocat' -Name 'HOST_NAME' -Value 'github.com' -Context $GitHubContext - - Creates a new organization variable named `HOST_NAME` with the value `github.com` in the specified organization. - - .LINK - [Create an organization variable](https://docs.github.com/rest/actions/variables#create-an-organization-variable) - #> - [OutputType([void])] - [CmdletBinding(SupportsShouldProcess)] - param( - [Parameter(Mandatory)] - [string] $Owner, - - # The name of the variable. - [Parameter(Mandatory)] - [string] $Name, - - # The value of the variable. - [Parameter(Mandatory)] - [string] $Value, - - # The visibility of the variable. Can be `private`, `selected`, or `all`. - # `private` - The variable is only available to the organization. - # `selected` - The variable is available to selected repositories. - # `all` - The variable is available to all repositories in the organization. - [Parameter()] - [ValidateSet('private', 'selected', 'all')] - [string] $Visibility = 'private', - - # The IDs of the repositories to which the variable is available. - # This parameter is only used when the `-Visibility` parameter is set to `selected`. - # The IDs can be obtained from the `Get-GitHubRepository` function. - [Parameter()] - [UInt64[]] $SelectedRepositories, - - # The context to run the command in. Used to get the details for the API call. - # Can be either a string or a GitHubContext object. - [Parameter(Mandatory)] - [object] $Context - ) - - begin { - $stackPath = Get-PSCallStackPath - Write-Debug "[$stackPath] - Start" - Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - } - - process { - $body = @{ - name = $Name - value = $Value - visibility = $Visibility - } - - if ($Visibility -eq 'selected') { - if (-not $SelectedRepositories) { - throw 'You must specify the -SelectedRepositories parameter when using the -Visibility selected switch.' - } - $body['selected_repository_ids'] = $SelectedRepositories - } - - $inputObject = @{ - Method = 'POST' - APIEndpoint = "/orgs/$Owner/actions/variables" - Body = $body - Context = $Context - } - - if ($PSCmdlet.ShouldProcess("variable [$Name] on [$Owner]", 'Create')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } - } - - end { - Write-Debug "[$stackPath] - End" - } -} diff --git a/src/functions/private/Variables/New-GitHubVariableOnRepository.ps1 b/src/functions/private/Variables/New-GitHubVariableOnRepository.ps1 deleted file mode 100644 index 48c1d7eec..000000000 --- a/src/functions/private/Variables/New-GitHubVariableOnRepository.ps1 +++ /dev/null @@ -1,73 +0,0 @@ -function New-GitHubVariableOnRepository { - <# - .SYNOPSIS - Create a repository variable. - - .DESCRIPTION - Creates a repository variable that you can reference in a GitHub Actions workflow. - Authenticated users must have collaborator access to a repository to create, update, or read variables. - OAuth tokens and personal access tokens (classic) need the `repo` scope to use this endpoint. - - .EXAMPLE - New-GitHubVariableOnRepository -Owner 'octocat' -Repository 'Hello-World' -Name 'HOST_NAME' -Value 'github.com' -Context $GitHubContext - - Creates a new repository variable named `HOST_NAME` with the value `github.com` in the specified repository. - - .LINK - [Create a repository variable](https://docs.github.com/rest/actions/variables#create-a-repository-variable) - #> - [OutputType([void])] - [CmdletBinding(SupportsShouldProcess)] - param( - # The account owner of the repository. The name is not case sensitive. - [Parameter(Mandatory)] - [string] $Owner, - - # The name of the repository. The name is not case sensitive. - [Parameter(Mandatory)] - [string] $Repository, - - # The name of the variable. - [Parameter(Mandatory)] - [string] $Name, - - # The value of the variable. - [Parameter(Mandatory)] - [string] $Value, - - # The context to run the command in. Used to get the details for the API call. - # Can be either a string or a GitHubContext object. - [Parameter(Mandatory)] - [object] $Context - ) - - begin { - $stackPath = Get-PSCallStackPath - Write-Debug "[$stackPath] - Start" - Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - } - - process { - $body = @{ - name = $Name - value = $Value - } - - $inputObject = @{ - Method = 'POST' - APIEndpoint = "/repos/$Owner/$Repository/actions/variables" - Body = $body - Context = $Context - } - - if ($PSCmdlet.ShouldProcess("variable [$Name] on [$Owner/$Repository]", 'Create')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } - } - - end { - Write-Debug "[$stackPath] - End" - } -} diff --git a/src/functions/private/Variables/Remove-GitHubVariableOnEnvironment.ps1 b/src/functions/private/Variables/Remove-GitHubVariableOnEnvironment.ps1 deleted file mode 100644 index 3ae29bba2..000000000 --- a/src/functions/private/Variables/Remove-GitHubVariableOnEnvironment.ps1 +++ /dev/null @@ -1,67 +0,0 @@ -function Remove-GitHubVariableOnEnvironment { - <# - .SYNOPSIS - Delete an environment variable. - - .DESCRIPTION - Deletes an environment variable using the variable name. - Authenticated users must have collaborator access to a repository to create, update, or read variables. - OAuth tokens and personal access tokens (classic) need the `repo` scope to use this endpoint. - - .EXAMPLE - Remove-GitHubVariableOnEnvironment -Owner 'octocat' -Repository 'Hello-World' -Environment 'dev' -Name 'HOST_NAME' -Context $GitHubContext - - Deletes the specified variable from the specified environment. - - .LINK - [Delete an environment variable](https://docs.github.com/rest/actions/variables#delete-an-environment-variable) - #> - [OutputType([void])] - [CmdletBinding(SupportsShouldProcess)] - param( - # The account owner of the repository. The name is not case sensitive. - [Parameter(Mandatory)] - [string] $Owner, - - # The name of the repository. The name is not case sensitive. - [Parameter(Mandatory)] - [string] $Repository, - - # The name of the repository environment. - [Parameter(Mandatory)] - [string] $Environment, - - # The name of the variable. - [Parameter(Mandatory)] - [string] $Name, - - # The context to run the command in. Used to get the details for the API call. - # Can be either a string or a GitHubContext object. - [Parameter(Mandatory)] - [object] $Context - ) - - begin { - $stackPath = Get-PSCallStackPath - Write-Debug "[$stackPath] - Start" - Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - } - - process { - $inputObject = @{ - Method = 'DELETE' - APIEndpoint = "/repos/$Owner/$Repository/environments/$Environment/variables/$Name" - Context = $Context - } - - if ($PSCmdlet.ShouldProcess("variable [$Name] on [$Owner/$Repository/$Environment]", 'Delete')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } - } - - end { - Write-Debug "[$stackPath] - End" - } -} diff --git a/src/functions/private/Variables/Remove-GitHubVariableOnOwner.ps1 b/src/functions/private/Variables/Remove-GitHubVariableOnOwner.ps1 deleted file mode 100644 index 2433555fc..000000000 --- a/src/functions/private/Variables/Remove-GitHubVariableOnOwner.ps1 +++ /dev/null @@ -1,60 +0,0 @@ -function Remove-GitHubVariableOnOwner { - <# - .SYNOPSIS - Delete an organization variable. - - .DESCRIPTION - Deletes an organization variable using the variable name. - Authenticated users must have collaborator access to a repository to create, update, or read variables. - OAuth tokens and personal access tokens (classic) need the`admin:org` scope to use this endpoint. If the repository is private, - OAuth tokens and personal access tokens (classic) need the `repo` scope to use this endpoint. - - .EXAMPLE - Remove-GitHubVariableOnOwner -Owner 'octocat' -Name 'HOST_NAME' -Context $GitHubContext - - Deletes the specified variable from the specified organization. - - .LINK - [Delete an organization variable](https://docs.github.com/rest/actions/variables#delete-an-organization-variable) - #> - [OutputType([void])] - [CmdletBinding(SupportsShouldProcess)] - param( - # The account owner of the repository. The name is not case sensitive. - [Parameter(Mandatory)] - [string] $Owner, - - # The name of the variable. - [Parameter(Mandatory)] - [string] $Name, - - # The context to run the command in. Used to get the details for the API call. - # Can be either a string or a GitHubContext object. - [Parameter(Mandatory)] - [object] $Context - ) - - begin { - $stackPath = Get-PSCallStackPath - Write-Debug "[$stackPath] - Start" - Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - } - - process { - $inputObject = @{ - Method = 'DELETE' - APIEndpoint = "/orgs/$Owner/actions/variables/$Name" - Context = $Context - } - - if ($PSCmdlet.ShouldProcess("variable [$Name] on [$Owner]", 'Delete')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } - } - - end { - Write-Debug "[$stackPath] - End" - } -} diff --git a/src/functions/private/Variables/Remove-GitHubVariableOnRepository.ps1 b/src/functions/private/Variables/Remove-GitHubVariableOnRepository.ps1 deleted file mode 100644 index 9970eb133..000000000 --- a/src/functions/private/Variables/Remove-GitHubVariableOnRepository.ps1 +++ /dev/null @@ -1,63 +0,0 @@ -function Remove-GitHubVariableOnRepository { - <# - .SYNOPSIS - Delete a repository variable. - - .DESCRIPTION - Deletes a repository variable using the variable name. - Authenticated users must have collaborator access to a repository to create, update, or read variables. - OAuth tokens and personal access tokens (classic) need the `repo` scope to use this endpoint. - - .EXAMPLE - Remove-GitHubVariableOnRepository -Owner 'octocat' -Repository 'Hello-World' -Name 'HOST_NAME' -Context $GitHubContext - - Deletes the specified variable from the specified repository. - - .LINK - [Delete a repository variable](https://docs.github.com/rest/actions/variables#delete-a-repository-variable) - #> - [OutputType([void])] - [CmdletBinding(SupportsShouldProcess)] - param( - # The account owner of the repository. The name is not case sensitive. - [Parameter(Mandatory)] - [string] $Owner, - - # The name of the repository. The name is not case sensitive. - [Parameter(Mandatory)] - [string] $Repository, - - # The name of the variable. - [Parameter(Mandatory)] - [string] $Name, - - # The context to run the command in. Used to get the details for the API call. - # Can be either a string or a GitHubContext object. - [Parameter(Mandatory)] - [object] $Context - ) - - begin { - $stackPath = Get-PSCallStackPath - Write-Debug "[$stackPath] - Start" - Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - } - - process { - $inputObject = @{ - Method = 'DELETE' - APIEndpoint = "/repos/$Owner/$Repository/actions/variables/$Name" - Context = $Context - } - - if ($PSCmdlet.ShouldProcess("variable [$Name] on [$Owner/$Repository]", 'Delete')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } - } - - end { - Write-Debug "[$stackPath] - End" - } -} diff --git a/src/functions/private/Variables/Update-GitHubVariableOnEnvironment.ps1 b/src/functions/private/Variables/Update-GitHubVariableOnEnvironment.ps1 deleted file mode 100644 index 80877c33b..000000000 --- a/src/functions/private/Variables/Update-GitHubVariableOnEnvironment.ps1 +++ /dev/null @@ -1,91 +0,0 @@ -function Update-GitHubVariableOnEnvironment { - <# - .SYNOPSIS - Update an environment variable. - - .DESCRIPTION - Updates an environment variable that you can reference in a GitHub Actions workflow. - Authenticated users must have collaborator access to a repository to create, update, or read variables. - OAuth app tokens and personal access tokens (classic) need the `repo` scope to use this endpoint. - - - .EXAMPLE - $params = @{ - Owner = 'octocat' - Repository = 'Hello-World' - Environment = 'dev' - Name = 'HOST_NAME' - Value = 'github.com' - Context = $GitHubContext - } - Update-GitHubVariableOnEnvironment @params - - Updates the environment variable named `HOST_NAME` with the value `github.com` in the specified environment. - - .LINK - [Update an environment variable](https://docs.github.com/rest/actions/variables#update-an-environment-variable) - #> - [OutputType([void])] - [CmdletBinding(SupportsShouldProcess)] - param( - # The account owner of the repository. The name is not case sensitive. - [Parameter(Mandatory)] - [string] $Owner, - - # The name of the repository. The name is not case sensitive. - [Parameter(Mandatory)] - [string] $Repository, - - # The name of the repository environment. - [Parameter(Mandatory)] - [string] $Environment, - - # The name of the variable. - [Parameter(Mandatory)] - [string] $Name, - - # The new name of the variable. - [Parameter()] - [string] $NewName, - - # The value of the variable. - [Parameter()] - [string] $Value, - - # The context to run the command in. Used to get the details for the API call. - # Can be either a string or a GitHubContext object. - [Parameter(Mandatory)] - [object] $Context - ) - - begin { - $stackPath = Get-PSCallStackPath - Write-Debug "[$stackPath] - Start" - Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - } - - process { - $body = @{} - if ($PSBoundParameters.ContainsKey('NewName')) { - $body.name = $NewName - } - if ($PSBoundParameters.ContainsKey('Value')) { - $body.value = $Value - } - - $inputObject = @{ - Method = 'PATCH' - APIEndpoint = "/repos/$Owner/$Repository/environments/$Environment/variables/$Name" - Body = $body - Context = $Context - } - - if ($PSCmdlet.ShouldProcess("variable [$Name] on [$Owner/$Repository/$Environment]", 'Update')) { - $null = Invoke-GitHubAPI @inputObject - } - } - - end { - Write-Debug "[$stackPath] - End" - } -} diff --git a/src/functions/private/Variables/Update-GitHubVariableOnOwner.ps1 b/src/functions/private/Variables/Update-GitHubVariableOnOwner.ps1 deleted file mode 100644 index 086fbd013..000000000 --- a/src/functions/private/Variables/Update-GitHubVariableOnOwner.ps1 +++ /dev/null @@ -1,102 +0,0 @@ -function Update-GitHubVariableOnOwner { - <# - .SYNOPSIS - Update an organization variable. - - .DESCRIPTION - Updates an organization variable that you can reference in a GitHub Actions workflow. - Authenticated users must have collaborator access to a repository to create, update, or read variables. - OAuth app tokens and personal access tokens (classic) need the `admin:org` scope to use this endpoint. If the repository is private, - the `repo` scope is also required. - - .EXAMPLE - Update-GitHubVariableOnOwner -Owner 'octocat' -Name 'HOST_NAME' -Value 'github.com' -Context $GitHubContext - - Updates the organization variable named `HOST_NAME` with the value `github.com` in the specified organization. - - .LINK - [Update an organization variable](https://docs.github.com/rest/actions/variables#update-an-organization-variable) - #> - [OutputType([void])] - [CmdletBinding(SupportsShouldProcess)] - param( - # The account owner of the repository. The name is not case sensitive. - [Parameter(Mandatory)] - [string] $Owner, - - # The name of the variable. - [Parameter(Mandatory)] - [string] $Name, - - # The new name of the variable. - [Parameter()] - [string] $NewName, - - # The value of the variable. - [Parameter()] - [string] $Value, - - # The visibility of the variable. Can be `private`, `selected`, or `all`. - # `private` - The variable is only available to the organization. - # `selected` - The variable is available to selected repositories. - # `all` - The variable is available to all repositories in the organization. - [Parameter()] - [ValidateSet('private', 'selected', 'all')] - [string] $Visibility, - - # The IDs of the repositories to which the variable is available. - # This parameter is only used when the `-Visibility` parameter is set to `selected`. - # The IDs can be obtained from the `Get-GitHubRepository` function. - [Parameter()] - [UInt64[]] $SelectedRepositories, - - # The context to run the command in. Used to get the details for the API call. - # Can be either a string or a GitHubContext object. - [Parameter(Mandatory)] - [object] $Context - ) - - begin { - $stackPath = Get-PSCallStackPath - Write-Debug "[$stackPath] - Start" - Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - } - - process { - $body = @{} - if ($PSBoundParameters.ContainsKey('NewName')) { - $body.name = $NewName - } - if ($PSBoundParameters.ContainsKey('Value')) { - $body.value = $Value - } - if ($PSBoundParameters.ContainsKey('Visibility')) { - $body.visibility = $Visibility - } - if ($PSBoundParameters.ContainsKey('SelectedRepositories')) { - $body.selected_repository_ids = $SelectedRepositories - } - - if ($Visibility -eq 'selected') { - if (-not $SelectedRepositories) { - throw 'You must specify the -SelectedRepositories parameter when using the -Visibility selected switch.' - } - $body['selected_repository_ids'] = $SelectedRepositories - } - - $inputObject = @{ - Method = 'PATCH' - APIEndpoint = "/orgs/$Owner/actions/variables/$Name" - Body = $body - Context = $Context - } - - if ($PSCmdlet.ShouldProcess("variable [$Name] on [$Owner]", 'Update')) { - $null = Invoke-GitHubAPI @inputObject - } - } - - end { - Write-Debug "[$stackPath] - End" - } -} diff --git a/src/functions/private/Variables/Update-GitHubVariableOnRepository.ps1 b/src/functions/private/Variables/Update-GitHubVariableOnRepository.ps1 deleted file mode 100644 index ba97a4952..000000000 --- a/src/functions/private/Variables/Update-GitHubVariableOnRepository.ps1 +++ /dev/null @@ -1,78 +0,0 @@ -function Update-GitHubVariableOnRepository { - <# - .SYNOPSIS - Update a repository variable. - - .DESCRIPTION - Updates a repository variable that you can reference in a GitHub Actions workflow. - Authenticated users must have collaborator access to a repository to create, update, or read variables. - OAuth app tokens and personal access tokens (classic) need the `repo` scope to use this endpoint. - - .EXAMPLE - Update-GitHubVariableOnRepository -Owner 'octocat' -Repository 'Hello-World' -Name 'HOST_NAME' -Value 'github.com' -Context $GitHubContext - - Updates the repository variable named `HOST_NAME` with the value `github.com` in the specified repository. - - .LINK - [Update a repository variable](https://docs.github.com/rest/actions/variables#update-a-repository-variable) - #> - [OutputType([void])] - [CmdletBinding(SupportsShouldProcess)] - param( - # The account owner of the repository. The name is not case sensitive. - [Parameter(Mandatory)] - [string] $Owner, - - # The name of the repository. The name is not case sensitive. - [Parameter(Mandatory)] - [string] $Repository, - - # The name of the variable. - [Parameter(Mandatory)] - [string] $Name, - - # The new name of the variable. - [Parameter()] - [string] $NewName, - - # The value of the variable. - [Parameter()] - [string] $Value, - - # The context to run the command in. Used to get the details for the API call. - # Can be either a string or a GitHubContext object. - [Parameter(Mandatory)] - [object] $Context - ) - - begin { - $stackPath = Get-PSCallStackPath - Write-Debug "[$stackPath] - Start" - Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - } - - process { - $body = @{} - if ($PSBoundParameters.ContainsKey('NewName')) { - $body.name = $NewName - } - if ($PSBoundParameters.ContainsKey('Value')) { - $body.value = $Value - } - - $inputObject = @{ - Method = 'PATCH' - APIEndpoint = "/repos/$Owner/$Repository/actions/variables/$Name" - Body = $body - Context = $Context - } - - if ($PSCmdlet.ShouldProcess("variable [$Name] on [$Owner/$Repository]", 'Update')) { - $null = Invoke-GitHubAPI @inputObject - } - } - - end { - Write-Debug "[$stackPath] - End" - } -} diff --git a/src/functions/public/Variables/Get-GitHubVariable.ps1 b/src/functions/public/Variables/Get-GitHubVariable.ps1 deleted file mode 100644 index 4b22b2261..000000000 --- a/src/functions/public/Variables/Get-GitHubVariable.ps1 +++ /dev/null @@ -1,195 +0,0 @@ -function Get-GitHubVariable { - <# - .SYNOPSIS - Retrieves a variable from GitHub based on the specified scope. - - .DESCRIPTION - Gets a variable from GitHub, which can be at the organization, repository, or environment level. - This function determines the appropriate API call based on the provided parameters. - Authenticated users must have the required access rights to read variables. - OAuth tokens and personal access tokens (classic) need the `repo` scope for repositories, - `admin:org` for organizations, and collaborator access for environments. - - .EXAMPLE - Get-GitHubVariable -Owner 'octocat' -Name 'HOST_NAME' -Context $GitHubContext - - Output: - ```powershell - Name : HOST_NAME - Value : github.com - Owner : octocat - Repository : - Environment : - ``` - - Retrieves the specified variable from the organization level. - - .EXAMPLE - Get-GitHubVariable -Owner 'octocat' -Repository 'Hello-World' -Name 'GUID' -Context $GitHubContext - - Output: - ```powershell - Name : GUID - Value : 354aa0b0-65b1-46c8-9c3e-1576f4167a41 - Owner : octocat - Repository : Hello-World - Environment : - ``` - - Retrieves the specified variable from the repository level. - - .EXAMPLE - Get-GitHubVariable -Owner 'octocat' -Repository 'Hello-World' -Environment 'dev' -Name 'DB_SERVER' -Context $GitHubContext - - Output: - ```powershell - Name : DB_SERVER - Value : db.example.com - Owner : octocat - Repository : Hello-World - Environment : dev - ``` - - Retrieves the specified variable from the environment level within a repository. - - .EXAMPLE - Get-GitHubVariable -Owner 'octocat' -Context $GitHubContext - - Output: - ```powershell - Name : MAX_THREADS - Value : 10 - Owner : octocat - Repository : - Environment : - - Name : API_TIMEOUT - Value : 30 - Owner : octocat - Repository : - Environment : - ``` - - Retrieves all variables available at the organization level. - - .EXAMPLE - Get-GitHubVariable -Owner 'octocat' -Repository 'Hello-World' -Context $GitHubContext - - Output: - ```powershell - Name : LOG_LEVEL - Value : INFO - Owner : octocat - Repository : Hello-World - Environment : - - Name : FEATURE_FLAG - Value : Enabled - Owner : octocat - Repository : Hello-World - Environment : - ``` - - Retrieves all variables available at the repository level. - - .EXAMPLE - Get-GitHubVariable -Owner 'octocat' -Repository 'Hello-World' -Environment 'staging' -Context $GitHubContext - - Output: - ```powershell - Name : CACHE_DURATION - Value : 3600 - Owner : octocat - Repository : Hello-World - Environment : staging - - Name : CONNECTION_RETRIES - Value : 5 - Owner : octocat - Repository : Hello-World - Environment : staging - ``` - - Retrieves all variables available in the 'staging' environment within the repository. - - .OUTPUTS - GitHubVariable - - .NOTES - An object representing the GitHub variable, containing Name, Value, Owner, - Repository, and Environment details. - - .LINK - https://psmodule.io/GitHub/Functions/Variables/Get-GitHubVariable - #> - [OutputType([GitHubVariable])] - [CmdletBinding()] - param( - # The account owner of the repository. The name is not case sensitive. - [Parameter(Mandatory, ParameterSetName = 'Organization')] - [Parameter(Mandatory, ParameterSetName = 'Repository')] - [Parameter(Mandatory, ParameterSetName = 'Environment')] - [Alias('Organization', 'User')] - [string] $Owner, - - # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter(Mandatory, ParameterSetName = 'Repository')] - [Parameter(Mandatory, ParameterSetName = 'Environment')] - [string] $Repository, - - # The name of the environment. - [Parameter(Mandatory, ParameterSetName = 'Environment')] - [string] $Environment, - - # The name of the variable. - [Parameter()] - [SupportsWildcards()] - [string] $Name = '*', - - # List all variables that are inherited. - [Parameter()] - [switch] $All, - - # The context to run the command in. Used to get the details for the API call. - # Can be either a string or a GitHubContext object. - [Parameter()] - [object] $Context = (Get-GitHubContext) - ) - - begin { - $stackPath = Get-PSCallStackPath - Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context - Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - } - - process { - $variables = @() - switch ($PSCmdlet.ParameterSetName) { - 'Organization' { - $variables += Get-GitHubVariableOwnerList -Owner $Owner -Context $Context - break - } - 'Repository' { - if ($All) { - $variables += Get-GitHubVariableFromOrganization -Owner $Owner -Repository $Repository -Context $Context - } - $variables += Get-GitHubVariableRepositoryList -Owner $Owner -Repository $Repository -Context $Context - break - } - 'Environment' { - if ($All) { - $variables += Get-GitHubVariableFromOrganization -Owner $Owner -Repository $Repository -Context $Context - $variables += Get-GitHubVariableRepositoryList -Owner $Owner -Repository $Repository -Context $Context - } - $variables += Get-GitHubVariableEnvironmentList -Owner $Owner -Repository $Repository -Environment $Environment -Context $Context - break - } - } - $variables | Where-Object { $_.Name -like $Name } - } - - end { - Write-Debug "[$stackPath] - End" - } -} diff --git a/src/functions/public/Variables/New-GitHubVariable.ps1 b/src/functions/public/Variables/New-GitHubVariable.ps1 deleted file mode 100644 index 77700b9dc..000000000 --- a/src/functions/public/Variables/New-GitHubVariable.ps1 +++ /dev/null @@ -1,141 +0,0 @@ -function New-GitHubVariable { - <# - .SYNOPSIS - Creates a GitHub Actions variable at the organization, repository, or environment level. - - .DESCRIPTION - This function creates a GitHub Actions variable that can be referenced in a workflow. The variable can be scoped to an organization, - repository, or environment. - - - Organization-level variables require the `admin:org` scope for OAuth tokens and personal access tokens (classic). If the repository is - private, the `repo` scope is also required. - - Repository-level variables require the `repo` scope. - - Environment-level variables require collaborator access to the repository. - - .EXAMPLE - New-GitHubVariable -Owner 'octocat' -Repository 'Hello-World' -Name 'HOST_NAME' -Value 'github.com' -Context $GitHubContext - - Creates a new repository variable named `HOST_NAME` with the value `github.com` in the specified repository. - - .EXAMPLE - New-GitHubVariable -Owner 'octocat' -Name 'HOST_NAME' -Value 'github.com' -Visibility 'all' -Context $GitHubContext - - Creates a new organization variable named `HOST_NAME` with the value `github.com` and - makes it available to all repositories in the organization. - - .EXAMPLE - New-GitHubVariable -Owner 'octocat' -Repository 'Hello-World' -Environment 'dev' -Name 'HOST_NAME' -Value 'github.com' -Context $GitHubContext - - Creates a new environment variable named `HOST_NAME` with the value `github.com` in the specified environment. - - .LINK - https://psmodule.io/GitHub/Functions/Variables/New-GitHubVariable/ - #> - [Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSShouldProcess', '', Scope = 'Function', - Justification = 'This check is performed in the private functions.' - )] - [OutputType([GitHubVariable])] - [CmdletBinding(SupportsShouldProcess)] - param( - # The account owner of the repository. The name is not case sensitive. - [Parameter(Mandatory, ParameterSetName = 'Organization')] - [Parameter(Mandatory, ParameterSetName = 'Repository')] - [Parameter(Mandatory, ParameterSetName = 'Environment')] - [Alias('Organization', 'User')] - [string] $Owner, - - # The name of the repository. The name is not case sensitive. - [Parameter(Mandatory, ParameterSetName = 'Repository')] - [Parameter(Mandatory, ParameterSetName = 'Environment')] - [string] $Repository, - - # The name of the repository environment. - [Parameter(Mandatory, ParameterSetName = 'Environment')] - [string] $Environment, - - # The name of the variable. - [Parameter(Mandatory)] - [string] $Name, - - # The value of the variable. - [Parameter(Mandatory)] - [string] $Value, - - # The visibility of the variable. Can be `private`, `selected`, or `all`. - # `private` - The variable is only available to the organization. - # `selected` - The variable is available to selected repositories. - # `all` - The variable is available to all repositories in the organization. - [Parameter(ParameterSetName = 'Organization')] - [ValidateSet('private', 'selected', 'all')] - [string] $Visibility = 'private', - - # The IDs of the repositories to which the variable is available. - # This parameter is only used when the `-Visibility` parameter is set to `selected`. - [Parameter(ParameterSetName = 'Organization')] - [UInt64[]] $SelectedRepositories, - - # The context to run the command in. Used to get the details for the API call. - # Can be either a string or a GitHubContext object. - [Parameter()] - [object] $Context = (Get-GitHubContext) - ) - - begin { - $stackPath = Get-PSCallStackPath - Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context - Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - } - - process { - $params = @{ - Owner = $Owner - Repository = $Repository - Environment = $Environment - Name = $Name - Value = $Value - SelectedRepositories = $SelectedRepositories - Context = $Context - ErrorAction = 'Stop' - } - $params | Remove-HashtableEntry -NullOrEmptyValues - switch ($PSCmdlet.ParameterSetName) { - 'Organization' { - $params.Visibility = $Visibility - New-GitHubVariableOnOwner @params - break - } - 'Repository' { - New-GitHubVariableOnRepository @params - break - } - 'Environment' { - New-GitHubVariableOnEnvironment @params - break - } - } - $params = @{ - Owner = $Owner - Repository = $Repository - Environment = $Environment - Name = $Name - Context = $Context - } - $params | Remove-HashtableEntry -NullOrEmptyValues - - for ($i = 0; $i -le 5; $i++) { - Start-Sleep -Seconds 1 - $tmp = $script:GitHub.Config.RetryCount - $script:GitHub.Config.RetryCount = 5 - $result = Get-GitHubVariable @params - $script:GitHub.Config.RetryCount = $tmp - if ($result) { break } - } - $result - } - - end { - Write-Debug "[$stackPath] - End" - } -} diff --git a/src/functions/public/Variables/Remove-GitHubVariable.ps1 b/src/functions/public/Variables/Remove-GitHubVariable.ps1 deleted file mode 100644 index 39fdfe50a..000000000 --- a/src/functions/public/Variables/Remove-GitHubVariable.ps1 +++ /dev/null @@ -1,169 +0,0 @@ -function Remove-GitHubVariable { - <# - .SYNOPSIS - Deletes a GitHub variable from an organization, repository, or environment. - - .DESCRIPTION - Deletes a GitHub variable based on the provided scope (organization, repository, or environment). - - Supports pipeline input from Get-GitHubVariable or direct array input. - - Authenticated users must have collaborator access to a repository to manage variables. - OAuth tokens and personal access tokens (classic) require specific scopes: - - `admin:org` for organization-level variables. - - `repo` for repository and environment-level variables. - - .EXAMPLE - Get-GitHubVariable -Owner 'octocat' -Repository 'Hello-World' | Remove-GitHubVariable - - Removes all variables retrieved from the specified repository. - - .EXAMPLE - Remove-GitHubVariable -Owner 'octocat' -Name 'HOST_NAME' -Context $GitHubContext - - Deletes the specified variable from the specified organization. - - .EXAMPLE - Remove-GitHubVariable -Variable $variablesArray - - Removes all variables provided in the array. - - .INPUTS - GitHubVariable - - .OUTPUTS - void - - .LINK - https://psmodule.io/GitHub/Functions/Variables/Remove-GitHubVariable/ - #> - [Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSShouldProcess', '', Scope = 'Function', - Justification = 'This check is performed in the private functions.' - )] - [OutputType([void])] - [CmdletBinding(SupportsShouldProcess)] - param( - [Parameter(Mandatory, ParameterSetName = 'Organization', ValueFromPipelineByPropertyName)] - [Parameter(Mandatory, ParameterSetName = 'Repository', ValueFromPipelineByPropertyName)] - [Parameter(Mandatory, ParameterSetName = 'Environment', ValueFromPipelineByPropertyName)] - [Alias('Organization', 'User')] - [string] $Owner, - - [Parameter(Mandatory, ParameterSetName = 'Repository', ValueFromPipelineByPropertyName)] - [Parameter(Mandatory, ParameterSetName = 'Environment', ValueFromPipelineByPropertyName)] - [string] $Repository, - - [Parameter(Mandatory, ParameterSetName = 'Environment', ValueFromPipelineByPropertyName)] - [string] $Environment, - - [Parameter(Mandatory, ValueFromPipelineByPropertyName)] - [string] $Name, - - [Parameter(ValueFromPipelineByPropertyName)] - [object] $Context = (Get-GitHubContext), - - [Parameter(Mandatory, ParameterSetName = 'ArrayInput', ValueFromPipeline)] - [GitHubVariable[]] $InputObject - ) - - begin { - $stackPath = Get-PSCallStackPath - Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context - Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - } - - process { - switch ($PSCmdlet.ParameterSetName) { - 'ArrayInput' { - foreach ($item in $InputObject) { - if ($item.Environment) { - $params = @{ - Owner = $item.Owner - Repository = $item.Repository - Environment = $item.Environment - Name = $item.Name - Context = $Context - } - Remove-GitHubVariableOnEnvironment @params - } elseif ($item.Repository) { - $params = @{ - Owner = $item.Owner - Repository = $item.Repository - Name = $item.Name - Context = $Context - } - Remove-GitHubVariableOnRepository @params - } else { - $params = @{ - Owner = $item.Owner - Name = $item.Name - Context = $Context - } - Remove-GitHubVariableOnOwner @params - } - $scopeParam = @{ - Owner = $item.Owner - Repository = $item.Repository - Environment = $item.Environment - Context = $Context - } - $scopeParam | Remove-HashtableEntry -NullOrEmptyValues - for ($i = 0; $i -le 10; $i++) { - Start-Sleep -Seconds 1 - $variable = Get-GitHubVariable @scopeParam | Where-Object { $_.Name -eq $Name } - if (-not $variable) { break } - } - } - return - } - 'Organization' { - $params = @{ - Owner = $Owner - Name = $Name - Context = $Context - } - Remove-GitHubVariableOnOwner @params - break - } - 'Repository' { - $params = @{ - Owner = $Owner - Repository = $Repository - Name = $Name - Context = $Context - } - Remove-GitHubVariableOnRepository @params - break - } - 'Environment' { - $params = @{ - Owner = $Owner - Repository = $Repository - Environment = $Environment - Name = $Name - Context = $Context - } - Remove-GitHubVariableOnEnvironment @params - break - } - } - - $scopeParam = @{ - Owner = $Owner - Repository = $Repository - Environment = $Environment - } - $scopeParam | Remove-HashtableEntry -NullOrEmptyValues - for ($i = 0; $i -le 10; $i++) { - Start-Sleep -Seconds 1 - $variable = Get-GitHubVariable @scopeParam | Where-Object { $_.Name -eq $Name } - if (-not $variable) { break } - } - } - - end { - Write-Debug "[$stackPath] - End" - } -} diff --git a/src/functions/public/Variables/Set-GitHubVariable.ps1 b/src/functions/public/Variables/Set-GitHubVariable.ps1 deleted file mode 100644 index c893271f1..000000000 --- a/src/functions/public/Variables/Set-GitHubVariable.ps1 +++ /dev/null @@ -1,126 +0,0 @@ -function Set-GitHubVariable { - <# - .SYNOPSIS - Creates or updates a GitHub Actions variable at the organization, repository, or environment level. - - .DESCRIPTION - This function checks if a GitHub Actions variable exists at the specified level (organization, repository, or environment). - If the variable exists, it updates it with the new value. If it does not exist, it creates a new variable. - - - Organization-level variables require the `admin:org` scope for OAuth tokens and personal access tokens (classic). If the repository is - private, the `repo` scope is also required. - - Repository-level variables require the `repo` scope. - - Environment-level variables require collaborator access to the repository. - - .EXAMPLE - Set-GitHubVariable -Owner 'octocat' -Repository 'Hello-World' -Name 'HOST_NAME' -Value 'github.com' -Context $GitHubContext - - Creates or updates a repository variable named `HOST_NAME` with the value `github.com` in the specified repository. - - .EXAMPLE - Set-GitHubVariable -Owner 'octocat' -Name 'HOST_NAME' -Value 'github.com' -Visibility 'all' -Context $GitHubContext - - Creates or updates an organization variable named `HOST_NAME` with the value `github.com` and - makes it available to all repositories in the organization. - - .EXAMPLE - Set-GitHubVariable -Owner 'octocat' -Repository 'Hello-World' -Environment 'dev' -Name 'HOST_NAME' -Value 'github.com' -Context $GitHubContext - - Creates or updates an environment variable named `HOST_NAME` with the value `github.com` in the specified environment. - - .LINK - https://psmodule.io/GitHub/Functions/Variables/Set-GitHubVariable/ - #> - [Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSShouldProcess', '', Scope = 'Function', - Justification = 'This check is performed in the private functions.' - )] - [OutputType([GitHubVariable])] - [CmdletBinding(SupportsShouldProcess)] - param( - # The account owner of the repository. The name is not case sensitive. - [Parameter(Mandatory, ParameterSetName = 'Organization')] - [Parameter(Mandatory, ParameterSetName = 'Repository')] - [Parameter(Mandatory, ParameterSetName = 'Environment')] - [Alias('Organization', 'User')] - [string] $Owner, - - # The name of the repository. The name is not case sensitive. - [Parameter(Mandatory, ParameterSetName = 'Repository')] - [Parameter(Mandatory, ParameterSetName = 'Environment')] - [string] $Repository, - - # The name of the repository environment. - [Parameter(Mandatory, ParameterSetName = 'Environment')] - [string] $Environment, - - # The name of the variable. - [Parameter(Mandatory)] - [string] $Name, - - # The value of the variable. - [Parameter()] - [string] $Value, - - # The visibility of the variable when updating an organization variable. - # Can be `private`, `selected`, or `all`. - [Parameter(ParameterSetName = 'Organization')] - [ValidateSet('private', 'selected', 'all')] - [string] $Visibility = 'private', - - # The IDs of the repositories to which the variable is available. - # Used only when the `-Visibility` parameter is set to `selected`. - [Parameter(ParameterSetName = 'Organization')] - [UInt64[]] $SelectedRepositories, - - # The context to run the command in. Can be either a string or a GitHubContext object. - [Parameter()] - [object] $Context = (Get-GitHubContext) - ) - - begin { - $stackPath = Get-PSCallStackPath - Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context - Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - } - - process { - $getParams = @{ - Owner = $Owner - Repository = $Repository - Environment = $Environment - Context = $Context - } - $getParams | Remove-HashtableEntry -NullOrEmptyValues - - $params = @{ - Owner = $Owner - Repository = $Repository - Environment = $Environment - Name = $Name - Value = $Value - SelectedRepositories = $SelectedRepositories - Context = $Context - ErrorAction = 'Stop' - } - if ($PSCmdlet.ParameterSetName -eq 'Organization') { - $params.Visibility = $Visibility - } - $params | Remove-HashtableEntry -NullOrEmptyValues - - $variable = Get-GitHubVariable @getParams | Where-Object { $_.Name -eq $Name } - - if ($variable) { - $null = Update-GitHubVariable @params - } else { - $null = New-GitHubVariable @params - } - - Get-GitHubVariable @getParams -Name $Name - } - - end { - Write-Debug "[$stackPath] - End" - } -} diff --git a/src/functions/public/Variables/Update-GitHubVariable.ps1 b/src/functions/public/Variables/Update-GitHubVariable.ps1 deleted file mode 100644 index b0c0b6a50..000000000 --- a/src/functions/public/Variables/Update-GitHubVariable.ps1 +++ /dev/null @@ -1,141 +0,0 @@ -function Update-GitHubVariable { - <# - .SYNOPSIS - Update a GitHub variable at the organization, repository, or environment level. - - .DESCRIPTION - Updates a GitHub Actions variable that can be referenced in workflows. This function supports updating variables - at different levels: organization, repository, or environment. It delegates the update process to the appropriate - private function based on the specified parameters. - - To modify an organization variable, users must have `admin:org` scope. Repository variables require `repo` scope, - and environment variables require collaborator access. - - .EXAMPLE - Update-GitHubVariable -Owner 'octocat' -Repository 'Hello-World' -Name 'HOST_NAME' -Value 'github.com' - - Updates the repository variable named `HOST_NAME` with the value `github.com` in the specified repository. - - .EXAMPLE - Update-GitHubVariable -Owner 'octocat' -Name 'HOST_NAME' -Value 'github.com' -Visibility 'private' - - Updates the organization variable named `HOST_NAME` with the value `github.com`, making it private. - - .EXAMPLE - Update-GitHubVariable -Owner 'octocat' -Repository 'Hello-World' -Environment 'dev' -Name 'HOST_NAME' -Value 'github.com' - - Updates the environment variable named `HOST_NAME` with the value `github.com` in the specified environment. - - .LINK - https://psmodule.io/GitHub/Functions/Variables/Update-GitHubVariable/ - #> - [Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSShouldProcess', '', Scope = 'Function', - Justification = 'This check is performed in the private functions.' - )] - [OutputType([GitHubVariable])] - [CmdletBinding(SupportsShouldProcess)] - param( - # The account owner of the repository. The name is not case sensitive. - [Parameter(Mandatory, ParameterSetName = 'Organization')] - [Parameter(Mandatory, ParameterSetName = 'Repository')] - [Parameter(Mandatory, ParameterSetName = 'Environment')] - [Alias('Organization', 'User')] - [string] $Owner, - - # The name of the repository. The name is not case sensitive. - [Parameter(Mandatory, ParameterSetName = 'Repository')] - [Parameter(Mandatory, ParameterSetName = 'Environment')] - [string] $Repository, - - # The name of the repository environment. - [Parameter(Mandatory, ParameterSetName = 'Environment')] - [string] $Environment, - - # The name of the variable. - [Parameter(Mandatory)] - [string] $Name, - - # The new name of the variable. - [Parameter()] - [string] $NewName, - - # The value of the variable. - [Parameter()] - [string] $Value, - - # The visibility of the variable when updating an organization variable. - # Can be `private`, `selected`, or `all`. - [Parameter(ParameterSetName = 'Organization')] - [ValidateSet('private', 'selected', 'all')] - [string] $Visibility = 'private', - - # The IDs of the repositories to which the variable is available. - # Used only when the `-Visibility` parameter is set to `selected`. - [Parameter(ParameterSetName = 'Organization')] - [UInt64[]] $SelectedRepositories, - - # If specified, the function will return the updated variable object. - [Parameter()] - [switch] $PassThru, - - # The context to run the command in. Can be either a string or a GitHubContext object. - [Parameter()] - [object] $Context = (Get-GitHubContext) - ) - - begin { - $stackPath = Get-PSCallStackPath - Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context - Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - } - - process { - $params = @{ - Owner = $Owner - Repository = $Repository - Environment = $Environment - Name = $Name - Context = $Context - NewName = $NewName - Value = $Value - SelectedRepositories = $SelectedRepositories - ErrorAction = 'Stop' - } - $params | Remove-HashtableEntry -NullOrEmptyValues - switch ($PSCmdlet.ParameterSetName) { - 'Organization' { - $params.Visibility = $Visibility - Update-GitHubVariableOnOwner @params - break - } - 'Repository' { - Update-GitHubVariableOnRepository @params - break - } - 'Environment' { - Update-GitHubVariableOnEnvironment @params - break - } - } - if ($PassThru) { - $params = @{ - Owner = $Owner - Repository = $Repository - Environment = $Environment - Name = $PSBoundParameters.ContainsKey('NewName') ? $NewName : $Name - Context = $Context - } - $params | Remove-HashtableEntry -NullOrEmptyValues - $tmp = $script:GitHub.Config.RetryCount - $script:GitHub.Config.RetryCount = 5 - Get-GitHubVariable @params - $script:GitHub.Config.RetryCount = $tmp - } - } - - end { - Write-Debug "[$stackPath] - End" - } -} diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 deleted file mode 100644 index 15d9db755..000000000 --- a/tests/Variables.Tests.ps1 +++ /dev/null @@ -1,931 +0,0 @@ -#Requires -Modules @{ ModuleName = 'Pester'; RequiredVersion = '5.7.1' } - -[Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSUseDeclaredVarsMoreThanAssignments', '', - Justification = 'Pester grouping syntax: known issue.' -)] -[Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSAvoidUsingConvertToSecureStringWithPlainText', '', - Justification = 'Used to create a secure string for testing.' -)] -[Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSAvoidUsingWriteHost', '', - Justification = 'Outputs into logs from the tests.' -)] -[CmdletBinding()] -param() - -BeforeAll { - $DebugPreference = 'Continue' - $VerbosePreference = 'Continue' - $testName = 'VariableTest' - $os = Get-GitHubRunnerData | Select-Object -ExpandProperty OS -} - -Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT)' { - BeforeAll { - Connect-GitHubAccount -Token $env:TEST_USER_USER_FG_PAT - LogGroup 'Context' { Write-Host "$(Get-GitHubContext | Format-List | Out-String)" } - $owner = 'psmodule-user' - $testType = 'USER_FG_PAT' - $repoName = "$testName-$os-$testType" - $varName = "$testName`_$os`_$testType" - $variablePrefix = "$varName`_" - $environmentName = "$testName-$os-$testType" - $repo = New-GitHubRepository -Name $repoName -AllowSquashMerge - } - AfterAll { - Remove-GitHubRepository -Owner $owner -Name $repoName -Confirm:$false - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - Context 'Repository' { - BeforeAll { - $scope = @{ - Owner = $owner - Repository = $repoName - } - Set-GitHubVariable @scope -Name $varName -Value 'repository' - } - It 'Set-GitHubVariable' { - $param = @{ - Name = "$variablePrefix`TestVariable" - Value = 'TestValue' - } - $result = Set-GitHubVariable @param @scope - $result = Set-GitHubVariable @param @scope - $result | Should -Not -BeNullOrEmpty - } - - It 'Update-GitHubVariable' { - $param = @{ - Name = "$variablePrefix`TestVariable" - Value = 'TestValue1234' - } - $result = Update-GitHubVariable @param @scope -PassThru - $result | Should -Not -BeNullOrEmpty - } - - It 'New-GitHubVariable' { - $param = @{ - Name = "$variablePrefix`TestVariable2" - Value = 'TestValue123' - } - $result = New-GitHubVariable @param @scope - $result | Should -Not -BeNullOrEmpty - } - - It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($result | Format-Table | Out-String)" - $result | Should -Not -BeNullOrEmpty - } - - It 'Remove-GitHubVariable' { - $before = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($before | Format-Table | Out-String)" - $before | Remove-GitHubVariable - $after = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($after | Format-Table | Out-String)" - $after.Count | Should -Be 0 - } - } - Context 'Environment' { - BeforeAll { - $scope = @{ - Owner = $owner - Repository = $repoName - Environment = $environmentName - } - Set-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName - Set-GitHubVariable @scope -Name $varName -Value 'environment' - } - It 'Set-GitHubVariable' { - $param = @{ - Name = "$variablePrefix`TestVariable" - Value = 'TestValue' - } - $result = Set-GitHubVariable @param @scope - $result = Set-GitHubVariable @param @scope - $result | Should -Not -BeNullOrEmpty - } - - It 'Update-GitHubVariable' { - $param = @{ - Name = "$variablePrefix`TestVariable" - Value = 'TestValue1234' - } - $result = Update-GitHubVariable @param @scope -PassThru - $result | Should -Not -BeNullOrEmpty - } - - It 'New-GitHubVariable' { - $param = @{ - Name = "$variablePrefix`TestVariable2" - Value = 'TestValue123' - } - $result = New-GitHubVariable @param @scope - $result | Should -Not -BeNullOrEmpty - } - - It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($result | Format-Table | Out-String)" - $result | Should -Not -BeNullOrEmpty - } - - It 'Remove-GitHubVariable' { - $before = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($before | Format-Table | Out-String)" - $before | Remove-GitHubVariable - $after = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($after | Format-Table | Out-String)" - $after.Count | Should -Be 0 - } - } -} - -Describe 'As a user - Fine-grained PAT token - organization account access (ORG_FG_PAT)' { - BeforeAll { - Connect-GitHubAccount -Token $env:TEST_USER_ORG_FG_PAT - LogGroup 'Context' { Write-Host "$(Get-GitHubContext | Format-List | Out-String)" } - $owner = 'psmodule-test-org2' - $testType = 'ORG_FG_PAT' - $repoName = "$testName-$os-$testType" - $varName = "$testName`_$os`_$testType" - $variablePrefix = "$varName`_" - $environmentName = "$testName-$os-$testType" - $repo = New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge - } - AfterAll { - Remove-GitHubRepository -Owner $owner -Name $repoName -Confirm:$false - Get-GitHubVariable -Owner $owner -Name "*$os*" | Remove-GitHubVariable - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - Context 'Organization' { - BeforeAll { - $scope = @{ - Owner = $owner - } - Set-GitHubVariable @scope -Name $varName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id - } - It 'Set-GitHubVariable' { - $param = @{ - Name = "$variablePrefix`TestVariable" - Value = 'TestValue' - } - $result = Set-GitHubVariable @param @scope - $result = Set-GitHubVariable @param @scope - $result | Should -Not -BeNullOrEmpty - } - - It 'Update-GitHubVariable' { - $param = @{ - Name = "$variablePrefix`TestVariable" - Value = 'TestValue1234' - Visibility = 'all' - } - $result = Update-GitHubVariable @param @scope -PassThru - $result | Should -Not -BeNullOrEmpty - } - - It 'New-GitHubVariable' { - $param = @{ - Name = "$variablePrefix`TestVariable2" - Value = 'TestValue123' - } - $result = New-GitHubVariable @param @scope - $result | Should -Not -BeNullOrEmpty - } - - It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($result | Format-Table | Out-String)" - $result | Should -Not -BeNullOrEmpty - } - - It 'Get-GitHubVariable -All' { - $result = Get-GitHubVariable @scope -Name "*$os*" -All - Write-Host "$($result | Format-Table | Out-String)" - $result | Should -Not -BeNullOrEmpty - } - - It 'Remove-GitHubVariable' { - $before = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($before | Format-Table | Out-String)" - $before | Remove-GitHubVariable - $after = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($after | Format-Table | Out-String)" - $after.Count | Should -Be 0 - } - } - Context 'Repository' { - BeforeAll { - $scope = @{ - Owner = $owner - Repository = $repoName - } - Set-GitHubVariable @scope -Name $varName -Value 'repository' - } - It 'Set-GitHubVariable' { - $param = @{ - Name = "$variablePrefix`TestVariable" - Value = 'TestValue' - } - $result = Set-GitHubVariable @param @scope - $result = Set-GitHubVariable @param @scope - $result | Should -Not -BeNullOrEmpty - } - - It 'Update-GitHubVariable' { - $param = @{ - Name = "$variablePrefix`TestVariable" - Value = 'TestValue1234' - } - $result = Update-GitHubVariable @param @scope -PassThru - $result | Should -Not -BeNullOrEmpty - } - - It 'New-GitHubVariable' { - $param = @{ - Name = "$variablePrefix`TestVariable2" - Value = 'TestValue123' - } - $result = New-GitHubVariable @param @scope - $result | Should -Not -BeNullOrEmpty - } - - It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($result | Format-Table | Out-String)" - $result | Should -Not -BeNullOrEmpty - } - - It 'Get-GitHubVariable -All' { - $result = Get-GitHubVariable @scope -Name "*$os*" -All - Write-Host "$($result | Format-Table | Out-String)" - $result | Should -Not -BeNullOrEmpty - } - - It 'Remove-GitHubVariable' { - $before = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($before | Format-Table | Out-String)" - $before | Remove-GitHubVariable - $after = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($after | Format-Table | Out-String)" - $after.Count | Should -Be 0 - } - } - Context 'Environment' { - BeforeAll { - $scope = @{ - Owner = $owner - Repository = $repoName - Environment = $environmentName - } - Set-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName - Set-GitHubVariable @scope -Name $varName -Value 'environment' - } - It 'Set-GitHubVariable' { - $param = @{ - Name = "$variablePrefix`TestVariable" - Value = 'TestValue' - } - $result = Set-GitHubVariable @param @scope - $result = Set-GitHubVariable @param @scope - $result | Should -Not -BeNullOrEmpty - } - - It 'Update-GitHubVariable' { - $param = @{ - Name = "$variablePrefix`TestVariable" - Value = 'TestValue1234' - } - $result = Update-GitHubVariable @param @scope -PassThru - $result | Should -Not -BeNullOrEmpty - } - - It 'New-GitHubVariable' { - $param = @{ - Name = "$variablePrefix`TestVariable2" - Value = 'TestValue123' - } - $result = New-GitHubVariable @param @scope - $result | Should -Not -BeNullOrEmpty - } - - It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($result | Format-Table | Out-String)" - $result | Should -Not -BeNullOrEmpty - } - - It 'Get-GitHubVariable -All' { - $result = Get-GitHubVariable @scope -Name "*$os*" -All - Write-Host "$($result | Format-Table | Out-String)" - $result | Should -Not -BeNullOrEmpty - } - - It 'Remove-GitHubVariable' { - $before = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($before | Format-Table | Out-String)" - $before | Remove-GitHubVariable - $after = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($after | Format-Table | Out-String)" - $after.Count | Should -Be 0 - } - } -} - -Describe 'As a user - Classic PAT token (PAT)' { - BeforeAll { - Connect-GitHubAccount -Token $env:TEST_USER_PAT - LogGroup 'Context' { Write-Host "$(Get-GitHubContext | Format-List | Out-String)" } - $owner = 'psmodule-test-org2' - $testType = 'PAT' - $repoName = "$testName-$os-$testType" - $varName = "$testName`_$os`_$testType" - $variablePrefix = "$varName`_" - $environmentName = "$testName-$os-$testType" - $repo = New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge - } - AfterAll { - Remove-GitHubRepository -Owner $owner -Name $repoName -Confirm:$false - Get-GitHubVariable -Owner $owner -Name "*$os*" | Remove-GitHubVariable - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - Context 'Organization' { - BeforeAll { - $scope = @{ - Owner = $owner - } - Set-GitHubVariable @scope -Name $varName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id - } - It 'Set-GitHubVariable' { - $param = @{ - Name = "$variablePrefix`TestVariable" - Value = 'TestValue' - } - $result = Set-GitHubVariable @param @scope - $result = Set-GitHubVariable @param @scope - $result | Should -Not -BeNullOrEmpty - } - - It 'Update-GitHubVariable' { - $param = @{ - Name = "$variablePrefix`TestVariable" - Value = 'TestValue1234' - Visibility = 'all' - } - $result = Update-GitHubVariable @param @scope -PassThru - $result | Should -Not -BeNullOrEmpty - } - - It 'New-GitHubVariable' { - $param = @{ - Name = "$variablePrefix`TestVariable2" - Value = 'TestValue123' - } - $result = New-GitHubVariable @param @scope - $result | Should -Not -BeNullOrEmpty - } - - It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($result | Format-Table | Out-String)" - $result | Should -Not -BeNullOrEmpty - } - - It 'Get-GitHubVariable -All' { - $result = Get-GitHubVariable @scope -Name "*$os*" -All - Write-Host "$($result | Format-Table | Out-String)" - $result | Should -Not -BeNullOrEmpty - } - - It 'Remove-GitHubVariable' { - $before = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($before | Format-Table | Out-String)" - $before | Remove-GitHubVariable - $after = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($after | Format-Table | Out-String)" - $after.Count | Should -Be 0 - } - } - Context 'Repository' { - BeforeAll { - $scope = @{ - Owner = $owner - Repository = $repoName - } - Set-GitHubVariable @scope -Name $varName -Value 'repository' - } - It 'Set-GitHubVariable' { - $param = @{ - Name = "$variablePrefix`TestVariable" - Value = 'TestValue' - } - $result = Set-GitHubVariable @param @scope - $result = Set-GitHubVariable @param @scope - $result | Should -Not -BeNullOrEmpty - } - - It 'Update-GitHubVariable' { - $param = @{ - Name = "$variablePrefix`TestVariable" - Value = 'TestValue1234' - } - $result = Update-GitHubVariable @param @scope -PassThru - $result | Should -Not -BeNullOrEmpty - } - - It 'New-GitHubVariable' { - $param = @{ - Name = "$variablePrefix`TestVariable2" - Value = 'TestValue123' - } - $result = New-GitHubVariable @param @scope - $result | Should -Not -BeNullOrEmpty - } - - It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($result | Format-Table | Out-String)" - $result | Should -Not -BeNullOrEmpty - } - - It 'Get-GitHubVariable -All' { - $result = Get-GitHubVariable @scope -Name "*$os*" -All - Write-Host "$($result | Format-Table | Out-String)" - $result | Should -Not -BeNullOrEmpty - } - - It 'Remove-GitHubVariable' { - $before = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($before | Format-Table | Out-String)" - $before | Remove-GitHubVariable - $after = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($after | Format-Table | Out-String)" - $after.Count | Should -Be 0 - } - } - Context 'Environment' { - BeforeAll { - $scope = @{ - Owner = $owner - Repository = $repoName - Environment = $environmentName - } - Set-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName - Set-GitHubVariable @scope -Name $varName -Value 'environment' - } - It 'Set-GitHubVariable' { - $param = @{ - Name = "$variablePrefix`TestVariable" - Value = 'TestValue' - } - $result = Set-GitHubVariable @param @scope - $result = Set-GitHubVariable @param @scope - $result | Should -Not -BeNullOrEmpty - } - - It 'Update-GitHubVariable' { - $param = @{ - Name = "$variablePrefix`TestVariable" - Value = 'TestValue1234' - } - $result = Update-GitHubVariable @param @scope -PassThru - $result | Should -Not -BeNullOrEmpty - } - - It 'New-GitHubVariable' { - $param = @{ - Name = "$variablePrefix`TestVariable2" - Value = 'TestValue123' - } - $result = New-GitHubVariable @param @scope - $result | Should -Not -BeNullOrEmpty - } - - It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($result | Format-Table | Out-String)" - $result | Should -Not -BeNullOrEmpty - } - - It 'Get-GitHubVariable -All' { - $result = Get-GitHubVariable @scope -Name "*$os*" -All - Write-Host "$($result | Format-Table | Out-String)" - $result | Should -Not -BeNullOrEmpty - } - - It 'Remove-GitHubVariable' { - $before = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($before | Format-Table | Out-String)" - $before | Remove-GitHubVariable - $after = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($after | Format-Table | Out-String)" - $after.Count | Should -Be 0 - } - } -} - -Describe 'As GitHub Actions (GHA)' { - BeforeAll { - Connect-GitHubAccount - LogGroup 'Context' { Write-Host "$(Get-GitHubContext | Format-List | Out-String)" } - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - Context 'Variables' { - - } -} - -Describe 'As a GitHub App - Enterprise (APP_ENT)' { - BeforeAll { - Connect-GitHubAccount -ClientID $env:TEST_APP_ENT_CLIENT_ID -PrivateKey $env:TEST_APP_ENT_PRIVATE_KEY - LogGroup 'Context' { Write-Host "$(Get-GitHubContext | Format-List | Out-String)" } - $owner = 'psmodule-test-org3' - Connect-GitHubApp -Organization $owner -Default - LogGroup 'Context' { Write-Host "$(Get-GitHubContext | Format-List | Out-String)" } - $testType = 'APP_ENT' - $repoName = "$testName-$os-$testType" - $varName = "$testName`_$os`_$testType" - $variablePrefix = "$varName`_" - $environmentName = "$testName-$os-$testType" - $repo = New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge - } - AfterAll { - Remove-GitHubRepository -Owner $owner -Name $repoName -Confirm:$false - Get-GitHubVariable -Owner $owner -Name "*$os*" | Remove-GitHubVariable - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - Context 'Organization' { - BeforeAll { - $scope = @{ - Owner = $owner - } - Set-GitHubVariable @scope -Name $varName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id - } - - It 'Set-GitHubVariable' { - $param = @{ - Name = "$variablePrefix`TestVariable" - Value = 'TestValue' - } - $result = Set-GitHubVariable @param @scope - $result = Set-GitHubVariable @param @scope - $result | Should -Not -BeNullOrEmpty - } - - It 'Update-GitHubVariable' { - $param = @{ - Name = "$variablePrefix`TestVariable" - Value = 'TestValue1234' - Visibility = 'all' - } - $result = Update-GitHubVariable @param @scope -PassThru - $result | Should -Not -BeNullOrEmpty - } - - It 'New-GitHubVariable' { - $param = @{ - Name = "$variablePrefix`TestVariable2" - Value = 'TestValue123' - } - $result = New-GitHubVariable @param @scope - $result | Should -Not -BeNullOrEmpty - } - - It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($result | Format-Table | Out-String)" - $result | Should -Not -BeNullOrEmpty - } - - It 'Get-GitHubVariable -All' { - $result = Get-GitHubVariable @scope -Name "*$os*" -All - Write-Host "$($result | Format-Table | Out-String)" - $result | Should -Not -BeNullOrEmpty - } - - It 'Remove-GitHubVariable' { - $before = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($before | Format-Table | Out-String)" - $before | Remove-GitHubVariable - $after = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($after | Format-Table | Out-String)" - $after.Count | Should -Be 0 - } - } - Context 'Repository' { - BeforeAll { - $scope = @{ - Owner = $owner - Repository = $repoName - } - Set-GitHubVariable @scope -Name $varName -Value 'repository' - } - It 'Set-GitHubVariable' { - $param = @{ - Name = "$variablePrefix`TestVariable" - Value = 'TestValue' - } - $result = Set-GitHubVariable @param @scope - $result = Set-GitHubVariable @param @scope - $result | Should -Not -BeNullOrEmpty - } - - It 'Update-GitHubVariable' { - $param = @{ - Name = "$variablePrefix`TestVariable" - Value = 'TestValue1234' - } - $result = Update-GitHubVariable @param @scope -PassThru - $result | Should -Not -BeNullOrEmpty - } - - It 'New-GitHubVariable' { - $param = @{ - Name = "$variablePrefix`TestVariable2" - Value = 'TestValue123' - } - $result = New-GitHubVariable @param @scope - $result | Should -Not -BeNullOrEmpty - } - - It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($result | Format-Table | Out-String)" - $result | Should -Not -BeNullOrEmpty - } - - It 'Get-GitHubVariable -All' { - $result = Get-GitHubVariable @scope -Name "*$os*" -All - Write-Host "$($result | Format-Table | Out-String)" - $result | Should -Not -BeNullOrEmpty - } - - It 'Remove-GitHubVariable' { - $before = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($before | Format-Table | Out-String)" - $before | Remove-GitHubVariable - $after = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($after | Format-Table | Out-String)" - $after.Count | Should -Be 0 - } - } - Context 'Environment' { - BeforeAll { - $scope = @{ - Owner = $owner - Repository = $repoName - Environment = $environmentName - } - Set-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName - Set-GitHubVariable @scope -Name $varName -Value 'environment' - } - It 'Set-GitHubVariable' { - $param = @{ - Name = "$variablePrefix`TestVariable" - Value = 'TestValue' - } - $result = Set-GitHubVariable @param @scope - $result = Set-GitHubVariable @param @scope - $result | Should -Not -BeNullOrEmpty - } - - It 'Update-GitHubVariable' { - $param = @{ - Name = "$variablePrefix`TestVariable" - Value = 'TestValue1234' - } - $result = Update-GitHubVariable @param @scope -PassThru - $result | Should -Not -BeNullOrEmpty - } - - It 'New-GitHubVariable' { - $param = @{ - Name = "$variablePrefix`TestVariable2" - Value = 'TestValue123' - } - $result = New-GitHubVariable @param @scope - $result | Should -Not -BeNullOrEmpty - } - - It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($result | Format-Table | Out-String)" - $result | Should -Not -BeNullOrEmpty - } - - It 'Get-GitHubVariable -All' { - $result = Get-GitHubVariable @scope -Name "*$os*" -All - Write-Host "$($result | Format-Table | Out-String)" - $result | Should -Not -BeNullOrEmpty - } - - It 'Remove-GitHubVariable' { - $before = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($before | Format-Table | Out-String)" - $before | Remove-GitHubVariable - $after = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($after | Format-Table | Out-String)" - $after.Count | Should -Be 0 - } - } -} - -Describe 'As a GitHub App - Organization (APP_ORG)' { - BeforeAll { - Connect-GitHubAccount -ClientID $env:TEST_APP_ORG_CLIENT_ID -PrivateKey $env:TEST_APP_ORG_PRIVATE_KEY - LogGroup 'Context' { Write-Host "$(Get-GitHubContext | Format-List | Out-String)" } - $owner = 'psmodule-test-org' - Connect-GitHubApp -Organization $owner -Default - LogGroup 'Context' { Write-Host "$(Get-GitHubContext | Format-List | Out-String)" } - $testType = 'APP_ORG' - $repoName = "$testName-$os-$testType" - $varName = "$testName`_$os`_$testType" - $variablePrefix = "$varName`_" - $environmentName = "$testName-$os-$testType" - $repo = New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge - } - AfterAll { - Remove-GitHubRepository -Owner $owner -Name $repoName -Confirm:$false - Get-GitHubVariable -Owner $owner -Name "*$os*" | Remove-GitHubVariable - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - Context 'Organization' { - BeforeAll { - $scope = @{ - Owner = $owner - } - Set-GitHubVariable @scope -Name $varName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id - } - It 'Set-GitHubVariable' { - $param = @{ - Name = "$variablePrefix`TestVariable" - Value = 'TestValue' - } - $result = Set-GitHubVariable @param @scope - $result = Set-GitHubVariable @param @scope - $result | Should -Not -BeNullOrEmpty - } - - It 'Update-GitHubVariable' { - $param = @{ - Name = "$variablePrefix`TestVariable" - Value = 'TestValue1234' - Visibility = 'all' - } - $result = Update-GitHubVariable @param @scope -PassThru - $result | Should -Not -BeNullOrEmpty - } - - It 'New-GitHubVariable' { - $param = @{ - Name = "$variablePrefix`TestVariable2" - Value = 'TestValue123' - } - $result = New-GitHubVariable @param @scope - $result | Should -Not -BeNullOrEmpty - } - - It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($result | Format-Table | Out-String)" - $result | Should -Not -BeNullOrEmpty - } - - It 'Get-GitHubVariable -All' { - $result = Get-GitHubVariable @scope -Name "*$os*" -All - Write-Host "$($result | Format-Table | Out-String)" - $result | Should -Not -BeNullOrEmpty - } - - It 'Remove-GitHubVariable' { - $before = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($before | Format-Table | Out-String)" - $before | Remove-GitHubVariable - $after = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($after | Format-Table | Out-String)" - $after.Count | Should -Be 0 - } - } - Context 'Repository' { - BeforeAll { - $scope = @{ - Owner = $owner - Repository = $repoName - } - Set-GitHubVariable @scope -Name $varName -Value 'repository' - } - It 'Set-GitHubVariable' { - $param = @{ - Name = "$variablePrefix`TestVariable" - Value = 'TestValue' - } - $result = Set-GitHubVariable @param @scope - $result = Set-GitHubVariable @param @scope - $result | Should -Not -BeNullOrEmpty - } - - It 'Update-GitHubVariable' { - $param = @{ - Name = "$variablePrefix`TestVariable" - Value = 'TestValue1234' - } - $result = Update-GitHubVariable @param @scope -PassThru - $result | Should -Not -BeNullOrEmpty - } - - It 'New-GitHubVariable' { - $param = @{ - Name = "$variablePrefix`TestVariable2" - Value = 'TestValue123' - } - $result = New-GitHubVariable @param @scope - $result | Should -Not -BeNullOrEmpty - } - - It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($result | Format-Table | Out-String)" - $result | Should -Not -BeNullOrEmpty - } - - It 'Get-GitHubVariable -All' { - $result = Get-GitHubVariable @scope -Name "*$os*" -All - Write-Host "$($result | Format-Table | Out-String)" - $result | Should -Not -BeNullOrEmpty - } - - It 'Remove-GitHubVariable' { - $before = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($before | Format-Table | Out-String)" - $before | Remove-GitHubVariable - $after = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($after | Format-Table | Out-String)" - $after.Count | Should -Be 0 - } - } - Context 'Environment' { - BeforeAll { - $scope = @{ - Owner = $owner - Repository = $repoName - Environment = $environmentName - } - Set-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName - Set-GitHubVariable @scope -Name $varName -Value 'environment' - } - It 'Set-GitHubVariable' { - $param = @{ - Name = "$variablePrefix`TestVariable" - Value = 'TestValue' - } - $result = Set-GitHubVariable @param @scope - $result = Set-GitHubVariable @param @scope - $result | Should -Not -BeNullOrEmpty - } - - It 'Update-GitHubVariable' { - $param = @{ - Name = "$variablePrefix`TestVariable" - Value = 'TestValue1234' - } - $result = Update-GitHubVariable @param @scope -PassThru - $result | Should -Not -BeNullOrEmpty - } - - It 'New-GitHubVariable' { - $param = @{ - Name = "$variablePrefix`TestVariable2" - Value = 'TestValue123' - } - $result = New-GitHubVariable @param @scope - $result | Should -Not -BeNullOrEmpty - } - - It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($result | Format-Table | Out-String)" - $result | Should -Not -BeNullOrEmpty - } - - It 'Get-GitHubVariable -All' { - $result = Get-GitHubVariable @scope -Name "*$os*" -All - Write-Host "$($result | Format-Table | Out-String)" - $result | Should -Not -BeNullOrEmpty - } - - It 'Remove-GitHubVariable' { - $before = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($before | Format-Table | Out-String)" - $before | Remove-GitHubVariable - $after = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($after | Format-Table | Out-String)" - $after.Count | Should -Be 0 - } - } -} From a740b36d4ca1eb225a02e52ab7cd31713fbf15a6 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions@users.noreply.github.com> Date: Wed, 19 Mar 2025 14:30:30 +0000 Subject: [PATCH 84/85] Auto-generated changes --- Coverage.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Coverage.md b/Coverage.md index 3edbc30b1..6382d8bdf 100644 --- a/Coverage.md +++ b/Coverage.md @@ -9,7 +9,7 @@ Covered functions - 181 + 164 Missing functions @@ -131,9 +131,9 @@ | `/orgs/{org}/actions/secrets/{secret_name}` | :x: | :x: | | | :x: | | `/orgs/{org}/actions/secrets/{secret_name}/repositories` | | :x: | | | :x: | | `/orgs/{org}/actions/secrets/{secret_name}/repositories/{repository_id}` | :x: | | | | :x: | -| `/orgs/{org}/actions/variables` | | :white_check_mark: | | :white_check_mark: | | -| `/orgs/{org}/actions/variables/{name}` | :white_check_mark: | :white_check_mark: | :white_check_mark: | | | -| `/orgs/{org}/actions/variables/{name}/repositories` | | :white_check_mark: | | | :x: | +| `/orgs/{org}/actions/variables` | | :x: | | :x: | | +| `/orgs/{org}/actions/variables/{name}` | :x: | :x: | :x: | | | +| `/orgs/{org}/actions/variables/{name}/repositories` | | :x: | | | :x: | | `/orgs/{org}/actions/variables/{name}/repositories/{repository_id}` | :x: | | | | :x: | | `/orgs/{org}/attestations/{subject_digest}` | | :x: | | | | | `/orgs/{org}/blocks` | | :white_check_mark: | | | | @@ -298,7 +298,7 @@ | `/repos/{owner}/{repo}/actions/jobs/{job_id}/rerun` | | | | :x: | | | `/repos/{owner}/{repo}/actions/oidc/customization/sub` | | :x: | | | :x: | | `/repos/{owner}/{repo}/actions/organization-secrets` | | :x: | | | | -| `/repos/{owner}/{repo}/actions/organization-variables` | | :white_check_mark: | | | | +| `/repos/{owner}/{repo}/actions/organization-variables` | | :x: | | | | | `/repos/{owner}/{repo}/actions/permissions` | | :x: | | | :x: | | `/repos/{owner}/{repo}/actions/permissions/access` | | :x: | | | :x: | | `/repos/{owner}/{repo}/actions/permissions/selected-actions` | | :x: | | | :x: | @@ -331,8 +331,8 @@ | `/repos/{owner}/{repo}/actions/secrets` | | :x: | | | | | `/repos/{owner}/{repo}/actions/secrets/public-key` | | :x: | | | | | `/repos/{owner}/{repo}/actions/secrets/{secret_name}` | :x: | :x: | | | :x: | -| `/repos/{owner}/{repo}/actions/variables` | | :white_check_mark: | | :white_check_mark: | | -| `/repos/{owner}/{repo}/actions/variables/{name}` | :white_check_mark: | :white_check_mark: | :white_check_mark: | | | +| `/repos/{owner}/{repo}/actions/variables` | | :x: | | :x: | | +| `/repos/{owner}/{repo}/actions/variables/{name}` | :x: | :x: | :x: | | | | `/repos/{owner}/{repo}/actions/workflows` | | :white_check_mark: | | | | | `/repos/{owner}/{repo}/actions/workflows/{workflow_id}` | | :white_check_mark: | | | | | `/repos/{owner}/{repo}/actions/workflows/{workflow_id}/disable` | | | | | :white_check_mark: | @@ -438,8 +438,8 @@ | `/repos/{owner}/{repo}/environments/{environment_name}/secrets` | | :x: | | | | | `/repos/{owner}/{repo}/environments/{environment_name}/secrets/public-key` | | :x: | | | | | `/repos/{owner}/{repo}/environments/{environment_name}/secrets/{secret_name}` | :x: | :x: | | | :x: | -| `/repos/{owner}/{repo}/environments/{environment_name}/variables` | | :white_check_mark: | | :white_check_mark: | | -| `/repos/{owner}/{repo}/environments/{environment_name}/variables/{name}` | :white_check_mark: | :white_check_mark: | :white_check_mark: | | | +| `/repos/{owner}/{repo}/environments/{environment_name}/variables` | | :x: | | :x: | | +| `/repos/{owner}/{repo}/environments/{environment_name}/variables/{name}` | :x: | :x: | :x: | | | | `/repos/{owner}/{repo}/events` | | :x: | | | | | `/repos/{owner}/{repo}/forks` | | :white_check_mark: | | :white_check_mark: | | | `/repos/{owner}/{repo}/git/blobs` | | | | :x: | | From 5527f22b71124cdb480a4e7984374bcd762c0f4d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 19 Mar 2025 16:01:25 +0100 Subject: [PATCH 85/85] Remove AllowNull attribute from $Context parameter in Resolve-GitHubContext.ps1 --- src/functions/private/Auth/Context/Resolve-GitHubContext.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/src/functions/private/Auth/Context/Resolve-GitHubContext.ps1 b/src/functions/private/Auth/Context/Resolve-GitHubContext.ps1 index 5593f4906..60f1b3158 100644 --- a/src/functions/private/Auth/Context/Resolve-GitHubContext.ps1 +++ b/src/functions/private/Auth/Context/Resolve-GitHubContext.ps1 @@ -29,7 +29,6 @@ Mandatory, ValueFromPipeline )] - [AllowNull()] [object] $Context )