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 001/210] 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 002/210] 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 003/210] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Refactor=20va?= =?UTF-8?q?riable=20handling=20and=20improve=20code=20consistency=20in=20G?= =?UTF-8?q?itHub=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 004/210] 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 005/210] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Standardize?= =?UTF-8?q?=20formatting=20and=20improve=20documentation=20for=20GitHub=20?= =?UTF-8?q?variable=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 006/210] 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 007/210] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20para?= =?UTF-8?q?meter=20set=20names=20and=20add=20new=20functions=20for=20creat?= =?UTF-8?q?ing=20GitHub=20variables=20on=20repositories=20and=20environmen?= =?UTF-8?q?ts?= 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 008/210] 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 009/210] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Add=20functio?= =?UTF-8?q?ns=20to=20remove=20GitHub=20variables=20from=20environments,=20?= =?UTF-8?q?repositories,=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 010/210] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Enhance=20doc?= =?UTF-8?q?umentation=20for=20variable=20removal=20functions=20and=20impro?= =?UTF-8?q?ve=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 011/210] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Enhance=20Rem?= =?UTF-8?q?ove-GitHubVariable=20function=20to=20support=20array=20input=20?= =?UTF-8?q?and=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 012/210] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20Remo?= =?UTF-8?q?ve-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 013/210] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Refactor=20va?= =?UTF-8?q?riable=20removal=20functions=20to=20use=20ForEach-Object=20cons?= =?UTF-8?q?istently=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 014/210] 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 015/210] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Rename=20Sele?= =?UTF-8?q?ctedRepository=20parameter=20to=20SelectedRepositories=20for=20?= =?UTF-8?q?consistency=20and=20clarity;=20add=20Update-GitHubVariableOnRep?= =?UTF-8?q?ository=20and=20Update-GitHubVariableOnEnvironment=20functions?= =?UTF-8?q?=20for=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 016/210] 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 017/210] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Remove=20unus?= =?UTF-8?q?ed=20NewName=20parameter=20from=20Update-GitHubVariable=20funct?= =?UTF-8?q?ion=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 018/210] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Remove=20Valu?= =?UTF-8?q?e=20parameter=20from=20Update-GitHubVariable=20function=20for?= =?UTF-8?q?=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 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 019/210] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Remove=20mand?= =?UTF-8?q?atory=20requirement=20for=20Value=20parameter=20in=20Update-Git?= =?UTF-8?q?HubVariableOnOwner=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 020/210] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20APIE?= =?UTF-8?q?ndpoint=20in=20Update-GitHubVariableOnRepository=20function=20t?= =?UTF-8?q?o=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 021/210] 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 022/210] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Add=20PassThr?= =?UTF-8?q?u=20parameter=20to=20New-GitHubVariable=20and=20Update-GitHubVa?= =?UTF-8?q?riable=20functions=20for=20optional=20return=20of=20updated=20v?= =?UTF-8?q?ariable=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 023/210] 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 024/210] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Simplify=20AP?= =?UTF-8?q?I=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 025/210] 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 026/210] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Add=20RetryCo?= =?UTF-8?q?unt=20and=20RetryInterval=20parameters=20to=20Invoke-GitHubAPI?= =?UTF-8?q?=20for=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 027/210] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Refactor=20Ne?= =?UTF-8?q?w-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 028/210] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Add=20AllowNu?= =?UTF-8?q?ll=20attribute=20to=20Context=20parameter=20in=20Resolve-GitHub?= =?UTF-8?q?Context=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 029/210] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Remove=20unus?= =?UTF-8?q?ed=20PassThru=20parameter=20from=20New-GitHubVariable=20functio?= =?UTF-8?q?n=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 030/210] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20Upda?= =?UTF-8?q?te-GitHubVariable=20function=20to=20conditionally=20use=20NewNa?= =?UTF-8?q?me=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 031/210] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Restore=20Vis?= =?UTF-8?q?ibility=20parameter=20in=20New-GitHubVariable=20and=20Update-Gi?= =?UTF-8?q?tHubVariable=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 032/210] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20Outp?= =?UTF-8?q?utType=20for=20New-GitHubVariable,=20Remove-GitHubVariable,=20S?= =?UTF-8?q?et-GitHubVariable,=20and=20Update-GitHubVariable=20functions=20?= =?UTF-8?q?for=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 033/210] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Refactor=20Se?= =?UTF-8?q?t-GitHubVariable=20function=20to=20filter=20Get-GitHubVariable?= =?UTF-8?q?=20results=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 034/210] =?UTF-8?q?=F0=9F=A9=B9=20[Test]:=20Add=20Pester?= =?UTF-8?q?=20tests=20for=20Set-GitHubVariable=20function=20across=20user?= =?UTF-8?q?=20and=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 035/210] =?UTF-8?q?=F0=9F=A9=B9=20[Test]:=20Add=20Set-GitH?= =?UTF-8?q?ubEnvironment=20calls=20in=20repository=20tests=20for=20improve?= =?UTF-8?q?d=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 036/210] =?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 037/210] 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 038/210] 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 039/210] =?UTF-8?q?=F0=9F=A9=B9=20[Test]:=20Add=20Connect-?= =?UTF-8?q?GitHubApp=20calls=20for=20organization=20tests=20to=20improve?= =?UTF-8?q?=20setup?= 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 040/210] =?UTF-8?q?=F0=9F=A9=B9=20[Test]:=20Update=20test?= =?UTF-8?q?=20variable=20values=20for=20consistency=20across=20user=20and?= =?UTF-8?q?=20organization=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 041/210] =?UTF-8?q?=F0=9F=A9=B9=20[Test]:=20Add=20delay=20?= =?UTF-8?q?in=20Remove-GitHubVariable=20tests=20to=20ensure=20proper=20cle?= =?UTF-8?q?anup?= 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 042/210] =?UTF-8?q?=F0=9F=A9=B9=20[Test]:=20Replace=20Star?= =?UTF-8?q?t-Sleep=20with=20Write-Verbose=20for=20improved=20variable=20cl?= =?UTF-8?q?eanup=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 043/210] =?UTF-8?q?=F0=9F=A9=B9=20[Test]:=20Simplify=20ass?= =?UTF-8?q?ertions=20in=20Remove-GitHubVariable=20tests=20by=20checking=20?= =?UTF-8?q?count=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 044/210] =?UTF-8?q?=F0=9F=A9=B9=20[Fix]:=20Improve=20varia?= =?UTF-8?q?ble=20cleanup=20in=20Remove-GitHubVariable=20by=20adding=20dela?= =?UTF-8?q?y=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 045/210] =?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 046/210] =?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 047/210] =?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 048/210] =?UTF-8?q?=F0=9F=A9=B9=20[Fix]:=20Improve=20warni?= =?UTF-8?q?ng=20output=20formatting=20in=20Connect-GithubCli=20and=20ensur?= =?UTF-8?q?e=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 049/210] =?UTF-8?q?=F0=9F=A9=B9=20[Fix]:=20Improve=20warni?= =?UTF-8?q?ng=20output=20and=20debug=20logging=20in=20Connect-GithubCli=20?= =?UTF-8?q?for=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 050/210] =?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 051/210] =?UTF-8?q?=F0=9F=A9=B9=20[Fix]:=20Replace=20Write?= =?UTF-8?q?-Verbose=20with=20Write-Host=20in=20Remove-GitHubVariable=20tes?= =?UTF-8?q?ts=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 052/210] =?UTF-8?q?=F0=9F=A9=B9=20[Refactor]:=20Migrate=20?= =?UTF-8?q?test=20files=20to=20new=20directory=20structure=20and=20update?= =?UTF-8?q?=20README=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 053/210] --- {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 054/210] =?UTF-8?q?=F0=9F=A9=B9=20[Refactor]:=20Move=20rep?= =?UTF-8?q?ository=20tests=20to=20a=20new=20directory=20and=20restructure?= =?UTF-8?q?=20for=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 055/210] 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 056/210] 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 057/210] 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 058/210] 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 059/210] 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 060/210] 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 061/210] 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 062/210] 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 063/210] 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 064/210] 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 065/210] 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 066/210] 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 067/210] 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 068/210] 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 069/210] 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 070/210] 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 071/210] 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 072/210] 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 073/210] 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 074/210] 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 075/210] 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 076/210] 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 077/210] 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 078/210] 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 079/210] 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 080/210] 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 081/210] 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 c5b9da065eb483ab07d5cde46364b7f70c1ef683 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 19 Mar 2025 17:38:58 +0100 Subject: [PATCH 082/210] Update APIEndpoint to use ApiBaseUri for Set-GitHubEnvironment function --- src/functions/public/Environments/Set-GitHubEnvironment.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions/public/Environments/Set-GitHubEnvironment.ps1 b/src/functions/public/Environments/Set-GitHubEnvironment.ps1 index f3925138a..aa1a1bae0 100644 --- a/src/functions/public/Environments/Set-GitHubEnvironment.ps1 +++ b/src/functions/public/Environments/Set-GitHubEnvironment.ps1 @@ -213,7 +213,7 @@ filter Set-GitHubEnvironment { $inputObject = @{ Method = 'PUT' - APIEndpoint = "/repos/$Owner/$Repository/environments/$Name" + Uri = $Context.ApiBaseUri + "/repos/$Owner/$Repository/environments/$Name" Body = $body Context = $Context } From 05f0c002a1819584239346bb25060ebd8b449bd3 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions@users.noreply.github.com> Date: Wed, 19 Mar 2025 16:41:43 +0000 Subject: [PATCH 083/210] Auto-generated changes --- Coverage.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Coverage.md b/Coverage.md index 3edbc30b1..2c1293386 100644 --- a/Coverage.md +++ b/Coverage.md @@ -13,11 +13,11 @@ Missing functions - 859 + 842 Coverage - 16.03% + 17.69% From 95f12fa1e5835a0220a24bb7c6754732d8b03249 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 19 Mar 2025 23:23:51 +0100 Subject: [PATCH 084/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Remove=20c?= =?UTF-8?q?ommented-out=20lines=20and=20unnecessary=20attribute=20from=20G?= =?UTF-8?q?itHub=20workflow=20and=20context=20resolution?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/Process-PSModule.yml | 2 -- src/functions/private/Auth/Context/Resolve-GitHubContext.ps1 | 1 - 2 files changed, 3 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 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 ) From 59ab4f9a5bcd9a2dbf315428c664724a9437bdca Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Mar 2025 16:07:23 +0100 Subject: [PATCH 085/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Simplify?= =?UTF-8?q?=20API=20request=20parameters=20in=20Get-GitHubVariableFromOrga?= =?UTF-8?q?nization=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../private/Variables/Get-GitHubVariableFromOrganization.ps1 | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/functions/private/Variables/Get-GitHubVariableFromOrganization.ps1 b/src/functions/private/Variables/Get-GitHubVariableFromOrganization.ps1 index 2c22cf0ae..89e269263 100644 --- a/src/functions/private/Variables/Get-GitHubVariableFromOrganization.ps1 +++ b/src/functions/private/Variables/Get-GitHubVariableFromOrganization.ps1 @@ -76,9 +76,7 @@ function Get-GitHubVariableFromOrganization { $inputObject = @{ Method = 'GET' APIEndpoint = "/repos/$Owner/$Repository/actions/organization-variables" - Body = @{ - per_page = 30 - } + PerPage = 30 Context = $Context } From 8d470813c0bc4a3f6ab7c983046fa41c4b661b17 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 22 Mar 2025 15:24:19 +0100 Subject: [PATCH 086/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Replace=20?= =?UTF-8?q?Set-GitHubDefaultContext=20with=20Switch-GitHubContext=20and=20?= =?UTF-8?q?simplify=20test=20setup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/functions/private/Auth/Context/Set-GitHubContext.ps1 | 2 +- tests/Variables.Tests.ps1 | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/functions/private/Auth/Context/Set-GitHubContext.ps1 b/src/functions/private/Auth/Context/Set-GitHubContext.ps1 index a81d9906d..360fb5f83 100644 --- a/src/functions/private/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/private/Auth/Context/Set-GitHubContext.ps1 @@ -146,7 +146,7 @@ function Set-GitHubContext { Write-Debug "Saving context: [$($script:GitHub.Config.ID)/$($contextObj['Name'])]" Set-Context -ID "$($script:GitHub.Config.ID)/$($contextObj['Name'])" -Context $contextObj if ($Default) { - Set-GitHubDefaultContext -Context $contextObj['Name'] + Switch-GitHubContext -Context $contextObj['Name'] } if ($script:GitHub.EnvironmentType -eq 'GHA') { if ($contextObj['AuthType'] -ne 'APP') { diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 15d9db755..ab9125323 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -16,10 +16,8 @@ param() BeforeAll { - $DebugPreference = 'Continue' - $VerbosePreference = 'Continue' $testName = 'VariableTest' - $os = Get-GitHubRunnerData | Select-Object -ExpandProperty OS + $os = $env:RUNNER_OS } Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT)' { From 223c79d69a50845c86d3e92cf134fa954e0fa98b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 22 Mar 2025 21:01:48 +0100 Subject: [PATCH 087/210] =?UTF-8?q?=F0=9F=94=A7=20[Tests]:=20Add=20TokenTy?= =?UTF-8?q?pe=20field=20for=20various=20authentication=20cases=20in=20Auth?= =?UTF-8?q?Cases.ps1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Data/AuthCases.ps1 | 6 + tests/Variables.Tests.ps1 | 411 +++++++++++++++++++------------------- 2 files changed, 217 insertions(+), 200 deletions(-) diff --git a/tests/Data/AuthCases.ps1 b/tests/Data/AuthCases.ps1 index 3aeefead5..8172d67d3 100644 --- a/tests/Data/AuthCases.ps1 +++ b/tests/Data/AuthCases.ps1 @@ -3,6 +3,7 @@ AuthType = 'PAT' Type = 'a user' Case = 'Fine-grained PAT token' + TokenType = 'USER_FG_PAT' Target = 'it self (user account)' Owner = 'psmodule-user' OwnerType = 'user' @@ -14,6 +15,7 @@ AuthType = 'PAT' Type = 'a user' Case = 'Fine-grained PAT token' + TokenType = 'ORG_FG_PAT' Target = 'organization account' Owner = 'psmodule-test-org2' OwnerType = 'organization' @@ -25,6 +27,7 @@ AuthType = 'PAT' Type = 'a user' Case = 'Classic PAT token' + TokenType = 'PAT' Target = 'user account' Owner = 'psmodule-user' OwnerType = 'user' @@ -36,6 +39,7 @@ AuthType = 'IAT' Type = 'GitHub Actions' Case = 'GITHUB_TOKEN' + TokenType = 'GITHUB_TOKEN' Target = 'this repository (GitHub)' Owner = 'PSModule' Repo = 'GitHub' @@ -48,6 +52,7 @@ AuthType = 'App' Type = 'a GitHub App from an Enterprise' Case = 'PEM + IAT' + TokenType = 'APP_ENT' Target = 'organization account' Owner = 'psmodule-test-org3' OwnerType = 'organization' @@ -63,6 +68,7 @@ AuthType = 'App' Type = 'a GitHub App from an Organization' Case = 'PEM + IAT' + TokenType = 'APP_ORG' Target = 'organization account' Owner = 'psmodule-test-org' OwnerType = 'organization' diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index ab9125323..a29feca54 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -20,22 +20,218 @@ BeforeAll { $os = $env:RUNNER_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 +Describe 'Template' { + $authCases = . "$PSScriptRoot/Data/AuthCases.ps1" + + Context 'As using on ' -ForEach $authCases { + BeforeAll { + $context = Connect-GitHubAccount @connectParams -PassThru -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } + $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 -Silent + } + + # Tests for APP goes here + if ($AuthType -eq 'APP') { + It 'Connect-GitHubApp - Connects as a GitHub App to ' { + $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } + } + } + + # Tests for runners goes here + if ($Type -eq 'GitHub Actions') {} + + # Tests for IAT UAT and PAT goes here + Context 'Organization' -Skip:($TokenType -in 'GITHUB_TOKEN') { + 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 - Fine-grained PAT token - user account access (USER_FG_PAT)' { + Context 'Repository' { BeforeAll { $scope = @{ @@ -351,192 +547,7 @@ Describe 'As a user - Classic PAT token (PAT)' { 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)' { From 07d68a0d395cd5847a80fc83fe27bb86639f9c11 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 22 Mar 2025 21:05:48 +0100 Subject: [PATCH 088/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Update=20r?= =?UTF-8?q?epository=20creation=20logic=20based=20on=20user=20type=20and?= =?UTF-8?q?=20clean=20up=20variable=20management=20in=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 132 ++------------------------------------ 1 file changed, 6 insertions(+), 126 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index a29feca54..219d9ee9e 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -33,10 +33,15 @@ Describe 'Template' { $varName = "$testName`_$os`_$testType" $variablePrefix = "$varName`_" $environmentName = "$testName-$os-$testType" - $repo = New-GitHubRepository -Name $repoName -AllowSquashMerge + if ($Type = 'user') { + $repo = New-GitHubRepository -Name $repoName -AllowSquashMerge + } else { + $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 -Silent } @@ -230,131 +235,6 @@ Describe 'Template' { } } -Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT)' { - - 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 = @{ From df4c4f5ba5e82aaba189c9adc8753c9f130e4271 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 22 Mar 2025 21:07:07 +0100 Subject: [PATCH 089/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Remove=20r?= =?UTF-8?q?edundant=20tests=20for=20GitHub=20variable=20management=20in=20?= =?UTF-8?q?Variables.Tests.ps1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 172 -------------------------------------- 1 file changed, 172 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 219d9ee9e..0f3e5c461 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -235,179 +235,7 @@ Describe 'Template' { } } - 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)' { From 95757dded6528803818d24aac6b08267bf19ca26 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 22 Mar 2025 21:37:37 +0100 Subject: [PATCH 090/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Simplify?= =?UTF-8?q?=20repository=20creation=20logic=20and=20clean=20up=20variable?= =?UTF-8?q?=20management=20in=20organization=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 228 ++------------------------------------ 1 file changed, 7 insertions(+), 221 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 0f3e5c461..150cd1241 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -33,15 +33,17 @@ Describe 'Template' { $varName = "$testName`_$os`_$testType" $variablePrefix = "$varName`_" $environmentName = "$testName-$os-$testType" - if ($Type = 'user') { - $repo = New-GitHubRepository -Name $repoName -AllowSquashMerge - } else { + if ($OwnerType -eq 'organization') { $repo = New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge + } else { + $repo = New-GitHubRepository -Name $repoName -AllowSquashMerge } } AfterAll { Remove-GitHubRepository -Owner $owner -Name $repoName -Confirm:$false - Get-GitHubVariable -Owner $owner -Name "*$os*" | Remove-GitHubVariable + if ($OwnerType -eq 'organization') { + Get-GitHubVariable -Owner $owner -Name "*$os*" | Remove-GitHubVariable + } Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent } @@ -66,6 +68,7 @@ Describe 'Template' { } Set-GitHubVariable @scope -Name $varName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id } + It 'Set-GitHubVariable' { $param = @{ Name = "$variablePrefix`TestVariable" @@ -236,223 +239,6 @@ Describe 'Template' { } -} - -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 - } - -} - -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 From 785efa616b11b8b3dec4246a2f25eada798cd622 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 22 Mar 2025 21:39:01 +0100 Subject: [PATCH 091/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Rename=20t?= =?UTF-8?q?est=20suite=20from=20'Template'=20to=20'Variables'=20and=20remo?= =?UTF-8?q?ve=20obsolete=20GitHub=20App=20organization=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 197 +------------------------------------- 1 file changed, 1 insertion(+), 196 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 150cd1241..696960520 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -20,7 +20,7 @@ BeforeAll { $os = $env:RUNNER_OS } -Describe 'Template' { +Describe 'Variables' { $authCases = . "$PSScriptRoot/Data/AuthCases.ps1" Context 'As using on ' -ForEach $authCases { @@ -237,198 +237,3 @@ Describe 'Template' { } } } - - -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 cc0f3022159b192e1196949ba0b1c3ee7c37baf4 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 22 Mar 2025 22:11:01 +0100 Subject: [PATCH 092/210] Refactor: Improve variable handling and streamline test suite organization --- tests/Variables.Tests.ps1 | 351 +++++++++++++++++++------------------- 1 file changed, 173 insertions(+), 178 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 696960520..d369f36e2 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -35,9 +35,13 @@ Describe 'Variables' { $environmentName = "$testName-$os-$testType" if ($OwnerType -eq 'organization') { $repo = New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge + Set-GitHubVariable -Owner $owner -Name $varName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id } else { $repo = New-GitHubRepository -Name $repoName -AllowSquashMerge } + LogGroup "Repository" { + Write-Host ($repo | Format-List | Out-String) + } } AfterAll { Remove-GitHubRepository -Owner $owner -Name $repoName -Confirm:$false @@ -57,183 +61,174 @@ Describe 'Variables' { } } - # Tests for runners goes here - if ($Type -eq 'GitHub Actions') {} - - # Tests for IAT UAT and PAT goes here - Context 'Organization' -Skip:($TokenType -in 'GITHUB_TOKEN') { - 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 - } - } + # # Tests for IAT UAT and PAT goes here + # Context 'Organization' -Skip:($TokenType -in 'GITHUB_TOKEN') { + + # 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 7ad88b0d03e6c386ead78d204e8d59153cc4a562 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 22 Mar 2025 22:14:53 +0100 Subject: [PATCH 093/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Move=20rep?= =?UTF-8?q?ository=20setup=20logic=20to=20BeforeAll=20context=20in=20Varia?= =?UTF-8?q?bles.Tests.ps1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index d369f36e2..da999728a 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -33,15 +33,6 @@ Describe 'Variables' { $varName = "$testName`_$os`_$testType" $variablePrefix = "$varName`_" $environmentName = "$testName-$os-$testType" - if ($OwnerType -eq 'organization') { - $repo = New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge - Set-GitHubVariable -Owner $owner -Name $varName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id - } else { - $repo = New-GitHubRepository -Name $repoName -AllowSquashMerge - } - LogGroup "Repository" { - Write-Host ($repo | Format-List | Out-String) - } } AfterAll { Remove-GitHubRepository -Owner $owner -Name $repoName -Confirm:$false @@ -61,6 +52,20 @@ Describe 'Variables' { } } + Context 'Prep' { + BeforeAll { + if ($OwnerType -eq 'organization') { + $repo = New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge + Set-GitHubVariable -Owner $owner -Name $varName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id + } else { + $repo = New-GitHubRepository -Name $repoName -AllowSquashMerge + } + LogGroup 'Repository' { + Write-Host ($repo | Format-List | Out-String) + } + } + } + # # Tests for IAT UAT and PAT goes here # Context 'Organization' -Skip:($TokenType -in 'GITHUB_TOKEN') { From 780248c59a24085b15c6e2ec7eda256b9a8d6201 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 22 Mar 2025 22:50:00 +0100 Subject: [PATCH 094/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Update=20v?= =?UTF-8?q?ariable=20naming=20conventions=20in=20Variables.Tests.ps1=20for?= =?UTF-8?q?=20clarity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index da999728a..25be0968f 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -29,10 +29,10 @@ Describe 'Variables' { LogGroup 'Context' { Write-Host ($context | Format-List | Out-String) } - $repoName = "$testName-$os-$testType" - $varName = "$testName`_$os`_$testType" + $repoName = "$testName-$os-$TokenType" + $varName = "$testName`_$os`_$TokenType" $variablePrefix = "$varName`_" - $environmentName = "$testName-$os-$testType" + $environmentName = "$testName-$os-$TokenType" } AfterAll { Remove-GitHubRepository -Owner $owner -Name $repoName -Confirm:$false From 3c0e107554e23732660f9ab90e947d4686fd8c19 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 22 Mar 2025 22:56:06 +0100 Subject: [PATCH 095/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Comment=20?= =?UTF-8?q?out=20obsolete=20repository=20and=20variable=20cleanup=20logic?= =?UTF-8?q?=20in=20Variables.Tests.ps1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 52 +++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 25be0968f..4b24cda67 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -35,36 +35,36 @@ Describe 'Variables' { $environmentName = "$testName-$os-$TokenType" } AfterAll { - Remove-GitHubRepository -Owner $owner -Name $repoName -Confirm:$false - if ($OwnerType -eq 'organization') { - Get-GitHubVariable -Owner $owner -Name "*$os*" | Remove-GitHubVariable - } + # Remove-GitHubRepository -Owner $owner -Name $repoName -Confirm:$false + # if ($OwnerType -eq 'organization') { + # Get-GitHubVariable -Owner $owner -Name "*$os*" | Remove-GitHubVariable + # } Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent } - # Tests for APP goes here - if ($AuthType -eq 'APP') { - It 'Connect-GitHubApp - Connects as a GitHub App to ' { - $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent - LogGroup 'Context' { - Write-Host ($context | Format-List | Out-String) - } - } - } + # # Tests for APP goes here + # if ($AuthType -eq 'APP') { + # It 'Connect-GitHubApp - Connects as a GitHub App to ' { + # $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent + # LogGroup 'Context' { + # Write-Host ($context | Format-List | Out-String) + # } + # } + # } - Context 'Prep' { - BeforeAll { - if ($OwnerType -eq 'organization') { - $repo = New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge - Set-GitHubVariable -Owner $owner -Name $varName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id - } else { - $repo = New-GitHubRepository -Name $repoName -AllowSquashMerge - } - LogGroup 'Repository' { - Write-Host ($repo | Format-List | Out-String) - } - } - } + # Context 'Prep' { + # BeforeAll { + # if ($OwnerType -eq 'organization') { + # $repo = New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge + # Set-GitHubVariable -Owner $owner -Name $varName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id + # } else { + # $repo = New-GitHubRepository -Name $repoName -AllowSquashMerge + # } + # LogGroup 'Repository' { + # Write-Host ($repo | Format-List | Out-String) + # } + # } + # } # # Tests for IAT UAT and PAT goes here # Context 'Organization' -Skip:($TokenType -in 'GITHUB_TOKEN') { From 8bce4f2421acb1ac2427deac4ada22a71aa0d377 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 22 Mar 2025 23:06:23 +0100 Subject: [PATCH 096/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Uncomment?= =?UTF-8?q?=20and=20enhance=20repository=20and=20variable=20management=20l?= =?UTF-8?q?ogic=20in=20Variables.Tests.ps1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 164 ++++++++++++++++++++------------------ 1 file changed, 86 insertions(+), 78 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 4b24cda67..4c8591b58 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -35,36 +35,36 @@ Describe 'Variables' { $environmentName = "$testName-$os-$TokenType" } AfterAll { - # Remove-GitHubRepository -Owner $owner -Name $repoName -Confirm:$false - # if ($OwnerType -eq 'organization') { - # Get-GitHubVariable -Owner $owner -Name "*$os*" | Remove-GitHubVariable - # } + Remove-GitHubRepository -Owner $owner -Name $repoName -Confirm:$false + if ($OwnerType -eq 'organization') { + Get-GitHubVariable -Owner $owner -Name "*$os*" | Remove-GitHubVariable + } Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent } - # # Tests for APP goes here - # if ($AuthType -eq 'APP') { - # It 'Connect-GitHubApp - Connects as a GitHub App to ' { - # $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent - # LogGroup 'Context' { - # Write-Host ($context | Format-List | Out-String) - # } - # } - # } + # Tests for APP goes here + if ($AuthType -eq 'APP') { + It 'Connect-GitHubApp - Connects as a GitHub App to ' { + $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } + } + } - # Context 'Prep' { - # BeforeAll { - # if ($OwnerType -eq 'organization') { - # $repo = New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge - # Set-GitHubVariable -Owner $owner -Name $varName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id - # } else { - # $repo = New-GitHubRepository -Name $repoName -AllowSquashMerge - # } - # LogGroup 'Repository' { - # Write-Host ($repo | Format-List | Out-String) - # } - # } - # } + Context 'Prep' { + BeforeAll { + if ($OwnerType -eq 'organization') { + $repo = New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge + Set-GitHubVariable -Owner $owner -Name $varName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id + } else { + $repo = New-GitHubRepository -Name $repoName -AllowSquashMerge + } + LogGroup 'Repository' { + Write-Host ($repo | Format-List | Out-String) + } + } + } # # Tests for IAT UAT and PAT goes here # Context 'Organization' -Skip:($TokenType -in 'GITHUB_TOKEN') { @@ -119,63 +119,71 @@ Describe 'Variables' { # $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 - # } + 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 '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 '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' { + $result = Get-GitHubVariable @scope -Name "*$os*" + LogGroup 'Variables' { + 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 'Get-GitHubVariable -All' { + $result = Get-GitHubVariable @scope -Name "*$os*" -All + LogGroup 'Variables' { + 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 - # } - # } + It 'Remove-GitHubVariable' { + $before = Get-GitHubVariable @scope -Name "*$os*" + LogGroup 'Variables - Before' { + Write-Host "$($before | Format-Table | Out-String)" + } + $before | Remove-GitHubVariable + $after = Get-GitHubVariable @scope -Name "*$os*" + LogGroup 'Variables -After' { + Write-Host "$($after | Format-Table | Out-String)" + } + $after.Count | Should -Be 0 + } + } # Context 'Environment' { # BeforeAll { # $scope = @{ From e2ac41664046427049e027d35bb565ca7746194b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Mar 2025 00:05:30 +0100 Subject: [PATCH 097/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Streamline?= =?UTF-8?q?=20GitHub=20App=20connection=20logic=20and=20comment=20out=20ob?= =?UTF-8?q?solete=20repository=20tests=20in=20Variables.Tests.ps1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 137 ++++++++++++++++++-------------------- 1 file changed, 66 insertions(+), 71 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 4c8591b58..7d1d2fa1e 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -42,18 +42,14 @@ Describe 'Variables' { Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent } - # Tests for APP goes here - if ($AuthType -eq 'APP') { - It 'Connect-GitHubApp - Connects as a GitHub App to ' { - $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent - LogGroup 'Context' { - Write-Host ($context | Format-List | Out-String) - } - } - } - Context 'Prep' { BeforeAll { + if ($AuthType -eq 'APP') { + $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } + } if ($OwnerType -eq 'organization') { $repo = New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge Set-GitHubVariable -Owner $owner -Name $varName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id @@ -68,7 +64,6 @@ Describe 'Variables' { # # Tests for IAT UAT and PAT goes here # Context 'Organization' -Skip:($TokenType -in 'GITHUB_TOKEN') { - # It 'Set-GitHubVariable' { # $param = @{ # Name = "$variablePrefix`TestVariable" @@ -119,71 +114,71 @@ Describe 'Variables' { # $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 - } + # 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 '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 '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*" - LogGroup 'Variables' { - Write-Host "$($result | Format-Table | Out-String)" - } - $result | Should -Not -BeNullOrEmpty - } + # It 'Get-GitHubVariable' { + # $result = Get-GitHubVariable @scope -Name "*$os*" + # LogGroup 'Variables' { + # Write-Host "$($result | Format-Table | Out-String)" + # } + # $result | Should -Not -BeNullOrEmpty + # } - It 'Get-GitHubVariable -All' { - $result = Get-GitHubVariable @scope -Name "*$os*" -All - LogGroup 'Variables' { - Write-Host "$($result | Format-Table | Out-String)" - } - $result | Should -Not -BeNullOrEmpty - } + # It 'Get-GitHubVariable -All' { + # $result = Get-GitHubVariable @scope -Name "*$os*" -All + # LogGroup 'Variables' { + # Write-Host "$($result | Format-Table | Out-String)" + # } + # $result | Should -Not -BeNullOrEmpty + # } - It 'Remove-GitHubVariable' { - $before = Get-GitHubVariable @scope -Name "*$os*" - LogGroup 'Variables - Before' { - Write-Host "$($before | Format-Table | Out-String)" - } - $before | Remove-GitHubVariable - $after = Get-GitHubVariable @scope -Name "*$os*" - LogGroup 'Variables -After' { - Write-Host "$($after | Format-Table | Out-String)" - } - $after.Count | Should -Be 0 - } - } + # It 'Remove-GitHubVariable' { + # $before = Get-GitHubVariable @scope -Name "*$os*" + # LogGroup 'Variables - Before' { + # Write-Host "$($before | Format-Table | Out-String)" + # } + # $before | Remove-GitHubVariable + # $after = Get-GitHubVariable @scope -Name "*$os*" + # LogGroup 'Variables -After' { + # Write-Host "$($after | Format-Table | Out-String)" + # } + # $after.Count | Should -Be 0 + # } + # } # Context 'Environment' { # BeforeAll { # $scope = @{ From a270426b1b63b9a8a44d54518c90c5a5669c56bc Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Mar 2025 08:37:16 +0100 Subject: [PATCH 098/210] =?UTF-8?q?=F0=9F=94=A7=20[Add]:=20Introduce=20tes?= =?UTF-8?q?ting=20framework=20files=20including=20IssueForm,=20README,=20T?= =?UTF-8?q?EMPLATE,=20Emojis.Tests,=20and=20User.Tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/Process-PSModule.yml | 2 + {tests => test2}/API.Tests.ps1 | 0 {tests => test2}/Apps.Tests.ps1 | 0 {tests => test2}/Auth.Tests.ps1 | 0 {tests => test2}/Emojis.Tests.ps1 | 0 {tests => test2}/Environments.Tests.ps1 | 0 {tests => test2}/GitHub.Tests.ps1 | 0 {tests => test2}/IssueForm.md | 0 {tests => test2}/Organizations.Tests.ps1 | 0 {tests => test2}/README.md | 0 {tests => test2}/Repositories.Tests.ps1 | 0 {tests => test2}/TEMPLATE.ps1 | 0 {tests => test2}/User.Tests.ps1 | 0 test2/Variables.ps1 | 242 ++++++++++++++++++++ tests/Variables.Tests.ps1 | 272 ++++++++--------------- 15 files changed, 339 insertions(+), 177 deletions(-) rename {tests => test2}/API.Tests.ps1 (100%) rename {tests => test2}/Apps.Tests.ps1 (100%) rename {tests => test2}/Auth.Tests.ps1 (100%) rename {tests => test2}/Emojis.Tests.ps1 (100%) rename {tests => test2}/Environments.Tests.ps1 (100%) rename {tests => test2}/GitHub.Tests.ps1 (100%) rename {tests => test2}/IssueForm.md (100%) rename {tests => test2}/Organizations.Tests.ps1 (100%) rename {tests => test2}/README.md (100%) rename {tests => test2}/Repositories.Tests.ps1 (100%) rename {tests => test2}/TEMPLATE.ps1 (100%) rename {tests => test2}/User.Tests.ps1 (100%) create mode 100644 test2/Variables.ps1 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/API.Tests.ps1 b/test2/API.Tests.ps1 similarity index 100% rename from tests/API.Tests.ps1 rename to test2/API.Tests.ps1 diff --git a/tests/Apps.Tests.ps1 b/test2/Apps.Tests.ps1 similarity index 100% rename from tests/Apps.Tests.ps1 rename to test2/Apps.Tests.ps1 diff --git a/tests/Auth.Tests.ps1 b/test2/Auth.Tests.ps1 similarity index 100% rename from tests/Auth.Tests.ps1 rename to test2/Auth.Tests.ps1 diff --git a/tests/Emojis.Tests.ps1 b/test2/Emojis.Tests.ps1 similarity index 100% rename from tests/Emojis.Tests.ps1 rename to test2/Emojis.Tests.ps1 diff --git a/tests/Environments.Tests.ps1 b/test2/Environments.Tests.ps1 similarity index 100% rename from tests/Environments.Tests.ps1 rename to test2/Environments.Tests.ps1 diff --git a/tests/GitHub.Tests.ps1 b/test2/GitHub.Tests.ps1 similarity index 100% rename from tests/GitHub.Tests.ps1 rename to test2/GitHub.Tests.ps1 diff --git a/tests/IssueForm.md b/test2/IssueForm.md similarity index 100% rename from tests/IssueForm.md rename to test2/IssueForm.md diff --git a/tests/Organizations.Tests.ps1 b/test2/Organizations.Tests.ps1 similarity index 100% rename from tests/Organizations.Tests.ps1 rename to test2/Organizations.Tests.ps1 diff --git a/tests/README.md b/test2/README.md similarity index 100% rename from tests/README.md rename to test2/README.md diff --git a/tests/Repositories.Tests.ps1 b/test2/Repositories.Tests.ps1 similarity index 100% rename from tests/Repositories.Tests.ps1 rename to test2/Repositories.Tests.ps1 diff --git a/tests/TEMPLATE.ps1 b/test2/TEMPLATE.ps1 similarity index 100% rename from tests/TEMPLATE.ps1 rename to test2/TEMPLATE.ps1 diff --git a/tests/User.Tests.ps1 b/test2/User.Tests.ps1 similarity index 100% rename from tests/User.Tests.ps1 rename to test2/User.Tests.ps1 diff --git a/test2/Variables.ps1 b/test2/Variables.ps1 new file mode 100644 index 000000000..7d1d2fa1e --- /dev/null +++ b/test2/Variables.ps1 @@ -0,0 +1,242 @@ +#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 { + $testName = 'VariableTest' + $os = $env:RUNNER_OS +} + +Describe 'Variables' { + $authCases = . "$PSScriptRoot/Data/AuthCases.ps1" + + Context 'As using on ' -ForEach $authCases { + BeforeAll { + $context = Connect-GitHubAccount @connectParams -PassThru -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } + $repoName = "$testName-$os-$TokenType" + $varName = "$testName`_$os`_$TokenType" + $variablePrefix = "$varName`_" + $environmentName = "$testName-$os-$TokenType" + } + AfterAll { + Remove-GitHubRepository -Owner $owner -Name $repoName -Confirm:$false + if ($OwnerType -eq 'organization') { + Get-GitHubVariable -Owner $owner -Name "*$os*" | Remove-GitHubVariable + } + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent + } + + Context 'Prep' { + BeforeAll { + if ($AuthType -eq 'APP') { + $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } + } + if ($OwnerType -eq 'organization') { + $repo = New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge + Set-GitHubVariable -Owner $owner -Name $varName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id + } else { + $repo = New-GitHubRepository -Name $repoName -AllowSquashMerge + } + LogGroup 'Repository' { + Write-Host ($repo | Format-List | Out-String) + } + } + } + + # # Tests for IAT UAT and PAT goes here + # Context 'Organization' -Skip:($TokenType -in 'GITHUB_TOKEN') { + # 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*" + # LogGroup 'Variables' { + # Write-Host "$($result | Format-Table | Out-String)" + # } + # $result | Should -Not -BeNullOrEmpty + # } + + # It 'Get-GitHubVariable -All' { + # $result = Get-GitHubVariable @scope -Name "*$os*" -All + # LogGroup 'Variables' { + # Write-Host "$($result | Format-Table | Out-String)" + # } + # $result | Should -Not -BeNullOrEmpty + # } + + # It 'Remove-GitHubVariable' { + # $before = Get-GitHubVariable @scope -Name "*$os*" + # LogGroup 'Variables - Before' { + # Write-Host "$($before | Format-Table | Out-String)" + # } + # $before | Remove-GitHubVariable + # $after = Get-GitHubVariable @scope -Name "*$os*" + # LogGroup 'Variables -After' { + # 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 + # } + # } + } +} diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 7d1d2fa1e..6e9034f06 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -2,7 +2,7 @@ [Diagnostics.CodeAnalysis.SuppressMessageAttribute( 'PSUseDeclaredVarsMoreThanAssignments', '', - Justification = 'Pester grouping syntax: known issue.' + Justification = 'Pester grouping syntax - known issue.' )] [Diagnostics.CodeAnalysis.SuppressMessageAttribute( 'PSAvoidUsingConvertToSecureStringWithPlainText', '', @@ -10,17 +10,18 @@ )] [Diagnostics.CodeAnalysis.SuppressMessageAttribute( 'PSAvoidUsingWriteHost', '', - Justification = 'Outputs into logs from the tests.' + Justification = 'Log outputs to GitHub Actions logs.' )] [CmdletBinding()] param() BeforeAll { - $testName = 'VariableTest' + $repoSuffix = 'EnvironmentTest' + $environmentName = 'production' $os = $env:RUNNER_OS } -Describe 'Variables' { +Describe 'Environments' { $authCases = . "$PSScriptRoot/Data/AuthCases.ps1" Context 'As using on ' -ForEach $authCases { @@ -29,214 +30,131 @@ Describe 'Variables' { LogGroup 'Context' { Write-Host ($context | Format-List | Out-String) } - $repoName = "$testName-$os-$TokenType" - $varName = "$testName`_$os`_$TokenType" - $variablePrefix = "$varName`_" - $environmentName = "$testName-$os-$TokenType" + $guid = [guid]::NewGuid().ToString() + $repo = "$repoSuffix-$guid" } + AfterAll { - Remove-GitHubRepository -Owner $owner -Name $repoName -Confirm:$false - if ($OwnerType -eq 'organization') { - Get-GitHubVariable -Owner $owner -Name "*$os*" | Remove-GitHubVariable - } + Remove-GitHubRepository -Owner $owner -Name $repo -Confirm:$false Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent } - Context 'Prep' { - BeforeAll { - if ($AuthType -eq 'APP') { - $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent - LogGroup 'Context' { - Write-Host ($context | Format-List | Out-String) - } - } - if ($OwnerType -eq 'organization') { - $repo = New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge - Set-GitHubVariable -Owner $owner -Name $varName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id - } else { - $repo = New-GitHubRepository -Name $repoName -AllowSquashMerge - } - LogGroup 'Repository' { - Write-Host ($repo | Format-List | Out-String) + # Tests for APP goes here + if ($AuthType -eq 'APP') { + It 'Connect-GitHubApp - Connects as a GitHub App to ' { + $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) } } } - # # Tests for IAT UAT and PAT goes here - # Context 'Organization' -Skip:($TokenType -in 'GITHUB_TOKEN') { - # It 'Set-GitHubVariable' { - # $param = @{ - # Name = "$variablePrefix`TestVariable" - # Value = 'TestValue' - # } - # $result = Set-GitHubVariable @param @scope - # $result = Set-GitHubVariable @param @scope - # $result | Should -Not -BeNullOrEmpty - # } + It 'New-GitHubVariable - should create a new organization variable' -Skip:($OwnerType -eq 'organization') { + $result = New-GitHubVariable -Owner $owner -Name "$os-$repo" -Value 'Test' -Visibility Organization + LogGroup 'Variable' { + Write-Host ($result | Format-Table | Out-String) + } + $result | Should -Not -BeNullOrEmpty + $result | Should -BeOfType [GitHubVariable] + $result.Name | Should -Be "$os-$repo" + } - # It 'Update-GitHubVariable' { - # $param = @{ - # Name = "$variablePrefix`TestVariable" - # Value = 'TestValue1234' - # Visibility = 'all' + # # Tests for runners goes here + # if ($Type -ne 'GitHub Actions') { + # # Tests for IAT UAT and PAT goes here + # It 'Prep - New-GitHubRepository' { + # if ($OwnerType -eq 'user') { + # New-GitHubRepository -Name $repo -AllowSquashMerge + # } else { + # New-GitHubRepository -Owner $owner -Name $repo -AllowSquashMerge # } - # $result = Update-GitHubVariable @param @scope -PassThru - # $result | Should -Not -BeNullOrEmpty # } - - # It 'New-GitHubVariable' { - # $param = @{ - # Name = "$variablePrefix`TestVariable2" - # Value = 'TestValue123' + # It 'Get-GitHubEnvironment - should return an empty list when no environments exist' { + # $result = Get-GitHubEnvironment -Owner $owner -Repository $repo + # LogGroup 'Environment' { + # Write-Host ($result | Format-Table | Out-String) # } - # $result = New-GitHubVariable @param @scope - # $result | Should -Not -BeNullOrEmpty + # $result | Should -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' + # It 'Get-GitHubEnvironment - should return null when retrieving a non-existent environment' { + # $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName + # LogGroup 'Environment' { + # Write-Host ($result | Format-Table | Out-String) # } - # $result = Set-GitHubVariable @param @scope - # $result = Set-GitHubVariable @param @scope - # $result | Should -Not -BeNullOrEmpty + # $result | Should -BeNullOrEmpty # } - - # It 'Update-GitHubVariable' { - # $param = @{ - # Name = "$variablePrefix`TestVariable" - # Value = 'TestValue1234' + # It 'Set-GitHubEnvironment - should successfully create an environment with a wait timer of 10' { + # $result = Set-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName -WaitTimer 10 + # LogGroup 'Environment' { + # Write-Host ($result | Format-List | Out-String) # } - # $result = Update-GitHubVariable @param @scope -PassThru # $result | Should -Not -BeNullOrEmpty - # } - - # It 'New-GitHubVariable' { - # $param = @{ - # Name = "$variablePrefix`TestVariable2" - # Value = 'TestValue123' + # $result | Should -BeOfType [GitHubEnvironment] + # $result.Name | Should -Be $environmentName + # $result.ProtectionRules.wait_timer | Should -Be 10 + # } + # It 'Get-GitHubEnvironment - should retrieve the environment that was created' { + # $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName + # LogGroup 'Environment' { + # Write-Host ($result | Format-List | Out-String) # } - # $result = New-GitHubVariable @param @scope # $result | Should -Not -BeNullOrEmpty + # $result.Name | Should -Be $environmentName # } - - # It 'Get-GitHubVariable' { - # $result = Get-GitHubVariable @scope -Name "*$os*" - # LogGroup 'Variables' { - # Write-Host "$($result | Format-Table | Out-String)" + # It 'Set-GitHubEnvironment - should successfully create an environment with a slash in its name' { + # $result = Set-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" + # LogGroup 'Environment' { + # Write-Host ($result | Format-List | Out-String) # } # $result | Should -Not -BeNullOrEmpty + # $result.Name | Should -Be "$environmentName/$os" # } - - # It 'Get-GitHubVariable -All' { - # $result = Get-GitHubVariable @scope -Name "*$os*" -All - # LogGroup 'Variables' { - # Write-Host "$($result | Format-Table | Out-String)" + # It 'Get-GitHubEnvironment - should retrieve the environment with a slash in its name' { + # $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" + # LogGroup 'Environment' { + # Write-Host ($result | Format-Table | Out-String) # } # $result | Should -Not -BeNullOrEmpty + # $result.Name | Should -Be "$environmentName/$os" # } - - # It 'Remove-GitHubVariable' { - # $before = Get-GitHubVariable @scope -Name "*$os*" - # LogGroup 'Variables - Before' { - # Write-Host "$($before | Format-Table | Out-String)" - # } - # $before | Remove-GitHubVariable - # $after = Get-GitHubVariable @scope -Name "*$os*" - # LogGroup 'Variables -After' { - # Write-Host "$($after | Format-Table | Out-String)" - # } - # $after.Count | Should -Be 0 + # It 'Remove-GitHubEnvironment - should delete the environment with a slash in its name without errors' { + # { + # Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" | Remove-GitHubEnvironment -Confirm:$false + # } | Should -Not -Throw # } - # } - # Context 'Environment' { - # BeforeAll { - # $scope = @{ - # Owner = $owner - # Repository = $repoName - # Environment = $environmentName + # It 'Get-GitHubEnvironment - should return null when retrieving the deleted environment with a slash in its name' { + # $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" + # LogGroup 'Environment' { + # Write-Host ($result | Format-Table | Out-String) # } - # Set-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName - # Set-GitHubVariable @scope -Name $varName -Value 'environment' + # $result | Should -BeNullOrEmpty # } - # It 'Set-GitHubVariable' { - # $param = @{ - # Name = "$variablePrefix`TestVariable" - # Value = 'TestValue' + # It 'Get-GitHubEnvironment - should list one remaining environment' { + # $result = Get-GitHubEnvironment -Owner $owner -Repository $repo + # LogGroup 'Environment' { + # Write-Host ($result | Format-Table | Out-String) # } - # $result = Set-GitHubVariable @param @scope - # $result = Set-GitHubVariable @param @scope - # $result | Should -Not -BeNullOrEmpty + # $result.Count | Should -Be 1 # } - - # It 'Update-GitHubVariable' { - # $param = @{ - # Name = "$variablePrefix`TestVariable" - # Value = 'TestValue1234' - # } - # $result = Update-GitHubVariable @param @scope -PassThru - # $result | Should -Not -BeNullOrEmpty + # It 'Remove-GitHubEnvironment - should delete the remaining environment without errors' { + # { Remove-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName -Confirm:$false } | Should -Not -Throw # } - - # It 'New-GitHubVariable' { - # $param = @{ - # Name = "$variablePrefix`TestVariable2" - # Value = 'TestValue123' + # It 'Get-GitHubEnvironment - should return null when retrieving an environment that does not exist' { + # $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName + # LogGroup 'Environment' { + # Write-Host ($result | Format-Table | Out-String) # } - # $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 + # $result | Should -BeNullOrEmpty # } # } + + It 'Remove-GitHubVariable - should delete the organization variable' -Skip:($OwnerType -eq 'organization') { + $result = Get-GitHubVariable -Owner $owner -Name "*$os*" + LogGroup 'Variable' { + Write-Host ($result | Format-Table | Out-String) + } + $result | Should -Not -BeNullOrEmpty + $result | Remove-GitHubVariable + } } } From 91222ee6c1817675c068d1ab60e818a5935355d0 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Mar 2025 08:41:23 +0100 Subject: [PATCH 099/210] =?UTF-8?q?=F0=9F=94=A7=20[Fix]:=20Correct=20skip?= =?UTF-8?q?=20condition=20for=20organization=20variable=20creation=20test?= =?UTF-8?q?=20in=20Variables.Tests.ps1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 6e9034f06..761b4bc2f 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -49,8 +49,8 @@ Describe 'Environments' { } } - It 'New-GitHubVariable - should create a new organization variable' -Skip:($OwnerType -eq 'organization') { - $result = New-GitHubVariable -Owner $owner -Name "$os-$repo" -Value 'Test' -Visibility Organization + It 'New-GitHubVariable - should create a new organization variable' -Skip:($OwnerType -ne 'organization') { + $result = New-GitHubVariable -Owner $owner -Name "$os-$repo" -Value 'Test' LogGroup 'Variable' { Write-Host ($result | Format-Table | Out-String) } From be67603bce1c2db2c23a04cf8585bc3399eaa606 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Mar 2025 08:54:13 +0100 Subject: [PATCH 100/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Rename=20r?= =?UTF-8?q?epository=20variable=20and=20adjust=20skip=20conditions=20for?= =?UTF-8?q?=20organization=20variable=20tests=20in=20Variables.Tests.ps1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 761b4bc2f..8d90e114d 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -31,7 +31,7 @@ Describe 'Environments' { Write-Host ($context | Format-List | Out-String) } $guid = [guid]::NewGuid().ToString() - $repo = "$repoSuffix-$guid" + $repoName = "$repoSuffix-$guid" } AfterAll { @@ -49,8 +49,16 @@ Describe 'Environments' { } } - It 'New-GitHubVariable - should create a new organization variable' -Skip:($OwnerType -ne 'organization') { - $result = New-GitHubVariable -Owner $owner -Name "$os-$repo" -Value 'Test' + It 'Prep - New-GitHubRepository' -Skip:($Type -eq 'GitHub Actions') { + if ($OwnerType -eq 'user') { + New-GitHubRepository -Name $repo -AllowSquashMerge + } else { + New-GitHubRepository -Owner $owner -Name $repo -AllowSquashMerge + } + } + + It 'Set-GitHubVariable - should ensure existance of a organization variable' -Skip:($OwnerType -ne 'organization') { + Set-GitHubVariable -Owner $owner -Name $varName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id LogGroup 'Variable' { Write-Host ($result | Format-Table | Out-String) } @@ -148,7 +156,7 @@ Describe 'Environments' { # } # } - It 'Remove-GitHubVariable - should delete the organization variable' -Skip:($OwnerType -eq 'organization') { + It 'Remove-GitHubVariable - should delete the organization variable' -Skip:($OwnerType -ne 'organization') { $result = Get-GitHubVariable -Owner $owner -Name "*$os*" LogGroup 'Variable' { Write-Host ($result | Format-Table | Out-String) From 2f1a35491010b45851cb2ba396b6613e15a066af Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Mar 2025 09:02:48 +0100 Subject: [PATCH 101/210] =?UTF-8?q?=F0=9F=94=A7=20[Fix]:=20Correct=20skip?= =?UTF-8?q?=20condition=20for=20organization=20variable=20tests=20in=20Var?= =?UTF-8?q?iables.Tests.ps1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 8d90e114d..9e19606d8 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -57,7 +57,7 @@ Describe 'Environments' { } } - It 'Set-GitHubVariable - should ensure existance of a organization variable' -Skip:($OwnerType -ne 'organization') { + It 'Set-GitHubVariable - should ensure existance of a organization variable' -Skip:($OwnerType -eq 'organization') { Set-GitHubVariable -Owner $owner -Name $varName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id LogGroup 'Variable' { Write-Host ($result | Format-Table | Out-String) @@ -156,7 +156,7 @@ Describe 'Environments' { # } # } - It 'Remove-GitHubVariable - should delete the organization variable' -Skip:($OwnerType -ne 'organization') { + It 'Remove-GitHubVariable - should delete the organization variable' -Skip:($OwnerType -eq 'organization') { $result = Get-GitHubVariable -Owner $owner -Name "*$os*" LogGroup 'Variable' { Write-Host ($result | Format-Table | Out-String) From c0e3ce29d29d74d1a6fde92bad2e2a1ee42f237f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Mar 2025 09:06:10 +0100 Subject: [PATCH 102/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Update=20v?= =?UTF-8?q?ariable=20name=20for=20repository=20in=20Variables.Tests.ps1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 9e19606d8..33bc9d22d 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -35,7 +35,7 @@ Describe 'Environments' { } AfterAll { - Remove-GitHubRepository -Owner $owner -Name $repo -Confirm:$false + Remove-GitHubRepository -Owner $owner -Name $repoName -Confirm:$false Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent } @@ -51,9 +51,9 @@ Describe 'Environments' { It 'Prep - New-GitHubRepository' -Skip:($Type -eq 'GitHub Actions') { if ($OwnerType -eq 'user') { - New-GitHubRepository -Name $repo -AllowSquashMerge + New-GitHubRepository -Name $repoName -AllowSquashMerge } else { - New-GitHubRepository -Owner $owner -Name $repo -AllowSquashMerge + New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge } } From b435cc5edb36dada90c0cd4d0e6a25b20663e66d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Mar 2025 09:13:36 +0100 Subject: [PATCH 103/210] =?UTF-8?q?=F0=9F=94=A7=20[Fix]:=20Update=20skip?= =?UTF-8?q?=20condition=20for=20organization=20variable=20tests=20in=20Var?= =?UTF-8?q?iables.Tests.ps1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 33bc9d22d..701bf60cc 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -57,7 +57,7 @@ Describe 'Environments' { } } - It 'Set-GitHubVariable - should ensure existance of a organization variable' -Skip:($OwnerType -eq 'organization') { + It 'Set-GitHubVariable - should ensure existance of a organization variable' -Skip:($OwnerType -ne 'organization') { Set-GitHubVariable -Owner $owner -Name $varName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id LogGroup 'Variable' { Write-Host ($result | Format-Table | Out-String) @@ -156,7 +156,7 @@ Describe 'Environments' { # } # } - It 'Remove-GitHubVariable - should delete the organization variable' -Skip:($OwnerType -eq 'organization') { + It 'Remove-GitHubVariable - should delete the organization variable' -Skip:($OwnerType -ne 'organization') { $result = Get-GitHubVariable -Owner $owner -Name "*$os*" LogGroup 'Variable' { Write-Host ($result | Format-Table | Out-String) From 7b8f522e34dc27efc37f5f95f297caa650b63586 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Mar 2025 09:59:52 +0100 Subject: [PATCH 104/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Rename=20r?= =?UTF-8?q?epository=20suffix=20to=20testName=20in=20Environments.Tests.ps?= =?UTF-8?q?1=20and=20Variables.Tests.ps1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test2/Environments.Tests.ps1 | 4 ++-- test2/Variables.ps1 | 5 ----- tests/Variables.Tests.ps1 | 42 ++++++++++++++++++------------------ 3 files changed, 23 insertions(+), 28 deletions(-) diff --git a/test2/Environments.Tests.ps1 b/test2/Environments.Tests.ps1 index 8295495b7..99f88a42f 100644 --- a/test2/Environments.Tests.ps1 +++ b/test2/Environments.Tests.ps1 @@ -16,7 +16,7 @@ param() BeforeAll { - $repoSuffix = 'EnvironmentTest' + $testName = 'EnvironmentTest' $environmentName = 'production' $os = $env:RUNNER_OS } @@ -31,7 +31,7 @@ Describe 'Environments' { Write-Host ($context | Format-List | Out-String) } $guid = [guid]::NewGuid().ToString() - $repo = "$repoSuffix-$guid" + $repo = "$testName-$guid" } AfterAll { diff --git a/test2/Variables.ps1 b/test2/Variables.ps1 index 7d1d2fa1e..601dce71e 100644 --- a/test2/Variables.ps1 +++ b/test2/Variables.ps1 @@ -15,11 +15,6 @@ [CmdletBinding()] param() -BeforeAll { - $testName = 'VariableTest' - $os = $env:RUNNER_OS -} - Describe 'Variables' { $authCases = . "$PSScriptRoot/Data/AuthCases.ps1" diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 701bf60cc..c3964bcb8 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -16,8 +16,7 @@ param() BeforeAll { - $repoSuffix = 'EnvironmentTest' - $environmentName = 'production' + $testName = 'VariableTest' $os = $env:RUNNER_OS } @@ -30,31 +29,32 @@ Describe 'Environments' { LogGroup 'Context' { Write-Host ($context | Format-List | Out-String) } - $guid = [guid]::NewGuid().ToString() - $repoName = "$repoSuffix-$guid" - } - - AfterAll { - Remove-GitHubRepository -Owner $owner -Name $repoName -Confirm:$false - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent - } - - # Tests for APP goes here - if ($AuthType -eq 'APP') { - It 'Connect-GitHubApp - Connects as a GitHub App to ' { + if ($AuthType -eq 'APP') { $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent - LogGroup 'Context' { + LogGroup 'Context - Installation' { Write-Host ($context | Format-List | Out-String) } } + $repoName = "$testName-$guid" + $repoName = "$testName-$os-$TokenType" + $varName = "$testName`_$os`_$TokenType" + $variablePrefix = "$varName`_" + $environmentName = "$testName-$os-$TokenType" + + if ($Type -ne 'GitHub Actions') { + if ($OwnerType -eq 'user') { + New-GitHubRepository -Name $repoName -AllowSquashMerge + } else { + New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge + } + } } - It 'Prep - New-GitHubRepository' -Skip:($Type -eq 'GitHub Actions') { - if ($OwnerType -eq 'user') { - New-GitHubRepository -Name $repoName -AllowSquashMerge - } else { - New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge + AfterAll { + if ($Type -ne 'GitHub Actions') { + Remove-GitHubRepository -Owner $owner -Name $repoName -Confirm:$false } + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent } It 'Set-GitHubVariable - should ensure existance of a organization variable' -Skip:($OwnerType -ne 'organization') { @@ -157,7 +157,7 @@ Describe 'Environments' { # } It 'Remove-GitHubVariable - should delete the organization variable' -Skip:($OwnerType -ne 'organization') { - $result = Get-GitHubVariable -Owner $owner -Name "*$os*" + $result = Get-GitHubVariable -Owner $owner -Name "$varName*" LogGroup 'Variable' { Write-Host ($result | Format-Table | Out-String) } From ae83d61e1f251b9ee98cc247d47aff46e974bed1 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Mar 2025 10:06:04 +0100 Subject: [PATCH 105/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Store=20re?= =?UTF-8?q?sult=20of=20New-GitHubRepository=20calls=20in=20a=20variable=20?= =?UTF-8?q?in=20Variables.Tests.ps1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index c3964bcb8..0de53d5b5 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -43,9 +43,9 @@ Describe 'Environments' { if ($Type -ne 'GitHub Actions') { if ($OwnerType -eq 'user') { - New-GitHubRepository -Name $repoName -AllowSquashMerge + $repo = New-GitHubRepository -Name $repoName -AllowSquashMerge } else { - New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge + $repo = New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge } } } From e10471ad9fd64aba3b1300bee8c54dd8d8eb712f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Mar 2025 12:46:49 +0100 Subject: [PATCH 106/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Rename=20'?= =?UTF-8?q?SkipTests'=20to=20'Skip'=20in=20Process-PSModule.yml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/Process-PSModule.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Process-PSModule.yml b/.github/workflows/Process-PSModule.yml index 0e06d4b96..5729031f7 100644 --- a/.github/workflows/Process-PSModule.yml +++ b/.github/workflows/Process-PSModule.yml @@ -37,4 +37,4 @@ jobs: TEST_USER_USER_FG_PAT: ${{ secrets.TEST_USER_USER_FG_PAT }} TEST_USER_PAT: ${{ secrets.TEST_USER_PAT }} with: - SkipTests: SourceCode + Skip: SourceCode From 6660e8aa70e7400c701929953d817cb8bde7c79d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 25 Mar 2025 08:45:28 +0100 Subject: [PATCH 107/210] =?UTF-8?q?=F0=9F=94=A7=20[Add]:=20Implement=20env?= =?UTF-8?q?ironment=20tests=20in=20Environments.Tests.ps1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Environments.Tests.ps1 | 141 +++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 tests/Environments.Tests.ps1 diff --git a/tests/Environments.Tests.ps1 b/tests/Environments.Tests.ps1 new file mode 100644 index 000000000..8295495b7 --- /dev/null +++ b/tests/Environments.Tests.ps1 @@ -0,0 +1,141 @@ +#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 = 'Log outputs to GitHub Actions logs.' +)] +[CmdletBinding()] +param() + +BeforeAll { + $repoSuffix = 'EnvironmentTest' + $environmentName = 'production' + $os = $env:RUNNER_OS +} + +Describe 'Environments' { + $authCases = . "$PSScriptRoot/Data/AuthCases.ps1" + + Context 'As using on ' -ForEach $authCases { + BeforeAll { + $context = Connect-GitHubAccount @connectParams -PassThru -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } + $guid = [guid]::NewGuid().ToString() + $repo = "$repoSuffix-$guid" + } + + AfterAll { + Remove-GitHubRepository -Owner $owner -Name $repo -Confirm:$false + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent + } + + # Tests for APP goes here + if ($AuthType -eq 'APP') { + It 'Connect-GitHubApp - Connects as a GitHub App to ' { + $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } + } + } + + # Tests for runners goes here + if ($Type -ne 'GitHub Actions') { + # Tests for IAT UAT and PAT goes here + It 'Prep - New-GitHubRepository' { + if ($OwnerType -eq 'user') { + New-GitHubRepository -Name $repo -AllowSquashMerge + } else { + New-GitHubRepository -Owner $owner -Name $repo -AllowSquashMerge + } + } + It 'Get-GitHubEnvironment - should return an empty list when no environments exist' { + $result = Get-GitHubEnvironment -Owner $owner -Repository $repo + LogGroup 'Environment' { + Write-Host ($result | Format-Table | Out-String) + } + $result | Should -BeNullOrEmpty + } + It 'Get-GitHubEnvironment - should return null when retrieving a non-existent environment' { + $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName + LogGroup 'Environment' { + Write-Host ($result | Format-Table | Out-String) + } + $result | Should -BeNullOrEmpty + } + It 'Set-GitHubEnvironment - should successfully create an environment with a wait timer of 10' { + $result = Set-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName -WaitTimer 10 + LogGroup 'Environment' { + Write-Host ($result | Format-List | Out-String) + } + $result | Should -Not -BeNullOrEmpty + $result | Should -BeOfType [GitHubEnvironment] + $result.Name | Should -Be $environmentName + $result.ProtectionRules.wait_timer | Should -Be 10 + } + It 'Get-GitHubEnvironment - should retrieve the environment that was created' { + $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName + LogGroup 'Environment' { + Write-Host ($result | Format-List | Out-String) + } + $result | Should -Not -BeNullOrEmpty + $result.Name | Should -Be $environmentName + } + It 'Set-GitHubEnvironment - should successfully create an environment with a slash in its name' { + $result = Set-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" + LogGroup 'Environment' { + Write-Host ($result | Format-List | Out-String) + } + $result | Should -Not -BeNullOrEmpty + $result.Name | Should -Be "$environmentName/$os" + } + It 'Get-GitHubEnvironment - should retrieve the environment with a slash in its name' { + $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" + LogGroup 'Environment' { + Write-Host ($result | Format-Table | Out-String) + } + $result | Should -Not -BeNullOrEmpty + $result.Name | Should -Be "$environmentName/$os" + } + It 'Remove-GitHubEnvironment - should delete the environment with a slash in its name without errors' { + { + Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" | Remove-GitHubEnvironment -Confirm:$false + } | Should -Not -Throw + } + It 'Get-GitHubEnvironment - should return null when retrieving the deleted environment with a slash in its name' { + $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" + LogGroup 'Environment' { + Write-Host ($result | Format-Table | Out-String) + } + $result | Should -BeNullOrEmpty + } + It 'Get-GitHubEnvironment - should list one remaining environment' { + $result = Get-GitHubEnvironment -Owner $owner -Repository $repo + LogGroup 'Environment' { + Write-Host ($result | Format-Table | Out-String) + } + $result.Count | Should -Be 1 + } + It 'Remove-GitHubEnvironment - should delete the remaining environment without errors' { + { Remove-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName -Confirm:$false } | Should -Not -Throw + } + It 'Get-GitHubEnvironment - should return null when retrieving an environment that does not exist' { + $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName + LogGroup 'Environment' { + Write-Host ($result | Format-Table | Out-String) + } + $result | Should -BeNullOrEmpty + } + } + } +} From 2ce11c732a05ec51bfde72f8eb095b7746f8b161 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 25 Mar 2025 12:03:30 +0100 Subject: [PATCH 108/210] =?UTF-8?q?=F0=9F=94=A7=20[Add]:=20Create=20PSModu?= =?UTF-8?q?le.yml=20for=20test=20configuration=20and=20code=20coverage=20s?= =?UTF-8?q?ettings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/PSModule.yml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .github/PSModule.yml diff --git a/.github/PSModule.yml b/.github/PSModule.yml new file mode 100644 index 000000000..aeaaf81bb --- /dev/null +++ b/.github/PSModule.yml @@ -0,0 +1,7 @@ +Test: + SourceCode: + Skip: true + PSModule: + Skip: true + CodeCoverage: + PercentTarget: 50 From 7ae3dba72adbed886b1864084179d5ec341186e2 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 25 Mar 2025 12:03:46 +0100 Subject: [PATCH 109/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Remove=20'?= =?UTF-8?q?Skip'=20parameter=20from=20Process-PSModule.yml=20workflow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .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 5729031f7..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: - Skip: SourceCode From 925e316cd2365d0262947d13da03315961db6330 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 25 Mar 2025 12:21:24 +0100 Subject: [PATCH 110/210] =?UTF-8?q?=F0=9F=94=A7=20[Add]:=20Log=20repositor?= =?UTF-8?q?y=20details=20after=20creation=20in=20Variables.Tests.ps1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 0de53d5b5..83f58d409 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -47,6 +47,9 @@ Describe 'Environments' { } else { $repo = New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge } + LogGroup 'Repository' { + Write-Host ($repo | Format-List | Out-String) + } } } From d919037dff13a71c00ce59322a35e266cfd14c7c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 25 Mar 2025 12:54:31 +0100 Subject: [PATCH 111/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Update=20G?= =?UTF-8?q?et-GitHubVariable=20and=20related=20functions=20to=20use=20Incl?= =?UTF-8?q?udeInherited=20parameter=20and=20improve=20variable=20retrieval?= =?UTF-8?q?=20logic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/PSModule.yml | 3 ++ .../public/Variables/Get-GitHubVariable.ps1 | 47 +++++++++++++++---- .../public/Variables/New-GitHubVariable.ps1 | 3 -- .../public/Variables/Set-GitHubVariable.ps1 | 2 +- .../Variables/Update-GitHubVariable.ps1 | 10 ++-- 5 files changed, 47 insertions(+), 18 deletions(-) diff --git a/.github/PSModule.yml b/.github/PSModule.yml index aeaaf81bb..d037f0109 100644 --- a/.github/PSModule.yml +++ b/.github/PSModule.yml @@ -5,3 +5,6 @@ Test: Skip: true CodeCoverage: PercentTarget: 50 +Build: + Docs: + Skip: true diff --git a/src/functions/public/Variables/Get-GitHubVariable.ps1 b/src/functions/public/Variables/Get-GitHubVariable.ps1 index 4b22b2261..6434f2c45 100644 --- a/src/functions/public/Variables/Get-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Get-GitHubVariable.ps1 @@ -148,7 +148,7 @@ function Get-GitHubVariable { # List all variables that are inherited. [Parameter()] - [switch] $All, + [switch] $IncludeInherited, # 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. @@ -165,28 +165,55 @@ function Get-GitHubVariable { process { $variables = @() + $params = @{ + Context = $Context + Owner = $Owner + } switch ($PSCmdlet.ParameterSetName) { 'Organization' { - $variables += Get-GitHubVariableOwnerList -Owner $Owner -Context $Context + if ($Name.Contains('*')) { + $variables += Get-GitHubVariableOwnerList @params | + Where-Object { $_.Name -like $Name } + } else { + $variables += Get-GitHubVariableOwnerByName @params -Name $Name + } break } 'Repository' { - if ($All) { - $variables += Get-GitHubVariableFromOrganization -Owner $Owner -Repository $Repository -Context $Context + $params['Repository'] = $Repository + if ($IncludeInherited) { + $variables += Get-GitHubVariableFromOrganization @params | + Where-Object { $_.Name -like $Name } + } + if ($Name.Contains('*')) { + $variables += Get-GitHubVariableRepositoryList @params | + Where-Object { $_.Name -like $Name } + } else { + $variables += Get-GitHubVariableRepositoryByName @params -Name $Name } - $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 + if ($IncludeInherited) { + $variables += Get-GitHubVariableFromOrganization @params | + Where-Object { $_.Name -like $Name } + if ($Name.Contains('*')) { + $variables += Get-GitHubVariableRepositoryList @params | + Where-Object { $_.Name -like $Name } + } else { + $variables += Get-GitHubVariableRepositoryByName @params -Name $Name + } + } + $params['Environment'] = $Environment + if ($Name.Contains('*')) { + $variables += Get-GitHubVariableEnvironmentList @params | + Where-Object { $_.Name -like $Name } + } else { + $variables += Get-GitHubVariableEnvironmentByName @params -Name $Name } - $variables += Get-GitHubVariableEnvironmentList -Owner $Owner -Repository $Repository -Environment $Environment -Context $Context break } } - $variables | Where-Object { $_.Name -like $Name } } end { diff --git a/src/functions/public/Variables/New-GitHubVariable.ps1 b/src/functions/public/Variables/New-GitHubVariable.ps1 index 77700b9dc..cae1c8659 100644 --- a/src/functions/public/Variables/New-GitHubVariable.ps1 +++ b/src/functions/public/Variables/New-GitHubVariable.ps1 @@ -126,10 +126,7 @@ function New-GitHubVariable { 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 diff --git a/src/functions/public/Variables/Set-GitHubVariable.ps1 b/src/functions/public/Variables/Set-GitHubVariable.ps1 index c893271f1..adb979c77 100644 --- a/src/functions/public/Variables/Set-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Set-GitHubVariable.ps1 @@ -112,7 +112,7 @@ function Set-GitHubVariable { $variable = Get-GitHubVariable @getParams | Where-Object { $_.Name -eq $Name } if ($variable) { - $null = Update-GitHubVariable @params + $null = Update-GitHubVariable @params -PassThru } else { $null = New-GitHubVariable @params } diff --git a/src/functions/public/Variables/Update-GitHubVariable.ps1 b/src/functions/public/Variables/Update-GitHubVariable.ps1 index b0c0b6a50..e7926a3bf 100644 --- a/src/functions/public/Variables/Update-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Update-GitHubVariable.ps1 @@ -128,10 +128,12 @@ 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 + for ($i = 0; $i -le 5; $i++) { + Start-Sleep -Seconds 1 + $result = Get-GitHubVariable @params + if ($result) { break } + } + $result } } From 8c7216958f0d4c90f426ecad01aba2f566001f00 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 25 Mar 2025 15:58:50 +0100 Subject: [PATCH 112/210] fix --- .github/workflows/Process-PSModule.yml | 3 +++ .github/workflows/Update-CoverageReport.yml | 2 +- .../private/Variables/Get-GitHubVariableVisibilityList.ps1 | 6 +++--- src/functions/public/Variables/Set-GitHubVariable.ps1 | 5 ++--- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/workflows/Process-PSModule.yml b/.github/workflows/Process-PSModule.yml index 2fdfe0422..eb49d367b 100644 --- a/.github/workflows/Process-PSModule.yml +++ b/.github/workflows/Process-PSModule.yml @@ -36,3 +36,6 @@ 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: + Debug: true + Verbose: true diff --git a/.github/workflows/Update-CoverageReport.yml b/.github/workflows/Update-CoverageReport.yml index 9b444e246..9cc37e711 100644 --- a/.github/workflows/Update-CoverageReport.yml +++ b/.github/workflows/Update-CoverageReport.yml @@ -22,4 +22,4 @@ jobs: - name: Update-CoverageReport uses: PSModule/GitHub-Script@v1 with: - Script: . '.\scripts\Update-CoverageReport.ps1' + Script: scripts/Update-CoverageReport.ps1 diff --git a/src/functions/private/Variables/Get-GitHubVariableVisibilityList.ps1 b/src/functions/private/Variables/Get-GitHubVariableVisibilityList.ps1 index 3cf783c13..3d058520d 100644 --- a/src/functions/private/Variables/Get-GitHubVariableVisibilityList.ps1 +++ b/src/functions/private/Variables/Get-GitHubVariableVisibilityList.ps1 @@ -41,9 +41,9 @@ function Get-GitHubVariableVisibilityList { ) begin { - # $stackPath = Get-PSCallStackPath - # Write-Debug "[$stackPath] - Start" - # Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + $stackPath = Get-PSCallStackPath + Write-Debug "[$stackPath] - Start" + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { diff --git a/src/functions/public/Variables/Set-GitHubVariable.ps1 b/src/functions/public/Variables/Set-GitHubVariable.ps1 index adb979c77..7a6d03d22 100644 --- a/src/functions/public/Variables/Set-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Set-GitHubVariable.ps1 @@ -93,6 +93,7 @@ function Set-GitHubVariable { Context = $Context } $getParams | Remove-HashtableEntry -NullOrEmptyValues + $variable = Get-GitHubVariable @getParams | Where-Object { $_.Name -eq $Name } $params = @{ Owner = $Owner @@ -105,12 +106,10 @@ function Set-GitHubVariable { ErrorAction = 'Stop' } if ($PSCmdlet.ParameterSetName -eq 'Organization') { - $params.Visibility = $Visibility + $params['Visibility'] = $Visibility } $params | Remove-HashtableEntry -NullOrEmptyValues - $variable = Get-GitHubVariable @getParams | Where-Object { $_.Name -eq $Name } - if ($variable) { $null = Update-GitHubVariable @params -PassThru } else { From 87c0926651fda4214473d824111834b0742d4435 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 25 Mar 2025 16:20:22 +0100 Subject: [PATCH 113/210] add output --- src/functions/public/Variables/Get-GitHubVariable.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/src/functions/public/Variables/Get-GitHubVariable.ps1 b/src/functions/public/Variables/Get-GitHubVariable.ps1 index 6434f2c45..704a7e39f 100644 --- a/src/functions/public/Variables/Get-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Get-GitHubVariable.ps1 @@ -214,6 +214,7 @@ function Get-GitHubVariable { break } } + $variables } end { From 98756ef158827d1fdf91b311a5db524a0cf19a59 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 25 Mar 2025 16:27:10 +0100 Subject: [PATCH 114/210] cleanup --- tests/Environments.Tests.ps1 | 141 ----------------------------------- 1 file changed, 141 deletions(-) delete mode 100644 tests/Environments.Tests.ps1 diff --git a/tests/Environments.Tests.ps1 b/tests/Environments.Tests.ps1 deleted file mode 100644 index 8295495b7..000000000 --- a/tests/Environments.Tests.ps1 +++ /dev/null @@ -1,141 +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 = 'Log outputs to GitHub Actions logs.' -)] -[CmdletBinding()] -param() - -BeforeAll { - $repoSuffix = 'EnvironmentTest' - $environmentName = 'production' - $os = $env:RUNNER_OS -} - -Describe 'Environments' { - $authCases = . "$PSScriptRoot/Data/AuthCases.ps1" - - Context 'As using on ' -ForEach $authCases { - BeforeAll { - $context = Connect-GitHubAccount @connectParams -PassThru -Silent - LogGroup 'Context' { - Write-Host ($context | Format-List | Out-String) - } - $guid = [guid]::NewGuid().ToString() - $repo = "$repoSuffix-$guid" - } - - AfterAll { - Remove-GitHubRepository -Owner $owner -Name $repo -Confirm:$false - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent - } - - # Tests for APP goes here - if ($AuthType -eq 'APP') { - It 'Connect-GitHubApp - Connects as a GitHub App to ' { - $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent - LogGroup 'Context' { - Write-Host ($context | Format-List | Out-String) - } - } - } - - # Tests for runners goes here - if ($Type -ne 'GitHub Actions') { - # Tests for IAT UAT and PAT goes here - It 'Prep - New-GitHubRepository' { - if ($OwnerType -eq 'user') { - New-GitHubRepository -Name $repo -AllowSquashMerge - } else { - New-GitHubRepository -Owner $owner -Name $repo -AllowSquashMerge - } - } - It 'Get-GitHubEnvironment - should return an empty list when no environments exist' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo - LogGroup 'Environment' { - Write-Host ($result | Format-Table | Out-String) - } - $result | Should -BeNullOrEmpty - } - It 'Get-GitHubEnvironment - should return null when retrieving a non-existent environment' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName - LogGroup 'Environment' { - Write-Host ($result | Format-Table | Out-String) - } - $result | Should -BeNullOrEmpty - } - It 'Set-GitHubEnvironment - should successfully create an environment with a wait timer of 10' { - $result = Set-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName -WaitTimer 10 - LogGroup 'Environment' { - Write-Host ($result | Format-List | Out-String) - } - $result | Should -Not -BeNullOrEmpty - $result | Should -BeOfType [GitHubEnvironment] - $result.Name | Should -Be $environmentName - $result.ProtectionRules.wait_timer | Should -Be 10 - } - It 'Get-GitHubEnvironment - should retrieve the environment that was created' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName - LogGroup 'Environment' { - Write-Host ($result | Format-List | Out-String) - } - $result | Should -Not -BeNullOrEmpty - $result.Name | Should -Be $environmentName - } - It 'Set-GitHubEnvironment - should successfully create an environment with a slash in its name' { - $result = Set-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" - LogGroup 'Environment' { - Write-Host ($result | Format-List | Out-String) - } - $result | Should -Not -BeNullOrEmpty - $result.Name | Should -Be "$environmentName/$os" - } - It 'Get-GitHubEnvironment - should retrieve the environment with a slash in its name' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" - LogGroup 'Environment' { - Write-Host ($result | Format-Table | Out-String) - } - $result | Should -Not -BeNullOrEmpty - $result.Name | Should -Be "$environmentName/$os" - } - It 'Remove-GitHubEnvironment - should delete the environment with a slash in its name without errors' { - { - Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" | Remove-GitHubEnvironment -Confirm:$false - } | Should -Not -Throw - } - It 'Get-GitHubEnvironment - should return null when retrieving the deleted environment with a slash in its name' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" - LogGroup 'Environment' { - Write-Host ($result | Format-Table | Out-String) - } - $result | Should -BeNullOrEmpty - } - It 'Get-GitHubEnvironment - should list one remaining environment' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo - LogGroup 'Environment' { - Write-Host ($result | Format-Table | Out-String) - } - $result.Count | Should -Be 1 - } - It 'Remove-GitHubEnvironment - should delete the remaining environment without errors' { - { Remove-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName -Confirm:$false } | Should -Not -Throw - } - It 'Get-GitHubEnvironment - should return null when retrieving an environment that does not exist' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName - LogGroup 'Environment' { - Write-Host ($result | Format-Table | Out-String) - } - $result | Should -BeNullOrEmpty - } - } - } -} From f2222299aa7ad1280f86458e864143a4994501c2 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 25 Mar 2025 17:29:13 +0100 Subject: [PATCH 115/210] =?UTF-8?q?=F0=9F=94=A7=20[Add]:=20Include=20debug?= =?UTF-8?q?=20and=20verbose=20logging=20in=20Set-GitHubVariable=20test=20f?= =?UTF-8?q?or=20better=20traceability?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 83f58d409..1ec4a3656 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -61,6 +61,9 @@ Describe 'Environments' { } It 'Set-GitHubVariable - should ensure existance of a organization variable' -Skip:($OwnerType -ne 'organization') { + Write-Debug "Test to see if Debug is working" + Write-Verbose 'Test to see if Verbose is working' + Write-Verbose 'Test to see if Verbose is working with switch' -Verbose Set-GitHubVariable -Owner $owner -Name $varName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id LogGroup 'Variable' { Write-Host ($result | Format-Table | Out-String) From 2ce014887a958c4e100d24f65bc41d243aa04974 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 25 Mar 2025 17:33:25 +0100 Subject: [PATCH 116/210] =?UTF-8?q?=F0=9F=94=A7=20[Enhance]:=20Add=20-Verb?= =?UTF-8?q?ose=20flag=20to=20Set-GitHubVariable=20in=20tests=20for=20impro?= =?UTF-8?q?ved=20logging?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 1ec4a3656..fce03c40d 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -64,7 +64,7 @@ Describe 'Environments' { Write-Debug "Test to see if Debug is working" Write-Verbose 'Test to see if Verbose is working' Write-Verbose 'Test to see if Verbose is working with switch' -Verbose - Set-GitHubVariable -Owner $owner -Name $varName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id + Set-GitHubVariable -Owner $owner -Name $varName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id -Verbose LogGroup 'Variable' { Write-Host ($result | Format-Table | Out-String) } From 899b66f2d05c0178ab79e33c07e24372c45a1fca Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 25 Mar 2025 17:36:40 +0100 Subject: [PATCH 117/210] =?UTF-8?q?=F0=9F=94=A7=20[Enhance]:=20Add=20-Debu?= =?UTF-8?q?g=20flag=20to=20Set-GitHubVariable=20in=20tests=20for=20improve?= =?UTF-8?q?d=20logging?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index fce03c40d..8284af645 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -64,7 +64,7 @@ Describe 'Environments' { Write-Debug "Test to see if Debug is working" Write-Verbose 'Test to see if Verbose is working' Write-Verbose 'Test to see if Verbose is working with switch' -Verbose - Set-GitHubVariable -Owner $owner -Name $varName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id -Verbose + Set-GitHubVariable -Owner $owner -Name $varName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id -Verbose -Debug LogGroup 'Variable' { Write-Host ($result | Format-Table | Out-String) } From a7ce9d359de34bb45ab9778937458683f49d47f4 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 25 Mar 2025 17:41:13 +0100 Subject: [PATCH 118/210] =?UTF-8?q?=F0=9F=94=A7=20[Enhance]:=20Move=20Set-?= =?UTF-8?q?GitHubVariable=20call=20inside=20LogGroup=20for=20improved=20lo?= =?UTF-8?q?gging=20context?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 8284af645..873c1fb5e 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -64,8 +64,8 @@ Describe 'Environments' { Write-Debug "Test to see if Debug is working" Write-Verbose 'Test to see if Verbose is working' Write-Verbose 'Test to see if Verbose is working with switch' -Verbose - Set-GitHubVariable -Owner $owner -Name $varName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id -Verbose -Debug LogGroup 'Variable' { + Set-GitHubVariable -Owner $owner -Name $varName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id -Verbose -Debug Write-Host ($result | Format-Table | Out-String) } $result | Should -Not -BeNullOrEmpty From 57c4938f460f0d31ce37ffa9f130eacf1534231b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 25 Mar 2025 18:14:28 +0100 Subject: [PATCH 119/210] =?UTF-8?q?=F0=9F=94=A7=20[Enhance]:=20Refactor=20?= =?UTF-8?q?repository=20creation=20logic=20for=20improved=20readability=20?= =?UTF-8?q?and=20logging=20context?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 873c1fb5e..e85e882be 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -42,12 +42,12 @@ Describe 'Environments' { $environmentName = "$testName-$os-$TokenType" if ($Type -ne 'GitHub Actions') { - if ($OwnerType -eq 'user') { - $repo = New-GitHubRepository -Name $repoName -AllowSquashMerge - } else { - $repo = New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge - } LogGroup 'Repository' { + if ($OwnerType -eq 'user') { + $repo = New-GitHubRepository -Name $repoName -AllowSquashMerge + } else { + $repo = New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge + } Write-Host ($repo | Format-List | Out-String) } } @@ -61,11 +61,8 @@ Describe 'Environments' { } It 'Set-GitHubVariable - should ensure existance of a organization variable' -Skip:($OwnerType -ne 'organization') { - Write-Debug "Test to see if Debug is working" - Write-Verbose 'Test to see if Verbose is working' - Write-Verbose 'Test to see if Verbose is working with switch' -Verbose LogGroup 'Variable' { - Set-GitHubVariable -Owner $owner -Name $varName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id -Verbose -Debug + $result = Set-GitHubVariable -Owner $owner -Name $varName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id Write-Host ($result | Format-Table | Out-String) } $result | Should -Not -BeNullOrEmpty From 6510ad7d34d3cd81a2aa8e5b4b0c6d85d631e6bf Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 25 Mar 2025 18:21:17 +0100 Subject: [PATCH 120/210] =?UTF-8?q?=F0=9F=94=A7=20[Fix]:=20Update=20reposi?= =?UTF-8?q?tory=20name=20format=20in=20environment=20tests=20for=20consist?= =?UTF-8?q?ency?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index e85e882be..3ce2a2714 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -35,7 +35,6 @@ Describe 'Environments' { Write-Host ($context | Format-List | Out-String) } } - $repoName = "$testName-$guid" $repoName = "$testName-$os-$TokenType" $varName = "$testName`_$os`_$TokenType" $variablePrefix = "$varName`_" @@ -67,7 +66,7 @@ Describe 'Environments' { } $result | Should -Not -BeNullOrEmpty $result | Should -BeOfType [GitHubVariable] - $result.Name | Should -Be "$os-$repo" + $result.Name | Should -Be $varName } # # Tests for runners goes here From 27fc142911718bf7d08f739a4f96c6eb30b3d7cc Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 25 Mar 2025 18:31:56 +0100 Subject: [PATCH 121/210] =?UTF-8?q?=F0=9F=94=A7=20[Fix]:=20Update=20OwnerT?= =?UTF-8?q?ype=20in=20AuthCases.ps1=20from=20'organization'=20to=20'reposi?= =?UTF-8?q?tory'=20for=20accuracy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Data/AuthCases.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Data/AuthCases.ps1 b/tests/Data/AuthCases.ps1 index 8172d67d3..63c7f1438 100644 --- a/tests/Data/AuthCases.ps1 +++ b/tests/Data/AuthCases.ps1 @@ -43,7 +43,7 @@ Target = 'this repository (GitHub)' Owner = 'PSModule' Repo = 'GitHub' - OwnerType = 'organization' + OwnerType = 'repository' ConnectParams = @{ Token = $env:GITHUB_TOKEN } From 4f115afed8223e884d6210f5f03dbc64ccd1f38e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 25 Mar 2025 18:48:18 +0100 Subject: [PATCH 122/210] =?UTF-8?q?=F0=9F=94=A7=20[Enhance]:=20Update=20Lo?= =?UTF-8?q?gGroup=20formatting=20in=20Variables.Tests.ps1=20for=20improved?= =?UTF-8?q?=20clarity=20and=20context?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 3ce2a2714..3f77af778 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -41,7 +41,7 @@ Describe 'Environments' { $environmentName = "$testName-$os-$TokenType" if ($Type -ne 'GitHub Actions') { - LogGroup 'Repository' { + LogGroup "Repository - [$repoName]" { if ($OwnerType -eq 'user') { $repo = New-GitHubRepository -Name $repoName -AllowSquashMerge } else { @@ -59,8 +59,8 @@ Describe 'Environments' { Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent } - It 'Set-GitHubVariable - should ensure existance of a organization variable' -Skip:($OwnerType -ne 'organization') { - LogGroup 'Variable' { + It "Set-GitHubVariable - should ensure existance of a organization variable" -Skip:($OwnerType -ne 'organization') { + LogGroup "Variable - [$varName]" { $result = Set-GitHubVariable -Owner $owner -Name $varName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id Write-Host ($result | Format-Table | Out-String) } From b158468f91953b30a71d3e3b73316762a70407d2 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 25 Mar 2025 19:16:31 +0100 Subject: [PATCH 123/210] commit message goes here --- tests/Variables.Tests.ps1 | 269 ++++++++++++++++++++++++-------------- 1 file changed, 174 insertions(+), 95 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 3f77af778..914b2a26a 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -59,104 +59,183 @@ Describe 'Environments' { Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent } - It "Set-GitHubVariable - should ensure existance of a organization variable" -Skip:($OwnerType -ne 'organization') { - LogGroup "Variable - [$varName]" { - $result = Set-GitHubVariable -Owner $owner -Name $varName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id - Write-Host ($result | Format-Table | Out-String) + + # Tests for IAT UAT and PAT goes here + Context 'Organization' -Skip:($OwnerType -ne 'organization') { + It "Set-GitHubVariable - should ensure existance of a organization variable" { + LogGroup "Variable - [$varName]" { + $result = Set-GitHubVariable -Owner $owner -Name $varName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id + Write-Host ($result | Format-Table | Out-String) + } + $result | Should -Not -BeNullOrEmpty + $result | Should -BeOfType [GitHubVariable] + $result.Name | Should -Be $varName + } + + 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 } - $result | Should -Not -BeNullOrEmpty - $result | Should -BeOfType [GitHubVariable] - $result.Name | Should -Be $varName } + 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 + } - # # Tests for runners goes here - # if ($Type -ne 'GitHub Actions') { - # # Tests for IAT UAT and PAT goes here - # It 'Prep - New-GitHubRepository' { - # if ($OwnerType -eq 'user') { - # New-GitHubRepository -Name $repo -AllowSquashMerge - # } else { - # New-GitHubRepository -Owner $owner -Name $repo -AllowSquashMerge - # } - # } - # It 'Get-GitHubEnvironment - should return an empty list when no environments exist' { - # $result = Get-GitHubEnvironment -Owner $owner -Repository $repo - # LogGroup 'Environment' { - # Write-Host ($result | Format-Table | Out-String) - # } - # $result | Should -BeNullOrEmpty - # } - # It 'Get-GitHubEnvironment - should return null when retrieving a non-existent environment' { - # $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName - # LogGroup 'Environment' { - # Write-Host ($result | Format-Table | Out-String) - # } - # $result | Should -BeNullOrEmpty - # } - # It 'Set-GitHubEnvironment - should successfully create an environment with a wait timer of 10' { - # $result = Set-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName -WaitTimer 10 - # LogGroup 'Environment' { - # Write-Host ($result | Format-List | Out-String) - # } - # $result | Should -Not -BeNullOrEmpty - # $result | Should -BeOfType [GitHubEnvironment] - # $result.Name | Should -Be $environmentName - # $result.ProtectionRules.wait_timer | Should -Be 10 - # } - # It 'Get-GitHubEnvironment - should retrieve the environment that was created' { - # $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName - # LogGroup 'Environment' { - # Write-Host ($result | Format-List | Out-String) - # } - # $result | Should -Not -BeNullOrEmpty - # $result.Name | Should -Be $environmentName - # } - # It 'Set-GitHubEnvironment - should successfully create an environment with a slash in its name' { - # $result = Set-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" - # LogGroup 'Environment' { - # Write-Host ($result | Format-List | Out-String) - # } - # $result | Should -Not -BeNullOrEmpty - # $result.Name | Should -Be "$environmentName/$os" - # } - # It 'Get-GitHubEnvironment - should retrieve the environment with a slash in its name' { - # $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" - # LogGroup 'Environment' { - # Write-Host ($result | Format-Table | Out-String) - # } - # $result | Should -Not -BeNullOrEmpty - # $result.Name | Should -Be "$environmentName/$os" - # } - # It 'Remove-GitHubEnvironment - should delete the environment with a slash in its name without errors' { - # { - # Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" | Remove-GitHubEnvironment -Confirm:$false - # } | Should -Not -Throw - # } - # It 'Get-GitHubEnvironment - should return null when retrieving the deleted environment with a slash in its name' { - # $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" - # LogGroup 'Environment' { - # Write-Host ($result | Format-Table | Out-String) - # } - # $result | Should -BeNullOrEmpty - # } - # It 'Get-GitHubEnvironment - should list one remaining environment' { - # $result = Get-GitHubEnvironment -Owner $owner -Repository $repo - # LogGroup 'Environment' { - # Write-Host ($result | Format-Table | Out-String) - # } - # $result.Count | Should -Be 1 - # } - # It 'Remove-GitHubEnvironment - should delete the remaining environment without errors' { - # { Remove-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName -Confirm:$false } | Should -Not -Throw - # } - # It 'Get-GitHubEnvironment - should return null when retrieving an environment that does not exist' { - # $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName - # LogGroup 'Environment' { - # Write-Host ($result | Format-Table | Out-String) - # } - # $result | Should -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*" + LogGroup 'Variables' { + Write-Host "$($result | Format-Table | Out-String)" + } + $result | Should -Not -BeNullOrEmpty + } + + It 'Get-GitHubVariable -All' { + $result = Get-GitHubVariable @scope -Name "*$os*" -All + LogGroup 'Variables' { + Write-Host "$($result | Format-Table | Out-String)" + } + $result | Should -Not -BeNullOrEmpty + } + + It 'Remove-GitHubVariable' { + $before = Get-GitHubVariable @scope -Name "*$os*" + LogGroup 'Variables - Before' { + Write-Host "$($before | Format-Table | Out-String)" + } + $before | Remove-GitHubVariable + $after = Get-GitHubVariable @scope -Name "*$os*" + LogGroup 'Variables -After' { + 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 + } + } It 'Remove-GitHubVariable - should delete the organization variable' -Skip:($OwnerType -ne 'organization') { $result = Get-GitHubVariable -Owner $owner -Name "$varName*" From 6857adbeae7caeb52aba0daae0efded10f72679c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 25 Mar 2025 21:45:28 +0100 Subject: [PATCH 124/210] =?UTF-8?q?=F0=9F=94=A7=20[Enhance]:=20Simplify=20?= =?UTF-8?q?Get-GitHubVariable=20examples=20by=20removing=20unnecessary=20C?= =?UTF-8?q?ontext=20parameter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../public/Variables/Get-GitHubVariable.ps1 | 12 +-- tests/Variables.Tests.ps1 | 91 +++++++++++++++---- 2 files changed, 77 insertions(+), 26 deletions(-) diff --git a/src/functions/public/Variables/Get-GitHubVariable.ps1 b/src/functions/public/Variables/Get-GitHubVariable.ps1 index 704a7e39f..5bbbef752 100644 --- a/src/functions/public/Variables/Get-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Get-GitHubVariable.ps1 @@ -11,7 +11,7 @@ function Get-GitHubVariable { `admin:org` for organizations, and collaborator access for environments. .EXAMPLE - Get-GitHubVariable -Owner 'octocat' -Name 'HOST_NAME' -Context $GitHubContext + Get-GitHubVariable -Owner 'octocat' -Name 'HOST_NAME' Output: ```powershell @@ -25,7 +25,7 @@ function Get-GitHubVariable { Retrieves the specified variable from the organization level. .EXAMPLE - Get-GitHubVariable -Owner 'octocat' -Repository 'Hello-World' -Name 'GUID' -Context $GitHubContext + Get-GitHubVariable -Owner 'octocat' -Repository 'Hello-World' -Name 'GUID' Output: ```powershell @@ -39,7 +39,7 @@ function Get-GitHubVariable { Retrieves the specified variable from the repository level. .EXAMPLE - Get-GitHubVariable -Owner 'octocat' -Repository 'Hello-World' -Environment 'dev' -Name 'DB_SERVER' -Context $GitHubContext + Get-GitHubVariable -Owner 'octocat' -Repository 'Hello-World' -Environment 'dev' -Name 'DB_SERVER' Output: ```powershell @@ -53,7 +53,7 @@ function Get-GitHubVariable { Retrieves the specified variable from the environment level within a repository. .EXAMPLE - Get-GitHubVariable -Owner 'octocat' -Context $GitHubContext + Get-GitHubVariable -Owner 'octocat' Output: ```powershell @@ -73,7 +73,7 @@ function Get-GitHubVariable { Retrieves all variables available at the organization level. .EXAMPLE - Get-GitHubVariable -Owner 'octocat' -Repository 'Hello-World' -Context $GitHubContext + Get-GitHubVariable -Owner 'octocat' -Repository 'Hello-World' Output: ```powershell @@ -93,7 +93,7 @@ function Get-GitHubVariable { Retrieves all variables available at the repository level. .EXAMPLE - Get-GitHubVariable -Owner 'octocat' -Repository 'Hello-World' -Environment 'staging' -Context $GitHubContext + Get-GitHubVariable -Owner 'octocat' -Repository 'Hello-World' -Environment 'staging' Output: ```powershell diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 914b2a26a..1733068ce 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -30,8 +30,8 @@ Describe 'Environments' { Write-Host ($context | Format-List | Out-String) } if ($AuthType -eq 'APP') { - $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent LogGroup 'Context - Installation' { + $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent Write-Host ($context | Format-List | Out-String) } } @@ -50,6 +50,13 @@ Describe 'Environments' { Write-Host ($repo | Format-List | Out-String) } } + + if ($OwnerType -eq 'organization') { + LogGroup "Org variable - [$varName]" { + $result = Set-GitHubVariable -Owner $owner -Name $varName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id + Write-Host ($result | Format-Table | Out-String) + } + } } AfterAll { @@ -59,46 +66,90 @@ Describe 'Environments' { Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent } - # Tests for IAT UAT and PAT goes here Context 'Organization' -Skip:($OwnerType -ne 'organization') { - It "Set-GitHubVariable - should ensure existance of a organization variable" { + BeforeAll { + $scope = @{ + Owner = $owner + } + } + It 'Set-GitHubVariable - should ensure existance of a organization variable' { + $name = "$variablePrefix`TestVariable" LogGroup "Variable - [$varName]" { - $result = Set-GitHubVariable -Owner $owner -Name $varName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id + $param = @{ + Name = $name + Value = 'TestValue1234' + Visibility = 'private' + } + $result = Set-GitHubVariable @param @scope Write-Host ($result | Format-Table | Out-String) } $result | Should -Not -BeNullOrEmpty $result | Should -BeOfType [GitHubVariable] - $result.Name | Should -Be $varName + $result.Name | Should -Be $name + $result.Value | Should -Be 'TestValue1234' + $result.Visibility | Should -Be 'private' } - It 'Update-GitHubVariable' { + It 'Set-GitHubVariable - should update an existing organization variable' { + $name = "$variablePrefix`TestVariable" + LogGroup "Variable - [$varName]" { + $param = @{ + Name = $name + Value = 'TestValue123456789' + Visibility = 'all' + } + $result = Set-GitHubVariable @param @scope + Write-Host ($result | Format-Table | Out-String) + } + $result | Should -Not -BeNullOrEmpty + $result | Should -BeOfType [GitHubVariable] + $result.Name | Should -Be $name + $result.Value | Should -Be 'TestValue123456789' + $result.Visibility | Should -Be 'all' + } + + It 'Update-GitHubVariable - should update an existing organization variable' { + $name = "$variablePrefix`TestVariable" $param = @{ - Name = "$variablePrefix`TestVariable" + Name = $name Value = 'TestValue1234' - Visibility = 'all' } $result = Update-GitHubVariable @param @scope -PassThru + Write-Host ($result | Format-Table | Out-String) $result | Should -Not -BeNullOrEmpty + $result | Should -BeOfType [GitHubVariable] + $result.Name | Should -Be $name + $result.Value | Should -Be 'TestValue1234' + $result.Visibility | Should -Be 'all' } - It 'New-GitHubVariable' { + It 'New-GitHubVariable - should create a new organization variable' { + $name = "$variablePrefix`TestVariable2" $param = @{ - Name = "$variablePrefix`TestVariable2" + Name = $name Value = 'TestValue123' } $result = New-GitHubVariable @param @scope + Write-Host ($result | Format-Table | Out-String) $result | Should -Not -BeNullOrEmpty + $result | Should -BeOfType [GitHubVariable] + $result.Name | Should -Be $name + $result.Value | Should -Be 'TestValue123' + $result.Visibility | Should -Be 'private' } - It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($result | Format-Table | Out-String)" - $result | Should -Not -BeNullOrEmpty + It 'New-GitHubVariable - should throw if creating an organization variable that exists' { + $name = "$variablePrefix`TestVariable2" + $param = @{ + Name = $name + Value = 'TestValue123' + } + { New-GitHubVariable @param @scope } | Should -Throw } - It 'Get-GitHubVariable -All' { - $result = Get-GitHubVariable @scope -Name "*$os*" -All + It 'Get-GitHubVariable' { + $result = Get-GitHubVariable @scope -Name "*$os*" Write-Host "$($result | Format-Table | Out-String)" $result | Should -Not -BeNullOrEmpty } @@ -156,8 +207,8 @@ Describe 'Environments' { $result | Should -Not -BeNullOrEmpty } - It 'Get-GitHubVariable -All' { - $result = Get-GitHubVariable @scope -Name "*$os*" -All + It 'Get-GitHubVariable -IncludeInherited' { + $result = Get-GitHubVariable @scope -Name "*$os*" -IncludeInherited LogGroup 'Variables' { Write-Host "$($result | Format-Table | Out-String)" } @@ -221,8 +272,8 @@ Describe 'Environments' { $result | Should -Not -BeNullOrEmpty } - It 'Get-GitHubVariable -All' { - $result = Get-GitHubVariable @scope -Name "*$os*" -All + It 'Get-GitHubVariable -IncludeInherited' { + $result = Get-GitHubVariable @scope -Name "*$os*" -IncludeInherited Write-Host "$($result | Format-Table | Out-String)" $result | Should -Not -BeNullOrEmpty } From 4f66fdadfaf79896662b267e4eae9ab743631e3a Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 25 Mar 2025 22:09:22 +0100 Subject: [PATCH 125/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Comment=20?= =?UTF-8?q?out=20unused=20test=20cases=20in=20Variables.Tests.ps1=20for=20?= =?UTF-8?q?clarity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 228 +++++++++++++++++++------------------- 1 file changed, 114 insertions(+), 114 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 1733068ce..a15fa40a3 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -163,130 +163,130 @@ Describe 'Environments' { $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 - } + # 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 '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 '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*" - LogGroup 'Variables' { - Write-Host "$($result | Format-Table | Out-String)" - } - $result | Should -Not -BeNullOrEmpty - } + # It 'Get-GitHubVariable' { + # $result = Get-GitHubVariable @scope -Name "*$os*" + # LogGroup 'Variables' { + # Write-Host "$($result | Format-Table | Out-String)" + # } + # $result | Should -Not -BeNullOrEmpty + # } - It 'Get-GitHubVariable -IncludeInherited' { - $result = Get-GitHubVariable @scope -Name "*$os*" -IncludeInherited - LogGroup 'Variables' { - Write-Host "$($result | Format-Table | Out-String)" - } - $result | Should -Not -BeNullOrEmpty - } + # It 'Get-GitHubVariable -IncludeInherited' { + # $result = Get-GitHubVariable @scope -Name "*$os*" -IncludeInherited + # LogGroup 'Variables' { + # Write-Host "$($result | Format-Table | Out-String)" + # } + # $result | Should -Not -BeNullOrEmpty + # } - It 'Remove-GitHubVariable' { - $before = Get-GitHubVariable @scope -Name "*$os*" - LogGroup 'Variables - Before' { - Write-Host "$($before | Format-Table | Out-String)" - } - $before | Remove-GitHubVariable - $after = Get-GitHubVariable @scope -Name "*$os*" - LogGroup 'Variables -After' { - 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 'Remove-GitHubVariable' { + # $before = Get-GitHubVariable @scope -Name "*$os*" + # LogGroup 'Variables - Before' { + # Write-Host "$($before | Format-Table | Out-String)" + # } + # $before | Remove-GitHubVariable + # $after = Get-GitHubVariable @scope -Name "*$os*" + # LogGroup 'Variables -After' { + # 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 '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 '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' { + # $result = Get-GitHubVariable @scope -Name "*$os*" + # Write-Host "$($result | Format-Table | Out-String)" + # $result | Should -Not -BeNullOrEmpty + # } - It 'Get-GitHubVariable -IncludeInherited' { - $result = Get-GitHubVariable @scope -Name "*$os*" -IncludeInherited - Write-Host "$($result | Format-Table | Out-String)" - $result | Should -Not -BeNullOrEmpty - } + # It 'Get-GitHubVariable -IncludeInherited' { + # $result = Get-GitHubVariable @scope -Name "*$os*" -IncludeInherited + # 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 - } - } + # 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 + # } + # } It 'Remove-GitHubVariable - should delete the organization variable' -Skip:($OwnerType -ne 'organization') { $result = Get-GitHubVariable -Owner $owner -Name "$varName*" From a636512ea869d36467d0638c71c7f4442994f1cc Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 25 Mar 2025 22:24:36 +0100 Subject: [PATCH 126/210] Refactor: Remove redundant variables in DataProcessing.ps1 for improved readability --- tests/Variables.Tests.ps1 | 298 ++++++++++++++++++++------------------ 1 file changed, 157 insertions(+), 141 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index a15fa40a3..8e7738d1c 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -111,12 +111,14 @@ Describe 'Environments' { It 'Update-GitHubVariable - should update an existing organization variable' { $name = "$variablePrefix`TestVariable" - $param = @{ - Name = $name - Value = 'TestValue1234' + LogGroup "Variable - [$varName]" { + $param = @{ + Name = $name + Value = 'TestValue1234' + } + $result = Update-GitHubVariable @param @scope -PassThru + Write-Host ($result | Format-Table | Out-String) } - $result = Update-GitHubVariable @param @scope -PassThru - Write-Host ($result | Format-Table | Out-String) $result | Should -Not -BeNullOrEmpty $result | Should -BeOfType [GitHubVariable] $result.Name | Should -Be $name @@ -126,12 +128,14 @@ Describe 'Environments' { It 'New-GitHubVariable - should create a new organization variable' { $name = "$variablePrefix`TestVariable2" - $param = @{ - Name = $name - Value = 'TestValue123' + LogGroup "Variable - [$varName]" { + $param = @{ + Name = $name + Value = 'TestValue123' + } + $result = New-GitHubVariable @param @scope + Write-Host ($result | Format-Table | Out-String) } - $result = New-GitHubVariable @param @scope - Write-Host ($result | Format-Table | Out-String) $result | Should -Not -BeNullOrEmpty $result | Should -BeOfType [GitHubVariable] $result.Name | Should -Be $name @@ -141,160 +145,172 @@ Describe 'Environments' { It 'New-GitHubVariable - should throw if creating an organization variable that exists' { $name = "$variablePrefix`TestVariable2" - $param = @{ - Name = $name - Value = 'TestValue123' + LogGroup "Variable - [$varName]" { + $param = @{ + Name = $name + Value = 'TestValue123' + } + { + $result = New-GitHubVariable @param @scope + Write-Host ($result | Format-Table | Out-String) + } | Should -Throw } - { New-GitHubVariable @param @scope } | Should -Throw } + } - It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope -Name "*$os*" + It 'Get-GitHubVariable' { + $result = Get-GitHubVariable @scope -Name "*$os*" + LogGroup 'Variables' { Write-Host "$($result | Format-Table | Out-String)" - $result | Should -Not -BeNullOrEmpty } + $result | Should -Not -BeNullOrEmpty + } - It 'Remove-GitHubVariable' { - $before = Get-GitHubVariable @scope -Name "*$os*" + It 'Remove-GitHubVariable' { + $before = Get-GitHubVariable @scope -Name "*$os*" + LogGroup 'Before remove' { Write-Host "$($before | Format-Table | Out-String)" $before | Remove-GitHubVariable + } + LogGroup 'After remove' { $after = Get-GitHubVariable @scope -Name "*$os*" Write-Host "$($after | Format-Table | Out-String)" - $after.Count | Should -Be 0 } + $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 - # } + } + # 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 '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 '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*" - # LogGroup 'Variables' { - # Write-Host "$($result | Format-Table | Out-String)" - # } - # $result | Should -Not -BeNullOrEmpty - # } + # It 'Get-GitHubVariable' { + # $result = Get-GitHubVariable @scope -Name "*$os*" + # LogGroup 'Variables' { + # Write-Host "$($result | Format-Table | Out-String)" + # } + # $result | Should -Not -BeNullOrEmpty + # } - # It 'Get-GitHubVariable -IncludeInherited' { - # $result = Get-GitHubVariable @scope -Name "*$os*" -IncludeInherited - # LogGroup 'Variables' { - # Write-Host "$($result | Format-Table | Out-String)" - # } - # $result | Should -Not -BeNullOrEmpty - # } + # It 'Get-GitHubVariable -IncludeInherited' { + # $result = Get-GitHubVariable @scope -Name "*$os*" -IncludeInherited + # LogGroup 'Variables' { + # Write-Host "$($result | Format-Table | Out-String)" + # } + # $result | Should -Not -BeNullOrEmpty + # } - # It 'Remove-GitHubVariable' { - # $before = Get-GitHubVariable @scope -Name "*$os*" - # LogGroup 'Variables - Before' { - # Write-Host "$($before | Format-Table | Out-String)" - # } - # $before | Remove-GitHubVariable - # $after = Get-GitHubVariable @scope -Name "*$os*" - # LogGroup 'Variables -After' { - # 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 'Remove-GitHubVariable' { + # $before = Get-GitHubVariable @scope -Name "*$os*" + # LogGroup 'Variables - Before' { + # Write-Host "$($before | Format-Table | Out-String)" + # } + # $before | Remove-GitHubVariable + # $after = Get-GitHubVariable @scope -Name "*$os*" + # LogGroup 'Variables -After' { + # 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 '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 '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' { + # $result = Get-GitHubVariable @scope -Name "*$os*" + # Write-Host "$($result | Format-Table | Out-String)" + # $result | Should -Not -BeNullOrEmpty + # } - # It 'Get-GitHubVariable -IncludeInherited' { - # $result = Get-GitHubVariable @scope -Name "*$os*" -IncludeInherited - # Write-Host "$($result | Format-Table | Out-String)" - # $result | Should -Not -BeNullOrEmpty - # } + # It 'Get-GitHubVariable -IncludeInherited' { + # $result = Get-GitHubVariable @scope -Name "*$os*" -IncludeInherited + # 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 - # } - # } + # 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 + # } + # } - It 'Remove-GitHubVariable - should delete the organization variable' -Skip:($OwnerType -ne 'organization') { - $result = Get-GitHubVariable -Owner $owner -Name "$varName*" - LogGroup 'Variable' { - Write-Host ($result | Format-Table | Out-String) - } - $result | Should -Not -BeNullOrEmpty - $result | Remove-GitHubVariable + It 'Remove-GitHubVariable - should delete the organization variable' -Skip:($OwnerType -ne 'organization') { + $result = Get-GitHubVariable -Owner $owner -Name "$varName*" + LogGroup 'Variable' { + Write-Host ($result | Format-Table | Out-String) } + $result | Should -Not -BeNullOrEmpty + $result | Remove-GitHubVariable } } +} From d530777c97112562536756ca50d8ae91d3f5f61f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 25 Mar 2025 22:30:47 +0100 Subject: [PATCH 127/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Remove=20u?= =?UTF-8?q?nnecessary=20closing=20brace=20in=20Variables.Tests.ps1=20for?= =?UTF-8?q?=20cleaner=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 8e7738d1c..f11af7d4e 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -313,4 +313,3 @@ Describe 'Environments' { $result | Remove-GitHubVariable } } -} From 92a22a65e6d620dce0037f139d37d4e4dafd736f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 25 Mar 2025 22:48:06 +0100 Subject: [PATCH 128/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Improve=20?= =?UTF-8?q?test=20structure=20in=20Variables.Tests.ps1=20for=20better=20re?= =?UTF-8?q?adability=20and=20clarity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index f11af7d4e..895eaba14 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -156,27 +156,27 @@ Describe 'Environments' { } | Should -Throw } } - } - It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope -Name "*$os*" - LogGroup 'Variables' { - Write-Host "$($result | Format-Table | Out-String)" + It 'Get-GitHubVariable' { + $result = Get-GitHubVariable @scope -Name "*$os*" + LogGroup 'Variables' { + Write-Host "$($result | Format-Table | Out-String)" + } + $result | Should -Not -BeNullOrEmpty } - $result | Should -Not -BeNullOrEmpty - } - It 'Remove-GitHubVariable' { - $before = Get-GitHubVariable @scope -Name "*$os*" - LogGroup 'Before remove' { - Write-Host "$($before | Format-Table | Out-String)" - $before | Remove-GitHubVariable - } - LogGroup 'After remove' { - $after = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($after | Format-Table | Out-String)" + It 'Remove-GitHubVariable' { + $before = Get-GitHubVariable @scope -Name "*$os*" + LogGroup 'Before remove' { + Write-Host "$($before | Format-Table | Out-String)" + $before | Remove-GitHubVariable + } + LogGroup 'After remove' { + $after = Get-GitHubVariable @scope -Name "*$os*" + Write-Host "$($after | Format-Table | Out-String)" + } + $after.Count | Should -Be 0 } - $after.Count | Should -Be 0 } } # Context 'Repository' { From 6843557bc5d211aeed8945ba444837e8634d05c5 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 25 Mar 2025 23:00:47 +0100 Subject: [PATCH 129/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Update=20v?= =?UTF-8?q?isibility=20parameter=20in=20Update-GitHubVariable=20function?= =?UTF-8?q?=20and=20correct=20variable=20name=20in=20test=20logs=20for=20c?= =?UTF-8?q?onsistency?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/functions/public/Variables/Update-GitHubVariable.ps1 | 2 +- tests/Variables.Tests.ps1 | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/functions/public/Variables/Update-GitHubVariable.ps1 b/src/functions/public/Variables/Update-GitHubVariable.ps1 index e7926a3bf..4354ac82c 100644 --- a/src/functions/public/Variables/Update-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Update-GitHubVariable.ps1 @@ -68,7 +68,7 @@ function Update-GitHubVariable { # Can be `private`, `selected`, or `all`. [Parameter(ParameterSetName = 'Organization')] [ValidateSet('private', 'selected', 'all')] - [string] $Visibility = 'private', + [string] $Visibility, # The IDs of the repositories to which the variable is available. # Used only when the `-Visibility` parameter is set to `selected`. diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 895eaba14..01703ef0c 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -75,7 +75,7 @@ Describe 'Environments' { } It 'Set-GitHubVariable - should ensure existance of a organization variable' { $name = "$variablePrefix`TestVariable" - LogGroup "Variable - [$varName]" { + LogGroup "Variable - [$name]" { $param = @{ Name = $name Value = 'TestValue1234' @@ -93,7 +93,7 @@ Describe 'Environments' { It 'Set-GitHubVariable - should update an existing organization variable' { $name = "$variablePrefix`TestVariable" - LogGroup "Variable - [$varName]" { + LogGroup "Variable - [$name]" { $param = @{ Name = $name Value = 'TestValue123456789' @@ -111,7 +111,7 @@ Describe 'Environments' { It 'Update-GitHubVariable - should update an existing organization variable' { $name = "$variablePrefix`TestVariable" - LogGroup "Variable - [$varName]" { + LogGroup "Variable - [$name]" { $param = @{ Name = $name Value = 'TestValue1234' @@ -128,7 +128,7 @@ Describe 'Environments' { It 'New-GitHubVariable - should create a new organization variable' { $name = "$variablePrefix`TestVariable2" - LogGroup "Variable - [$varName]" { + LogGroup "Variable - [$name]" { $param = @{ Name = $name Value = 'TestValue123' From 50da57fbf7a3e0a6fb21a67311807cc388cbb04e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 25 Mar 2025 23:05:42 +0100 Subject: [PATCH 130/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Update=20W?= =?UTF-8?q?rite-Host=20statements=20in=20Variables.Tests.ps1=20to=20use=20?= =?UTF-8?q?Select-Object=20for=20improved=20output=20clarity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 01703ef0c..dcab3b171 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -54,7 +54,7 @@ Describe 'Environments' { if ($OwnerType -eq 'organization') { LogGroup "Org variable - [$varName]" { $result = Set-GitHubVariable -Owner $owner -Name $varName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id - Write-Host ($result | Format-Table | Out-String) + Write-Host ($result | Select-Object * | Format-Table | Out-String) } } } @@ -82,7 +82,7 @@ Describe 'Environments' { Visibility = 'private' } $result = Set-GitHubVariable @param @scope - Write-Host ($result | Format-Table | Out-String) + Write-Host ($result | Select-Object * | Format-Table | Out-String) } $result | Should -Not -BeNullOrEmpty $result | Should -BeOfType [GitHubVariable] @@ -100,7 +100,7 @@ Describe 'Environments' { Visibility = 'all' } $result = Set-GitHubVariable @param @scope - Write-Host ($result | Format-Table | Out-String) + Write-Host ($result | Select-Object * | Format-Table | Out-String) } $result | Should -Not -BeNullOrEmpty $result | Should -BeOfType [GitHubVariable] @@ -117,7 +117,7 @@ Describe 'Environments' { Value = 'TestValue1234' } $result = Update-GitHubVariable @param @scope -PassThru - Write-Host ($result | Format-Table | Out-String) + Write-Host ($result | Select-Object * | Format-Table | Out-String) } $result | Should -Not -BeNullOrEmpty $result | Should -BeOfType [GitHubVariable] @@ -134,7 +134,7 @@ Describe 'Environments' { Value = 'TestValue123' } $result = New-GitHubVariable @param @scope - Write-Host ($result | Format-Table | Out-String) + Write-Host ($result | Select-Object * | Format-Table | Out-String) } $result | Should -Not -BeNullOrEmpty $result | Should -BeOfType [GitHubVariable] @@ -152,7 +152,7 @@ Describe 'Environments' { } { $result = New-GitHubVariable @param @scope - Write-Host ($result | Format-Table | Out-String) + Write-Host ($result | Select-Object * | Format-Table | Out-String) } | Should -Throw } } @@ -160,7 +160,7 @@ Describe 'Environments' { It 'Get-GitHubVariable' { $result = Get-GitHubVariable @scope -Name "*$os*" LogGroup 'Variables' { - Write-Host "$($result | Format-Table | Out-String)" + Write-Host "$($result | Select-Object * | Format-Table | Out-String)" } $result | Should -Not -BeNullOrEmpty } @@ -218,7 +218,7 @@ Describe 'Environments' { # It 'Get-GitHubVariable' { # $result = Get-GitHubVariable @scope -Name "*$os*" # LogGroup 'Variables' { - # Write-Host "$($result | Format-Table | Out-String)" + # Write-Host "$($result | Select-Object * | Format-Table | Out-String)" # } # $result | Should -Not -BeNullOrEmpty # } @@ -226,7 +226,7 @@ Describe 'Environments' { # It 'Get-GitHubVariable -IncludeInherited' { # $result = Get-GitHubVariable @scope -Name "*$os*" -IncludeInherited # LogGroup 'Variables' { - # Write-Host "$($result | Format-Table | Out-String)" + # Write-Host "$($result | Select-Object * | Format-Table | Out-String)" # } # $result | Should -Not -BeNullOrEmpty # } @@ -284,13 +284,13 @@ Describe 'Environments' { # It 'Get-GitHubVariable' { # $result = Get-GitHubVariable @scope -Name "*$os*" - # Write-Host "$($result | Format-Table | Out-String)" + # Write-Host "$($result | Select-Object * | Format-Table | Out-String)" # $result | Should -Not -BeNullOrEmpty # } # It 'Get-GitHubVariable -IncludeInherited' { # $result = Get-GitHubVariable @scope -Name "*$os*" -IncludeInherited - # Write-Host "$($result | Format-Table | Out-String)" + # Write-Host "$($result | Select-Object * | Format-Table | Out-String)" # $result | Should -Not -BeNullOrEmpty # } @@ -307,7 +307,7 @@ Describe 'Environments' { It 'Remove-GitHubVariable - should delete the organization variable' -Skip:($OwnerType -ne 'organization') { $result = Get-GitHubVariable -Owner $owner -Name "$varName*" LogGroup 'Variable' { - Write-Host ($result | Format-Table | Out-String) + Write-Host ($result | Select-Object * | Format-Table | Out-String) } $result | Should -Not -BeNullOrEmpty $result | Remove-GitHubVariable From d67ba10de70ca96f7b7e2a57023b85dfd7ab3dae Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 25 Mar 2025 23:06:49 +0100 Subject: [PATCH 131/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Update=20W?= =?UTF-8?q?rite-Host=20statements=20in=20Variables.Tests.ps1=20to=20use=20?= =?UTF-8?q?Format-List=20for=20improved=20output=20readability?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 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 dcab3b171..90d919c99 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -82,7 +82,7 @@ Describe 'Environments' { Visibility = 'private' } $result = Set-GitHubVariable @param @scope - Write-Host ($result | Select-Object * | Format-Table | Out-String) + Write-Host ($result | Select-Object * | Format-List | Out-String) } $result | Should -Not -BeNullOrEmpty $result | Should -BeOfType [GitHubVariable] @@ -100,7 +100,7 @@ Describe 'Environments' { Visibility = 'all' } $result = Set-GitHubVariable @param @scope - Write-Host ($result | Select-Object * | Format-Table | Out-String) + Write-Host ($result | Select-Object * | Format-List | Out-String) } $result | Should -Not -BeNullOrEmpty $result | Should -BeOfType [GitHubVariable] @@ -117,7 +117,7 @@ Describe 'Environments' { Value = 'TestValue1234' } $result = Update-GitHubVariable @param @scope -PassThru - Write-Host ($result | Select-Object * | Format-Table | Out-String) + Write-Host ($result | Select-Object * | Format-List | Out-String) } $result | Should -Not -BeNullOrEmpty $result | Should -BeOfType [GitHubVariable] @@ -134,7 +134,7 @@ Describe 'Environments' { Value = 'TestValue123' } $result = New-GitHubVariable @param @scope - Write-Host ($result | Select-Object * | Format-Table | Out-String) + Write-Host ($result | Select-Object * | Format-List | Out-String) } $result | Should -Not -BeNullOrEmpty $result | Should -BeOfType [GitHubVariable] @@ -152,7 +152,7 @@ Describe 'Environments' { } { $result = New-GitHubVariable @param @scope - Write-Host ($result | Select-Object * | Format-Table | Out-String) + Write-Host ($result | Select-Object * | Format-List | Out-String) } | Should -Throw } } @@ -160,7 +160,7 @@ Describe 'Environments' { It 'Get-GitHubVariable' { $result = Get-GitHubVariable @scope -Name "*$os*" LogGroup 'Variables' { - Write-Host "$($result | Select-Object * | Format-Table | Out-String)" + Write-Host "$($result | Select-Object * | Format-List | Out-String)" } $result | Should -Not -BeNullOrEmpty } @@ -168,12 +168,12 @@ Describe 'Environments' { It 'Remove-GitHubVariable' { $before = Get-GitHubVariable @scope -Name "*$os*" LogGroup 'Before remove' { - Write-Host "$($before | Format-Table | Out-String)" + Write-Host "$($before | Format-List | Out-String)" $before | Remove-GitHubVariable } LogGroup 'After remove' { $after = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($after | Format-Table | Out-String)" + Write-Host "$($after | Format-List | Out-String)" } $after.Count | Should -Be 0 } From f3c9be10a4d07370385383b87561b1655c3c666e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 25 Mar 2025 23:22:20 +0100 Subject: [PATCH 132/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Add=20null?= =?UTF-8?q?=20or=20empty=20check=20for=20Visibility=20parameter=20in=20Upd?= =?UTF-8?q?ate-GitHubVariable=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/functions/public/Variables/Update-GitHubVariable.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/functions/public/Variables/Update-GitHubVariable.ps1 b/src/functions/public/Variables/Update-GitHubVariable.ps1 index 4354ac82c..60f6dddbe 100644 --- a/src/functions/public/Variables/Update-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Update-GitHubVariable.ps1 @@ -106,7 +106,9 @@ function Update-GitHubVariable { $params | Remove-HashtableEntry -NullOrEmptyValues switch ($PSCmdlet.ParameterSetName) { 'Organization' { - $params.Visibility = $Visibility + if ($PSBoundParameters.ContainsKey('Visibility') -and -not [string]::IsNullOrEmpty($Visibility)) { + $params.Visibility = $Visibility + } Update-GitHubVariableOnOwner @params break } From 9b68055cdbad3c9e2bfb08783dd9c44d65e454f5 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 25 Mar 2025 23:42:39 +0100 Subject: [PATCH 133/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Comment=20?= =?UTF-8?q?out=20type=20check=20for=20$result=20in=20Variables.Tests.ps1?= =?UTF-8?q?=20to=20streamline=20test=20output?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 90d919c99..a6863d021 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -137,7 +137,7 @@ Describe 'Environments' { Write-Host ($result | Select-Object * | Format-List | Out-String) } $result | Should -Not -BeNullOrEmpty - $result | Should -BeOfType [GitHubVariable] + # $result | Should -BeOfType [GitHubVariable] $result.Name | Should -Be $name $result.Value | Should -Be 'TestValue123' $result.Visibility | Should -Be 'private' From 2b0d0d04ea9acf5f2c835ceb4f7124b5753447d0 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 25 Mar 2025 23:54:06 +0100 Subject: [PATCH 134/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Simplify?= =?UTF-8?q?=20API=20invocation=20by=20removing=20unnecessary=20output=20ha?= =?UTF-8?q?ndling=20in=20variable=20creation=20functions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../private/Variables/New-GitHubVariableOnEnvironment.ps1 | 4 +--- src/functions/private/Variables/New-GitHubVariableOnOwner.ps1 | 4 +--- .../private/Variables/New-GitHubVariableOnRepository.ps1 | 4 +--- src/functions/public/Variables/New-GitHubVariable.ps1 | 2 +- 4 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/functions/private/Variables/New-GitHubVariableOnEnvironment.ps1 b/src/functions/private/Variables/New-GitHubVariableOnEnvironment.ps1 index d1cd48899..e101fdc9c 100644 --- a/src/functions/private/Variables/New-GitHubVariableOnEnvironment.ps1 +++ b/src/functions/private/Variables/New-GitHubVariableOnEnvironment.ps1 @@ -73,9 +73,7 @@ function New-GitHubVariableOnEnvironment { } if ($PSCmdlet.ShouldProcess("variable [$Name] on [$Owner/$Repository/$Environment]", 'Create')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + $null = Invoke-GitHubAPI @inputObject } } diff --git a/src/functions/private/Variables/New-GitHubVariableOnOwner.ps1 b/src/functions/private/Variables/New-GitHubVariableOnOwner.ps1 index 3a5f28c18..8110f967f 100644 --- a/src/functions/private/Variables/New-GitHubVariableOnOwner.ps1 +++ b/src/functions/private/Variables/New-GitHubVariableOnOwner.ps1 @@ -79,9 +79,7 @@ function New-GitHubVariableOnOwner { } if ($PSCmdlet.ShouldProcess("variable [$Name] on [$Owner]", 'Create')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + $null = Invoke-GitHubAPI @inputObject } } diff --git a/src/functions/private/Variables/New-GitHubVariableOnRepository.ps1 b/src/functions/private/Variables/New-GitHubVariableOnRepository.ps1 index 48c1d7eec..e117173a3 100644 --- a/src/functions/private/Variables/New-GitHubVariableOnRepository.ps1 +++ b/src/functions/private/Variables/New-GitHubVariableOnRepository.ps1 @@ -61,9 +61,7 @@ function New-GitHubVariableOnRepository { } if ($PSCmdlet.ShouldProcess("variable [$Name] on [$Owner/$Repository]", 'Create')) { - 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 cae1c8659..ea1f61546 100644 --- a/src/functions/public/Variables/New-GitHubVariable.ps1 +++ b/src/functions/public/Variables/New-GitHubVariable.ps1 @@ -100,7 +100,7 @@ function New-GitHubVariable { ErrorAction = 'Stop' } $params | Remove-HashtableEntry -NullOrEmptyValues - switch ($PSCmdlet.ParameterSetName) { + $null = switch ($PSCmdlet.ParameterSetName) { 'Organization' { $params.Visibility = $Visibility New-GitHubVariableOnOwner @params From e739b3c1ca89ffa4a951b9aa0254abe2ef010a47 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 26 Mar 2025 00:06:12 +0100 Subject: [PATCH 135/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Uncomment?= =?UTF-8?q?=20test=20cases=20in=20Variables.Tests.ps1=20for=20improved=20t?= =?UTF-8?q?est=20coverage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 243 +++++++++++++++++++------------------- 1 file changed, 122 insertions(+), 121 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index a6863d021..937e3cbe1 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -178,138 +178,139 @@ Describe 'Environments' { $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 - # } + # 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 '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*" - # LogGroup 'Variables' { - # Write-Host "$($result | Select-Object * | Format-Table | Out-String)" - # } - # $result | Should -Not -BeNullOrEmpty - # } + # It 'Get-GitHubVariable' { + # $result = Get-GitHubVariable @scope -Name "*$os*" + # LogGroup 'Variables' { + # Write-Host "$($result | Select-Object * | Format-Table | Out-String)" + # } + # $result | Should -Not -BeNullOrEmpty + # } - # It 'Get-GitHubVariable -IncludeInherited' { - # $result = Get-GitHubVariable @scope -Name "*$os*" -IncludeInherited - # LogGroup 'Variables' { - # Write-Host "$($result | Select-Object * | Format-Table | Out-String)" - # } - # $result | Should -Not -BeNullOrEmpty - # } + # It 'Get-GitHubVariable -IncludeInherited' { + # $result = Get-GitHubVariable @scope -Name "*$os*" -IncludeInherited + # LogGroup 'Variables' { + # Write-Host "$($result | Select-Object * | Format-Table | Out-String)" + # } + # $result | Should -Not -BeNullOrEmpty + # } - # It 'Remove-GitHubVariable' { - # $before = Get-GitHubVariable @scope -Name "*$os*" - # LogGroup 'Variables - Before' { - # Write-Host "$($before | Format-Table | Out-String)" - # } - # $before | Remove-GitHubVariable - # $after = Get-GitHubVariable @scope -Name "*$os*" - # LogGroup 'Variables -After' { - # 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 'Remove-GitHubVariable' { + # $before = Get-GitHubVariable @scope -Name "*$os*" + # LogGroup 'Variables - Before' { + # Write-Host "$($before | Format-Table | Out-String)" + # } + # $before | Remove-GitHubVariable + # $after = Get-GitHubVariable @scope -Name "*$os*" + # LogGroup 'Variables -After' { + # 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 '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 '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 | Select-Object * | Format-Table | Out-String)" - # $result | Should -Not -BeNullOrEmpty - # } + # It 'Get-GitHubVariable' { + # $result = Get-GitHubVariable @scope -Name "*$os*" + # Write-Host "$($result | Select-Object * | Format-Table | Out-String)" + # $result | Should -Not -BeNullOrEmpty + # } - # It 'Get-GitHubVariable -IncludeInherited' { - # $result = Get-GitHubVariable @scope -Name "*$os*" -IncludeInherited - # Write-Host "$($result | Select-Object * | Format-Table | Out-String)" - # $result | Should -Not -BeNullOrEmpty - # } + # It 'Get-GitHubVariable -IncludeInherited' { + # $result = Get-GitHubVariable @scope -Name "*$os*" -IncludeInherited + # Write-Host "$($result | Select-Object * | 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 - # } - # } + # 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 + # } + # } - It 'Remove-GitHubVariable - should delete the organization variable' -Skip:($OwnerType -ne 'organization') { - $result = Get-GitHubVariable -Owner $owner -Name "$varName*" - LogGroup 'Variable' { - Write-Host ($result | Select-Object * | Format-Table | Out-String) + It 'Remove-GitHubVariable - should delete the organization variable' -Skip:($OwnerType -ne 'organization') { + $result = Get-GitHubVariable -Owner $owner -Name "$varName*" + LogGroup 'Variable' { + Write-Host ($result | Select-Object * | Format-Table | Out-String) + } + $result | Should -Not -BeNullOrEmpty + $result | Remove-GitHubVariable } - $result | Should -Not -BeNullOrEmpty - $result | Remove-GitHubVariable } } From 4499620b92dd6c4a1ed94ff939bb4c87f81fb58e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 26 Mar 2025 00:16:51 +0100 Subject: [PATCH 136/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Update=20G?= =?UTF-8?q?et-GitHubVariable=20call=20in=20Variables.Tests.ps1=20to=20remo?= =?UTF-8?q?ve=20wildcard=20and=20enhance=20output=20formatting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 937e3cbe1..5bf691d21 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -305,9 +305,9 @@ Describe 'Environments' { # } It 'Remove-GitHubVariable - should delete the organization variable' -Skip:($OwnerType -ne 'organization') { - $result = Get-GitHubVariable -Owner $owner -Name "$varName*" + $result = Get-GitHubVariable -Owner $owner LogGroup 'Variable' { - Write-Host ($result | Select-Object * | Format-Table | Out-String) + Write-Host ($result | Select-Object * | Format-List | Out-String) } $result | Should -Not -BeNullOrEmpty $result | Remove-GitHubVariable From 4d4657a0e1fd219e0906ec093d99f3a057c915f7 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 26 Mar 2025 08:29:01 +0100 Subject: [PATCH 137/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Update=20P?= =?UTF-8?q?SModule.yml=20to=20skip=20TestResults=20and=20CodeCoverage=20se?= =?UTF-8?q?ctions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/PSModule.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/PSModule.yml b/.github/PSModule.yml index d037f0109..de287a813 100644 --- a/.github/PSModule.yml +++ b/.github/PSModule.yml @@ -3,7 +3,10 @@ Test: Skip: true PSModule: Skip: true + TestResults: + Skip: true CodeCoverage: + Skip: true PercentTarget: 50 Build: Docs: From 3fa581c0f61bfaab2c2a01789252566f6fb62666 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 26 Mar 2025 09:04:38 +0100 Subject: [PATCH 138/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Enhance=20?= =?UTF-8?q?logging=20in=20Remove-GitHubVariable=20test=20by=20adding=20deb?= =?UTF-8?q?ug=20and=20verbose=20output?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 5bf691d21..c8e9c1623 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -166,10 +166,12 @@ Describe 'Environments' { } It 'Remove-GitHubVariable' { - $before = Get-GitHubVariable @scope -Name "*$os*" LogGroup 'Before remove' { + $before = Get-GitHubVariable @scope -Name "*$os*" Write-Host "$($before | Format-List | Out-String)" - $before | Remove-GitHubVariable + } + LogGroup 'Remove' { + $before | Remove-GitHubVariable -Debug -Verbose } LogGroup 'After remove' { $after = Get-GitHubVariable @scope -Name "*$os*" From befb6d7aadcb4f12f8734e8e82c2f0406bb23f3b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 26 Mar 2025 21:34:50 +0100 Subject: [PATCH 139/210] Fix test --- tests/Variables.Tests.ps1 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index c8e9c1623..6b4824a4d 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -158,7 +158,7 @@ Describe 'Environments' { } It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope -Name "*$os*" + $result = Get-GitHubVariable @scope -Name "$variablePrefix*" LogGroup 'Variables' { Write-Host "$($result | Select-Object * | Format-List | Out-String)" } @@ -166,6 +166,7 @@ Describe 'Environments' { } It 'Remove-GitHubVariable' { + $before = Get-GitHubVariable @scope -Name "$variablePrefix*" LogGroup 'Before remove' { $before = Get-GitHubVariable @scope -Name "*$os*" Write-Host "$($before | Format-List | Out-String)" @@ -174,7 +175,7 @@ Describe 'Environments' { $before | Remove-GitHubVariable -Debug -Verbose } LogGroup 'After remove' { - $after = Get-GitHubVariable @scope -Name "*$os*" + $after = Get-GitHubVariable @scope -Name "$variablePrefix*" Write-Host "$($after | Format-List | Out-String)" } $after.Count | Should -Be 0 From 9ad06040e6afd0663bd91e6b5799c28d066e1624 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 26 Mar 2025 21:44:19 +0100 Subject: [PATCH 140/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Correct=20?= =?UTF-8?q?Get-GitHubVariable=20call=20in=20Remove-GitHubVariable=20test?= =?UTF-8?q?=20to=20use=20variablePrefix=20for=20improved=20accuracy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 6b4824a4d..a6c72ca56 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -166,9 +166,8 @@ Describe 'Environments' { } It 'Remove-GitHubVariable' { - $before = Get-GitHubVariable @scope -Name "$variablePrefix*" LogGroup 'Before remove' { - $before = Get-GitHubVariable @scope -Name "*$os*" + $before = Get-GitHubVariable @scope -Name "$variablePrefix*" Write-Host "$($before | Format-List | Out-String)" } LogGroup 'Remove' { From 2a09ffab092d883909e1fe21df04ed329025f496 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 27 Mar 2025 15:13:47 +0100 Subject: [PATCH 141/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Update=20P?= =?UTF-8?q?SModule.yml=20to=20skip=20MacOS=20and=20Windows=20module=20test?= =?UTF-8?q?s=20for=20improved=20configuration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/PSModule.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/PSModule.yml b/.github/PSModule.yml index de287a813..669009014 100644 --- a/.github/PSModule.yml +++ b/.github/PSModule.yml @@ -3,6 +3,11 @@ Test: Skip: true PSModule: Skip: true + Module: + MacOS: + Skip: true + Windows: + Skip: true TestResults: Skip: true CodeCoverage: From 9d5d8fa954b35b589576f116dd6ab2fdeb0650ae Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions@users.noreply.github.com> Date: Thu, 27 Mar 2025 14:15:20 +0000 Subject: [PATCH 142/210] Auto-generated changes --- Coverage.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Coverage.md b/Coverage.md index 2c1293386..672d5925c 100644 --- a/Coverage.md +++ b/Coverage.md @@ -5,7 +5,7 @@ - + @@ -13,11 +13,11 @@ - + - +
Available functions10231021
Covered functions
Missing functions842840
Coverage17.69%17.73%
@@ -159,7 +159,6 @@ | `/orgs/{org}/copilot/billing/selected_teams` | :x: | | | :x: | | | `/orgs/{org}/copilot/billing/selected_users` | :x: | | | :x: | | | `/orgs/{org}/copilot/metrics` | | :x: | | | | -| `/orgs/{org}/copilot/usage` | | :x: | | | | | `/orgs/{org}/dependabot/alerts` | | :x: | | | | | `/orgs/{org}/dependabot/secrets` | | :x: | | | | | `/orgs/{org}/dependabot/secrets/public-key` | | :x: | | | | @@ -255,7 +254,6 @@ | `/orgs/{org}/settings/network-configurations/{network_configuration_id}` | :x: | :x: | :x: | | | | `/orgs/{org}/settings/network-settings/{network_settings_id}` | | :x: | | | | | `/orgs/{org}/team/{team_slug}/copilot/metrics` | | :x: | | | | -| `/orgs/{org}/team/{team_slug}/copilot/usage` | | :x: | | | | | `/orgs/{org}/teams` | | :white_check_mark: | | :white_check_mark: | | | `/orgs/{org}/teams/{team_slug}` | :white_check_mark: | :white_check_mark: | :white_check_mark: | | | | `/orgs/{org}/teams/{team_slug}/discussions` | | :x: | | :x: | | From 999898216ba65f205db77a0893db72b9e88e794e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 27 Mar 2025 17:47:52 +0100 Subject: [PATCH 143/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Remove=20u?= =?UTF-8?q?nnecessary=20null=20or=20empty=20check=20for=20result=20in=20En?= =?UTF-8?q?vironments=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index a6c72ca56..212b015bc 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -311,7 +311,6 @@ Describe 'Environments' { LogGroup 'Variable' { Write-Host ($result | Select-Object * | Format-List | Out-String) } - $result | Should -Not -BeNullOrEmpty $result | Remove-GitHubVariable } } From c953273f166a81f2dc92bf27817350d84663cc9c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 27 Mar 2025 18:09:24 +0100 Subject: [PATCH 144/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Enhance=20?= =?UTF-8?q?Remove-GitHubVariable=20logic=20to=20skip=20organization=20chec?= =?UTF-8?q?ks=20and=20streamline=20variable=20removal=20process?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 212b015bc..1d8f3e397 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -60,6 +60,9 @@ Describe 'Environments' { } AfterAll { + if ($OwnerType -ne 'organization') { + Get-GitHubVariable -Owner $owner | Remove-GitHubVariable + } if ($Type -ne 'GitHub Actions') { Remove-GitHubRepository -Owner $owner -Name $repoName -Confirm:$false } @@ -171,7 +174,7 @@ Describe 'Environments' { Write-Host "$($before | Format-List | Out-String)" } LogGroup 'Remove' { - $before | Remove-GitHubVariable -Debug -Verbose + $before | Remove-GitHubVariable } LogGroup 'After remove' { $after = Get-GitHubVariable @scope -Name "$variablePrefix*" @@ -305,13 +308,5 @@ Describe 'Environments' { # $after.Count | Should -Be 0 # } # } - - It 'Remove-GitHubVariable - should delete the organization variable' -Skip:($OwnerType -ne 'organization') { - $result = Get-GitHubVariable -Owner $owner - LogGroup 'Variable' { - Write-Host ($result | Select-Object * | Format-List | Out-String) - } - $result | Remove-GitHubVariable - } } } From 401dc144c0f54bd6b2817833efec5ba95a206d98 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 27 Mar 2025 18:09:41 +0100 Subject: [PATCH 145/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Correct=20?= =?UTF-8?q?condition=20in=20AfterAll=20block=20to=20remove=20GitHub=20vari?= =?UTF-8?q?ables=20only=20for=20organization=20owners?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 1d8f3e397..fa331687a 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -60,7 +60,7 @@ Describe 'Environments' { } AfterAll { - if ($OwnerType -ne 'organization') { + if ($OwnerType -eq 'organization') { Get-GitHubVariable -Owner $owner | Remove-GitHubVariable } if ($Type -ne 'GitHub Actions') { From 423136d3076aac8ff97414dada7c3fc120bbd74f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 27 Mar 2025 18:35:43 +0100 Subject: [PATCH 146/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Simplify?= =?UTF-8?q?=20Set-GitHubVariable=20calls=20with=20parameter=20hashtables?= =?UTF-8?q?=20and=20enhance=20test=20structure=20for=20clarity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 237 ++++++++++++++++++++------------------ 1 file changed, 122 insertions(+), 115 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index fa331687a..f3622409f 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -53,7 +53,14 @@ Describe 'Environments' { if ($OwnerType -eq 'organization') { LogGroup "Org variable - [$varName]" { - $result = Set-GitHubVariable -Owner $owner -Name $varName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id + $params = @{ + Owner = $owner + Name = $varName + Value = 'organization' + Visibility = 'selected' + SelectedRepositories = $repo.id + } + $result = Set-GitHubVariable @params Write-Host ($result | Select-Object * | Format-Table | Out-String) } } @@ -184,129 +191,129 @@ Describe 'Environments' { } } - # 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 - # } + 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 '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 '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*" - # LogGroup 'Variables' { - # Write-Host "$($result | Select-Object * | Format-Table | Out-String)" - # } - # $result | Should -Not -BeNullOrEmpty - # } + It 'Get-GitHubVariable' { + $result = Get-GitHubVariable @scope -Name "*$os*" + LogGroup 'Variables' { + Write-Host "$($result | Select-Object * | Format-Table | Out-String)" + } + $result | Should -Not -BeNullOrEmpty + } - # It 'Get-GitHubVariable -IncludeInherited' { - # $result = Get-GitHubVariable @scope -Name "*$os*" -IncludeInherited - # LogGroup 'Variables' { - # Write-Host "$($result | Select-Object * | Format-Table | Out-String)" - # } - # $result | Should -Not -BeNullOrEmpty - # } + It 'Get-GitHubVariable -IncludeInherited' { + $result = Get-GitHubVariable @scope -Name "*$os*" -IncludeInherited + LogGroup 'Variables' { + Write-Host "$($result | Select-Object * | Format-Table | Out-String)" + } + $result | Should -Not -BeNullOrEmpty + } - # It 'Remove-GitHubVariable' { - # $before = Get-GitHubVariable @scope -Name "*$os*" - # LogGroup 'Variables - Before' { - # Write-Host "$($before | Format-Table | Out-String)" - # } - # $before | Remove-GitHubVariable - # $after = Get-GitHubVariable @scope -Name "*$os*" - # LogGroup 'Variables -After' { - # 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 'Remove-GitHubVariable' { + $before = Get-GitHubVariable @scope -Name "*$os*" + LogGroup 'Variables - Before' { + Write-Host "$($before | Format-Table | Out-String)" + } + $before | Remove-GitHubVariable + $after = Get-GitHubVariable @scope -Name "*$os*" + LogGroup 'Variables -After' { + 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 '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 '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 | Select-Object * | Format-Table | Out-String)" - # $result | Should -Not -BeNullOrEmpty - # } + It 'Get-GitHubVariable' { + $result = Get-GitHubVariable @scope -Name "*$os*" + Write-Host "$($result | Select-Object * | Format-Table | Out-String)" + $result | Should -Not -BeNullOrEmpty + } - # It 'Get-GitHubVariable -IncludeInherited' { - # $result = Get-GitHubVariable @scope -Name "*$os*" -IncludeInherited - # Write-Host "$($result | Select-Object * | Format-Table | Out-String)" - # $result | Should -Not -BeNullOrEmpty - # } + It 'Get-GitHubVariable -IncludeInherited' { + $result = Get-GitHubVariable @scope -Name "*$os*" -IncludeInherited + Write-Host "$($result | Select-Object * | 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 - # } - # } + 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 d23d299565ee9676593cce0505c959dba079fa91 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 27 Mar 2025 19:01:21 +0100 Subject: [PATCH 147/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Add=20Repo?= =?UTF-8?q?sitory=20parameter=20to=20Get-GitHubVariable=20and=20skip=20tes?= =?UTF-8?q?ts=20for=20Repository=20and=20Environment=20contexts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/functions/public/Variables/Get-GitHubVariable.ps1 | 1 + tests/Variables.Tests.ps1 | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/functions/public/Variables/Get-GitHubVariable.ps1 b/src/functions/public/Variables/Get-GitHubVariable.ps1 index 5bbbef752..9169cfdb8 100644 --- a/src/functions/public/Variables/Get-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Get-GitHubVariable.ps1 @@ -194,6 +194,7 @@ function Get-GitHubVariable { break } 'Environment' { + $params['Repository'] = $Repository if ($IncludeInherited) { $variables += Get-GitHubVariableFromOrganization @params | Where-Object { $_.Name -like $Name } diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index f3622409f..2c423bde8 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -191,7 +191,7 @@ Describe 'Environments' { } } - Context 'Repository' { + Context 'Repository' -Skip: { BeforeAll { $scope = @{ Owner = $owner @@ -256,7 +256,8 @@ Describe 'Environments' { $after.Count | Should -Be 0 } } - Context 'Environment' { + + Context 'Environment' -Skip: { BeforeAll { $scope = @{ Owner = $owner From 755df9532b71c27f0e89dbb8f1554a9bb5207afe Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 27 Mar 2025 19:02:29 +0100 Subject: [PATCH 148/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Update=20t?= =?UTF-8?q?est=20contexts=20to=20skip=20for=20GitHub=20Actions=20type=20in?= =?UTF-8?q?=20Variables.Tests.ps1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 2c423bde8..fe9e14347 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -191,7 +191,7 @@ Describe 'Environments' { } } - Context 'Repository' -Skip: { + Context 'Repository' -Skip:($Type -eq 'GitHub Actions') { BeforeAll { $scope = @{ Owner = $owner @@ -256,8 +256,8 @@ Describe 'Environments' { $after.Count | Should -Be 0 } } - - Context 'Environment' -Skip: { + + Context 'Environment' -Skip:($Type -eq 'GitHub Actions') { BeforeAll { $scope = @{ Owner = $owner From a3115676703498827eeb6d0620f30c3595ae57c5 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 27 Mar 2025 19:31:53 +0100 Subject: [PATCH 149/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Add=20erro?= =?UTF-8?q?r=20handling=20to=20Get-GitHubVariable=20for=20organization=20r?= =?UTF-8?q?etrieval=20and=20update=20test=20setup=20for=20Environment=20co?= =?UTF-8?q?ntext?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/functions/public/Variables/Get-GitHubVariable.ps1 | 4 ++-- tests/Variables.Tests.ps1 | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/functions/public/Variables/Get-GitHubVariable.ps1 b/src/functions/public/Variables/Get-GitHubVariable.ps1 index 9169cfdb8..c18f2f3bd 100644 --- a/src/functions/public/Variables/Get-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Get-GitHubVariable.ps1 @@ -182,7 +182,7 @@ function Get-GitHubVariable { 'Repository' { $params['Repository'] = $Repository if ($IncludeInherited) { - $variables += Get-GitHubVariableFromOrganization @params | + $variables += Get-GitHubVariableFromOrganization @params -ErrorAction SilentlyContinue | Where-Object { $_.Name -like $Name } } if ($Name.Contains('*')) { @@ -196,7 +196,7 @@ function Get-GitHubVariable { 'Environment' { $params['Repository'] = $Repository if ($IncludeInherited) { - $variables += Get-GitHubVariableFromOrganization @params | + $variables += Get-GitHubVariableFromOrganization @params -ErrorAction SilentlyContinue | Where-Object { $_.Name -like $Name } if ($Name.Contains('*')) { $variables += Get-GitHubVariableRepositoryList @params | diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index fe9e14347..d90afc606 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -259,6 +259,11 @@ Describe 'Environments' { Context 'Environment' -Skip:($Type -eq 'GitHub Actions') { BeforeAll { + $scope = @{ + Owner = $owner + Repository = $repoName + } + Set-GitHubVariable @scope -Name $varName -Value 'repository' $scope = @{ Owner = $owner Repository = $repoName From 693f99bcee9e0c475c0bfc329226494c4914c1f7 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 27 Mar 2025 19:43:39 +0100 Subject: [PATCH 150/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Add=20erro?= =?UTF-8?q?r=20handling=20to=20Get-GitHubVariable=20for=20organization=20r?= =?UTF-8?q?etrieval?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../public/Variables/Get-GitHubVariable.ps1 | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/functions/public/Variables/Get-GitHubVariable.ps1 b/src/functions/public/Variables/Get-GitHubVariable.ps1 index c18f2f3bd..1ba45533d 100644 --- a/src/functions/public/Variables/Get-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Get-GitHubVariable.ps1 @@ -182,8 +182,10 @@ function Get-GitHubVariable { 'Repository' { $params['Repository'] = $Repository if ($IncludeInherited) { - $variables += Get-GitHubVariableFromOrganization @params -ErrorAction SilentlyContinue | - Where-Object { $_.Name -like $Name } + try { + $variables += Get-GitHubVariableFromOrganization @params | + Where-Object { $_.Name -like $Name } + } catch {} } if ($Name.Contains('*')) { $variables += Get-GitHubVariableRepositoryList @params | @@ -196,8 +198,10 @@ function Get-GitHubVariable { 'Environment' { $params['Repository'] = $Repository if ($IncludeInherited) { - $variables += Get-GitHubVariableFromOrganization @params -ErrorAction SilentlyContinue | - Where-Object { $_.Name -like $Name } + try { + $variables += Get-GitHubVariableFromOrganization @params | + Where-Object { $_.Name -like $Name } + } catch {} if ($Name.Contains('*')) { $variables += Get-GitHubVariableRepositoryList @params | Where-Object { $_.Name -like $Name } From a3c53183d5f6338d124ce9a133dc44074d8f787e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 28 Mar 2025 20:39:05 +0100 Subject: [PATCH 151/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Enhance=20?= =?UTF-8?q?documentation=20for=20GitHub=20variable=20retrieval=20functions?= =?UTF-8?q?=20and=20add=20removal=20functions=20for=20organization=20and?= =?UTF-8?q?=20repository=20variables?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Variables/Get-GitHubVariableEnvironmentList.ps1 | 7 +++++-- .../Variables/Get-GitHubVariableFromOrganization.ps1 | 7 +++++++ .../Variables/Get-GitHubVariableOwnerList.ps1 | 9 ++++++++- .../Variables/Get-GitHubVariableRepositoryList.ps1 | 6 +++--- ....ps1 => Remove-GitHubVariableFromEnvironment.ps1} | 4 ++-- ...nOwner.ps1 => Remove-GitHubVariableFromOwner.ps1} | 4 ++-- ...y.ps1 => Remove-GitHubVariableFromRepository.ps1} | 4 ++-- .../public/Variables/Remove-GitHubVariable.ps1 | 12 ++++++------ 8 files changed, 35 insertions(+), 18 deletions(-) rename src/functions/private/Variables/{Remove-GitHubVariableOnEnvironment.ps1 => Remove-GitHubVariableFromEnvironment.ps1} (91%) rename src/functions/private/Variables/{Remove-GitHubVariableOnOwner.ps1 => Remove-GitHubVariableFromOwner.ps1} (93%) rename src/functions/private/Variables/{Remove-GitHubVariableOnRepository.ps1 => Remove-GitHubVariableFromRepository.ps1} (91%) diff --git a/src/functions/private/Variables/Get-GitHubVariableEnvironmentList.ps1 b/src/functions/private/Variables/Get-GitHubVariableEnvironmentList.ps1 index dea862f16..31b86173a 100644 --- a/src/functions/private/Variables/Get-GitHubVariableEnvironmentList.ps1 +++ b/src/functions/private/Variables/Get-GitHubVariableEnvironmentList.ps1 @@ -29,11 +29,14 @@ function Get-GitHubVariableEnvironmentList { Retrieves all variables for the specified environment. .OUTPUTS - GitHubVariable[]. An array of GitHubVariable objects representing the environment variables. + GitHubVariable[] + + .NOTES + 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 + [List environment variables](https://docs.github.com/rest/actions/variables#list-environment-variables) #> [OutputType([GitHubVariable[]])] [CmdletBinding()] diff --git a/src/functions/private/Variables/Get-GitHubVariableFromOrganization.ps1 b/src/functions/private/Variables/Get-GitHubVariableFromOrganization.ps1 index 89e269263..e89a19066 100644 --- a/src/functions/private/Variables/Get-GitHubVariableFromOrganization.ps1 +++ b/src/functions/private/Variables/Get-GitHubVariableFromOrganization.ps1 @@ -46,6 +46,13 @@ function Get-GitHubVariableFromOrganization { Lists the variables visible from 'PSModule' to the 'GitHub' repository. + .OUTPUTS + GitHubVariable[] + + .NOTES + An array of GitHubVariable objects representing the environment variables. + Each object contains Name, Value, CreatedAt, UpdatedAt, Owner, Repository, and Environment properties. + .LINK [List repository organization variables](https://docs.github.com/rest/actions/variables#list-repository-organization-variables) #> diff --git a/src/functions/private/Variables/Get-GitHubVariableOwnerList.ps1 b/src/functions/private/Variables/Get-GitHubVariableOwnerList.ps1 index 9ec90ba8c..5704a744d 100644 --- a/src/functions/private/Variables/Get-GitHubVariableOwnerList.ps1 +++ b/src/functions/private/Variables/Get-GitHubVariableOwnerList.ps1 @@ -47,8 +47,15 @@ function Get-GitHubVariableOwnerList { Retrieves all variables from the specified organization. + .OUTPUTS + GitHubVariable[] + + .NOTES + An array of GitHubVariable objects representing the environment variables. + Each object contains Name, Value, CreatedAt, UpdatedAt, Owner, Repository, and Environment properties. + .LINK - List organization variables](https://docs.github.com/rest/actions/variables#list-organization-variables) + [List organization variables](https://docs.github.com/rest/actions/variables#list-organization-variables) #> [OutputType([GitHubVariable[]])] [CmdletBinding()] diff --git a/src/functions/private/Variables/Get-GitHubVariableRepositoryList.ps1 b/src/functions/private/Variables/Get-GitHubVariableRepositoryList.ps1 index cad40d84e..74b5c20c5 100644 --- a/src/functions/private/Variables/Get-GitHubVariableRepositoryList.ps1 +++ b/src/functions/private/Variables/Get-GitHubVariableRepositoryList.ps1 @@ -29,11 +29,11 @@ function Get-GitHubVariableRepositoryList { Retrieves all variables for the specified repository. .OUTPUTS - GitHubVariable + GitHubVariable[] .NOTES - Returns an GitHubVariable object containing details about the environment variable, - including its name, value, associated repository, and environment details. + An array of GitHubVariable objects representing the environment variables. + Each object contains Name, Value, CreatedAt, UpdatedAt, Owner, Repository, and Environment properties. .LINK [List repository variables](https://docs.github.com/rest/actions/variables#list-repository-variables) diff --git a/src/functions/private/Variables/Remove-GitHubVariableOnEnvironment.ps1 b/src/functions/private/Variables/Remove-GitHubVariableFromEnvironment.ps1 similarity index 91% rename from src/functions/private/Variables/Remove-GitHubVariableOnEnvironment.ps1 rename to src/functions/private/Variables/Remove-GitHubVariableFromEnvironment.ps1 index 3ae29bba2..a4e234f5a 100644 --- a/src/functions/private/Variables/Remove-GitHubVariableOnEnvironment.ps1 +++ b/src/functions/private/Variables/Remove-GitHubVariableFromEnvironment.ps1 @@ -1,4 +1,4 @@ -function Remove-GitHubVariableOnEnvironment { +function Remove-GitHubVariableFromEnvironment { <# .SYNOPSIS Delete an environment variable. @@ -9,7 +9,7 @@ function Remove-GitHubVariableOnEnvironment { 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 + Remove-GitHubVariableFromEnvironment -Owner 'octocat' -Repository 'Hello-World' -Environment 'dev' -Name 'HOST_NAME' -Context $GitHubContext Deletes the specified variable from the specified environment. diff --git a/src/functions/private/Variables/Remove-GitHubVariableOnOwner.ps1 b/src/functions/private/Variables/Remove-GitHubVariableFromOwner.ps1 similarity index 93% rename from src/functions/private/Variables/Remove-GitHubVariableOnOwner.ps1 rename to src/functions/private/Variables/Remove-GitHubVariableFromOwner.ps1 index 2433555fc..3012dd07c 100644 --- a/src/functions/private/Variables/Remove-GitHubVariableOnOwner.ps1 +++ b/src/functions/private/Variables/Remove-GitHubVariableFromOwner.ps1 @@ -1,4 +1,4 @@ -function Remove-GitHubVariableOnOwner { +function Remove-GitHubVariableFromOwner { <# .SYNOPSIS Delete an organization variable. @@ -10,7 +10,7 @@ function Remove-GitHubVariableOnOwner { 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 + Remove-GitHubVariableFromOwner -Owner 'octocat' -Name 'HOST_NAME' -Context $GitHubContext Deletes the specified variable from the specified organization. diff --git a/src/functions/private/Variables/Remove-GitHubVariableOnRepository.ps1 b/src/functions/private/Variables/Remove-GitHubVariableFromRepository.ps1 similarity index 91% rename from src/functions/private/Variables/Remove-GitHubVariableOnRepository.ps1 rename to src/functions/private/Variables/Remove-GitHubVariableFromRepository.ps1 index 9970eb133..42ef1981d 100644 --- a/src/functions/private/Variables/Remove-GitHubVariableOnRepository.ps1 +++ b/src/functions/private/Variables/Remove-GitHubVariableFromRepository.ps1 @@ -1,4 +1,4 @@ -function Remove-GitHubVariableOnRepository { +function Remove-GitHubVariableFromRepository { <# .SYNOPSIS Delete a repository variable. @@ -9,7 +9,7 @@ function Remove-GitHubVariableOnRepository { 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 + Remove-GitHubVariableFromRepository -Owner 'octocat' -Repository 'Hello-World' -Name 'HOST_NAME' -Context $GitHubContext Deletes the specified variable from the specified repository. diff --git a/src/functions/public/Variables/Remove-GitHubVariable.ps1 b/src/functions/public/Variables/Remove-GitHubVariable.ps1 index 39fdfe50a..e80767840 100644 --- a/src/functions/public/Variables/Remove-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Remove-GitHubVariable.ps1 @@ -86,7 +86,7 @@ function Remove-GitHubVariable { Name = $item.Name Context = $Context } - Remove-GitHubVariableOnEnvironment @params + Remove-GitHubVariableFromEnvironment @params } elseif ($item.Repository) { $params = @{ Owner = $item.Owner @@ -94,14 +94,14 @@ function Remove-GitHubVariable { Name = $item.Name Context = $Context } - Remove-GitHubVariableOnRepository @params + Remove-GitHubVariableFromRepository @params } else { $params = @{ Owner = $item.Owner Name = $item.Name Context = $Context } - Remove-GitHubVariableOnOwner @params + Remove-GitHubVariableFromOwner @params } $scopeParam = @{ Owner = $item.Owner @@ -124,7 +124,7 @@ function Remove-GitHubVariable { Name = $Name Context = $Context } - Remove-GitHubVariableOnOwner @params + Remove-GitHubVariableFromOwner @params break } 'Repository' { @@ -134,7 +134,7 @@ function Remove-GitHubVariable { Name = $Name Context = $Context } - Remove-GitHubVariableOnRepository @params + Remove-GitHubVariableFromRepository @params break } 'Environment' { @@ -145,7 +145,7 @@ function Remove-GitHubVariable { Name = $Name Context = $Context } - Remove-GitHubVariableOnEnvironment @params + Remove-GitHubVariableFromEnvironment @params break } } From 2ab3a91b74b59b6a92b759acc3d0b5b02097182f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 28 Mar 2025 20:49:19 +0100 Subject: [PATCH 152/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Enhance=20?= =?UTF-8?q?output=20documentation=20for=20GitHub=20variable=20functions=20?= =?UTF-8?q?and=20update=20error=20handling=20in=20retrieval=20functions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Variables/Get-GitHubVariableVisibilityList.ps1 | 5 +++++ src/functions/public/Variables/Get-GitHubVariable.ps1 | 6 +++--- src/functions/public/Variables/New-GitHubVariable.ps1 | 8 ++++++++ src/functions/public/Variables/Set-GitHubVariable.ps1 | 7 +++++++ src/functions/public/Variables/Update-GitHubVariable.ps1 | 7 +++++++ 5 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/functions/private/Variables/Get-GitHubVariableVisibilityList.ps1 b/src/functions/private/Variables/Get-GitHubVariableVisibilityList.ps1 index 3d058520d..d37148f2d 100644 --- a/src/functions/private/Variables/Get-GitHubVariableVisibilityList.ps1 +++ b/src/functions/private/Variables/Get-GitHubVariableVisibilityList.ps1 @@ -35,6 +35,11 @@ function Get-GitHubVariableVisibilityList { [Parameter(Mandatory)] [object] $Context, + # The output format. Can be `json`, `pscustomobject`, `class`, or `raw`. + # `json` - Returns the output as a JSON string. + # `pscustomobject` - Returns the output as a PowerShell custom object. + # `class` - Returns the output as a PowerShell class object. + # `raw` - Returns the raw output from the API call. [Parameter()] [ValidateSet('json', 'pscustomobject', 'class', 'raw')] [string] $Output = 'class' diff --git a/src/functions/public/Variables/Get-GitHubVariable.ps1 b/src/functions/public/Variables/Get-GitHubVariable.ps1 index 1ba45533d..3dbb5d8c8 100644 --- a/src/functions/public/Variables/Get-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Get-GitHubVariable.ps1 @@ -116,7 +116,7 @@ function Get-GitHubVariable { GitHubVariable .NOTES - An object representing the GitHub variable, containing Name, Value, Owner, + An object or array of objects representing the GitHub variable, containing Name, Value, Owner, Repository, and Environment details. .LINK @@ -185,7 +185,7 @@ function Get-GitHubVariable { try { $variables += Get-GitHubVariableFromOrganization @params | Where-Object { $_.Name -like $Name } - } catch {} + } finally {} } if ($Name.Contains('*')) { $variables += Get-GitHubVariableRepositoryList @params | @@ -201,7 +201,7 @@ function Get-GitHubVariable { try { $variables += Get-GitHubVariableFromOrganization @params | Where-Object { $_.Name -like $Name } - } catch {} + } finally {} if ($Name.Contains('*')) { $variables += Get-GitHubVariableRepositoryList @params | Where-Object { $_.Name -like $Name } diff --git a/src/functions/public/Variables/New-GitHubVariable.ps1 b/src/functions/public/Variables/New-GitHubVariable.ps1 index ea1f61546..de029267c 100644 --- a/src/functions/public/Variables/New-GitHubVariable.ps1 +++ b/src/functions/public/Variables/New-GitHubVariable.ps1 @@ -28,6 +28,14 @@ function New-GitHubVariable { Creates a new environment variable named `HOST_NAME` with the value `github.com` in 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 https://psmodule.io/GitHub/Functions/Variables/New-GitHubVariable/ #> diff --git a/src/functions/public/Variables/Set-GitHubVariable.ps1 b/src/functions/public/Variables/Set-GitHubVariable.ps1 index 7a6d03d22..93477995e 100644 --- a/src/functions/public/Variables/Set-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Set-GitHubVariable.ps1 @@ -28,6 +28,13 @@ function Set-GitHubVariable { Creates or updates an environment variable named `HOST_NAME` with the value `github.com` in 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 https://psmodule.io/GitHub/Functions/Variables/Set-GitHubVariable/ #> diff --git a/src/functions/public/Variables/Update-GitHubVariable.ps1 b/src/functions/public/Variables/Update-GitHubVariable.ps1 index 60f6dddbe..d3bd0cf4d 100644 --- a/src/functions/public/Variables/Update-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Update-GitHubVariable.ps1 @@ -26,6 +26,13 @@ function Update-GitHubVariable { Updates the environment variable named `HOST_NAME` with the value `github.com` in 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 https://psmodule.io/GitHub/Functions/Variables/Update-GitHubVariable/ #> From 95a3a82b01f1fd5847c71d7629f42c7d7b37d878 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 28 Mar 2025 20:59:58 +0100 Subject: [PATCH 153/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Update=20G?= =?UTF-8?q?et-GitHubVariableVisibilityList=20to=20enhance=20output=20docum?= =?UTF-8?q?entation=20and=20streamline=20output=20handling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Get-GitHubVariableVisibilityList.ps1 | 56 ++++++------------- 1 file changed, 17 insertions(+), 39 deletions(-) diff --git a/src/functions/private/Variables/Get-GitHubVariableVisibilityList.ps1 b/src/functions/private/Variables/Get-GitHubVariableVisibilityList.ps1 index d37148f2d..096eff40a 100644 --- a/src/functions/private/Variables/Get-GitHubVariableVisibilityList.ps1 +++ b/src/functions/private/Variables/Get-GitHubVariableVisibilityList.ps1 @@ -12,6 +12,12 @@ function Get-GitHubVariableVisibilityList { .EXAMPLE Get-GitHubVariableVisibilityList -Owner 'PSModule' -Name 'SELECTEDVAR' -Context (Get-GitHubContext) + .OUTPUTS + GitHubRepository + + .NOTES + Returns a list of GitHubRepository objects that represent the repositories that can access the variable. + .LINK [List selected repositories for an organization variable](https://docs.github.com/rest/actions/variables#list-selected-repositories-for-an-organization-variable) #> @@ -19,7 +25,7 @@ function Get-GitHubVariableVisibilityList { 'PSAvoidLongLines', '', Justification = 'Long links' )] - [OutputType([pscustomobject])] + [OutputType([GitHubRepository])] [CmdletBinding()] param( # The account owner of the repository. The name is not case sensitive. @@ -33,16 +39,7 @@ function Get-GitHubVariableVisibilityList { # 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, - - # The output format. Can be `json`, `pscustomobject`, `class`, or `raw`. - # `json` - Returns the output as a JSON string. - # `pscustomobject` - Returns the output as a PowerShell custom object. - # `class` - Returns the output as a PowerShell class object. - # `raw` - Returns the raw output from the API call. - [Parameter()] - [ValidateSet('json', 'pscustomobject', 'class', 'raw')] - [string] $Output = 'class' + [object] $Context ) begin { @@ -59,34 +56,15 @@ function Get-GitHubVariableVisibilityList { } 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 + $_.Response.repositories | ForEach-Object { + [GitHubRepository]@{ + Name = $_.name + FullName = $_.full_name + NodeID = $_.node_id + DatabaseID = $_.id + Description = $_.description + Owner = $_.owner.login + URL = $_.html_url } } } From 954c32eaed81419a2cc3d9cb0cb5745a2d87699e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 28 Mar 2025 21:01:46 +0100 Subject: [PATCH 154/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Remove=20u?= =?UTF-8?q?nnecessary=20skip=20configurations=20in=20PSModule.yml=20and=20?= =?UTF-8?q?add=20test=20data=20and=20templates=20for=20user=20and=20emoji?= =?UTF-8?q?=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/PSModule.yml | 15 --------------- {test2 => tests}/API.Tests.ps1 | 0 {test2 => tests}/Apps.Tests.ps1 | 0 {test2 => tests}/Auth.Tests.ps1 | 0 {test2 => tests/Data}/IssueForm.md | 0 {test2 => tests}/Emojis.Tests.ps1 | 0 {test2 => tests}/Environments.Tests.ps1 | 0 {test2 => tests}/GitHub.Tests.ps1 | 2 +- {test2 => tests}/Organizations.Tests.ps1 | 0 {test2 => tests}/README.md | 0 {test2 => tests}/Repositories.Tests.ps1 | 0 {test2 => tests}/TEMPLATE.ps1 | 0 {test2 => tests}/User.Tests.ps1 | 0 {test2 => tests}/Variables.ps1 | 0 14 files changed, 1 insertion(+), 16 deletions(-) rename {test2 => tests}/API.Tests.ps1 (100%) rename {test2 => tests}/Apps.Tests.ps1 (100%) rename {test2 => tests}/Auth.Tests.ps1 (100%) rename {test2 => tests/Data}/IssueForm.md (100%) rename {test2 => tests}/Emojis.Tests.ps1 (100%) rename {test2 => tests}/Environments.Tests.ps1 (100%) rename {test2 => tests}/GitHub.Tests.ps1 (99%) rename {test2 => tests}/Organizations.Tests.ps1 (100%) rename {test2 => tests}/README.md (100%) rename {test2 => tests}/Repositories.Tests.ps1 (100%) rename {test2 => tests}/TEMPLATE.ps1 (100%) rename {test2 => tests}/User.Tests.ps1 (100%) rename {test2 => tests}/Variables.ps1 (100%) diff --git a/.github/PSModule.yml b/.github/PSModule.yml index 669009014..6d578178e 100644 --- a/.github/PSModule.yml +++ b/.github/PSModule.yml @@ -1,18 +1,3 @@ Test: - SourceCode: - Skip: true - PSModule: - Skip: true - Module: - MacOS: - Skip: true - Windows: - Skip: true - TestResults: - Skip: true CodeCoverage: - Skip: true PercentTarget: 50 -Build: - Docs: - Skip: true diff --git a/test2/API.Tests.ps1 b/tests/API.Tests.ps1 similarity index 100% rename from test2/API.Tests.ps1 rename to tests/API.Tests.ps1 diff --git a/test2/Apps.Tests.ps1 b/tests/Apps.Tests.ps1 similarity index 100% rename from test2/Apps.Tests.ps1 rename to tests/Apps.Tests.ps1 diff --git a/test2/Auth.Tests.ps1 b/tests/Auth.Tests.ps1 similarity index 100% rename from test2/Auth.Tests.ps1 rename to tests/Auth.Tests.ps1 diff --git a/test2/IssueForm.md b/tests/Data/IssueForm.md similarity index 100% rename from test2/IssueForm.md rename to tests/Data/IssueForm.md diff --git a/test2/Emojis.Tests.ps1 b/tests/Emojis.Tests.ps1 similarity index 100% rename from test2/Emojis.Tests.ps1 rename to tests/Emojis.Tests.ps1 diff --git a/test2/Environments.Tests.ps1 b/tests/Environments.Tests.ps1 similarity index 100% rename from test2/Environments.Tests.ps1 rename to tests/Environments.Tests.ps1 diff --git a/test2/GitHub.Tests.ps1 b/tests/GitHub.Tests.ps1 similarity index 99% rename from test2/GitHub.Tests.ps1 rename to tests/GitHub.Tests.ps1 index 4391ea3ec..c3ef277d8 100644 --- a/test2/GitHub.Tests.ps1 +++ b/tests/GitHub.Tests.ps1 @@ -204,7 +204,7 @@ string } Context 'IssueParser' { BeforeAll { - $issueTestFilePath = Join-Path -Path $PSScriptRoot -ChildPath 'IssueForm.md' + $issueTestFilePath = Join-Path -Path $PSScriptRoot -ChildPath 'Data/IssueForm.md' Write-Verbose "Reading from $issueTestFilePath" -Verbose $content = Get-Content -Path $issueTestFilePath -Raw Write-Verbose ($content | Out-String) -Verbose diff --git a/test2/Organizations.Tests.ps1 b/tests/Organizations.Tests.ps1 similarity index 100% rename from test2/Organizations.Tests.ps1 rename to tests/Organizations.Tests.ps1 diff --git a/test2/README.md b/tests/README.md similarity index 100% rename from test2/README.md rename to tests/README.md diff --git a/test2/Repositories.Tests.ps1 b/tests/Repositories.Tests.ps1 similarity index 100% rename from test2/Repositories.Tests.ps1 rename to tests/Repositories.Tests.ps1 diff --git a/test2/TEMPLATE.ps1 b/tests/TEMPLATE.ps1 similarity index 100% rename from test2/TEMPLATE.ps1 rename to tests/TEMPLATE.ps1 diff --git a/test2/User.Tests.ps1 b/tests/User.Tests.ps1 similarity index 100% rename from test2/User.Tests.ps1 rename to tests/User.Tests.ps1 diff --git a/test2/Variables.ps1 b/tests/Variables.ps1 similarity index 100% rename from test2/Variables.ps1 rename to tests/Variables.ps1 From 740142e9f7c77d1082fe726817815ce300c70271 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 28 Mar 2025 23:21:15 +0100 Subject: [PATCH 155/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Update=20t?= =?UTF-8?q?est=20cases=20for=20Get-GitHubVariable=20to=20include=20inherit?= =?UTF-8?q?ed=20variables=20for=20organizations=20and=20remove=20obsolete?= =?UTF-8?q?=20Variables.ps1=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 4 +- tests/Variables.ps1 | 237 -------------------------------------- 2 files changed, 2 insertions(+), 239 deletions(-) delete mode 100644 tests/Variables.ps1 diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index d90afc606..eb242693d 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -235,7 +235,7 @@ Describe 'Environments' { $result | Should -Not -BeNullOrEmpty } - It 'Get-GitHubVariable -IncludeInherited' { + It 'Get-GitHubVariable -IncludeInherited' -Skip:($OwnerType -ne 'organization') { $result = Get-GitHubVariable @scope -Name "*$os*" -IncludeInherited LogGroup 'Variables' { Write-Host "$($result | Select-Object * | Format-Table | Out-String)" @@ -306,7 +306,7 @@ Describe 'Environments' { $result | Should -Not -BeNullOrEmpty } - It 'Get-GitHubVariable -IncludeInherited' { + It 'Get-GitHubVariable -IncludeInherited' -Skip:($OwnerType -ne 'organization') { $result = Get-GitHubVariable @scope -Name "*$os*" -IncludeInherited Write-Host "$($result | Select-Object * | Format-Table | Out-String)" $result | Should -Not -BeNullOrEmpty diff --git a/tests/Variables.ps1 b/tests/Variables.ps1 deleted file mode 100644 index 601dce71e..000000000 --- a/tests/Variables.ps1 +++ /dev/null @@ -1,237 +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() - -Describe 'Variables' { - $authCases = . "$PSScriptRoot/Data/AuthCases.ps1" - - Context 'As using on ' -ForEach $authCases { - BeforeAll { - $context = Connect-GitHubAccount @connectParams -PassThru -Silent - LogGroup 'Context' { - Write-Host ($context | Format-List | Out-String) - } - $repoName = "$testName-$os-$TokenType" - $varName = "$testName`_$os`_$TokenType" - $variablePrefix = "$varName`_" - $environmentName = "$testName-$os-$TokenType" - } - AfterAll { - Remove-GitHubRepository -Owner $owner -Name $repoName -Confirm:$false - if ($OwnerType -eq 'organization') { - Get-GitHubVariable -Owner $owner -Name "*$os*" | Remove-GitHubVariable - } - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent - } - - Context 'Prep' { - BeforeAll { - if ($AuthType -eq 'APP') { - $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent - LogGroup 'Context' { - Write-Host ($context | Format-List | Out-String) - } - } - if ($OwnerType -eq 'organization') { - $repo = New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge - Set-GitHubVariable -Owner $owner -Name $varName -Value 'organization' -Visibility selected -SelectedRepositories $repo.id - } else { - $repo = New-GitHubRepository -Name $repoName -AllowSquashMerge - } - LogGroup 'Repository' { - Write-Host ($repo | Format-List | Out-String) - } - } - } - - # # Tests for IAT UAT and PAT goes here - # Context 'Organization' -Skip:($TokenType -in 'GITHUB_TOKEN') { - # 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*" - # LogGroup 'Variables' { - # Write-Host "$($result | Format-Table | Out-String)" - # } - # $result | Should -Not -BeNullOrEmpty - # } - - # It 'Get-GitHubVariable -All' { - # $result = Get-GitHubVariable @scope -Name "*$os*" -All - # LogGroup 'Variables' { - # Write-Host "$($result | Format-Table | Out-String)" - # } - # $result | Should -Not -BeNullOrEmpty - # } - - # It 'Remove-GitHubVariable' { - # $before = Get-GitHubVariable @scope -Name "*$os*" - # LogGroup 'Variables - Before' { - # Write-Host "$($before | Format-Table | Out-String)" - # } - # $before | Remove-GitHubVariable - # $after = Get-GitHubVariable @scope -Name "*$os*" - # LogGroup 'Variables -After' { - # 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 2247662bcd9d2a989bcbbf6fa84ae2623cde1b62 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 28 Mar 2025 23:54:57 +0100 Subject: [PATCH 156/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Move=20rem?= =?UTF-8?q?oval=20of=20organization=20variables=20to=20AfterAll=20block=20?= =?UTF-8?q?and=20simplify=20test=20case=20conditions=20for=20Get-GitHubVar?= =?UTF-8?q?iable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index eb242693d..fe82d2633 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -67,12 +67,12 @@ Describe 'Environments' { } AfterAll { - if ($OwnerType -eq 'organization') { - Get-GitHubVariable -Owner $owner | Remove-GitHubVariable - } if ($Type -ne 'GitHub Actions') { Remove-GitHubRepository -Owner $owner -Name $repoName -Confirm:$false } + if ($OwnerType -eq 'organization') { + Get-GitHubVariable -Owner $owner | Remove-GitHubVariable + } Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent } @@ -235,7 +235,7 @@ Describe 'Environments' { $result | Should -Not -BeNullOrEmpty } - It 'Get-GitHubVariable -IncludeInherited' -Skip:($OwnerType -ne 'organization') { + It 'Get-GitHubVariable -IncludeInherited' { $result = Get-GitHubVariable @scope -Name "*$os*" -IncludeInherited LogGroup 'Variables' { Write-Host "$($result | Select-Object * | Format-Table | Out-String)" @@ -306,7 +306,7 @@ Describe 'Environments' { $result | Should -Not -BeNullOrEmpty } - It 'Get-GitHubVariable -IncludeInherited' -Skip:($OwnerType -ne 'organization') { + It 'Get-GitHubVariable -IncludeInherited' { $result = Get-GitHubVariable @scope -Name "*$os*" -IncludeInherited Write-Host "$($result | Select-Object * | Format-Table | Out-String)" $result | Should -Not -BeNullOrEmpty From d1ac52a576a005b87342a86080537de5b6239d55 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 29 Mar 2025 00:24:02 +0100 Subject: [PATCH 157/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Update=20d?= =?UTF-8?q?ocumentation=20links=20in=20Update-GitHubTeam=20and=20improve?= =?UTF-8?q?=20error=20handling=20in=20Get-GitHubVariable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/functions/public/Teams/Update-GitHubTeam.ps1 | 4 ++-- src/functions/public/Variables/Get-GitHubVariable.ps1 | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/functions/public/Teams/Update-GitHubTeam.ps1 b/src/functions/public/Teams/Update-GitHubTeam.ps1 index 843a038d5..62fc3833b 100644 --- a/src/functions/public/Teams/Update-GitHubTeam.ps1 +++ b/src/functions/public/Teams/Update-GitHubTeam.ps1 @@ -23,7 +23,7 @@ visibility set to 'closed', notifications enabled, permission set to 'pull', and the parent team ID set to 123456. .NOTES - [Update a team](https://docs.github.com/en/rest/teams/teams?apiVersion=2022-11-28#update-a-team) + [Update a team](https://docs.github.com/rest/teams/teams#update-a-team) #> [OutputType([GitHubTeam])] [CmdletBinding(SupportsShouldProcess)] @@ -93,7 +93,7 @@ description = $Description privacy = $PSBoundParameters.ContainsKey('Visible') ? ($Visible ? 'closed' : 'secret') : $null notification_setting = $PSBoundParameters.ContainsKey('Notifications') ? - ($Notifications ? 'notifications_enabled' : 'notifications_disabled') : $null + ($Notifications ? 'notifications_enabled' : 'notifications_disabled') : $null permission = $Permission parent_team_id = $ParentTeamID -eq 0 ? $null : $ParentTeamID } diff --git a/src/functions/public/Variables/Get-GitHubVariable.ps1 b/src/functions/public/Variables/Get-GitHubVariable.ps1 index 3dbb5d8c8..8a9dc4126 100644 --- a/src/functions/public/Variables/Get-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Get-GitHubVariable.ps1 @@ -185,7 +185,7 @@ function Get-GitHubVariable { try { $variables += Get-GitHubVariableFromOrganization @params | Where-Object { $_.Name -like $Name } - } finally {} + } catch {} } if ($Name.Contains('*')) { $variables += Get-GitHubVariableRepositoryList @params | @@ -201,7 +201,7 @@ function Get-GitHubVariable { try { $variables += Get-GitHubVariableFromOrganization @params | Where-Object { $_.Name -like $Name } - } finally {} + } catch {} if ($Name.Contains('*')) { $variables += Get-GitHubVariableRepositoryList @params | Where-Object { $_.Name -like $Name } From fd70712c90125c013734cc3ad6adc3d384d03e31 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 29 Mar 2025 00:44:38 +0100 Subject: [PATCH 158/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Simplify?= =?UTF-8?q?=20error=20handling=20in=20Get-GitHubVariable=20by=20removing?= =?UTF-8?q?=20try-catch=20blocks=20for=20inherited=20variable=20retrieval?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Get-GitHubVariableFromOrganization.ps1 | 22 +++++++++++-------- .../public/Variables/Get-GitHubVariable.ps1 | 12 ++++------ 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/functions/private/Variables/Get-GitHubVariableFromOrganization.ps1 b/src/functions/private/Variables/Get-GitHubVariableFromOrganization.ps1 index e89a19066..716427266 100644 --- a/src/functions/private/Variables/Get-GitHubVariableFromOrganization.ps1 +++ b/src/functions/private/Variables/Get-GitHubVariableFromOrganization.ps1 @@ -87,17 +87,21 @@ function Get-GitHubVariableFromOrganization { 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 + try { + Invoke-GitHubAPI @inputObject | ForEach-Object { + $_.Response.variables | ForEach-Object { + [GitHubVariable]@{ + Name = $_.name + Value = $_.value + CreatedAt = $_.created_at + UpdatedAt = $_.updated_at + Owner = $Owner + Visibility = $_.visibility + } } } + } catch { + return $null } } diff --git a/src/functions/public/Variables/Get-GitHubVariable.ps1 b/src/functions/public/Variables/Get-GitHubVariable.ps1 index 8a9dc4126..ceb091599 100644 --- a/src/functions/public/Variables/Get-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Get-GitHubVariable.ps1 @@ -182,10 +182,8 @@ function Get-GitHubVariable { 'Repository' { $params['Repository'] = $Repository if ($IncludeInherited) { - try { - $variables += Get-GitHubVariableFromOrganization @params | - Where-Object { $_.Name -like $Name } - } catch {} + $variables += Get-GitHubVariableFromOrganization @params | + Where-Object { $_.Name -like $Name } } if ($Name.Contains('*')) { $variables += Get-GitHubVariableRepositoryList @params | @@ -198,10 +196,8 @@ function Get-GitHubVariable { 'Environment' { $params['Repository'] = $Repository if ($IncludeInherited) { - try { - $variables += Get-GitHubVariableFromOrganization @params | - Where-Object { $_.Name -like $Name } - } catch {} + $variables += Get-GitHubVariableFromOrganization @params | + Where-Object { $_.Name -like $Name } if ($Name.Contains('*')) { $variables += Get-GitHubVariableRepositoryList @params | Where-Object { $_.Name -like $Name } From 5094cc7f010e87f14f47115f0b10ae07e3591123 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 29 Mar 2025 09:07:06 +0100 Subject: [PATCH 159/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Replace=20?= =?UTF-8?q?Get-GitHubVariableVisibilityList=20with=20Get-GitHubVariableSel?= =?UTF-8?q?ectedRepository=20in=20variable=20retrieval=20functions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../private/Variables/Get-GitHubVariableOwnerByName.ps1 | 2 +- .../private/Variables/Get-GitHubVariableOwnerList.ps1 | 2 +- .../Get-GitHubVariableSelectedRepository.ps1} | 7 +++++-- 3 files changed, 7 insertions(+), 4 deletions(-) rename src/functions/{private/Variables/Get-GitHubVariableVisibilityList.ps1 => public/Variables/SelectedRepository/Get-GitHubVariableSelectedRepository.ps1} (90%) diff --git a/src/functions/private/Variables/Get-GitHubVariableOwnerByName.ps1 b/src/functions/private/Variables/Get-GitHubVariableOwnerByName.ps1 index 1645f3c3e..1f6219e2b 100644 --- a/src/functions/private/Variables/Get-GitHubVariableOwnerByName.ps1 +++ b/src/functions/private/Variables/Get-GitHubVariableOwnerByName.ps1 @@ -64,7 +64,7 @@ function Get-GitHubVariableOwnerByName { $_.Response | ForEach-Object { $selectedRepositories = @() if ($_.visibility -eq 'selected') { - $selectedRepositories = Get-GitHubVariableVisibilityList -Owner $Owner -Name $_.name -Context $Context + $selectedRepositories = Get-GitHubVariableSelectedRepository -Owner $Owner -Name $_.name -Context $Context } [GitHubVariable]@{ Name = $_.name diff --git a/src/functions/private/Variables/Get-GitHubVariableOwnerList.ps1 b/src/functions/private/Variables/Get-GitHubVariableOwnerList.ps1 index 5704a744d..029d5d3cb 100644 --- a/src/functions/private/Variables/Get-GitHubVariableOwnerList.ps1 +++ b/src/functions/private/Variables/Get-GitHubVariableOwnerList.ps1 @@ -87,7 +87,7 @@ function Get-GitHubVariableOwnerList { $_.Response.variables | ForEach-Object { $selectedRepositories = @() if ($_.visibility -eq 'selected') { - $selectedRepositories = Get-GitHubVariableVisibilityList -Owner $Owner -Name $_.name -Context $Context + $selectedRepositories = Get-GitHubVariableSelectedRepository -Owner $Owner -Name $_.name -Context $Context } [GitHubVariable]@{ Name = $_.name diff --git a/src/functions/private/Variables/Get-GitHubVariableVisibilityList.ps1 b/src/functions/public/Variables/SelectedRepository/Get-GitHubVariableSelectedRepository.ps1 similarity index 90% rename from src/functions/private/Variables/Get-GitHubVariableVisibilityList.ps1 rename to src/functions/public/Variables/SelectedRepository/Get-GitHubVariableSelectedRepository.ps1 index 096eff40a..7245d8784 100644 --- a/src/functions/private/Variables/Get-GitHubVariableVisibilityList.ps1 +++ b/src/functions/public/Variables/SelectedRepository/Get-GitHubVariableSelectedRepository.ps1 @@ -1,4 +1,4 @@ -function Get-GitHubVariableVisibilityList { +function Get-GitHubVariableSelectedRepository { <# .SYNOPSIS List selected repositories for an organization variable. @@ -10,7 +10,7 @@ function Get-GitHubVariableVisibilityList { the `repo` scope is also required. .EXAMPLE - Get-GitHubVariableVisibilityList -Owner 'PSModule' -Name 'SELECTEDVAR' -Context (Get-GitHubContext) + Get-GitHubVariableSelectedRepository -Owner 'PSModule' -Name 'SELECTEDVAR' -Context (Get-GitHubContext) .OUTPUTS GitHubRepository @@ -18,6 +18,9 @@ function Get-GitHubVariableVisibilityList { .NOTES Returns a list of GitHubRepository objects that represent the repositories that can access the variable. + .LINK + https://psmodule.io/GitHub/Functions/Variables/Get-GitHubVariable + .LINK [List selected repositories for an organization variable](https://docs.github.com/rest/actions/variables#list-selected-repositories-for-an-organization-variable) #> From bfe4cde7cba58d67a92cc6eaff9124f8d6a2dba3 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 29 Mar 2025 09:17:41 +0100 Subject: [PATCH 160/210] =?UTF-8?q?=F0=9F=94=A7=20[Add]:=20Implement=20Add?= =?UTF-8?q?-GitHubVariableSelectedRepository=20function=20for=20managing?= =?UTF-8?q?=20organization=20variables?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Add-GitHubVariableSelectedRepository.ps1 | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/functions/public/Variables/SelectedRepository/Add-GitHubVariableSelectedRepository.ps1 diff --git a/src/functions/public/Variables/SelectedRepository/Add-GitHubVariableSelectedRepository.ps1 b/src/functions/public/Variables/SelectedRepository/Add-GitHubVariableSelectedRepository.ps1 new file mode 100644 index 000000000..ef12dd3a5 --- /dev/null +++ b/src/functions/public/Variables/SelectedRepository/Add-GitHubVariableSelectedRepository.ps1 @@ -0,0 +1,71 @@ +function Add-GitHubVariableSelectedRepository { + <# + .SYNOPSIS + Add selected repository to an organization variable. + + .DESCRIPTION + Adds a repository to an organization variable that is available to selected repositories. + Organization variables that are available to selected repositories have their `visibility` field set to `selected`. + Authenticated users must have collaborator access to a repository to create, update, or read secrets. + 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 + + + .LINK + https://psmodule.io/GitHub/Functions/Variables/SelectedRepository/Add-GitHubVariableSelectedRepository + + .LINK + [Add selected repository to an organization variable](https://docs.github.com/rest/actions/variables#add-selected-repository-to-an-organization-variable) + #> + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidLongLines', '', + Justification = 'Long links' + )] + [OutputType([GitHubRepository])] + [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 ID of the repository to add to the variable. + [Parameter(Mandatory)] + [string] $RepositoryID, + + # 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 = @{ + repository_id = $RepositoryID + } + + $inputObject = @{ + Method = 'PUT' + APIEndpoint = "/orgs/$Owner/actions/variables/$Name/repositories" + Body = $body + Context = $Context + } + + $null = Invoke-GitHubAPI @inputObject + } + + end { + Write-Debug "[$stackPath] - End" + } +} From 6c848a6369bc5697dbc3f8a41fdc016dea7862e6 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 29 Mar 2025 09:19:04 +0100 Subject: [PATCH 161/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Update=20d?= =?UTF-8?q?ocumentation=20in=20Add-GitHubVariableSelectedRepository=20for?= =?UTF-8?q?=20clarity=20and=20accuracy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Add-GitHubVariableSelectedRepository.ps1 | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/functions/public/Variables/SelectedRepository/Add-GitHubVariableSelectedRepository.ps1 b/src/functions/public/Variables/SelectedRepository/Add-GitHubVariableSelectedRepository.ps1 index ef12dd3a5..d60fc646c 100644 --- a/src/functions/public/Variables/SelectedRepository/Add-GitHubVariableSelectedRepository.ps1 +++ b/src/functions/public/Variables/SelectedRepository/Add-GitHubVariableSelectedRepository.ps1 @@ -5,13 +5,23 @@ .DESCRIPTION Adds a repository to an organization variable that is available to selected repositories. - Organization variables that are available to selected repositories have their `visibility` field set to `selected`. - Authenticated users must have collaborator access to a repository to create, update, or read secrets. - 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. + Organization variables that are available to selected repositories have their visibility field set to 'selected'. + Authenticated users must have collaborator access to the repository to create, update, or read secrets. + OAuth and classic personal access tokens require the 'admin:org' scope. For private repositories, the 'repo' scope is also required. + Fine-grained tokens must have 'Variables' organization permission (write) and 'Metadata' repository permission (read). .EXAMPLE + Add-GitHubVariableSelectedRepository -Owner 'my-org' -Name 'API_KEY' -RepositoryID '654321' -Context $GitHubContext + Output: + ```powershell + Name : test-repo + Id : 654321 + FullName : my-org/test-repo + Private : True + ``` + + Adds the repository 'test-repo' to the 'API_KEY' variable in the organization 'my-org'. .LINK https://psmodule.io/GitHub/Functions/Variables/SelectedRepository/Add-GitHubVariableSelectedRepository @@ -23,7 +33,7 @@ 'PSAvoidLongLines', '', Justification = 'Long links' )] - [OutputType([GitHubRepository])] + [OutputType([void])] [CmdletBinding()] param( # The account owner of the repository. The name is not case sensitive. From 8033a84f8a5f8b67eaf4b6dcba295c1d17292aa9 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 29 Mar 2025 09:58:50 +0100 Subject: [PATCH 162/210] =?UTF-8?q?=F0=9F=94=A7=20[Add]:=20Implement=20Set?= =?UTF-8?q?-GitHubVariableSelectedRepository=20and=20Remove-GitHubVariable?= =?UTF-8?q?SelectedRepository=20functions=20for=20managing=20organization?= =?UTF-8?q?=20variable=20access?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Add-GitHubVariableSelectedRepository.ps1 | 30 +++---- .../Get-GitHubVariableSelectedRepository.ps1 | 7 +- ...emove-GitHubVariableSelectedRepository.ps1 | 84 +++++++++++++++++++ .../Set-GitHubVariableSelectedRepository.ps1 | 71 ++++++++++++++++ tests/Variables.Tests.ps1 | 78 +++++++++++++++-- 5 files changed, 243 insertions(+), 27 deletions(-) create mode 100644 src/functions/public/Variables/SelectedRepository/Remove-GitHubVariableSelectedRepository.ps1 create mode 100644 src/functions/public/Variables/SelectedRepository/Set-GitHubVariableSelectedRepository.ps1 diff --git a/src/functions/public/Variables/SelectedRepository/Add-GitHubVariableSelectedRepository.ps1 b/src/functions/public/Variables/SelectedRepository/Add-GitHubVariableSelectedRepository.ps1 index d60fc646c..554cfeed5 100644 --- a/src/functions/public/Variables/SelectedRepository/Add-GitHubVariableSelectedRepository.ps1 +++ b/src/functions/public/Variables/SelectedRepository/Add-GitHubVariableSelectedRepository.ps1 @@ -11,15 +11,7 @@ Fine-grained tokens must have 'Variables' organization permission (write) and 'Metadata' repository permission (read). .EXAMPLE - Add-GitHubVariableSelectedRepository -Owner 'my-org' -Name 'API_KEY' -RepositoryID '654321' -Context $GitHubContext - - Output: - ```powershell - Name : test-repo - Id : 654321 - FullName : my-org/test-repo - Private : True - ``` + Add-GitHubVariableSelectedRepository -Owner 'my-org' -Name 'API_KEY' -RepositoryID '654321' Adds the repository 'test-repo' to the 'API_KEY' variable in the organization 'my-org'. @@ -45,30 +37,30 @@ [string] $Name, # The ID of the repository to add to the variable. - [Parameter(Mandatory)] - [string] $RepositoryID, + [Parameter(, + Mandatory, + ValueFromPipelineByPropertyName + )] + [Alias('DatabaseID')] + [UInt64] $RepositoryID, # 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()] + [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 = @{ - repository_id = $RepositoryID - } - $inputObject = @{ Method = 'PUT' - APIEndpoint = "/orgs/$Owner/actions/variables/$Name/repositories" - Body = $body + APIEndpoint = "/orgs/$Owner/actions/variables/$Name/repositories/$RepositoryID" Context = $Context } diff --git a/src/functions/public/Variables/SelectedRepository/Get-GitHubVariableSelectedRepository.ps1 b/src/functions/public/Variables/SelectedRepository/Get-GitHubVariableSelectedRepository.ps1 index 7245d8784..0c4439955 100644 --- a/src/functions/public/Variables/SelectedRepository/Get-GitHubVariableSelectedRepository.ps1 +++ b/src/functions/public/Variables/SelectedRepository/Get-GitHubVariableSelectedRepository.ps1 @@ -10,7 +10,7 @@ function Get-GitHubVariableSelectedRepository { the `repo` scope is also required. .EXAMPLE - Get-GitHubVariableSelectedRepository -Owner 'PSModule' -Name 'SELECTEDVAR' -Context (Get-GitHubContext) + Get-GitHubVariableSelectedRepository -Owner 'PSModule' -Name 'SELECTEDVAR' .OUTPUTS GitHubRepository @@ -41,13 +41,14 @@ function Get-GitHubVariableSelectedRepository { # 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()] + [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 } diff --git a/src/functions/public/Variables/SelectedRepository/Remove-GitHubVariableSelectedRepository.ps1 b/src/functions/public/Variables/SelectedRepository/Remove-GitHubVariableSelectedRepository.ps1 new file mode 100644 index 000000000..b9a499667 --- /dev/null +++ b/src/functions/public/Variables/SelectedRepository/Remove-GitHubVariableSelectedRepository.ps1 @@ -0,0 +1,84 @@ +function Remove-GitHubVariableSelectedRepository { + <# + .SYNOPSIS + Remove selected repository from an organization variable. + + .DESCRIPTION + Removes a repository from an organization variable that is + available to selected repositories. Organization variables that are available to + selected repositories have their visibility field set to 'selected'. + + 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. + + Fine-grained personal access tokens must have 'Variables' organization permissions (write) and + 'Metadata' repository permissions (read). + + .EXAMPLE + Remove-GitHubVariableSelectedRepository -Owner 'my-org' -Name 'ENV_SECRET' -RepositoryID 123456 + + Removes repository with ID 123456 from the organization variable 'ENV_SECRET' in 'my-org'. + + .OUTPUTS + void. The function performs a deletion operation and does not return any output. + The response will be HTTP 204 if successful, or HTTP 409 if the variable visibility is not 'selected'. + + .LINK + https://psmodule.io/GitHub/Functions/Variables/SelectedRepository/Remove-GitHubVariableSelectedRepository + + .LINK + [Remove selected repository from an organization variable](https://docs.github.com/rest/actions/variables#remove-selected-repository-from-an-organization-variable) + #> + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidLongLines', '', + Justification = 'Long links' + )] + [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 ID of the repository to remove to the variable. + [Parameter(, + Mandatory, + ValueFromPipelineByPropertyName + )] + [Alias('DatabaseID')] + [UInt64] $RepositoryID, + + # 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 = "/orgs/$Owner/actions/variables/$Name/repositories/$RepositoryID" + Context = $Context + } + + if ($PSCmdlet.ShouldProcess("access to variable [$Owner/$Name] for repository [$RepositoryID]", 'Remove')) { + $null = Invoke-GitHubAPI @inputObject + } + } + + end { + Write-Debug "[$stackPath] - End" + } +} diff --git a/src/functions/public/Variables/SelectedRepository/Set-GitHubVariableSelectedRepository.ps1 b/src/functions/public/Variables/SelectedRepository/Set-GitHubVariableSelectedRepository.ps1 new file mode 100644 index 000000000..1ef04f1e4 --- /dev/null +++ b/src/functions/public/Variables/SelectedRepository/Set-GitHubVariableSelectedRepository.ps1 @@ -0,0 +1,71 @@ +function Set-GitHubVariableSelectedRepository { + <# + .SYNOPSIS + Set selected repositories for an organization variable. + + .DESCRIPTION + Sets which repositories has access to an organization variable. + Organization variables that are available to selected repositories have their `visibility` field set to `selected`. + 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 + + .LINK + https://psmodule.io/GitHub/Functions/Variables/SelectedRepository/Set-GitHubVariableSelectedRepository + + .LINK + [Set selected repositories for an organization variable](https://docs.github.com/rest/actions/variables#set-selected-repositories-for-an-organization-variable) + #> + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidLongLines', '', + Justification = 'Long links' + )] + [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 ID of the repository to set to the variable. + [Parameter(Mandatory)] + [UInt64[]] $RepositoryID, + + # 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 = @{ + selected_repository_ids = @($RepositoryID) + } + $inputObject = @{ + Method = 'PUT' + APIEndpoint = "/orgs/$Owner/actions/variables/$Name/repositories" + Body = $body + Context = $Context + } + + if ($PSCmdlet.ShouldProcess("access to variable [$Owner/$Name] for repository [$RepositoryID]", 'Set')) { + $null = Invoke-GitHubAPI @inputObject + } + } + + end { + Write-Debug "[$stackPath] - End" + } +} diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index fe82d2633..cb8e88312 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -42,12 +42,19 @@ Describe 'Environments' { if ($Type -ne 'GitHub Actions') { LogGroup "Repository - [$repoName]" { - if ($OwnerType -eq 'user') { - $repo = New-GitHubRepository -Name $repoName -AllowSquashMerge - } else { - $repo = New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge + switch ($OwnerType) { + 'user' { + $repo = New-GitHubRepository -Name $repoName -AllowSquashMerge + } + 'organization' { + $repo = New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge + $repo2 = New-GitHubRepository -Owner $owner -Name "$repoName-2" -AllowSquashMerge + $repo3 = New-GitHubRepository -Owner $owner -Name "$repoName-3" -AllowSquashMerge + } } Write-Host ($repo | Format-List | Out-String) + Write-Host ($repo2 | Format-List | Out-String) + Write-Host ($repo3 | Format-List | Out-String) } } @@ -69,6 +76,8 @@ Describe 'Environments' { AfterAll { if ($Type -ne 'GitHub Actions') { Remove-GitHubRepository -Owner $owner -Name $repoName -Confirm:$false + Remove-GitHubRepository -Owner $owner -Name "$repoName-2" -Confirm:$false + Remove-GitHubRepository -Owner $owner -Name "$repoName-3" -Confirm:$false } if ($OwnerType -eq 'organization') { Get-GitHubVariable -Owner $owner | Remove-GitHubVariable @@ -155,7 +164,7 @@ Describe 'Environments' { It 'New-GitHubVariable - should throw if creating an organization variable that exists' { $name = "$variablePrefix`TestVariable2" - LogGroup "Variable - [$varName]" { + LogGroup "Variable - [$name]" { $param = @{ Name = $name Value = 'TestValue123' @@ -189,6 +198,65 @@ Describe 'Environments' { } $after.Count | Should -Be 0 } + + Context 'SelectedRepository' { + It 'Get-GitHubVariableSelectedRepository - gets a list of selected repositories' { + $result = Get-GitHubVariableSelectedRepository -Owner $owner -Name $varName + LogGroup "SelectedRepositories - [$varName]" { + Write-Host "$($result | Select-Object * | Format-Table | Out-String)" + } + $result | Should -Not -BeNullOrEmpty + $result[0] | Should -BeOfType [GitHubRepository] + $result | Should -HaveCount 1 + } + It 'Add-GitHubVariableSelectedRepository - adds a repository to the list of selected repositories' { + Add-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo2.id + LogGroup "SelectedRepository - [$varName]" { + Write-Host "$($result | Select-Object * | Format-Table | Out-String)" + } + } + It 'Add-GitHubVariableSelectedRepository - adds a repository to the list of selected repositories using pipeline' { + { $repo3 | Add-GitHubVariableSelectedRepository -Owner $owner -Name $varName } | Should -Not -Throw + } + It 'Get-GitHubVariableSelectedRepository - gets 3 repositories' { + $result = Get-GitHubVariableSelectedRepository -Owner $owner -Name $varName + LogGroup "SelectedRepositories - [$varName]" { + Write-Host "$($result | Select-Object * | Format-Table | Out-String)" + } + $result | Should -Not -BeNullOrEmpty + $result[0] | Should -BeOfType [GitHubRepository] + $result | Should -HaveCount 3 + } + It 'Remove-GitHubVariableSelectedRepository - removes a repository from the list of selected repositories' { + { Remove-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo2.id } | Should -Not -Throw + } + It 'Remove-GitHubVariableSelectedRepository - removes a repository from the list of selected repositories using pipeline' { + { $repo3 | Remove-GitHubVariableSelectedRepository -Owner $owner -Name $varName } | Should -Not -Throw + } + It 'Get-GitHubVariableSelectedRepository - gets 1 repository' { + $result = Get-GitHubVariableSelectedRepository -Owner $owner -Name $varName + LogGroup "SelectedRepositories - [$varName]" { + Write-Host "$($result | Select-Object * | Format-Table | Out-String)" + } + $result | Should -Not -BeNullOrEmpty + $result[0] | Should -BeOfType [GitHubRepository] + $result | Should -HaveCount 1 + } + It 'Set-GitHubVariableSelectedRepository - should set the selected repositories for the variable' { + { Set-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo.id, $repo2.id, $repo3.id } | + Should -Not -Throw + } + + It 'Get-GitHubVariableSelectedRepository - gets 3 repository' { + $result = Get-GitHubVariableSelectedRepository -Owner $owner -Name $varName + LogGroup "SelectedRepositories - [$varName]" { + Write-Host "$($result | Select-Object * | Format-Table | Out-String)" + } + $result | Should -Not -BeNullOrEmpty + $result[0] | Should -BeOfType [GitHubRepository] + $result | Should -HaveCount 3 + } + } } Context 'Repository' -Skip:($Type -eq 'GitHub Actions') { From 29fea8ad2122218c79a5b8ebfebcb9e6f9dd67af Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions@users.noreply.github.com> Date: Sat, 29 Mar 2025 09:00:10 +0000 Subject: [PATCH 163/210] Auto-generated changes --- Coverage.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Coverage.md b/Coverage.md index 672d5925c..3a4f36833 100644 --- a/Coverage.md +++ b/Coverage.md @@ -9,15 +9,15 @@ Covered functions - 181 + 184 Missing functions - 840 + 837 Coverage - 17.73% + 18.02% @@ -133,8 +133,8 @@ | `/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/{name}/repositories/{repository_id}` | :x: | | | | :x: | +| `/orgs/{org}/actions/variables/{name}/repositories` | | :white_check_mark: | | | :white_check_mark: | +| `/orgs/{org}/actions/variables/{name}/repositories/{repository_id}` | :white_check_mark: | | | | :white_check_mark: | | `/orgs/{org}/attestations/{subject_digest}` | | :x: | | | | | `/orgs/{org}/blocks` | | :white_check_mark: | | | | | `/orgs/{org}/blocks/{username}` | :white_check_mark: | :white_check_mark: | | | :white_check_mark: | From 17d6072a18e7d96967e0dcefdbf7028bfa11d0f9 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 29 Mar 2025 10:17:10 +0100 Subject: [PATCH 164/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Update=20a?= =?UTF-8?q?lias=20for=20RepositoryID=20parameter=20in=20Add-GitHubVariable?= =?UTF-8?q?SelectedRepository=20and=20Remove-GitHubVariableSelectedReposit?= =?UTF-8?q?ory=20functions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Add-GitHubVariableSelectedRepository.ps1 | 2 +- .../Remove-GitHubVariableSelectedRepository.ps1 | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/functions/public/Variables/SelectedRepository/Add-GitHubVariableSelectedRepository.ps1 b/src/functions/public/Variables/SelectedRepository/Add-GitHubVariableSelectedRepository.ps1 index 554cfeed5..ed5d176b1 100644 --- a/src/functions/public/Variables/SelectedRepository/Add-GitHubVariableSelectedRepository.ps1 +++ b/src/functions/public/Variables/SelectedRepository/Add-GitHubVariableSelectedRepository.ps1 @@ -41,7 +41,7 @@ Mandatory, ValueFromPipelineByPropertyName )] - [Alias('DatabaseID')] + [Alias('DatabaseID', 'ID')] [UInt64] $RepositoryID, # The context to run the command in. Used to get the details for the API call. diff --git a/src/functions/public/Variables/SelectedRepository/Remove-GitHubVariableSelectedRepository.ps1 b/src/functions/public/Variables/SelectedRepository/Remove-GitHubVariableSelectedRepository.ps1 index b9a499667..675e93a8f 100644 --- a/src/functions/public/Variables/SelectedRepository/Remove-GitHubVariableSelectedRepository.ps1 +++ b/src/functions/public/Variables/SelectedRepository/Remove-GitHubVariableSelectedRepository.ps1 @@ -21,8 +21,7 @@ Removes repository with ID 123456 from the organization variable 'ENV_SECRET' in 'my-org'. .OUTPUTS - void. The function performs a deletion operation and does not return any output. - The response will be HTTP 204 if successful, or HTTP 409 if the variable visibility is not 'selected'. + void .LINK https://psmodule.io/GitHub/Functions/Variables/SelectedRepository/Remove-GitHubVariableSelectedRepository @@ -50,7 +49,7 @@ Mandatory, ValueFromPipelineByPropertyName )] - [Alias('DatabaseID')] + [Alias('DatabaseID', 'ID')] [UInt64] $RepositoryID, # The context to run the command in. Used to get the details for the API call. From 2087c468b5ba7935cc748dc2c2c57954f9a92829 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 29 Mar 2025 10:19:10 +0100 Subject: [PATCH 165/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Improve=20?= =?UTF-8?q?formatting=20of=20notification=5Fsetting=20assignment=20in=20Up?= =?UTF-8?q?date-GitHubTeam=20function=20for=20better=20readability?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/functions/public/Teams/Update-GitHubTeam.ps1 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/functions/public/Teams/Update-GitHubTeam.ps1 b/src/functions/public/Teams/Update-GitHubTeam.ps1 index 62fc3833b..025c3dda3 100644 --- a/src/functions/public/Teams/Update-GitHubTeam.ps1 +++ b/src/functions/public/Teams/Update-GitHubTeam.ps1 @@ -92,8 +92,9 @@ name = $NewName description = $Description privacy = $PSBoundParameters.ContainsKey('Visible') ? ($Visible ? 'closed' : 'secret') : $null - notification_setting = $PSBoundParameters.ContainsKey('Notifications') ? - ($Notifications ? 'notifications_enabled' : 'notifications_disabled') : $null + notification_setting = $PSBoundParameters.ContainsKey('Notifications') ? ( + $Notifications ? 'notifications_enabled' : 'notifications_disabled' + ) : $null permission = $Permission parent_team_id = $ParentTeamID -eq 0 ? $null : $ParentTeamID } From 7cab178fa280757e39d4f8da6440590b8fd92b8e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 29 Mar 2025 10:38:26 +0100 Subject: [PATCH 166/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Move=20rep?= =?UTF-8?q?ository=20removal=20logic=20to=20the=20organization=20block=20i?= =?UTF-8?q?n=20AfterAll=20for=20better=20clarity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index cb8e88312..2d7c97fac 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -76,11 +76,11 @@ Describe 'Environments' { AfterAll { if ($Type -ne 'GitHub Actions') { Remove-GitHubRepository -Owner $owner -Name $repoName -Confirm:$false - Remove-GitHubRepository -Owner $owner -Name "$repoName-2" -Confirm:$false - Remove-GitHubRepository -Owner $owner -Name "$repoName-3" -Confirm:$false } if ($OwnerType -eq 'organization') { Get-GitHubVariable -Owner $owner | Remove-GitHubVariable + Remove-GitHubRepository -Owner $owner -Name "$repoName-2" -Confirm:$false + Remove-GitHubRepository -Owner $owner -Name "$repoName-3" -Confirm:$false } Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent } From 43719a0c6f80692b78f69741b265922557a2fc4b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 29 Mar 2025 11:04:25 +0100 Subject: [PATCH 167/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Add=20-Deb?= =?UTF-8?q?ug=20and=20-Verbose=20parameters=20to=20Add-GitHubVariableSelec?= =?UTF-8?q?tedRepository=20and=20Remove-GitHubVariableSelectedRepository?= =?UTF-8?q?=20tests=20for=20enhanced=20debugging?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 2d7c97fac..f683b7ab2 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -216,7 +216,7 @@ Describe 'Environments' { } } It 'Add-GitHubVariableSelectedRepository - adds a repository to the list of selected repositories using pipeline' { - { $repo3 | Add-GitHubVariableSelectedRepository -Owner $owner -Name $varName } | Should -Not -Throw + { $repo3 | Add-GitHubVariableSelectedRepository -Owner $owner -Name $varName -Debug -Verbose } | Should -Not -Throw } It 'Get-GitHubVariableSelectedRepository - gets 3 repositories' { $result = Get-GitHubVariableSelectedRepository -Owner $owner -Name $varName @@ -231,7 +231,7 @@ Describe 'Environments' { { Remove-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo2.id } | Should -Not -Throw } It 'Remove-GitHubVariableSelectedRepository - removes a repository from the list of selected repositories using pipeline' { - { $repo3 | Remove-GitHubVariableSelectedRepository -Owner $owner -Name $varName } | Should -Not -Throw + { $repo3 | Remove-GitHubVariableSelectedRepository -Owner $owner -Name $varName -Debug -Verbose } | Should -Not -Throw } It 'Get-GitHubVariableSelectedRepository - gets 1 repository' { $result = Get-GitHubVariableSelectedRepository -Owner $owner -Name $varName From 0b573b66eaf5c6c2bf0a6d36ecb73982587107e6 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 29 Mar 2025 11:34:16 +0100 Subject: [PATCH 168/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Add=20idem?= =?UTF-8?q?potent=20tests=20for=20Add-GitHubVariableSelectedRepository,=20?= =?UTF-8?q?Remove-GitHubVariableSelectedRepository,=20and=20Set-GitHubVari?= =?UTF-8?q?ableSelectedRepository=20functions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index f683b7ab2..b98d6e91b 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -210,10 +210,10 @@ Describe 'Environments' { $result | Should -HaveCount 1 } It 'Add-GitHubVariableSelectedRepository - adds a repository to the list of selected repositories' { - Add-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo2.id - LogGroup "SelectedRepository - [$varName]" { - Write-Host "$($result | Select-Object * | Format-Table | Out-String)" - } + { Add-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo2.id } | Should -Not -Throw + } + It 'Add-GitHubVariableSelectedRepository - adds a repository to the list of selected repositories - idempotent test' { + { Add-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo2.id } | Should -Not -Throw } It 'Add-GitHubVariableSelectedRepository - adds a repository to the list of selected repositories using pipeline' { { $repo3 | Add-GitHubVariableSelectedRepository -Owner $owner -Name $varName -Debug -Verbose } | Should -Not -Throw @@ -230,6 +230,9 @@ Describe 'Environments' { It 'Remove-GitHubVariableSelectedRepository - removes a repository from the list of selected repositories' { { Remove-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo2.id } | Should -Not -Throw } + It 'Remove-GitHubVariableSelectedRepository - removes a repository from the list of selected repositories - idempotent test' { + { Remove-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo2.id } | Should -Not -Throw + } It 'Remove-GitHubVariableSelectedRepository - removes a repository from the list of selected repositories using pipeline' { { $repo3 | Remove-GitHubVariableSelectedRepository -Owner $owner -Name $varName -Debug -Verbose } | Should -Not -Throw } @@ -246,7 +249,10 @@ Describe 'Environments' { { Set-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo.id, $repo2.id, $repo3.id } | Should -Not -Throw } - + It 'Set-GitHubVariableSelectedRepository - should set the selected repositories for the variable - idempotent test' { + { Set-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo.id, $repo2.id, $repo3.id } | + Should -Not -Throw + } It 'Get-GitHubVariableSelectedRepository - gets 3 repository' { $result = Get-GitHubVariableSelectedRepository -Owner $owner -Name $varName LogGroup "SelectedRepositories - [$varName]" { From adff767156bf1865ccf1a3ddc126ac4e55911877 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 29 Mar 2025 11:45:57 +0100 Subject: [PATCH 169/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Update=20i?= =?UTF-8?q?dempotency=20test=20descriptions=20for=20Add-GitHubVariableSele?= =?UTF-8?q?ctedRepository,=20Remove-GitHubVariableSelectedRepository,=20an?= =?UTF-8?q?d=20Set-GitHubVariableSelectedRepository=20functions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 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 b98d6e91b..665e67c82 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -212,11 +212,11 @@ Describe 'Environments' { It 'Add-GitHubVariableSelectedRepository - adds a repository to the list of selected repositories' { { Add-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo2.id } | Should -Not -Throw } - It 'Add-GitHubVariableSelectedRepository - adds a repository to the list of selected repositories - idempotent test' { + It 'Add-GitHubVariableSelectedRepository - adds a repository to the list of selected repositories - idempotency test' { { Add-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo2.id } | Should -Not -Throw } It 'Add-GitHubVariableSelectedRepository - adds a repository to the list of selected repositories using pipeline' { - { $repo3 | Add-GitHubVariableSelectedRepository -Owner $owner -Name $varName -Debug -Verbose } | Should -Not -Throw + { $repo2 | Add-GitHubVariableSelectedRepository -Owner $owner -Name $varName -Debug -Verbose } | Should -Not -Throw } It 'Get-GitHubVariableSelectedRepository - gets 3 repositories' { $result = Get-GitHubVariableSelectedRepository -Owner $owner -Name $varName @@ -225,16 +225,16 @@ Describe 'Environments' { } $result | Should -Not -BeNullOrEmpty $result[0] | Should -BeOfType [GitHubRepository] - $result | Should -HaveCount 3 + $result | Should -HaveCount 2 } It 'Remove-GitHubVariableSelectedRepository - removes a repository from the list of selected repositories' { { Remove-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo2.id } | Should -Not -Throw } - It 'Remove-GitHubVariableSelectedRepository - removes a repository from the list of selected repositories - idempotent test' { + It 'Remove-GitHubVariableSelectedRepository - removes a repository from the list of selected repositories - idempotency test' { { Remove-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo2.id } | Should -Not -Throw } It 'Remove-GitHubVariableSelectedRepository - removes a repository from the list of selected repositories using pipeline' { - { $repo3 | Remove-GitHubVariableSelectedRepository -Owner $owner -Name $varName -Debug -Verbose } | Should -Not -Throw + { $repo2 | Remove-GitHubVariableSelectedRepository -Owner $owner -Name $varName -Debug -Verbose } | Should -Not -Throw } It 'Get-GitHubVariableSelectedRepository - gets 1 repository' { $result = Get-GitHubVariableSelectedRepository -Owner $owner -Name $varName @@ -249,7 +249,7 @@ Describe 'Environments' { { Set-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo.id, $repo2.id, $repo3.id } | Should -Not -Throw } - It 'Set-GitHubVariableSelectedRepository - should set the selected repositories for the variable - idempotent test' { + It 'Set-GitHubVariableSelectedRepository - should set the selected repositories for the variable - idempotency test' { { Set-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo.id, $repo2.id, $repo3.id } | Should -Not -Throw } From 2fd6bb1a14bd151d9f5d8a4dc37b7efd89e5466d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 29 Mar 2025 12:48:32 +0100 Subject: [PATCH 170/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Enhance=20?= =?UTF-8?q?variable=20removal=20functions=20to=20check=20for=20existence?= =?UTF-8?q?=20before=20deletion=20in=20Remove-GitHubVariable=20and=20Remov?= =?UTF-8?q?e-GitHubVariableSelectedRepository?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Variables/Remove-GitHubVariable.ps1 | 33 ++++++++++++++----- ...emove-GitHubVariableSelectedRepository.ps1 | 3 ++ tests/Variables.Tests.ps1 | 29 ++++++++++++---- 3 files changed, 50 insertions(+), 15 deletions(-) diff --git a/src/functions/public/Variables/Remove-GitHubVariable.ps1 b/src/functions/public/Variables/Remove-GitHubVariable.ps1 index e80767840..cec1a8118 100644 --- a/src/functions/public/Variables/Remove-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Remove-GitHubVariable.ps1 @@ -83,25 +83,31 @@ function Remove-GitHubVariable { Owner = $item.Owner Repository = $item.Repository Environment = $item.Environment - Name = $item.Name Context = $Context } - Remove-GitHubVariableFromEnvironment @params + $existingVariables = Get-GitHubVariableEnvironemntList @params + $variableExists = $item.Name -in $existingVariables.Name + if (-not $variableExists) { continue } + Remove-GitHubVariableFromEnvironment @params -Name $item.Name } elseif ($item.Repository) { $params = @{ Owner = $item.Owner Repository = $item.Repository - Name = $item.Name Context = $Context } - Remove-GitHubVariableFromRepository @params + $existingVariables = Get-GitHubVariableRepositoryList @params + $variableExists = $item.Name -in $existingVariables.Name + if (-not $variableExists) { continue } + Remove-GitHubVariableFromRepository @params -Name $item.Name } else { $params = @{ Owner = $item.Owner - Name = $item.Name Context = $Context } - Remove-GitHubVariableFromOwner @params + $existingVariables = Get-GitHubVariableOwnerList @params + $variableExists = $item.Name -in $existingVariables.Name + if (-not $variableExists) { continue } + Remove-GitHubVariableFromOwner @params -Name $item.Name } $scopeParam = @{ Owner = $item.Owner @@ -124,7 +130,10 @@ function Remove-GitHubVariable { Name = $Name Context = $Context } - Remove-GitHubVariableFromOwner @params + $existingVariables = Get-GitHubVariableOwnerList @params + $variableExists = $Name -in $existingVariables.Name + if (-not $variableExists) { continue } + Remove-GitHubVariableFromOwner @params -Name $Name break } 'Repository' { @@ -134,7 +143,10 @@ function Remove-GitHubVariable { Name = $Name Context = $Context } - Remove-GitHubVariableFromRepository @params + $existingVariables = Get-GitHubVariableRepositoryList @params + $variableExists = $Name -in $existingVariables.Name + if (-not $variableExists) { continue } + Remove-GitHubVariableFromRepository @params -Name $Name break } 'Environment' { @@ -145,7 +157,10 @@ function Remove-GitHubVariable { Name = $Name Context = $Context } - Remove-GitHubVariableFromEnvironment @params + $existingVariables = Get-GitHubVariableEnvironemntList @params + $variableExists = $Name -in $existingVariables.Name + if (-not $variableExists) { continue } + Remove-GitHubVariableFromEnvironment @params -Name $Name break } } diff --git a/src/functions/public/Variables/SelectedRepository/Remove-GitHubVariableSelectedRepository.ps1 b/src/functions/public/Variables/SelectedRepository/Remove-GitHubVariableSelectedRepository.ps1 index 675e93a8f..16b736317 100644 --- a/src/functions/public/Variables/SelectedRepository/Remove-GitHubVariableSelectedRepository.ps1 +++ b/src/functions/public/Variables/SelectedRepository/Remove-GitHubVariableSelectedRepository.ps1 @@ -66,6 +66,9 @@ } process { + $existingSelectedRepositories = Get-GitHubVariableSelectedRepository -Owner $Owner -Name $Name + $repoIsSelected = $Name -in $existingSelectedRepositories.Name + if (-not $repoIsSelected) { return } $inputObject = @{ Method = 'DELETE' APIEndpoint = "/orgs/$Owner/actions/variables/$Name/repositories/$RepositoryID" diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 665e67c82..ce091a849 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -353,6 +353,9 @@ Describe 'Environments' { } $result = Set-GitHubVariable @param @scope $result = Set-GitHubVariable @param @scope + LogGroup 'Variables' { + Write-Host "$($result | Select-Object * | Format-Table | Out-String)" + } $result | Should -Not -BeNullOrEmpty } @@ -362,6 +365,9 @@ Describe 'Environments' { Value = 'TestValue1234' } $result = Update-GitHubVariable @param @scope -PassThru + LogGroup 'Variables' { + Write-Host "$($result | Select-Object * | Format-Table | Out-String)" + } $result | Should -Not -BeNullOrEmpty } @@ -371,27 +377,38 @@ Describe 'Environments' { Value = 'TestValue123' } $result = New-GitHubVariable @param @scope + LogGroup 'Variables' { + Write-Host "$($result | Select-Object * | Format-Table | Out-String)" + } $result | Should -Not -BeNullOrEmpty } It 'Get-GitHubVariable' { $result = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($result | Select-Object * | Format-Table | Out-String)" + LogGroup 'Variables' { + Write-Host "$($result | Select-Object * | Format-Table | Out-String)" + } $result | Should -Not -BeNullOrEmpty } It 'Get-GitHubVariable -IncludeInherited' { $result = Get-GitHubVariable @scope -Name "*$os*" -IncludeInherited - Write-Host "$($result | Select-Object * | Format-Table | Out-String)" + LogGroup 'Variables' { + Write-Host "$($result | Select-Object * | Format-Table | Out-String)" + } $result | Should -Not -BeNullOrEmpty } It 'Remove-GitHubVariable' { - $before = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($before | Format-Table | Out-String)" + LogGroup 'Variables - Before' { + $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)" + LogGroup 'Variables - After' { + $after = Get-GitHubVariable @scope -Name "*$os*" + Write-Host "$($after | Format-Table | Out-String)" + } $after.Count | Should -Be 0 } } From a8c4bdc10a3004f78b767c34725a46a972482f57 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 29 Mar 2025 13:12:51 +0100 Subject: [PATCH 171/210] =?UTF-8?q?=F0=9F=94=A7=20[Fix]:=20Correct=20funct?= =?UTF-8?q?ion=20name=20typo=20in=20Remove-GitHubVariable=20and=20update?= =?UTF-8?q?=20related=20tests=20for=20improved=20clarity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../public/Variables/Remove-GitHubVariable.ps1 | 4 ++-- tests/Variables.Tests.ps1 | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/functions/public/Variables/Remove-GitHubVariable.ps1 b/src/functions/public/Variables/Remove-GitHubVariable.ps1 index cec1a8118..1b4604ca9 100644 --- a/src/functions/public/Variables/Remove-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Remove-GitHubVariable.ps1 @@ -85,7 +85,7 @@ function Remove-GitHubVariable { Environment = $item.Environment Context = $Context } - $existingVariables = Get-GitHubVariableEnvironemntList @params + $existingVariables = Get-GitHubVariableEnvironmentList @params $variableExists = $item.Name -in $existingVariables.Name if (-not $variableExists) { continue } Remove-GitHubVariableFromEnvironment @params -Name $item.Name @@ -157,7 +157,7 @@ function Remove-GitHubVariable { Name = $Name Context = $Context } - $existingVariables = Get-GitHubVariableEnvironemntList @params + $existingVariables = Get-GitHubVariableEnvironmentList @params $variableExists = $Name -in $existingVariables.Name if (-not $variableExists) { continue } Remove-GitHubVariableFromEnvironment @params -Name $Name diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index ce091a849..3138bc2ab 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -209,15 +209,15 @@ Describe 'Environments' { $result[0] | Should -BeOfType [GitHubRepository] $result | Should -HaveCount 1 } + It 'Add-GitHubVariableSelectedRepository - adds a repository to the list of selected repositories using pipeline' { + { $repo2 | Add-GitHubVariableSelectedRepository -Owner $owner -Name $varName -Debug -Verbose } | Should -Not -Throw + } It 'Add-GitHubVariableSelectedRepository - adds a repository to the list of selected repositories' { { Add-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo2.id } | Should -Not -Throw } It 'Add-GitHubVariableSelectedRepository - adds a repository to the list of selected repositories - idempotency test' { { Add-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo2.id } | Should -Not -Throw } - It 'Add-GitHubVariableSelectedRepository - adds a repository to the list of selected repositories using pipeline' { - { $repo2 | Add-GitHubVariableSelectedRepository -Owner $owner -Name $varName -Debug -Verbose } | Should -Not -Throw - } It 'Get-GitHubVariableSelectedRepository - gets 3 repositories' { $result = Get-GitHubVariableSelectedRepository -Owner $owner -Name $varName LogGroup "SelectedRepositories - [$varName]" { @@ -227,15 +227,15 @@ Describe 'Environments' { $result[0] | Should -BeOfType [GitHubRepository] $result | Should -HaveCount 2 } + It 'Remove-GitHubVariableSelectedRepository - removes a repository from the list of selected repositories using pipeline' { + { $repo2 | Remove-GitHubVariableSelectedRepository -Owner $owner -Name $varName -Debug -Verbose } | Should -Not -Throw + } It 'Remove-GitHubVariableSelectedRepository - removes a repository from the list of selected repositories' { { Remove-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo2.id } | Should -Not -Throw } It 'Remove-GitHubVariableSelectedRepository - removes a repository from the list of selected repositories - idempotency test' { { Remove-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo2.id } | Should -Not -Throw } - It 'Remove-GitHubVariableSelectedRepository - removes a repository from the list of selected repositories using pipeline' { - { $repo2 | Remove-GitHubVariableSelectedRepository -Owner $owner -Name $varName -Debug -Verbose } | Should -Not -Throw - } It 'Get-GitHubVariableSelectedRepository - gets 1 repository' { $result = Get-GitHubVariableSelectedRepository -Owner $owner -Name $varName LogGroup "SelectedRepositories - [$varName]" { From 92fa32d2c9b18e2c42e491411f1b8b922327464c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 29 Mar 2025 13:38:35 +0100 Subject: [PATCH 172/210] =?UTF-8?q?=F0=9F=94=A7=20[Fix]:=20Update=20reposi?= =?UTF-8?q?tory=20selection=20logic=20in=20Remove-GitHubVariableSelectedRe?= =?UTF-8?q?pository=20to=20use=20RepositoryID=20for=20accurate=20checks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Remove-GitHubVariableSelectedRepository.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions/public/Variables/SelectedRepository/Remove-GitHubVariableSelectedRepository.ps1 b/src/functions/public/Variables/SelectedRepository/Remove-GitHubVariableSelectedRepository.ps1 index 16b736317..b10777bcc 100644 --- a/src/functions/public/Variables/SelectedRepository/Remove-GitHubVariableSelectedRepository.ps1 +++ b/src/functions/public/Variables/SelectedRepository/Remove-GitHubVariableSelectedRepository.ps1 @@ -67,7 +67,7 @@ process { $existingSelectedRepositories = Get-GitHubVariableSelectedRepository -Owner $Owner -Name $Name - $repoIsSelected = $Name -in $existingSelectedRepositories.Name + $repoIsSelected = $existingSelectedRepositories.id -contains $RepositoryID if (-not $repoIsSelected) { return } $inputObject = @{ Method = 'DELETE' From 71e23b1f9a999fdbcc04daf18e2bb042c99b32de Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 29 Mar 2025 14:23:35 +0100 Subject: [PATCH 173/210] =?UTF-8?q?=F0=9F=94=A7=20[Fix]:=20Update=20logic?= =?UTF-8?q?=20in=20Remove-GitHubVariableSelectedRepository=20to=20correctl?= =?UTF-8?q?y=20check=20if=20a=20repository=20is=20selected=20before=20proc?= =?UTF-8?q?eeding=20with=20deletion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Remove-GitHubVariableSelectedRepository.ps1 | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/functions/public/Variables/SelectedRepository/Remove-GitHubVariableSelectedRepository.ps1 b/src/functions/public/Variables/SelectedRepository/Remove-GitHubVariableSelectedRepository.ps1 index b10777bcc..9f8f7cb6a 100644 --- a/src/functions/public/Variables/SelectedRepository/Remove-GitHubVariableSelectedRepository.ps1 +++ b/src/functions/public/Variables/SelectedRepository/Remove-GitHubVariableSelectedRepository.ps1 @@ -67,8 +67,11 @@ process { $existingSelectedRepositories = Get-GitHubVariableSelectedRepository -Owner $Owner -Name $Name - $repoIsSelected = $existingSelectedRepositories.id -contains $RepositoryID - if (-not $repoIsSelected) { return } + $repoIsNotSelected = $existingSelectedRepositories.id -notcontains $RepositoryID + if ($repoIsNotSelected) { + Write-Host 'Repo is not selected, returning' + return + } $inputObject = @{ Method = 'DELETE' APIEndpoint = "/orgs/$Owner/actions/variables/$Name/repositories/$RepositoryID" From a8cb6c5bd2d3e11e1f0579b9e204351d5bdae178 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 29 Mar 2025 14:35:03 +0100 Subject: [PATCH 174/210] =?UTF-8?q?=F0=9F=94=A7=20[Debug]:=20Add=20debug?= =?UTF-8?q?=20output=20to=20Remove-GitHubVariableSelectedRepository=20for?= =?UTF-8?q?=20existing=20selected=20repositories=20and=20repository=20ID?= =?UTF-8?q?=20checks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Remove-GitHubVariableSelectedRepository.ps1 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/functions/public/Variables/SelectedRepository/Remove-GitHubVariableSelectedRepository.ps1 b/src/functions/public/Variables/SelectedRepository/Remove-GitHubVariableSelectedRepository.ps1 index 9f8f7cb6a..5905376d5 100644 --- a/src/functions/public/Variables/SelectedRepository/Remove-GitHubVariableSelectedRepository.ps1 +++ b/src/functions/public/Variables/SelectedRepository/Remove-GitHubVariableSelectedRepository.ps1 @@ -67,6 +67,11 @@ process { $existingSelectedRepositories = Get-GitHubVariableSelectedRepository -Owner $Owner -Name $Name + $existingSelectedRepositories | Format-List | Out-String + Write-Host "What to check for" + Write-Host "$($existingSelectedRepositories.id)" + Write-Host "What to delete" + Write-Host "$($RepositoryID)" $repoIsNotSelected = $existingSelectedRepositories.id -notcontains $RepositoryID if ($repoIsNotSelected) { Write-Host 'Repo is not selected, returning' From 9a40b0624f19db2a8b643bebcb5189a851e14399 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 29 Mar 2025 14:51:30 +0100 Subject: [PATCH 175/210] =?UTF-8?q?=F0=9F=94=A7=20[Enhance]:=20Add=20conte?= =?UTF-8?q?xt=20parameter=20to=20Add-GitHubVariableSelectedRepository=20an?= =?UTF-8?q?d=20Remove-GitHubVariableSelectedRepository=20for=20improved=20?= =?UTF-8?q?repository=20selection=20checks;=20update=20tests=20for=20pipel?= =?UTF-8?q?ine=20usage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Add-GitHubVariableSelectedRepository.ps1 | 11 +++++++++++ ...Remove-GitHubVariableSelectedRepository.ps1 | 2 +- tests/Variables.Tests.ps1 | 18 ++++++++++++------ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/functions/public/Variables/SelectedRepository/Add-GitHubVariableSelectedRepository.ps1 b/src/functions/public/Variables/SelectedRepository/Add-GitHubVariableSelectedRepository.ps1 index ed5d176b1..5a94f2653 100644 --- a/src/functions/public/Variables/SelectedRepository/Add-GitHubVariableSelectedRepository.ps1 +++ b/src/functions/public/Variables/SelectedRepository/Add-GitHubVariableSelectedRepository.ps1 @@ -58,6 +58,17 @@ } process { + $existingSelectedRepositories = Get-GitHubVariableSelectedRepository -Owner $Owner -Name $Name -Context $Context + $existingSelectedRepositories | Format-List | Out-String + Write-Host 'What to check for' + Write-Host "$($existingSelectedRepositories.id)" + Write-Host 'What to add' + Write-Host "$($RepositoryID)" + $repoIsSelected = $existingSelectedRepositories.id -contains $RepositoryID + if ($repoIsSelected) { + Write-Host 'Repo is already selected, returning' + return + } $inputObject = @{ Method = 'PUT' APIEndpoint = "/orgs/$Owner/actions/variables/$Name/repositories/$RepositoryID" diff --git a/src/functions/public/Variables/SelectedRepository/Remove-GitHubVariableSelectedRepository.ps1 b/src/functions/public/Variables/SelectedRepository/Remove-GitHubVariableSelectedRepository.ps1 index 5905376d5..4c40e7be9 100644 --- a/src/functions/public/Variables/SelectedRepository/Remove-GitHubVariableSelectedRepository.ps1 +++ b/src/functions/public/Variables/SelectedRepository/Remove-GitHubVariableSelectedRepository.ps1 @@ -66,7 +66,7 @@ } process { - $existingSelectedRepositories = Get-GitHubVariableSelectedRepository -Owner $Owner -Name $Name + $existingSelectedRepositories = Get-GitHubVariableSelectedRepository -Owner $Owner -Name $Name -Context $Context $existingSelectedRepositories | Format-List | Out-String Write-Host "What to check for" Write-Host "$($existingSelectedRepositories.id)" diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 3138bc2ab..1557413e1 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -209,15 +209,18 @@ Describe 'Environments' { $result[0] | Should -BeOfType [GitHubRepository] $result | Should -HaveCount 1 } - It 'Add-GitHubVariableSelectedRepository - adds a repository to the list of selected repositories using pipeline' { - { $repo2 | Add-GitHubVariableSelectedRepository -Owner $owner -Name $varName -Debug -Verbose } | Should -Not -Throw - } It 'Add-GitHubVariableSelectedRepository - adds a repository to the list of selected repositories' { { Add-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo2.id } | Should -Not -Throw } It 'Add-GitHubVariableSelectedRepository - adds a repository to the list of selected repositories - idempotency test' { { Add-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo2.id } | Should -Not -Throw } + It 'Add-GitHubVariableSelectedRepository - adds a repository to the list of selected repositories using pipeline' { + LogGroup 'Repo3' { + $repo3 | Format-List | Out-String + } + { $repo3 | Add-GitHubVariableSelectedRepository -Owner $owner -Name $varName -Debug -Verbose } | Should -Not -Throw + } It 'Get-GitHubVariableSelectedRepository - gets 3 repositories' { $result = Get-GitHubVariableSelectedRepository -Owner $owner -Name $varName LogGroup "SelectedRepositories - [$varName]" { @@ -227,15 +230,18 @@ Describe 'Environments' { $result[0] | Should -BeOfType [GitHubRepository] $result | Should -HaveCount 2 } - It 'Remove-GitHubVariableSelectedRepository - removes a repository from the list of selected repositories using pipeline' { - { $repo2 | Remove-GitHubVariableSelectedRepository -Owner $owner -Name $varName -Debug -Verbose } | Should -Not -Throw - } It 'Remove-GitHubVariableSelectedRepository - removes a repository from the list of selected repositories' { { Remove-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo2.id } | Should -Not -Throw } It 'Remove-GitHubVariableSelectedRepository - removes a repository from the list of selected repositories - idempotency test' { { Remove-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo2.id } | Should -Not -Throw } + It 'Remove-GitHubVariableSelectedRepository - removes a repository from the list of selected repositories using pipeline' { + LogGroup 'Repo3' { + $repo3 | Format-List | Out-String + } + { $repo3 | Remove-GitHubVariableSelectedRepository -Owner $owner -Name $varName -Debug -Verbose } | Should -Not -Throw + } It 'Get-GitHubVariableSelectedRepository - gets 1 repository' { $result = Get-GitHubVariableSelectedRepository -Owner $owner -Name $varName LogGroup "SelectedRepositories - [$varName]" { From b314ff0ea90ad3cf292bd0ccb45bc337b5c895b7 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 29 Mar 2025 14:56:33 +0100 Subject: [PATCH 176/210] =?UTF-8?q?=F0=9F=94=A7=20[Fix]:=20Update=20reposi?= =?UTF-8?q?tory=20ID=20references=20in=20Add-GitHubVariableSelectedReposit?= =?UTF-8?q?ory=20and=20Remove-GitHubVariableSelectedRepository=20for=20acc?= =?UTF-8?q?urate=20selection=20checks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Add-GitHubVariableSelectedRepository.ps1 | 6 +++--- .../Remove-GitHubVariableSelectedRepository.ps1 | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/functions/public/Variables/SelectedRepository/Add-GitHubVariableSelectedRepository.ps1 b/src/functions/public/Variables/SelectedRepository/Add-GitHubVariableSelectedRepository.ps1 index 5a94f2653..bc94b574e 100644 --- a/src/functions/public/Variables/SelectedRepository/Add-GitHubVariableSelectedRepository.ps1 +++ b/src/functions/public/Variables/SelectedRepository/Add-GitHubVariableSelectedRepository.ps1 @@ -59,12 +59,12 @@ process { $existingSelectedRepositories = Get-GitHubVariableSelectedRepository -Owner $Owner -Name $Name -Context $Context - $existingSelectedRepositories | Format-List | Out-String + Write-Host "$($existingSelectedRepositories | Format-List | Out-String)" Write-Host 'What to check for' - Write-Host "$($existingSelectedRepositories.id)" + Write-Host "$($existingSelectedRepositories.DatabaseID)" Write-Host 'What to add' Write-Host "$($RepositoryID)" - $repoIsSelected = $existingSelectedRepositories.id -contains $RepositoryID + $repoIsSelected = $existingSelectedRepositories.DatabaseID -contains $RepositoryID if ($repoIsSelected) { Write-Host 'Repo is already selected, returning' return diff --git a/src/functions/public/Variables/SelectedRepository/Remove-GitHubVariableSelectedRepository.ps1 b/src/functions/public/Variables/SelectedRepository/Remove-GitHubVariableSelectedRepository.ps1 index 4c40e7be9..a2ffcb554 100644 --- a/src/functions/public/Variables/SelectedRepository/Remove-GitHubVariableSelectedRepository.ps1 +++ b/src/functions/public/Variables/SelectedRepository/Remove-GitHubVariableSelectedRepository.ps1 @@ -67,12 +67,12 @@ process { $existingSelectedRepositories = Get-GitHubVariableSelectedRepository -Owner $Owner -Name $Name -Context $Context - $existingSelectedRepositories | Format-List | Out-String + Write-Host "$($existingSelectedRepositories | Format-List | Out-String)" Write-Host "What to check for" - Write-Host "$($existingSelectedRepositories.id)" + Write-Host "$($existingSelectedRepositories.DatabaseID)" Write-Host "What to delete" Write-Host "$($RepositoryID)" - $repoIsNotSelected = $existingSelectedRepositories.id -notcontains $RepositoryID + $repoIsNotSelected = $existingSelectedRepositories.DatabaseID -notcontains $RepositoryID if ($repoIsNotSelected) { Write-Host 'Repo is not selected, returning' return From 0b21de3a70831e72870ebe34967f560d691e1e83 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 29 Mar 2025 15:11:54 +0100 Subject: [PATCH 177/210] =?UTF-8?q?=F0=9F=94=A7=20[Enhance]:=20Skip=20test?= =?UTF-8?q?s=20on=20MacOS=20and=20Windows=20in=20PSModule.yml;=20update=20?= =?UTF-8?q?expected=20count=20in=20Variables.Tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/PSModule.yml | 5 +++++ .../Remove-GitHubVariableSelectedRepository.ps1 | 6 +++--- {tests => test2}/API.Tests.ps1 | 0 {tests => test2}/Apps.Tests.ps1 | 0 {tests => test2}/Auth.Tests.ps1 | 0 {tests => test2}/Emojis.Tests.ps1 | 0 {tests => test2}/Environments.Tests.ps1 | 0 {tests => test2}/GitHub.Tests.ps1 | 0 {tests => test2}/Organizations.Tests.ps1 | 0 {tests => test2}/README.md | 0 {tests => test2}/Repositories.Tests.ps1 | 0 {tests => test2}/TEMPLATE.ps1 | 0 {tests => test2}/User.Tests.ps1 | 0 tests/Variables.Tests.ps1 | 2 +- 14 files changed, 9 insertions(+), 4 deletions(-) rename {tests => test2}/API.Tests.ps1 (100%) rename {tests => test2}/Apps.Tests.ps1 (100%) rename {tests => test2}/Auth.Tests.ps1 (100%) rename {tests => test2}/Emojis.Tests.ps1 (100%) rename {tests => test2}/Environments.Tests.ps1 (100%) rename {tests => test2}/GitHub.Tests.ps1 (100%) rename {tests => test2}/Organizations.Tests.ps1 (100%) rename {tests => test2}/README.md (100%) rename {tests => test2}/Repositories.Tests.ps1 (100%) rename {tests => test2}/TEMPLATE.ps1 (100%) rename {tests => test2}/User.Tests.ps1 (100%) diff --git a/.github/PSModule.yml b/.github/PSModule.yml index 6d578178e..7d41a2c23 100644 --- a/.github/PSModule.yml +++ b/.github/PSModule.yml @@ -1,3 +1,8 @@ Test: + Module: + MacOS: + Skip: true + Windows: + Skip: true CodeCoverage: PercentTarget: 50 diff --git a/src/functions/public/Variables/SelectedRepository/Remove-GitHubVariableSelectedRepository.ps1 b/src/functions/public/Variables/SelectedRepository/Remove-GitHubVariableSelectedRepository.ps1 index a2ffcb554..7b704cd25 100644 --- a/src/functions/public/Variables/SelectedRepository/Remove-GitHubVariableSelectedRepository.ps1 +++ b/src/functions/public/Variables/SelectedRepository/Remove-GitHubVariableSelectedRepository.ps1 @@ -34,7 +34,7 @@ Justification = 'Long links' )] [OutputType([void])] - [CmdletBinding(SupportsShouldProcess)] + [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Low')] param( # The account owner of the repository. The name is not case sensitive. [Parameter(Mandatory)] @@ -68,9 +68,9 @@ process { $existingSelectedRepositories = Get-GitHubVariableSelectedRepository -Owner $Owner -Name $Name -Context $Context Write-Host "$($existingSelectedRepositories | Format-List | Out-String)" - Write-Host "What to check for" + Write-Host 'What to check for' Write-Host "$($existingSelectedRepositories.DatabaseID)" - Write-Host "What to delete" + Write-Host 'What to delete' Write-Host "$($RepositoryID)" $repoIsNotSelected = $existingSelectedRepositories.DatabaseID -notcontains $RepositoryID if ($repoIsNotSelected) { diff --git a/tests/API.Tests.ps1 b/test2/API.Tests.ps1 similarity index 100% rename from tests/API.Tests.ps1 rename to test2/API.Tests.ps1 diff --git a/tests/Apps.Tests.ps1 b/test2/Apps.Tests.ps1 similarity index 100% rename from tests/Apps.Tests.ps1 rename to test2/Apps.Tests.ps1 diff --git a/tests/Auth.Tests.ps1 b/test2/Auth.Tests.ps1 similarity index 100% rename from tests/Auth.Tests.ps1 rename to test2/Auth.Tests.ps1 diff --git a/tests/Emojis.Tests.ps1 b/test2/Emojis.Tests.ps1 similarity index 100% rename from tests/Emojis.Tests.ps1 rename to test2/Emojis.Tests.ps1 diff --git a/tests/Environments.Tests.ps1 b/test2/Environments.Tests.ps1 similarity index 100% rename from tests/Environments.Tests.ps1 rename to test2/Environments.Tests.ps1 diff --git a/tests/GitHub.Tests.ps1 b/test2/GitHub.Tests.ps1 similarity index 100% rename from tests/GitHub.Tests.ps1 rename to test2/GitHub.Tests.ps1 diff --git a/tests/Organizations.Tests.ps1 b/test2/Organizations.Tests.ps1 similarity index 100% rename from tests/Organizations.Tests.ps1 rename to test2/Organizations.Tests.ps1 diff --git a/tests/README.md b/test2/README.md similarity index 100% rename from tests/README.md rename to test2/README.md diff --git a/tests/Repositories.Tests.ps1 b/test2/Repositories.Tests.ps1 similarity index 100% rename from tests/Repositories.Tests.ps1 rename to test2/Repositories.Tests.ps1 diff --git a/tests/TEMPLATE.ps1 b/test2/TEMPLATE.ps1 similarity index 100% rename from tests/TEMPLATE.ps1 rename to test2/TEMPLATE.ps1 diff --git a/tests/User.Tests.ps1 b/test2/User.Tests.ps1 similarity index 100% rename from tests/User.Tests.ps1 rename to test2/User.Tests.ps1 diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 1557413e1..97e2e81c2 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -228,7 +228,7 @@ Describe 'Environments' { } $result | Should -Not -BeNullOrEmpty $result[0] | Should -BeOfType [GitHubRepository] - $result | Should -HaveCount 2 + $result | Should -HaveCount 3 } It 'Remove-GitHubVariableSelectedRepository - removes a repository from the list of selected repositories' { { Remove-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo2.id } | Should -Not -Throw From a840b8baf38657e9e4a94c318bd03e9a6ca8a556 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 29 Mar 2025 15:19:57 +0100 Subject: [PATCH 178/210] =?UTF-8?q?=F0=9F=94=A7=20[Enhance]:=20Add=20skip?= =?UTF-8?q?=20options=20for=20SourceCode=20and=20PSModule=20tests=20in=20P?= =?UTF-8?q?SModule.yml=20to=20improve=20test=20management?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/PSModule.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/PSModule.yml b/.github/PSModule.yml index 7d41a2c23..da55dc046 100644 --- a/.github/PSModule.yml +++ b/.github/PSModule.yml @@ -1,4 +1,8 @@ Test: + SourceCode: + Skip: true + PSModule: + Skip: true Module: MacOS: Skip: true From 99b590bd81e995fd63bc77f01fb6616c59d6d377 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 29 Mar 2025 15:43:35 +0100 Subject: [PATCH 179/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Remove=20d?= =?UTF-8?q?ebug=20output=20from=20Add-GitHubVariableSelectedRepository=20a?= =?UTF-8?q?nd=20Remove-GitHubVariableSelectedRepository=20for=20cleaner=20?= =?UTF-8?q?code;=20update=20tests=20accordingly?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Add-GitHubVariableSelectedRepository.ps1 | 5 ----- .../Remove-GitHubVariableSelectedRepository.ps1 | 7 +------ tests/Variables.Tests.ps1 | 4 ++-- 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/src/functions/public/Variables/SelectedRepository/Add-GitHubVariableSelectedRepository.ps1 b/src/functions/public/Variables/SelectedRepository/Add-GitHubVariableSelectedRepository.ps1 index bc94b574e..e64cf9abd 100644 --- a/src/functions/public/Variables/SelectedRepository/Add-GitHubVariableSelectedRepository.ps1 +++ b/src/functions/public/Variables/SelectedRepository/Add-GitHubVariableSelectedRepository.ps1 @@ -59,11 +59,6 @@ process { $existingSelectedRepositories = Get-GitHubVariableSelectedRepository -Owner $Owner -Name $Name -Context $Context - Write-Host "$($existingSelectedRepositories | Format-List | Out-String)" - Write-Host 'What to check for' - Write-Host "$($existingSelectedRepositories.DatabaseID)" - Write-Host 'What to add' - Write-Host "$($RepositoryID)" $repoIsSelected = $existingSelectedRepositories.DatabaseID -contains $RepositoryID if ($repoIsSelected) { Write-Host 'Repo is already selected, returning' diff --git a/src/functions/public/Variables/SelectedRepository/Remove-GitHubVariableSelectedRepository.ps1 b/src/functions/public/Variables/SelectedRepository/Remove-GitHubVariableSelectedRepository.ps1 index 7b704cd25..731118343 100644 --- a/src/functions/public/Variables/SelectedRepository/Remove-GitHubVariableSelectedRepository.ps1 +++ b/src/functions/public/Variables/SelectedRepository/Remove-GitHubVariableSelectedRepository.ps1 @@ -67,14 +67,9 @@ process { $existingSelectedRepositories = Get-GitHubVariableSelectedRepository -Owner $Owner -Name $Name -Context $Context - Write-Host "$($existingSelectedRepositories | Format-List | Out-String)" - Write-Host 'What to check for' - Write-Host "$($existingSelectedRepositories.DatabaseID)" - Write-Host 'What to delete' - Write-Host "$($RepositoryID)" $repoIsNotSelected = $existingSelectedRepositories.DatabaseID -notcontains $RepositoryID if ($repoIsNotSelected) { - Write-Host 'Repo is not selected, returning' + Write-Debug 'Repo is not selected, returning' return } $inputObject = @{ diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 97e2e81c2..0c0834bfd 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -219,7 +219,7 @@ Describe 'Environments' { LogGroup 'Repo3' { $repo3 | Format-List | Out-String } - { $repo3 | Add-GitHubVariableSelectedRepository -Owner $owner -Name $varName -Debug -Verbose } | Should -Not -Throw + { $repo3 | Add-GitHubVariableSelectedRepository -Owner $owner -Name $varName } | Should -Not -Throw } It 'Get-GitHubVariableSelectedRepository - gets 3 repositories' { $result = Get-GitHubVariableSelectedRepository -Owner $owner -Name $varName @@ -240,7 +240,7 @@ Describe 'Environments' { LogGroup 'Repo3' { $repo3 | Format-List | Out-String } - { $repo3 | Remove-GitHubVariableSelectedRepository -Owner $owner -Name $varName -Debug -Verbose } | Should -Not -Throw + { $repo3 | Remove-GitHubVariableSelectedRepository -Owner $owner -Name $varName } | Should -Not -Throw } It 'Get-GitHubVariableSelectedRepository - gets 1 repository' { $result = Get-GitHubVariableSelectedRepository -Owner $owner -Name $varName From 5665a2f85829625db4cacee6db2407be57585e4c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 29 Mar 2025 15:55:49 +0100 Subject: [PATCH 180/210] =?UTF-8?q?=F0=9F=94=A7=20[Enhance]:=20Add=20skip?= =?UTF-8?q?=20options=20for=20CodeCoverage,=20TestResults,=20and=20Build?= =?UTF-8?q?=20Docs=20in=20PSModule.yml;=20update=20test=20logging=20for=20?= =?UTF-8?q?better=20output=20clarity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/PSModule.yml | 6 ++++++ tests/Variables.Tests.ps1 | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/PSModule.yml b/.github/PSModule.yml index da55dc046..300609e41 100644 --- a/.github/PSModule.yml +++ b/.github/PSModule.yml @@ -9,4 +9,10 @@ Test: Windows: Skip: true CodeCoverage: + Skip: true PercentTarget: 50 + TestResults: + Skip: true + Build: + Docs: + Skip: true diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 0c0834bfd..f2afc2d7f 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -217,7 +217,7 @@ Describe 'Environments' { } It 'Add-GitHubVariableSelectedRepository - adds a repository to the list of selected repositories using pipeline' { LogGroup 'Repo3' { - $repo3 | Format-List | Out-String + Write-Host "$($repo3 | Format-List | Out-String)" } { $repo3 | Add-GitHubVariableSelectedRepository -Owner $owner -Name $varName } | Should -Not -Throw } @@ -238,7 +238,7 @@ Describe 'Environments' { } It 'Remove-GitHubVariableSelectedRepository - removes a repository from the list of selected repositories using pipeline' { LogGroup 'Repo3' { - $repo3 | Format-List | Out-String + Write-Host "$($repo3 | Format-List | Out-String)" } { $repo3 | Remove-GitHubVariableSelectedRepository -Owner $owner -Name $varName } | Should -Not -Throw } From a89b086653ea747b5b569a4a8f1dde2f0b9d85ba Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 29 Mar 2025 16:12:59 +0100 Subject: [PATCH 181/210] =?UTF-8?q?=F0=9F=94=A7=20[Enhance]:=20Update=20PS?= =?UTF-8?q?Module.yml=20to=20skip=20Build=20Docs=20and=20improve=20test=20?= =?UTF-8?q?management;=20change=20debug=20output=20to=20Write-Debug=20in?= =?UTF-8?q?=20Add-GitHubVariableSelectedRepository=20for=20consistency?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/PSModule.yml | 8 ++++---- .../Add-GitHubVariableSelectedRepository.ps1 | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/PSModule.yml b/.github/PSModule.yml index 300609e41..0448a5571 100644 --- a/.github/PSModule.yml +++ b/.github/PSModule.yml @@ -1,4 +1,7 @@ -Test: +Build: + Docs: + Skip: true + Test: SourceCode: Skip: true PSModule: @@ -13,6 +16,3 @@ Test: PercentTarget: 50 TestResults: Skip: true - Build: - Docs: - Skip: true diff --git a/src/functions/public/Variables/SelectedRepository/Add-GitHubVariableSelectedRepository.ps1 b/src/functions/public/Variables/SelectedRepository/Add-GitHubVariableSelectedRepository.ps1 index e64cf9abd..9a5f26dbd 100644 --- a/src/functions/public/Variables/SelectedRepository/Add-GitHubVariableSelectedRepository.ps1 +++ b/src/functions/public/Variables/SelectedRepository/Add-GitHubVariableSelectedRepository.ps1 @@ -61,7 +61,7 @@ $existingSelectedRepositories = Get-GitHubVariableSelectedRepository -Owner $Owner -Name $Name -Context $Context $repoIsSelected = $existingSelectedRepositories.DatabaseID -contains $RepositoryID if ($repoIsSelected) { - Write-Host 'Repo is already selected, returning' + Write-Debug 'Repo is already selected, returning' return } $inputObject = @{ From 2b58b6610e82f4fca308994c51db7bf9bb4b9f73 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 29 Mar 2025 16:14:18 +0100 Subject: [PATCH 182/210] =?UTF-8?q?=F0=9F=94=A7=20[Enhance]:=20Update=20PS?= =?UTF-8?q?Module.yml=20to=20remove=20unnecessary=20skip=20options;=20add?= =?UTF-8?q?=20README.md=20for=20testing=20framework=20details=20and=20crea?= =?UTF-8?q?te=20template=20and=20user=20test=20scripts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/PSModule.yml | 17 +---------------- {test2 => tests}/API.Tests.ps1 | 0 {test2 => tests}/Apps.Tests.ps1 | 0 {test2 => tests}/Auth.Tests.ps1 | 0 {test2 => tests}/Emojis.Tests.ps1 | 0 {test2 => tests}/Environments.Tests.ps1 | 0 {test2 => tests}/GitHub.Tests.ps1 | 0 {test2 => tests}/Organizations.Tests.ps1 | 0 {test2 => tests}/README.md | 0 {test2 => tests}/Repositories.Tests.ps1 | 0 {test2 => tests}/TEMPLATE.ps1 | 0 {test2 => tests}/User.Tests.ps1 | 0 12 files changed, 1 insertion(+), 16 deletions(-) rename {test2 => tests}/API.Tests.ps1 (100%) rename {test2 => tests}/Apps.Tests.ps1 (100%) rename {test2 => tests}/Auth.Tests.ps1 (100%) rename {test2 => tests}/Emojis.Tests.ps1 (100%) rename {test2 => tests}/Environments.Tests.ps1 (100%) rename {test2 => tests}/GitHub.Tests.ps1 (100%) rename {test2 => tests}/Organizations.Tests.ps1 (100%) rename {test2 => tests}/README.md (100%) rename {test2 => tests}/Repositories.Tests.ps1 (100%) rename {test2 => tests}/TEMPLATE.ps1 (100%) rename {test2 => tests}/User.Tests.ps1 (100%) diff --git a/.github/PSModule.yml b/.github/PSModule.yml index 0448a5571..6d578178e 100644 --- a/.github/PSModule.yml +++ b/.github/PSModule.yml @@ -1,18 +1,3 @@ -Build: - Docs: - Skip: true - Test: - SourceCode: - Skip: true - PSModule: - Skip: true - Module: - MacOS: - Skip: true - Windows: - Skip: true +Test: CodeCoverage: - Skip: true PercentTarget: 50 - TestResults: - Skip: true diff --git a/test2/API.Tests.ps1 b/tests/API.Tests.ps1 similarity index 100% rename from test2/API.Tests.ps1 rename to tests/API.Tests.ps1 diff --git a/test2/Apps.Tests.ps1 b/tests/Apps.Tests.ps1 similarity index 100% rename from test2/Apps.Tests.ps1 rename to tests/Apps.Tests.ps1 diff --git a/test2/Auth.Tests.ps1 b/tests/Auth.Tests.ps1 similarity index 100% rename from test2/Auth.Tests.ps1 rename to tests/Auth.Tests.ps1 diff --git a/test2/Emojis.Tests.ps1 b/tests/Emojis.Tests.ps1 similarity index 100% rename from test2/Emojis.Tests.ps1 rename to tests/Emojis.Tests.ps1 diff --git a/test2/Environments.Tests.ps1 b/tests/Environments.Tests.ps1 similarity index 100% rename from test2/Environments.Tests.ps1 rename to tests/Environments.Tests.ps1 diff --git a/test2/GitHub.Tests.ps1 b/tests/GitHub.Tests.ps1 similarity index 100% rename from test2/GitHub.Tests.ps1 rename to tests/GitHub.Tests.ps1 diff --git a/test2/Organizations.Tests.ps1 b/tests/Organizations.Tests.ps1 similarity index 100% rename from test2/Organizations.Tests.ps1 rename to tests/Organizations.Tests.ps1 diff --git a/test2/README.md b/tests/README.md similarity index 100% rename from test2/README.md rename to tests/README.md diff --git a/test2/Repositories.Tests.ps1 b/tests/Repositories.Tests.ps1 similarity index 100% rename from test2/Repositories.Tests.ps1 rename to tests/Repositories.Tests.ps1 diff --git a/test2/TEMPLATE.ps1 b/tests/TEMPLATE.ps1 similarity index 100% rename from test2/TEMPLATE.ps1 rename to tests/TEMPLATE.ps1 diff --git a/test2/User.Tests.ps1 b/tests/User.Tests.ps1 similarity index 100% rename from test2/User.Tests.ps1 rename to tests/User.Tests.ps1 From b1cd08b7f8d3a82a76c77e7d2c9bfc953d6588a7 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 29 Mar 2025 17:41:02 +0100 Subject: [PATCH 183/210] =?UTF-8?q?=F0=9F=94=A7=20[Enhance]:=20Add=20clean?= =?UTF-8?q?up=20logic=20to=20remove=20test=20repositories=20after=20execut?= =?UTF-8?q?ion=20in=20Repositories.Tests.ps1=20and=20Variables.Tests.ps1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Repositories.Tests.ps1 | 2 ++ tests/Variables.Tests.ps1 | 1 + 2 files changed, 3 insertions(+) diff --git a/tests/Repositories.Tests.ps1 b/tests/Repositories.Tests.ps1 index 6f648d357..4450359f4 100644 --- a/tests/Repositories.Tests.ps1 +++ b/tests/Repositories.Tests.ps1 @@ -32,8 +32,10 @@ Describe 'Template' { $guid = [guid]::NewGuid().ToString() $repoPrefix = "$testPrefix-$os" $repo = "$repoPrefix-$guid" + Get-GitHubRepository -Owner $Owner | Where-Object { $_.name -like "$repoPrefix*" } | Remove-GitHubRepository -Confirm:$false } AfterAll { + Get-GitHubRepository -Owner $Owner | Where-Object { $_.name -like "$repoPrefix*" } | Remove-GitHubRepository -Confirm:$false Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent } diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index f2afc2d7f..7d311ad14 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -42,6 +42,7 @@ Describe 'Environments' { if ($Type -ne 'GitHub Actions') { LogGroup "Repository - [$repoName]" { + Get-GitHubRepository -Owner $Owner | Where-Object { $_.name -like "$repoName*" } | Remove-GitHubRepository -Confirm:$false switch ($OwnerType) { 'user' { $repo = New-GitHubRepository -Name $repoName -AllowSquashMerge From 752cddb35fb6057cf950c7cf665ed471083531c3 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 29 Mar 2025 18:11:37 +0100 Subject: [PATCH 184/210] =?UTF-8?q?=F0=9F=94=A7=20[Enhance]:=20Refactor=20?= =?UTF-8?q?repository=20cleanup=20logic=20in=20Repositories.Tests.ps1=20an?= =?UTF-8?q?d=20Variables.Tests.ps1=20to=20improve=20clarity=20and=20ensure?= =?UTF-8?q?=20proper=20handling=20based=20on=20OwnerType?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Repositories.Tests.ps1 | 22 ++++++++++++---------- tests/Variables.Tests.ps1 | 3 ++- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/tests/Repositories.Tests.ps1 b/tests/Repositories.Tests.ps1 index 4450359f4..1b33d5c13 100644 --- a/tests/Repositories.Tests.ps1 +++ b/tests/Repositories.Tests.ps1 @@ -29,25 +29,27 @@ Describe 'Template' { LogGroup 'Context' { Write-Host ($context | Format-List | Out-String) } + # Tests for APP goes here + if ($AuthType -eq 'APP') { + It 'Connect-GitHubApp - Connects as a GitHub App to ' { + $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } + } + } $guid = [guid]::NewGuid().ToString() $repoPrefix = "$testPrefix-$os" $repo = "$repoPrefix-$guid" - Get-GitHubRepository -Owner $Owner | Where-Object { $_.name -like "$repoPrefix*" } | Remove-GitHubRepository -Confirm:$false + if ($OwnerType -ne 'repo') { + Get-GitHubRepository -Owner $Owner | Where-Object { $_.name -like "$repoPrefix*" } | Remove-GitHubRepository -Confirm:$false + } } AfterAll { Get-GitHubRepository -Owner $Owner | Where-Object { $_.name -like "$repoPrefix*" } | Remove-GitHubRepository -Confirm:$false Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent } - # Tests for APP goes here - if ($AuthType -eq 'APP') { - It 'Connect-GitHubApp - Connects as a GitHub App to ' { - $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent - LogGroup 'Context' { - Write-Host ($context | Format-List | Out-String) - } - } - } if ($Type -ne 'GitHub Actions') { # Tests for IAT UAT and PAT goes here diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 7d311ad14..8e5a0090a 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -42,12 +42,13 @@ Describe 'Environments' { if ($Type -ne 'GitHub Actions') { LogGroup "Repository - [$repoName]" { - Get-GitHubRepository -Owner $Owner | Where-Object { $_.name -like "$repoName*" } | Remove-GitHubRepository -Confirm:$false switch ($OwnerType) { 'user' { + Get-GitHubRepository -Owner $Owner | Where-Object { $_.name -like "$repoName*" } | Remove-GitHubRepository -Confirm:$false $repo = New-GitHubRepository -Name $repoName -AllowSquashMerge } 'organization' { + Get-GitHubRepository -Owner $Owner | Where-Object { $_.name -like "$repoName*" } | Remove-GitHubRepository -Confirm:$false $repo = New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge $repo2 = New-GitHubRepository -Owner $owner -Name "$repoName-2" -AllowSquashMerge $repo3 = New-GitHubRepository -Owner $owner -Name "$repoName-3" -AllowSquashMerge From 4abec5392fbf29de2183cb2bbe0d483a5826531e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 29 Mar 2025 18:27:49 +0100 Subject: [PATCH 185/210] =?UTF-8?q?=F0=9F=94=A7=20[Enhance]:=20Update=20re?= =?UTF-8?q?pository=20cleanup=20logic=20in=20Repositories.Tests.ps1=20and?= =?UTF-8?q?=20Variables.Tests.ps1=20to=20improve=20handling=20based=20on?= =?UTF-8?q?=20OwnerType?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Repositories.Tests.ps1 | 6 +++-- tests/Variables.Tests.ps1 | 43 ++++++++++++++++++------------------ 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/tests/Repositories.Tests.ps1 b/tests/Repositories.Tests.ps1 index 1b33d5c13..c663a8ed2 100644 --- a/tests/Repositories.Tests.ps1 +++ b/tests/Repositories.Tests.ps1 @@ -41,12 +41,14 @@ Describe 'Template' { $guid = [guid]::NewGuid().ToString() $repoPrefix = "$testPrefix-$os" $repo = "$repoPrefix-$guid" - if ($OwnerType -ne 'repo') { + if ($OwnerType -ne 'repository') { Get-GitHubRepository -Owner $Owner | Where-Object { $_.name -like "$repoPrefix*" } | Remove-GitHubRepository -Confirm:$false } } AfterAll { - Get-GitHubRepository -Owner $Owner | Where-Object { $_.name -like "$repoPrefix*" } | Remove-GitHubRepository -Confirm:$false + if ($OwnerType -ne 'repository') { + Get-GitHubRepository -Owner $Owner | Where-Object { $_.name -like "$repoPrefix*" } | Remove-GitHubRepository -Confirm:$false + } Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent } diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 8e5a0090a..01cf7823b 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -52,6 +52,18 @@ Describe 'Environments' { $repo = New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge $repo2 = New-GitHubRepository -Owner $owner -Name "$repoName-2" -AllowSquashMerge $repo3 = New-GitHubRepository -Owner $owner -Name "$repoName-3" -AllowSquashMerge + + LogGroup "Org variable - [$varName]" { + $params = @{ + Owner = $owner + Name = $varName + Value = 'organization' + Visibility = 'selected' + SelectedRepositories = $repo.id + } + $result = Set-GitHubVariable @params + Write-Host ($result | Select-Object * | Format-Table | Out-String) + } } } Write-Host ($repo | Format-List | Out-String) @@ -59,30 +71,19 @@ Describe 'Environments' { Write-Host ($repo3 | Format-List | Out-String) } } - - if ($OwnerType -eq 'organization') { - LogGroup "Org variable - [$varName]" { - $params = @{ - Owner = $owner - Name = $varName - Value = 'organization' - Visibility = 'selected' - SelectedRepositories = $repo.id - } - $result = Set-GitHubVariable @params - Write-Host ($result | Select-Object * | Format-Table | Out-String) - } - } } AfterAll { - if ($Type -ne 'GitHub Actions') { - Remove-GitHubRepository -Owner $owner -Name $repoName -Confirm:$false - } - if ($OwnerType -eq 'organization') { - Get-GitHubVariable -Owner $owner | Remove-GitHubVariable - Remove-GitHubRepository -Owner $owner -Name "$repoName-2" -Confirm:$false - Remove-GitHubRepository -Owner $owner -Name "$repoName-3" -Confirm:$false + switch ($OwnerType) { + 'user' { + Remove-GitHubRepository -Owner $owner -Name $repoName -Confirm:$false + } + 'organization' { + Get-GitHubVariable -Owner $owner | Remove-GitHubVariable + Remove-GitHubRepository -Owner $owner -Name $repoName -Confirm:$false + Remove-GitHubRepository -Owner $owner -Name "$repoName-2" -Confirm:$false + Remove-GitHubRepository -Owner $owner -Name "$repoName-3" -Confirm:$false + } } Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent } From ccfa011e818d5fff2f58109f09c4967faf385f3f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 29 Mar 2025 19:37:27 +0100 Subject: [PATCH 186/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Simplify?= =?UTF-8?q?=20repository=20creation=20logic=20in=20Variables.Tests.ps1=20f?= =?UTF-8?q?or=20better=20clarity=20and=20organization?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 52 ++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 01cf7823b..498126f0c 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -40,37 +40,33 @@ Describe 'Environments' { $variablePrefix = "$varName`_" $environmentName = "$testName-$os-$TokenType" - if ($Type -ne 'GitHub Actions') { - LogGroup "Repository - [$repoName]" { - switch ($OwnerType) { - 'user' { - Get-GitHubRepository -Owner $Owner | Where-Object { $_.name -like "$repoName*" } | Remove-GitHubRepository -Confirm:$false - $repo = New-GitHubRepository -Name $repoName -AllowSquashMerge - } - 'organization' { - Get-GitHubRepository -Owner $Owner | Where-Object { $_.name -like "$repoName*" } | Remove-GitHubRepository -Confirm:$false - $repo = New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge - $repo2 = New-GitHubRepository -Owner $owner -Name "$repoName-2" -AllowSquashMerge - $repo3 = New-GitHubRepository -Owner $owner -Name "$repoName-3" -AllowSquashMerge + switch ($OwnerType) { + 'user' { + $repo = New-GitHubRepository -Name $repoName -AllowSquashMerge + } + 'organization' { + $repo = New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge + $repo2 = New-GitHubRepository -Owner $owner -Name "$repoName-2" -AllowSquashMerge + $repo3 = New-GitHubRepository -Owner $owner -Name "$repoName-3" -AllowSquashMerge - LogGroup "Org variable - [$varName]" { - $params = @{ - Owner = $owner - Name = $varName - Value = 'organization' - Visibility = 'selected' - SelectedRepositories = $repo.id - } - $result = Set-GitHubVariable @params - Write-Host ($result | Select-Object * | Format-Table | Out-String) - } + LogGroup "Org variable - [$varName]" { + $params = @{ + Owner = $owner + Name = $varName + Value = 'organization' + Visibility = 'selected' + SelectedRepositories = $repo.id } + $result = Set-GitHubVariable @params + Write-Host ($result | Select-Object * | Format-Table | Out-String) } - Write-Host ($repo | Format-List | Out-String) - Write-Host ($repo2 | Format-List | Out-String) - Write-Host ($repo3 | Format-List | Out-String) } } + LogGroup "Repository - [$repoName]" { + Write-Host ($repo | Format-List | Out-String) + Write-Host ($repo2 | Format-List | Out-String) + Write-Host ($repo3 | Format-List | Out-String) + } } AfterAll { @@ -274,7 +270,7 @@ Describe 'Environments' { } } - Context 'Repository' -Skip:($Type -eq 'GitHub Actions') { + Context 'Repository' -Skip:($OwnerType -eq 'repository') { BeforeAll { $scope = @{ Owner = $owner @@ -340,7 +336,7 @@ Describe 'Environments' { } } - Context 'Environment' -Skip:($Type -eq 'GitHub Actions') { + Context 'Environment' -Skip:($OwnerType -eq 'repository') { BeforeAll { $scope = @{ Owner = $owner From cf74ab259dbf2ba133583aa8c268bf34d939ff71 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 29 Mar 2025 20:21:06 +0100 Subject: [PATCH 187/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Rename=20v?= =?UTF-8?q?ariables=20for=20improved=20clarity=20in=20Repositories.Tests.p?= =?UTF-8?q?s1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Repositories.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Repositories.Tests.ps1 b/tests/Repositories.Tests.ps1 index c663a8ed2..01f4965d5 100644 --- a/tests/Repositories.Tests.ps1 +++ b/tests/Repositories.Tests.ps1 @@ -16,7 +16,7 @@ param() BeforeAll { - $testPrefix = 'RepositoryTest' + $testName = 'RepositoryTest' $os = $env:RUNNER_OS } @@ -39,7 +39,7 @@ Describe 'Template' { } } $guid = [guid]::NewGuid().ToString() - $repoPrefix = "$testPrefix-$os" + $repoPrefix = "$testName-$os-$TokenType" $repo = "$repoPrefix-$guid" if ($OwnerType -ne 'repository') { Get-GitHubRepository -Owner $Owner | Where-Object { $_.name -like "$repoPrefix*" } | Remove-GitHubRepository -Confirm:$false From fa39c1e77618d057156ccfa1f4827a531fbe7795 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 29 Mar 2025 20:42:38 +0100 Subject: [PATCH 188/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Update=20r?= =?UTF-8?q?epository=20name=20variable=20in=20Environments.Tests.ps1=20and?= =?UTF-8?q?=20Repositories.Tests.ps1=20for=20improved=20clarity=20and=20co?= =?UTF-8?q?nsistency?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Environments.Tests.ps1 | 31 +++++++++++++++---------------- tests/Repositories.Tests.ps1 | 10 ++++------ 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/tests/Environments.Tests.ps1 b/tests/Environments.Tests.ps1 index 99f88a42f..12992f87e 100644 --- a/tests/Environments.Tests.ps1 +++ b/tests/Environments.Tests.ps1 @@ -30,12 +30,11 @@ Describe 'Environments' { LogGroup 'Context' { Write-Host ($context | Format-List | Out-String) } - $guid = [guid]::NewGuid().ToString() - $repo = "$testName-$guid" + $repoName = "$testName-$os-$TokenType" } AfterAll { - Remove-GitHubRepository -Owner $owner -Name $repo -Confirm:$false + Remove-GitHubRepository -Owner $owner -Name $repoName -Confirm:$false Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent } @@ -54,27 +53,27 @@ Describe 'Environments' { # Tests for IAT UAT and PAT goes here It 'Prep - New-GitHubRepository' { if ($OwnerType -eq 'user') { - New-GitHubRepository -Name $repo -AllowSquashMerge + New-GitHubRepository -Name $repoName -AllowSquashMerge } else { - New-GitHubRepository -Owner $owner -Name $repo -AllowSquashMerge + New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge } } It 'Get-GitHubEnvironment - should return an empty list when no environments exist' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo + $result = Get-GitHubEnvironment -Owner $owner -Repository $repoName LogGroup 'Environment' { Write-Host ($result | Format-Table | Out-String) } $result | Should -BeNullOrEmpty } It 'Get-GitHubEnvironment - should return null when retrieving a non-existent environment' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName + $result = Get-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName LogGroup 'Environment' { Write-Host ($result | Format-Table | Out-String) } $result | Should -BeNullOrEmpty } It 'Set-GitHubEnvironment - should successfully create an environment with a wait timer of 10' { - $result = Set-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName -WaitTimer 10 + $result = Set-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName -WaitTimer 10 LogGroup 'Environment' { Write-Host ($result | Format-List | Out-String) } @@ -84,7 +83,7 @@ Describe 'Environments' { $result.ProtectionRules.wait_timer | Should -Be 10 } It 'Get-GitHubEnvironment - should retrieve the environment that was created' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName + $result = Get-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName LogGroup 'Environment' { Write-Host ($result | Format-List | Out-String) } @@ -92,7 +91,7 @@ Describe 'Environments' { $result.Name | Should -Be $environmentName } It 'Set-GitHubEnvironment - should successfully create an environment with a slash in its name' { - $result = Set-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" + $result = Set-GitHubEnvironment -Owner $owner -Repository $repoName -Name "$environmentName/$os" LogGroup 'Environment' { Write-Host ($result | Format-List | Out-String) } @@ -100,7 +99,7 @@ Describe 'Environments' { $result.Name | Should -Be "$environmentName/$os" } It 'Get-GitHubEnvironment - should retrieve the environment with a slash in its name' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" + $result = Get-GitHubEnvironment -Owner $owner -Repository $repoName -Name "$environmentName/$os" LogGroup 'Environment' { Write-Host ($result | Format-Table | Out-String) } @@ -109,28 +108,28 @@ Describe 'Environments' { } It 'Remove-GitHubEnvironment - should delete the environment with a slash in its name without errors' { { - Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" | Remove-GitHubEnvironment -Confirm:$false + Get-GitHubEnvironment -Owner $owner -Repository $repoName -Name "$environmentName/$os" | Remove-GitHubEnvironment -Confirm:$false } | Should -Not -Throw } It 'Get-GitHubEnvironment - should return null when retrieving the deleted environment with a slash in its name' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" + $result = Get-GitHubEnvironment -Owner $owner -Repository $repoName -Name "$environmentName/$os" LogGroup 'Environment' { Write-Host ($result | Format-Table | Out-String) } $result | Should -BeNullOrEmpty } It 'Get-GitHubEnvironment - should list one remaining environment' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo + $result = Get-GitHubEnvironment -Owner $owner -Repository $repoName LogGroup 'Environment' { Write-Host ($result | Format-Table | Out-String) } $result.Count | Should -Be 1 } It 'Remove-GitHubEnvironment - should delete the remaining environment without errors' { - { Remove-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName -Confirm:$false } | Should -Not -Throw + { Remove-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName -Confirm:$false } | Should -Not -Throw } It 'Get-GitHubEnvironment - should return null when retrieving an environment that does not exist' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName + $result = Get-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName LogGroup 'Environment' { Write-Host ($result | Format-Table | Out-String) } diff --git a/tests/Repositories.Tests.ps1 b/tests/Repositories.Tests.ps1 index 01f4965d5..63f2706b4 100644 --- a/tests/Repositories.Tests.ps1 +++ b/tests/Repositories.Tests.ps1 @@ -38,9 +38,7 @@ Describe 'Template' { } } } - $guid = [guid]::NewGuid().ToString() - $repoPrefix = "$testName-$os-$TokenType" - $repo = "$repoPrefix-$guid" + $repoName = "$testName-$os-$TokenType" if ($OwnerType -ne 'repository') { Get-GitHubRepository -Owner $Owner | Where-Object { $_.name -like "$repoPrefix*" } | Remove-GitHubRepository -Confirm:$false } @@ -57,9 +55,9 @@ Describe 'Template' { # Tests for IAT UAT and PAT goes here It 'New-GitHubRepository - Creates a new repository' { if ($OwnerType -eq 'user') { - New-GitHubRepository -Name $repo -AllowSquashMerge + New-GitHubRepository -Name $repoName -AllowSquashMerge } else { - New-GitHubRepository -Owner $Owner -Name $repo -AllowSquashMerge + New-GitHubRepository -Owner $Owner -Name $repoName -AllowSquashMerge } } if ($OwnerType -eq 'user') { @@ -107,7 +105,7 @@ Describe 'Template' { $repos | Should -Not -BeNullOrEmpty } It 'Remove-GitHubRepository - Removes all repositories' { - $repos = Get-GitHubRepository -Owner $Owner -Name $repo + $repos = Get-GitHubRepository -Owner $Owner -Name $repoName LogGroup 'Repositories' { Write-Host ($repos | Format-List | Out-String) } From 768a5d55f6512d59e03e34c22d87048942919a59 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 29 Mar 2025 21:00:16 +0100 Subject: [PATCH 189/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Simplify?= =?UTF-8?q?=20repository=20removal=20logic=20in=20Repositories.Tests.ps1?= =?UTF-8?q?=20for=20improved=20clarity=20and=20consistency?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Repositories.Tests.ps1 | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/tests/Repositories.Tests.ps1 b/tests/Repositories.Tests.ps1 index 63f2706b4..d4b1d0746 100644 --- a/tests/Repositories.Tests.ps1 +++ b/tests/Repositories.Tests.ps1 @@ -39,13 +39,10 @@ Describe 'Template' { } } $repoName = "$testName-$os-$TokenType" - if ($OwnerType -ne 'repository') { - Get-GitHubRepository -Owner $Owner | Where-Object { $_.name -like "$repoPrefix*" } | Remove-GitHubRepository -Confirm:$false - } } AfterAll { if ($OwnerType -ne 'repository') { - Get-GitHubRepository -Owner $Owner | Where-Object { $_.name -like "$repoPrefix*" } | Remove-GitHubRepository -Confirm:$false + Remove-GitHubRepository -Owner $Owner -Name $repoName -Confirm:$false } Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent } @@ -105,19 +102,17 @@ Describe 'Template' { $repos | Should -Not -BeNullOrEmpty } It 'Remove-GitHubRepository - Removes all repositories' { - $repos = Get-GitHubRepository -Owner $Owner -Name $repoName LogGroup 'Repositories' { + $repos = Get-GitHubRepository -Owner $Owner -Name $repoName Write-Host ($repos | Format-List | Out-String) } - $repos | ForEach-Object { - Remove-GitHubRepository -Owner $_.owner.login -Name $_.name -Confirm:$false - } + Remove-GitHubRepository -Owner $Owner -Name $repoName -Confirm:$false } It 'Get-GitHubRepository - Gets none repositories after removal' { if ($OwnerType -eq 'user') { - $repos = Get-GitHubRepository -Username $Owner | Where-Object { $_.name -like "$repoPrefix*" } + $repos = Get-GitHubRepository -Username $Owner | Where-Object { $_.name -like "$repoName*" } } else { - $repos = Get-GitHubRepository -Owner $Owner | Where-Object { $_.name -like "$repoPrefix*" } + $repos = Get-GitHubRepository -Owner $Owner | Where-Object { $_.name -like "$repoName*" } } LogGroup 'Repositories' { Write-Host ($repos | Format-List | Out-String) From 678de53002aa4eadaf4609ed0727aa70c509fed8 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 29 Mar 2025 21:16:37 +0100 Subject: [PATCH 190/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Enhance=20?= =?UTF-8?q?environment=20tests=20in=20Environments.Tests.ps1=20and=20strea?= =?UTF-8?q?mline=20GitHub=20App=20connection=20logic=20in=20Repositories.T?= =?UTF-8?q?ests.ps1=20for=20improved=20clarity=20and=20organization?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Environments.Tests.ps1 | 167 +++++++++++++++++------------------ tests/Repositories.Tests.ps1 | 7 +- 2 files changed, 82 insertions(+), 92 deletions(-) diff --git a/tests/Environments.Tests.ps1 b/tests/Environments.Tests.ps1 index 12992f87e..0acc32d8c 100644 --- a/tests/Environments.Tests.ps1 +++ b/tests/Environments.Tests.ps1 @@ -30,7 +30,21 @@ Describe 'Environments' { LogGroup 'Context' { Write-Host ($context | Format-List | Out-String) } + if ($AuthType -eq 'APP') { + LogGroup 'Context - Installation' { + $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent + Write-Host ($context | Format-List | Out-String) + } + } $repoName = "$testName-$os-$TokenType" + switch ($OwnerType) { + 'user' { + New-GitHubRepository -Name $repoName -AllowSquashMerge + } + 'organization' { + New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge + } + } } AfterAll { @@ -38,103 +52,82 @@ Describe 'Environments' { Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent } - # Tests for APP goes here - if ($AuthType -eq 'APP') { - It 'Connect-GitHubApp - Connects as a GitHub App to ' { - $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent - LogGroup 'Context' { - Write-Host ($context | Format-List | Out-String) - } + It 'Get-GitHubEnvironment - should return an empty list when no environments exist' -Skip:($OwnerType -eq 'repository') { + $result = Get-GitHubEnvironment -Owner $owner -Repository $repoName + LogGroup 'Environment' { + Write-Host ($result | Format-Table | Out-String) } + $result | Should -BeNullOrEmpty } - - # Tests for runners goes here - if ($Type -ne 'GitHub Actions') { - # Tests for IAT UAT and PAT goes here - It 'Prep - New-GitHubRepository' { - if ($OwnerType -eq 'user') { - New-GitHubRepository -Name $repoName -AllowSquashMerge - } else { - New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge - } - } - It 'Get-GitHubEnvironment - should return an empty list when no environments exist' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repoName - LogGroup 'Environment' { - Write-Host ($result | Format-Table | Out-String) - } - $result | Should -BeNullOrEmpty - } - It 'Get-GitHubEnvironment - should return null when retrieving a non-existent environment' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName - LogGroup 'Environment' { - Write-Host ($result | Format-Table | Out-String) - } - $result | Should -BeNullOrEmpty + It 'Get-GitHubEnvironment - should return null when retrieving a non-existent environment' -Skip:($OwnerType -eq 'repository') { + $result = Get-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName + LogGroup 'Environment' { + Write-Host ($result | Format-Table | Out-String) } - It 'Set-GitHubEnvironment - should successfully create an environment with a wait timer of 10' { - $result = Set-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName -WaitTimer 10 - LogGroup 'Environment' { - Write-Host ($result | Format-List | Out-String) - } - $result | Should -Not -BeNullOrEmpty - $result | Should -BeOfType [GitHubEnvironment] - $result.Name | Should -Be $environmentName - $result.ProtectionRules.wait_timer | Should -Be 10 - } - It 'Get-GitHubEnvironment - should retrieve the environment that was created' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName - LogGroup 'Environment' { - Write-Host ($result | Format-List | Out-String) - } - $result | Should -Not -BeNullOrEmpty - $result.Name | Should -Be $environmentName - } - It 'Set-GitHubEnvironment - should successfully create an environment with a slash in its name' { - $result = Set-GitHubEnvironment -Owner $owner -Repository $repoName -Name "$environmentName/$os" - LogGroup 'Environment' { - Write-Host ($result | Format-List | Out-String) - } - $result | Should -Not -BeNullOrEmpty - $result.Name | Should -Be "$environmentName/$os" + $result | Should -BeNullOrEmpty + } + It 'Set-GitHubEnvironment - should successfully create an environment with a wait timer of 10' -Skip:($OwnerType -eq 'repository') { + $result = Set-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName -WaitTimer 10 + LogGroup 'Environment' { + Write-Host ($result | Format-List | Out-String) } - It 'Get-GitHubEnvironment - should retrieve the environment with a slash in its name' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repoName -Name "$environmentName/$os" - LogGroup 'Environment' { - Write-Host ($result | Format-Table | Out-String) - } - $result | Should -Not -BeNullOrEmpty - $result.Name | Should -Be "$environmentName/$os" + $result | Should -Not -BeNullOrEmpty + $result | Should -BeOfType [GitHubEnvironment] + $result.Name | Should -Be $environmentName + $result.ProtectionRules.wait_timer | Should -Be 10 + } + It 'Get-GitHubEnvironment - should retrieve the environment that was created' -Skip:($OwnerType -eq 'repository') { + $result = Get-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName + LogGroup 'Environment' { + Write-Host ($result | Format-List | Out-String) } - It 'Remove-GitHubEnvironment - should delete the environment with a slash in its name without errors' { - { - Get-GitHubEnvironment -Owner $owner -Repository $repoName -Name "$environmentName/$os" | Remove-GitHubEnvironment -Confirm:$false - } | Should -Not -Throw + $result | Should -Not -BeNullOrEmpty + $result.Name | Should -Be $environmentName + } + It 'Set-GitHubEnvironment - should successfully create an environment with a slash in its name' -Skip:($OwnerType -eq 'repository') { + $result = Set-GitHubEnvironment -Owner $owner -Repository $repoName -Name "$environmentName/$os" + LogGroup 'Environment' { + Write-Host ($result | Format-List | Out-String) } - It 'Get-GitHubEnvironment - should return null when retrieving the deleted environment with a slash in its name' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repoName -Name "$environmentName/$os" - LogGroup 'Environment' { - Write-Host ($result | Format-Table | Out-String) - } - $result | Should -BeNullOrEmpty + $result | Should -Not -BeNullOrEmpty + $result.Name | Should -Be "$environmentName/$os" + } + It 'Get-GitHubEnvironment - should retrieve the environment with a slash in its name' -Skip:($OwnerType -eq 'repository') { + $result = Get-GitHubEnvironment -Owner $owner -Repository $repoName -Name "$environmentName/$os" + LogGroup 'Environment' { + Write-Host ($result | Format-Table | Out-String) } - It 'Get-GitHubEnvironment - should list one remaining environment' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repoName - LogGroup 'Environment' { - Write-Host ($result | Format-Table | Out-String) - } - $result.Count | Should -Be 1 + $result | Should -Not -BeNullOrEmpty + $result.Name | Should -Be "$environmentName/$os" + } + It 'Remove-GitHubEnvironment - should delete the environment with a slash in its name without errors' -Skip:($OwnerType -eq 'repository') { + { + Get-GitHubEnvironment -Owner $owner -Repository $repoName -Name "$environmentName/$os" | Remove-GitHubEnvironment -Confirm:$false + } | Should -Not -Throw + } + It 'Get-GitHubEnvironment - should return null when retrieving the deleted environment with a slash in its name' -Skip:($OwnerType -eq 'repository') { + $result = Get-GitHubEnvironment -Owner $owner -Repository $repoName -Name "$environmentName/$os" + LogGroup 'Environment' { + Write-Host ($result | Format-Table | Out-String) } - It 'Remove-GitHubEnvironment - should delete the remaining environment without errors' { - { Remove-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName -Confirm:$false } | Should -Not -Throw + $result | Should -BeNullOrEmpty + } + It 'Get-GitHubEnvironment - should list one remaining environment' -Skip:($OwnerType -eq 'repository') { + $result = Get-GitHubEnvironment -Owner $owner -Repository $repoName + LogGroup 'Environment' { + Write-Host ($result | Format-Table | Out-String) } - It 'Get-GitHubEnvironment - should return null when retrieving an environment that does not exist' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName - LogGroup 'Environment' { - Write-Host ($result | Format-Table | Out-String) - } - $result | Should -BeNullOrEmpty + $result.Count | Should -Be 1 + } + It 'Remove-GitHubEnvironment - should delete the remaining environment without errors' -Skip:($OwnerType -eq 'repository') { + { Remove-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName -Confirm:$false } | Should -Not -Throw + } + It 'Get-GitHubEnvironment - should return null when retrieving an environment that does not exist' -Skip:($OwnerType -eq 'repository') { + $result = Get-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName + LogGroup 'Environment' { + Write-Host ($result | Format-Table | Out-String) } + $result | Should -BeNullOrEmpty } } } diff --git a/tests/Repositories.Tests.ps1 b/tests/Repositories.Tests.ps1 index d4b1d0746..900f92b58 100644 --- a/tests/Repositories.Tests.ps1 +++ b/tests/Repositories.Tests.ps1 @@ -29,13 +29,10 @@ Describe 'Template' { LogGroup 'Context' { Write-Host ($context | Format-List | Out-String) } - # Tests for APP goes here if ($AuthType -eq 'APP') { - It 'Connect-GitHubApp - Connects as a GitHub App to ' { + LogGroup 'Context - Installation' { $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent - LogGroup 'Context' { - Write-Host ($context | Format-List | Out-String) - } + Write-Host ($context | Format-List | Out-String) } } $repoName = "$testName-$os-$TokenType" From d840dbf0555916060cc22cded4e24e5fc7a78508 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 29 Mar 2025 21:31:44 +0100 Subject: [PATCH 191/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Rename=20t?= =?UTF-8?q?est=20suite=20from=20'Template'=20to=20'Repositories'=20and=20s?= =?UTF-8?q?treamline=20repository-related=20tests=20for=20improved=20clari?= =?UTF-8?q?ty=20and=20organization?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Repositories.Tests.ps1 | 131 +++++++++++++++++------------------ 1 file changed, 62 insertions(+), 69 deletions(-) diff --git a/tests/Repositories.Tests.ps1 b/tests/Repositories.Tests.ps1 index 900f92b58..e27532630 100644 --- a/tests/Repositories.Tests.ps1 +++ b/tests/Repositories.Tests.ps1 @@ -20,7 +20,7 @@ BeforeAll { $os = $env:RUNNER_OS } -Describe 'Template' { +Describe 'Repositories' { $authCases = . "$PSScriptRoot/Data/AuthCases.ps1" Context 'As using on ' -ForEach $authCases { @@ -37,85 +37,78 @@ Describe 'Template' { } $repoName = "$testName-$os-$TokenType" } + AfterAll { - if ($OwnerType -ne 'repository') { - Remove-GitHubRepository -Owner $Owner -Name $repoName -Confirm:$false - } Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent } - - if ($Type -ne 'GitHub Actions') { - # Tests for IAT UAT and PAT goes here - It 'New-GitHubRepository - Creates a new repository' { - if ($OwnerType -eq 'user') { - New-GitHubRepository -Name $repoName -AllowSquashMerge - } else { - New-GitHubRepository -Owner $Owner -Name $repoName -AllowSquashMerge - } - } + # Tests for IAT UAT and PAT goes here + It 'New-GitHubRepository - Creates a new repository' -Skip:($OwnerType -eq 'repository') { if ($OwnerType -eq 'user') { - It "Get-GitHubRepository - Gets the authenticated user's repositories" { - $repos = Get-GitHubRepository - LogGroup 'Repositories' { - Write-Host ($repos | Format-List | Out-String) - } - $repos | Should -Not -BeNullOrEmpty - } - It "Get-GitHubRepository - Gets the authenticated user's public repositories" { - $repos = Get-GitHubRepository -Type 'public' - LogGroup 'Repositories' { - Write-Host ($repos | Format-List | Out-String) - } - $repos | Should -Not -BeNullOrEmpty - } - It 'Get-GitHubRepository - Gets the public repos where the authenticated user is owner' { - $repos = Get-GitHubRepository -Visibility 'public' -Affiliation 'owner' - LogGroup 'Repositories' { - Write-Host ($repos | Format-List | Out-String) - } - $repos | Should -Not -BeNullOrEmpty - } + New-GitHubRepository -Name $repoName -AllowSquashMerge + } else { + New-GitHubRepository -Owner $Owner -Name $repoName -AllowSquashMerge } - It 'Get-GitHubRepository - Gets a specific repository' { - $repo = Get-GitHubRepository -Owner 'PSModule' -Name 'GitHub' - LogGroup 'Repository' { - Write-Host ($repo | Format-List | Out-String) - } - $repo | Should -Not -BeNullOrEmpty + } + It "Get-GitHubRepository - Gets the authenticated user's repositories" -Skip:($OwnerType -ne 'user') { + $repos = Get-GitHubRepository + LogGroup 'Repositories' { + Write-Host ($repos | Format-List | Out-String) } - It 'Get-GitHubRepository - Gets all repositories from a organization' { - $repos = Get-GitHubRepository -Owner 'PSModule' - LogGroup 'Repositories' { - Write-Host ($repos | Format-List | Out-String) - } - $repos | Should -Not -BeNullOrEmpty + $repos | Should -Not -BeNullOrEmpty + } + It "Get-GitHubRepository - Gets the authenticated user's public repositories" -Skip:($OwnerType -ne 'user') { + $repos = Get-GitHubRepository -Type 'public' + LogGroup 'Repositories' { + Write-Host ($repos | Format-List | Out-String) } - It 'Get-GitHubRepository - Gets all repositories from a user' { - $repos = Get-GitHubRepository -Username 'MariusStorhaug' - LogGroup 'Repositories' { - Write-Host ($repos | Format-List | Out-String) - } - $repos | Should -Not -BeNullOrEmpty + $repos | Should -Not -BeNullOrEmpty + } + It 'Get-GitHubRepository - Gets the public repos where the authenticated user is owner' -Skip:($OwnerType -ne 'user') { + $repos = Get-GitHubRepository -Visibility 'public' -Affiliation 'owner' + LogGroup 'Repositories' { + Write-Host ($repos | Format-List | Out-String) } - It 'Remove-GitHubRepository - Removes all repositories' { - LogGroup 'Repositories' { - $repos = Get-GitHubRepository -Owner $Owner -Name $repoName - Write-Host ($repos | Format-List | Out-String) - } - Remove-GitHubRepository -Owner $Owner -Name $repoName -Confirm:$false + $repos | Should -Not -BeNullOrEmpty + } + It 'Get-GitHubRepository - Gets a specific repository' -Skip:($OwnerType -eq 'repository') { + $repo = Get-GitHubRepository -Owner 'PSModule' -Name 'GitHub' + LogGroup 'Repository' { + Write-Host ($repo | Format-List | Out-String) } - It 'Get-GitHubRepository - Gets none repositories after removal' { - if ($OwnerType -eq 'user') { - $repos = Get-GitHubRepository -Username $Owner | Where-Object { $_.name -like "$repoName*" } - } else { - $repos = Get-GitHubRepository -Owner $Owner | Where-Object { $_.name -like "$repoName*" } - } - LogGroup 'Repositories' { - Write-Host ($repos | Format-List | Out-String) - } - $repos | Should -BeNullOrEmpty + $repo | Should -Not -BeNullOrEmpty + } + It 'Get-GitHubRepository - Gets all repositories from a organization' -Skip:($OwnerType -eq 'repository') { + $repos = Get-GitHubRepository -Owner 'PSModule' + LogGroup 'Repositories' { + Write-Host ($repos | Format-List | Out-String) + } + $repos | Should -Not -BeNullOrEmpty + } + It 'Get-GitHubRepository - Gets all repositories from a user' -Skip:($OwnerType -eq 'repository') { + $repos = Get-GitHubRepository -Username 'MariusStorhaug' + LogGroup 'Repositories' { + Write-Host ($repos | Format-List | Out-String) + } + $repos | Should -Not -BeNullOrEmpty + } + It 'Remove-GitHubRepository - Removes all repositories' -Skip:($OwnerType -eq 'repository') { + LogGroup 'Repositories' { + $repos = Get-GitHubRepository -Owner $Owner -Name $repoName + Write-Host ($repos | Format-List | Out-String) + } + Remove-GitHubRepository -Owner $Owner -Name $repoName -Confirm:$false + } + It 'Get-GitHubRepository - Gets none repositories after removal' -Skip:($OwnerType -eq 'repository') { + if ($OwnerType -eq 'user') { + $repos = Get-GitHubRepository -Username $Owner | Where-Object { $_.name -like "$repoName*" } + } else { + $repos = Get-GitHubRepository -Owner $Owner | Where-Object { $_.name -like "$repoName*" } + } + LogGroup 'Repositories' { + Write-Host ($repos | Format-List | Out-String) } + $repos | Should -BeNullOrEmpty } } } From b15facf82eabe3bacb069e91eb99644e01c695a5 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 29 Mar 2025 21:44:13 +0100 Subject: [PATCH 192/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Remove=20c?= =?UTF-8?q?ommented-out=20tests=20for=20IAT=20UAT=20and=20PAT=20in=20Varia?= =?UTF-8?q?bles.Tests.ps1=20for=20improved=20clarity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 498126f0c..e3b819765 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -84,7 +84,6 @@ Describe 'Environments' { Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent } - # Tests for IAT UAT and PAT goes here Context 'Organization' -Skip:($OwnerType -ne 'organization') { BeforeAll { $scope = @{ From ee6916d90381a36dbb9062b86bb465a3cc8ba1e7 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 29 Mar 2025 22:30:25 +0100 Subject: [PATCH 193/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Add=20uniq?= =?UTF-8?q?ue=20GUID=20to=20repository=20names=20in=20Environments.Tests.p?= =?UTF-8?q?s1,=20Repositories.Tests.ps1,=20and=20Variables.Tests.ps1=20for?= =?UTF-8?q?=20improved=20test=20isolation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Environments.Tests.ps1 | 3 ++- tests/Repositories.Tests.ps1 | 3 ++- tests/Variables.Tests.ps1 | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/Environments.Tests.ps1 b/tests/Environments.Tests.ps1 index 0acc32d8c..c4df1be73 100644 --- a/tests/Environments.Tests.ps1 +++ b/tests/Environments.Tests.ps1 @@ -19,6 +19,7 @@ BeforeAll { $testName = 'EnvironmentTest' $environmentName = 'production' $os = $env:RUNNER_OS + $guid = [guid]::NewGuid().ToString() } Describe 'Environments' { @@ -36,7 +37,7 @@ Describe 'Environments' { Write-Host ($context | Format-List | Out-String) } } - $repoName = "$testName-$os-$TokenType" + $repoName = "$testName-$os-$TokenType-$guid" switch ($OwnerType) { 'user' { New-GitHubRepository -Name $repoName -AllowSquashMerge diff --git a/tests/Repositories.Tests.ps1 b/tests/Repositories.Tests.ps1 index e27532630..4153fc760 100644 --- a/tests/Repositories.Tests.ps1 +++ b/tests/Repositories.Tests.ps1 @@ -18,6 +18,7 @@ param() BeforeAll { $testName = 'RepositoryTest' $os = $env:RUNNER_OS + $guid = [guid]::NewGuid().ToString() } Describe 'Repositories' { @@ -35,7 +36,7 @@ Describe 'Repositories' { Write-Host ($context | Format-List | Out-String) } } - $repoName = "$testName-$os-$TokenType" + $repoName = "$testName-$os-$TokenType-$guid" } AfterAll { diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index e3b819765..7f5da9f13 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -18,6 +18,7 @@ param() BeforeAll { $testName = 'VariableTest' $os = $env:RUNNER_OS + $guid = [guid]::NewGuid().ToString() } Describe 'Environments' { @@ -35,7 +36,7 @@ Describe 'Environments' { Write-Host ($context | Format-List | Out-String) } } - $repoName = "$testName-$os-$TokenType" + $repoName = "$testName-$os-$TokenType-$guid" $varName = "$testName`_$os`_$TokenType" $variablePrefix = "$varName`_" $environmentName = "$testName-$os-$TokenType" From 055650b5af0ca64a684c0d68493a2c585336d675 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 29 Mar 2025 22:50:45 +0100 Subject: [PATCH 194/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Add=20addi?= =?UTF-8?q?tional=20GitHub=20repository=20creation=20for=20improved=20test?= =?UTF-8?q?=20coverage=20in=20Variables.Tests.ps1?= 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 7f5da9f13..f280d7ec0 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -44,6 +44,8 @@ Describe 'Environments' { switch ($OwnerType) { 'user' { $repo = New-GitHubRepository -Name $repoName -AllowSquashMerge + $repo2 = New-GitHubRepository -Name "$repoName-2" -AllowSquashMerge + $repo3 = New-GitHubRepository -Name "$repoName-3" -AllowSquashMerge } 'organization' { $repo = New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge From 2ef6ed20d3bb828e321980ea5c8338bf3e4cc7b0 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 30 Mar 2025 11:49:51 +0200 Subject: [PATCH 195/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Remove=20o?= =?UTF-8?q?bsolete=20test=20files=20and=20skip=20unnecessary=20tests=20in?= =?UTF-8?q?=20PSModule.yml=20for=20improved=20clarity=20and=20maintenance?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index f280d7ec0..3717ceab1 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -157,7 +157,7 @@ Describe 'Environments' { Write-Host ($result | Select-Object * | Format-List | Out-String) } $result | Should -Not -BeNullOrEmpty - # $result | Should -BeOfType [GitHubVariable] + $result | Should -BeOfType [GitHubVariable] $result.Name | Should -Be $name $result.Value | Should -Be 'TestValue123' $result.Visibility | Should -Be 'private' From c169d37f9bfb43cb0d8236d0da528699c643148d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 30 Mar 2025 12:24:44 +0200 Subject: [PATCH 196/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Skip=20unn?= =?UTF-8?q?ecessary=20tests=20in=20PSModule.yml=20and=20suppress=20long=20?= =?UTF-8?q?line=20warnings=20in=20test=20files=20for=20improved=20clarity?= =?UTF-8?q?=20and=20maintainability?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/PSModule.yml | 15 +++++++++++++++ tests/Environments.Tests.ps1 | 4 ++++ tests/TEMPLATE.ps1 | 4 ++++ tests/Variables.Tests.ps1 | 9 ++++++++- 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/.github/PSModule.yml b/.github/PSModule.yml index 6d578178e..518af9bf2 100644 --- a/.github/PSModule.yml +++ b/.github/PSModule.yml @@ -1,3 +1,18 @@ Test: + SourceCode: + Skip: true + PSModule: + Skip: true + Module: + MacOS: + Skip: true + Windows: + Skip: true CodeCoverage: + Skip: true PercentTarget: 50 + TestResults: + Skip: true +Build: + Docs: + Skip: true diff --git a/tests/Environments.Tests.ps1 b/tests/Environments.Tests.ps1 index c4df1be73..15a5eb731 100644 --- a/tests/Environments.Tests.ps1 +++ b/tests/Environments.Tests.ps1 @@ -12,6 +12,10 @@ 'PSAvoidUsingWriteHost', '', Justification = 'Log outputs to GitHub Actions logs.' )] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidLongLines', '', + Justification = 'Long test descriptions and skip switches' +)] [CmdletBinding()] param() diff --git a/tests/TEMPLATE.ps1 b/tests/TEMPLATE.ps1 index 0ce26b0a2..78585c107 100644 --- a/tests/TEMPLATE.ps1 +++ b/tests/TEMPLATE.ps1 @@ -12,6 +12,10 @@ 'PSAvoidUsingWriteHost', '', Justification = 'Log outputs to GitHub Actions logs.' )] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidLongLines', '', + Justification = 'Long test descriptions and skip switches' +)] [CmdletBinding()] param() diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 3717ceab1..2f2603ffb 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -214,9 +214,11 @@ Describe 'Environments' { { Add-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo2.id } | Should -Not -Throw } It 'Add-GitHubVariableSelectedRepository - adds a repository to the list of selected repositories - idempotency test' { + Start-Sleep -Seconds 10 { Add-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo2.id } | Should -Not -Throw } It 'Add-GitHubVariableSelectedRepository - adds a repository to the list of selected repositories using pipeline' { + Start-Sleep -Seconds 10 LogGroup 'Repo3' { Write-Host "$($repo3 | Format-List | Out-String)" } @@ -235,17 +237,20 @@ Describe 'Environments' { { Remove-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo2.id } | Should -Not -Throw } It 'Remove-GitHubVariableSelectedRepository - removes a repository from the list of selected repositories - idempotency test' { + Start-Sleep -Seconds 10 { Remove-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo2.id } | Should -Not -Throw } It 'Remove-GitHubVariableSelectedRepository - removes a repository from the list of selected repositories using pipeline' { + Start-Sleep -Seconds 10 LogGroup 'Repo3' { Write-Host "$($repo3 | Format-List | Out-String)" } { $repo3 | Remove-GitHubVariableSelectedRepository -Owner $owner -Name $varName } | Should -Not -Throw } It 'Get-GitHubVariableSelectedRepository - gets 1 repository' { - $result = Get-GitHubVariableSelectedRepository -Owner $owner -Name $varName + Start-Sleep -Seconds 10 LogGroup "SelectedRepositories - [$varName]" { + $result = Get-GitHubVariableSelectedRepository -Owner $owner -Name $varName Write-Host "$($result | Select-Object * | Format-Table | Out-String)" } $result | Should -Not -BeNullOrEmpty @@ -257,10 +262,12 @@ Describe 'Environments' { Should -Not -Throw } It 'Set-GitHubVariableSelectedRepository - should set the selected repositories for the variable - idempotency test' { + Start-Sleep -Seconds 10 { Set-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo.id, $repo2.id, $repo3.id } | Should -Not -Throw } It 'Get-GitHubVariableSelectedRepository - gets 3 repository' { + Start-Sleep -Seconds 10 $result = Get-GitHubVariableSelectedRepository -Owner $owner -Name $varName LogGroup "SelectedRepositories - [$varName]" { Write-Host "$($result | Select-Object * | Format-Table | Out-String)" From 4fae984fc6edcbf3f84f381b0ed32e33f0c2c47d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 30 Mar 2025 12:48:29 +0200 Subject: [PATCH 197/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Remove=20u?= =?UTF-8?q?nnecessary=20skip=20configurations=20in=20PSModule.yml=20for=20?= =?UTF-8?q?improved=20clarity=20and=20maintainability?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/PSModule.yml | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/.github/PSModule.yml b/.github/PSModule.yml index 518af9bf2..6d578178e 100644 --- a/.github/PSModule.yml +++ b/.github/PSModule.yml @@ -1,18 +1,3 @@ Test: - SourceCode: - Skip: true - PSModule: - Skip: true - Module: - MacOS: - Skip: true - Windows: - Skip: true CodeCoverage: - Skip: true PercentTarget: 50 - TestResults: - Skip: true -Build: - Docs: - Skip: true From 630bc931ddff3bbda80f76cd2f81d36a9772a1f6 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 30 Mar 2025 13:22:11 +0200 Subject: [PATCH 198/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Adjust=20s?= =?UTF-8?q?leep=20duration=20in=20Variables.Tests.ps1=20for=20improved=20t?= =?UTF-8?q?est=20reliability=20and=20performance?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 2f2603ffb..0f3fe4a6e 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -201,6 +201,11 @@ Describe 'Environments' { } Context 'SelectedRepository' { + BeforeEach { + LogGroup "Sleep 10 seconds" { + Start-Sleep -Seconds 15 + } + } It 'Get-GitHubVariableSelectedRepository - gets a list of selected repositories' { $result = Get-GitHubVariableSelectedRepository -Owner $owner -Name $varName LogGroup "SelectedRepositories - [$varName]" { @@ -214,11 +219,9 @@ Describe 'Environments' { { Add-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo2.id } | Should -Not -Throw } It 'Add-GitHubVariableSelectedRepository - adds a repository to the list of selected repositories - idempotency test' { - Start-Sleep -Seconds 10 { Add-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo2.id } | Should -Not -Throw } It 'Add-GitHubVariableSelectedRepository - adds a repository to the list of selected repositories using pipeline' { - Start-Sleep -Seconds 10 LogGroup 'Repo3' { Write-Host "$($repo3 | Format-List | Out-String)" } @@ -237,18 +240,15 @@ Describe 'Environments' { { Remove-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo2.id } | Should -Not -Throw } It 'Remove-GitHubVariableSelectedRepository - removes a repository from the list of selected repositories - idempotency test' { - Start-Sleep -Seconds 10 { Remove-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo2.id } | Should -Not -Throw } It 'Remove-GitHubVariableSelectedRepository - removes a repository from the list of selected repositories using pipeline' { - Start-Sleep -Seconds 10 LogGroup 'Repo3' { Write-Host "$($repo3 | Format-List | Out-String)" } { $repo3 | Remove-GitHubVariableSelectedRepository -Owner $owner -Name $varName } | Should -Not -Throw } It 'Get-GitHubVariableSelectedRepository - gets 1 repository' { - Start-Sleep -Seconds 10 LogGroup "SelectedRepositories - [$varName]" { $result = Get-GitHubVariableSelectedRepository -Owner $owner -Name $varName Write-Host "$($result | Select-Object * | Format-Table | Out-String)" @@ -262,12 +262,10 @@ Describe 'Environments' { Should -Not -Throw } It 'Set-GitHubVariableSelectedRepository - should set the selected repositories for the variable - idempotency test' { - Start-Sleep -Seconds 10 { Set-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo.id, $repo2.id, $repo3.id } | Should -Not -Throw } It 'Get-GitHubVariableSelectedRepository - gets 3 repository' { - Start-Sleep -Seconds 10 $result = Get-GitHubVariableSelectedRepository -Owner $owner -Name $varName LogGroup "SelectedRepositories - [$varName]" { Write-Host "$($result | Select-Object * | Format-Table | Out-String)" From eae3b7d3109ffbaaec066e2d4f6c60c0deb68c27 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 30 Mar 2025 13:53:24 +0200 Subject: [PATCH 199/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Update=20v?= =?UTF-8?q?ariable=20naming=20conventions=20in=20Variables.Tests.ps1=20for?= =?UTF-8?q?=20improved=20clarity=20and=20consistency?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 0f3fe4a6e..f75334080 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -37,9 +37,9 @@ Describe 'Environments' { } } $repoName = "$testName-$os-$TokenType-$guid" - $varName = "$testName`_$os`_$TokenType" - $variablePrefix = "$varName`_" - $environmentName = "$testName-$os-$TokenType" + $variablePrefix = "$testName`_$os`_$TokenType`_" + $varName = "$variablePrefix`_$guid" + $environmentName = "$testName-$os-$TokenType-$guid" switch ($OwnerType) { 'user' { From 57b843a9b5ff579243d34f489d630b9b179ad00f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 30 Mar 2025 14:01:28 +0200 Subject: [PATCH 200/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Replace=20?= =?UTF-8?q?hyphens=20with=20underscores=20in=20variable=20names=20for=20im?= =?UTF-8?q?proved=20consistency=20in=20Variables.Tests.ps1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index f75334080..92c5962e4 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -38,7 +38,7 @@ Describe 'Environments' { } $repoName = "$testName-$os-$TokenType-$guid" $variablePrefix = "$testName`_$os`_$TokenType`_" - $varName = "$variablePrefix`_$guid" + $varName = "$variablePrefix`_$guid" -replace '-', '_' $environmentName = "$testName-$os-$TokenType-$guid" switch ($OwnerType) { From 073230f95361f3275c474fa6e8e3cfc216a4d3a6 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 30 Mar 2025 14:13:20 +0200 Subject: [PATCH 201/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Update=20v?= =?UTF-8?q?ariable=20naming=20and=20adjust=20sleep=20duration=20in=20Varia?= =?UTF-8?q?bles.Tests.ps1=20for=20improved=20consistency=20and=20reliabili?= =?UTF-8?q?ty?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 92c5962e4..0679613ea 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -37,8 +37,8 @@ Describe 'Environments' { } } $repoName = "$testName-$os-$TokenType-$guid" - $variablePrefix = "$testName`_$os`_$TokenType`_" - $varName = "$variablePrefix`_$guid" -replace '-', '_' + $variablePrefix = "$testName`_$os`_$TokenType" -replace '-', '_' + $varName = "$variablePrefix-$guid" -replace '-', '_' $environmentName = "$testName-$os-$TokenType-$guid" switch ($OwnerType) { @@ -202,7 +202,7 @@ Describe 'Environments' { Context 'SelectedRepository' { BeforeEach { - LogGroup "Sleep 10 seconds" { + LogGroup 'Sleep 15 seconds' { Start-Sleep -Seconds 15 } } From 0c3d5c4229ab92834ec27d6196a3cd35a8667b5f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 30 Mar 2025 14:13:43 +0200 Subject: [PATCH 202/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Update=20v?= =?UTF-8?q?ariable=20concatenation=20in=20Variables.Tests.ps1=20for=20impr?= =?UTF-8?q?oved=20consistency=20in=20naming?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 0679613ea..164f7702a 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -38,7 +38,7 @@ Describe 'Environments' { } $repoName = "$testName-$os-$TokenType-$guid" $variablePrefix = "$testName`_$os`_$TokenType" -replace '-', '_' - $varName = "$variablePrefix-$guid" -replace '-', '_' + $varName = "$variablePrefix`_$guid" -replace '-', '_' $environmentName = "$testName-$os-$TokenType-$guid" switch ($OwnerType) { From 1cb9ee51394277a21c7ddf5b43ad802206d309fd Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 30 Mar 2025 14:33:42 +0200 Subject: [PATCH 203/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Update=20v?= =?UTF-8?q?ariable=20naming=20to=20uppercase=20for=20improved=20consistenc?= =?UTF-8?q?y=20in=20Variables.Tests.ps1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 164f7702a..757d691ff 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -37,8 +37,8 @@ Describe 'Environments' { } } $repoName = "$testName-$os-$TokenType-$guid" - $variablePrefix = "$testName`_$os`_$TokenType" -replace '-', '_' - $varName = "$variablePrefix`_$guid" -replace '-', '_' + $variablePrefix = ("$testName`_$os`_$TokenType" -replace '-', '_').ToUpper() + $varName = ("$variablePrefix`_$guid" -replace '-', '_').ToUpper() $environmentName = "$testName-$os-$TokenType-$guid" switch ($OwnerType) { @@ -207,8 +207,8 @@ Describe 'Environments' { } } It 'Get-GitHubVariableSelectedRepository - gets a list of selected repositories' { - $result = Get-GitHubVariableSelectedRepository -Owner $owner -Name $varName LogGroup "SelectedRepositories - [$varName]" { + $result = Get-GitHubVariableSelectedRepository -Owner $owner -Name $varName Write-Host "$($result | Select-Object * | Format-Table | Out-String)" } $result | Should -Not -BeNullOrEmpty @@ -228,8 +228,8 @@ Describe 'Environments' { { $repo3 | Add-GitHubVariableSelectedRepository -Owner $owner -Name $varName } | Should -Not -Throw } It 'Get-GitHubVariableSelectedRepository - gets 3 repositories' { - $result = Get-GitHubVariableSelectedRepository -Owner $owner -Name $varName LogGroup "SelectedRepositories - [$varName]" { + $result = Get-GitHubVariableSelectedRepository -Owner $owner -Name $varName Write-Host "$($result | Select-Object * | Format-Table | Out-String)" } $result | Should -Not -BeNullOrEmpty From 0a18a0f770ee65c891251fa05ed5372c46927a8a Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 30 Mar 2025 14:52:13 +0200 Subject: [PATCH 204/210] =?UTF-8?q?=F0=9F=94=A7=20[Cleanup]:=20Remove=20ob?= =?UTF-8?q?solete=20test=20files=20for=20Emojis=20and=20Auth=20to=20stream?= =?UTF-8?q?line=20the=20test=20suite?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/API.Tests.ps1 | 238 -------------------- tests/Apps.Tests.ps1 | 128 ----------- tests/Auth.Tests.ps1 | 121 ----------- tests/Emojis.Tests.ps1 | 66 ------ tests/GitHub.Tests.ps1 | 478 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 478 insertions(+), 553 deletions(-) delete mode 100644 tests/API.Tests.ps1 delete mode 100644 tests/Apps.Tests.ps1 delete mode 100644 tests/Auth.Tests.ps1 delete mode 100644 tests/Emojis.Tests.ps1 diff --git a/tests/API.Tests.ps1 b/tests/API.Tests.ps1 deleted file mode 100644 index b57f69f68..000000000 --- a/tests/API.Tests.ps1 +++ /dev/null @@ -1,238 +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 = 'Log outputs to GitHub Actions logs.' -)] -[CmdletBinding()] -param() - -BeforeAll { - # DEFAULTS ACCROSS ALL TESTS -} - -Describe 'Template' { - $authCases = . "$PSScriptRoot/Data/AuthCases.ps1" - - Context 'As using on ' -ForEach $authCases { - BeforeAll { - $context = Connect-GitHubAccount @connectParams -PassThru -Silent - LogGroup 'Context' { - Write-Host ($context | Format-List | Out-String) - } - $context | Should -Not -BeNullOrEmpty - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent - } - - # Tests for APP goes here - if ($AuthType -eq 'APP') { - It 'Invoke-GitHubAPI - Gets the app details' { - { - $app = Invoke-GitHubAPI -ApiEndpoint '/app' - LogGroup 'App' { - Write-Host ($app | Format-Table | Out-String) - } - } | Should -Not -Throw - } - - It 'Connect-GitHubApp - Connects as a GitHub App to ' { - $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent - LogGroup 'Context' { - Write-Host ($context | Format-List | Out-String) - } - $context | Should -Not -BeNullOrEmpty - } - } - - # Tests for runners goes here - if ($Type -eq 'GitHub Actions') {} - - # Tests for IAT UAT and PAT goes here - Context 'API' { - It 'Invoke-GitHubAPI - Gets the rate limits directly using APIEndpoint' { - { - $rateLimit = Invoke-GitHubAPI -ApiEndpoint '/rate_limit' - LogGroup 'RateLimit' { - Write-Host ($rateLimit | Format-Table | Out-String) - } - } | Should -Not -Throw - } - - It 'Invoke-GitHubAPI - Gets the rate limits directly using Uri' { - { - $rateLimit = Invoke-GitHubAPI -Uri ($context.ApiBaseUri + '/rate_limit') - LogGroup 'RateLimit' { - Write-Host ($rateLimit | Format-Table | Out-String) - } - } | Should -Not -Throw - } - - It 'Invoke-GitHubGraphQLQuery - Gets the viewer' { - { - $viewer = Invoke-GitHubGraphQLQuery -Query 'query { viewer { login } }' - LogGroup 'Viewer' { - Write-Host ($viewer | Format-Table | Out-String) - } - } | Should -Not -Throw - } - } - - Context 'Meta' { - It 'Get-GitHubRoot - Gets the GitHub API Root' { - $root = Get-GitHubRoot - LogGroup 'Root' { - Write-Host ($root | Format-Table | Out-String) - } - $root | Should -Not -BeNullOrEmpty - } - It 'Get-GitHubApiVersion - Gets all API versions' { - $apiVersion = Get-GitHubApiVersion - LogGroup 'ApiVersion' { - Write-Host ($apiVersion | Format-Table | Out-String) - } - $apiVersion | Should -Not -BeNullOrEmpty - } - It 'Get-GitHubMeta - Gets GitHub meta information' { - $meta = Get-GitHubMeta - LogGroup 'Meta' { - Write-Host ($meta | Format-Table | Out-String) - } - $meta | Should -Not -BeNullOrEmpty - } - It 'Get-GitHubOctocat - Gets the Octocat' { - $octocat = Get-GitHubOctocat - LogGroup 'Octocat' { - Write-Host ($octocat | Format-Table | Out-String) - } - $octocat | Should -Not -BeNullOrEmpty - } - It 'Get-GitHubZen - Gets the Zen of GitHub' { - $zen = Get-GitHubZen - LogGroup 'Zen' { - Write-Host ($zen | Format-Table | Out-String) - } - $zen | Should -Not -BeNullOrEmpty - } - } - - Context 'Rate-Limit' { - It 'Get-GitHubRateLimit - Gets the rate limit status for the authenticated user' { - $rateLimit = Get-GitHubRateLimit - LogGroup 'RateLimit' { - Write-Host ($rateLimit | Format-Table | Out-String) - } - $rateLimit | Should -Not -BeNullOrEmpty - } - } - - Context 'License' { - It 'Get-GitHubLicense - Gets a list of all popular license templates' { - $licenseList = Get-GitHubLicense - LogGroup 'Licenses' { - Write-Host ($licenseList | Format-Table | Out-String) - } - $licenseList | Should -Not -BeNullOrEmpty - } - It 'Get-GitHubLicense - Gets a spesific license' { - $mitLicense = Get-GitHubLicense -Name 'mit' - LogGroup 'MIT License' { - Write-Host ($mitLicense | Format-Table | Out-String) - } - $mitLicense | Should -Not -BeNullOrEmpty - } - It 'Get-GitHubLicense - Gets a license from a repository' { - $githubLicense = Get-GitHubLicense -Owner 'PSModule' -Repository 'GitHub' - LogGroup 'GitHub License' { - Write-Host ($githubLicense | Format-Table | Out-String) - } - $githubLicense | Should -Not -BeNullOrEmpty - } - } - - Context 'GitIgnore' { - It 'Get-GitHubGitignore - Gets a list of all gitignore templates names' { - $gitIgnoreList = Get-GitHubGitignore - LogGroup 'GitIgnoreList' { - Write-Host ($gitIgnoreList | Format-Table | Out-String) - } - $gitIgnoreList | Should -Not -BeNullOrEmpty - } - It 'Get-GitHubGitignore - Gets a gitignore template' { - $vsGitIgnore = Get-GitHubGitignore -Name 'VisualStudio' - LogGroup 'Visual Studio GitIgnore' { - Write-Host ($vsGitIgnore | Format-Table | Out-String) - } - $vsGitIgnore | Should -Not -BeNullOrEmpty - } - } - - Context 'Markdown' { - It 'Get-GitHubMarkdown - Gets the rendered markdown for provided text' { - $markdown = Get-GitHubMarkdown -Text 'Hello, World!' - LogGroup 'Markdown' { - Write-Host ($markdown | Format-Table | Out-String) - } - $markdown | Should -Not -BeNullOrEmpty - } - It 'Get-GitHubMarkdown - Gets the rendered markdown for provided text using GitHub Formated Markdown' { - $gfmMarkdown = Get-GitHubMarkdown -Text 'Hello, World!' -Mode gfm - LogGroup 'GFM Markdown' { - Write-Host ($gfmMarkdown | Format-Table | Out-String) - } - $gfmMarkdown | Should -Not -BeNullOrEmpty - } - It 'Get-GitHubMarkdownRaw - Gets the raw rendered markdown for provided text' { - $rawMarkdown = Get-GitHubMarkdownRaw -Text 'Hello, World!' - LogGroup 'Raw Markdown' { - Write-Host ($rawMarkdown | Format-Table | Out-String) - } - $rawMarkdown | Should -Not -BeNullOrEmpty - } - } - - Context 'Git' { - It "Get-GitHubGitConfig gets the 'local' (default) Git configuration" { - $gitConfig = Get-GitHubGitConfig - LogGroup 'GitConfig' { - Write-Host ($gitConfig | Format-List | Out-String) - } - $gitConfig | Should -Not -BeNullOrEmpty - } - It "Get-GitHubGitConfig gets the 'global' Git configuration" { - git config --global advice.pushfetchfirst false - $gitConfig = Get-GitHubGitConfig -Scope 'global' - LogGroup 'GitConfig - Global' { - Write-Host ($gitConfig | Format-List | Out-String) - } - $gitConfig | Should -Not -BeNullOrEmpty - } - It "Get-GitHubGitConfig gets the 'system' Git configuration" { - $gitConfig = Get-GitHubGitConfig -Scope 'system' - LogGroup 'GitConfig - System' { - Write-Host ($gitConfig | Format-List | Out-String) - } - $gitConfig | Should -Not -BeNullOrEmpty - } - It 'Set-GitHubGitConfig sets the Git configuration' { - { Set-GitHubGitConfig } | Should -Not -Throw - $gitConfig = Get-GitHubGitConfig -Scope 'global' - LogGroup 'GitConfig - Global' { - Write-Host ($gitConfig | Format-List | Out-String) - } - $gitConfig | Should -Not -BeNullOrEmpty - $gitConfig.'user.name' | Should -Not -BeNullOrEmpty - $gitConfig.'user.email' | Should -Not -BeNullOrEmpty - } - } - } -} diff --git a/tests/Apps.Tests.ps1 b/tests/Apps.Tests.ps1 deleted file mode 100644 index d6227d80f..000000000 --- a/tests/Apps.Tests.ps1 +++ /dev/null @@ -1,128 +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 = 'Log outputs to GitHub Actions logs.' -)] -[CmdletBinding()] -param() -BeforeAll { - # DEFAULTS ACCROSS ALL TESTS -} - -Describe 'Apps' { - $authCases = . "$PSScriptRoot/Data/AuthCases.ps1" - - Context 'As using on ' -ForEach $authCases { - BeforeAll { - $context = Connect-GitHubAccount @connectParams -PassThru -Silent - LogGroup 'Context' { - Write-Host ($context | Format-List | Out-String) - } - } - - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent - } - - # Tests for APP goes here - if ($AuthType -eq 'APP') { - Context 'GitHub Apps' { - It 'Get-GitHubApp - Can get app details' { - $app = Get-GitHubApp - LogGroup 'App' { - Write-Host ($app | Format-Table | Out-String) - } - $app | Should -Not -BeNullOrEmpty - } - - It 'Get-GitHubAppJSONWebToken - Can get a JWT for the app' { - $jwt = Get-GitHubAppJSONWebToken @connectParams - LogGroup 'JWT' { - Write-Host ($jwt | Format-Table | Out-String) - } - $jwt | Should -Not -BeNullOrEmpty - } - - It 'Get-GitHubAppInstallation - Can get app installations' { - $installations = Get-GitHubAppInstallation - LogGroup 'Installations' { - Write-Host ($installations | Format-Table | Out-String) - } - $installations | Should -Not -BeNullOrEmpty - } - It 'New-GitHubAppInstallationAccessToken - Can get app installation access tokens' { - $installations = Get-GitHubAppInstallation - $installations | ForEach-Object { - $token = New-GitHubAppInstallationAccessToken -InstallationID $_.id - LogGroup 'Token' { - Write-Host ($token | Format-Table | Out-String) - } - $token | Should -Not -BeNullOrEmpty - } - } - } - - Context 'Webhooks' { - It 'Get-GitHubAppWebhookConfiguration - Can get the webhook configuration' { - $webhookConfig = Get-GitHubAppWebhookConfiguration - LogGroup 'Webhook config' { - Write-Host ($webhookConfig | Format-Table | Out-String) - } - $webhookConfig | Should -Not -BeNullOrEmpty - } - - It 'Update-GitHubAppWebhookConfiguration - Can update the webhook configuration' { - { Update-GitHubAppWebhookConfiguration -ContentType 'form' } | Should -Not -Throw - $webhookConfig = Get-GitHubAppWebhookConfiguration - LogGroup 'Webhook config - form' { - Write-Host ($webhookConfig | Format-Table | Out-String) - } - { Update-GitHubAppWebhookConfiguration -ContentType 'json' } | Should -Not -Throw - $webhookConfig = Get-GitHubAppWebhookConfiguration - LogGroup 'Webhook config - json' { - Write-Host ($webhookConfig | Format-Table | Out-String) - } - } - - It 'Get-GitHubAppWebhookDelivery - Can get webhook deliveries' { - $deliveries = Get-GitHubAppWebhookDelivery - LogGroup 'Deliveries' { - Write-Host ($deliveries | Format-Table | Out-String) - } - $deliveries | Should -Not -BeNullOrEmpty - } - - It 'Get-GitHubAppWebhookDelivery - Can redeliver a webhook delivery' { - $deliveries = Get-GitHubAppWebhookDelivery | Select-Object -First 1 - LogGroup 'Delivery - redeliver' { - Write-Host ($deliveries | Format-Table | Out-String) - } - { Invoke-GitHubAppWebhookReDelivery -ID $deliveries.id } | Should -Not -Throw - LogGroup 'Delivery - redeliver' { - Write-Host ($deliveries | Format-Table | Out-String) - } - } - } - It 'Connect-GitHubApp - Connects as a GitHub App to ' { - $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent - LogGroup 'Context' { - Write-Host ($context | Format-List | Out-String) - } - } - } - - # Tests for runners goes here - if ($Type -eq 'GitHub Actions') {} - - # Tests for IAT UAT and PAT goes here - } -} diff --git a/tests/Auth.Tests.ps1 b/tests/Auth.Tests.ps1 deleted file mode 100644 index 2feca40a9..000000000 --- a/tests/Auth.Tests.ps1 +++ /dev/null @@ -1,121 +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 = 'Log outputs to GitHub Actions logs.' -)] -[CmdletBinding()] -param() - -Describe 'Auth' { - $authCases = . "$PSScriptRoot/Data/AuthCases.ps1" - - Context 'As using on ' -ForEach $authCases { - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent - } - - It 'Connect-GitHubAccount - Connects using the provided credentials' { - $context = Connect-GitHubAccount @connectParams -PassThru -Silent - LogGroup 'Context' { - Write-Host ($context | Format-List | Out-String) - } - $context | Should -Not -BeNullOrEmpty - } - - It 'Connect-GitHubAccount - Connects using the provided credentials - Double' { - $context = Connect-GitHubAccount @connectParams -PassThru -Silent - $context = Connect-GitHubAccount @connectParams -PassThru -Silent - LogGroup 'Context' { - Write-Host ($context | Format-List | Out-String) - } - $context | Should -Not -BeNullOrEmpty - } - - It 'Connect-GitHubAccount - Connects using the provided credentials - Relog' { - Disconnect-GitHub -Silent - $context = Connect-GitHubAccount @connectParams -PassThru -Silent - LogGroup 'Context' { - Write-Host ($context | Format-List | Out-String) - } - $context | Should -Not -BeNullOrEmpty - } - - It 'Switch-GitHubContext - Sets the default context' { - $context = Get-GitHubContext - Switch-GitHubContext -Context $context - $context = Get-GitHubContext - $context | Should -Not -BeNullOrEmpty - } - - # Tests for APP goes here - if ($AuthType -eq 'APP') { - It 'Connect-GitHubAccount - Connects using the provided credentials + AutoloadInstallations' { - $context = Connect-GitHubAccount @connectParams -PassThru -Silent -AutoloadInstallations - LogGroup 'Context' { - Write-Host ($context | Format-List | Out-String) - } - $context | Should -Not -BeNullOrEmpty - } - - It 'Connect-GitHubApp - Connects as a GitHub App to ' { - $contexts = Connect-GitHubApp -PassThru -Silent - LogGroup 'Contexts' { - Write-Host ($contexts | Format-List | Out-String) - } - $contexts | Should -Not -BeNullOrEmpty - } - - It 'Connect-GitHubApp - Connects as a GitHub App to ' { - $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent - LogGroup 'Context' { - Write-Host ($context | Format-List | Out-String) - } - $context | Should -Not -BeNullOrEmpty - } - } - - # Tests for runners goes here - if ($Type -eq 'GitHub Actions') {} - - # Tests for IAT UAT and PAT goes here - It 'Connect-GitHubAccount - Connects to GitHub CLI on runners' { - [string]::IsNullOrEmpty($(gh auth token)) | Should -Be $false - } - It 'Get-GitHubViewer - Gets the logged in context' { - $viewer = Get-GitHubViewer - LogGroup 'Viewer' { - Write-Host ($viewer | Format-List | Out-String) - } - $viewer | Should -Not -BeNullOrEmpty - } - - It 'GetGitHubContext - Gets the default context' { - $context = Get-GitHubContext - LogGroup 'Default context' { - Write-Host ($viewer | Format-List | Out-String) - } - } - - It 'GetGitHubContext - List all contexts' { - $contexts = Get-GitHubContext -ListAvailable - LogGroup 'Contexts' { - Write-Host ($contexts | Format-List | Out-String) - } - $contexts.count | Should -BeGreaterOrEqual 1 - } - - It 'Disconnect-GitHubAccount - Disconnects all contexts' { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent - (Get-GitHubContext -ListAvailable).count | Should -Be 0 - } - } -} diff --git a/tests/Emojis.Tests.ps1 b/tests/Emojis.Tests.ps1 deleted file mode 100644 index f3da2ff64..000000000 --- a/tests/Emojis.Tests.ps1 +++ /dev/null @@ -1,66 +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 = 'Log outputs to GitHub Actions logs.' -)] -[CmdletBinding()] -param() - -BeforeAll { - # DEFAULTS ACCROSS ALL TESTS -} - -Describe 'Emojies' { - $authCases = . "$PSScriptRoot/Data/AuthCases.ps1" - - Context 'As using on ' -ForEach $authCases { - BeforeAll { - $context = Connect-GitHubAccount @connectParams -PassThru -Silent - LogGroup 'Context' { - Write-Host ($context | Format-List | Out-String) - } - } - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent - } - - # Tests for APP goes here - if ($AuthType -eq 'APP') { - It 'Connect-GitHubApp - Connects as a GitHub App to ' { - $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent - LogGroup 'Context' { - Write-Host ($context | Format-List | Out-String) - } - } - } - - # Tests for runners goes here - if ($Type -eq 'GitHub Actions') {} - - # Tests for IAT UAT and PAT goes here - It 'Get-GitHubEmoji - Gets a list of all emojis' { - $emojies = Get-GitHubEmoji - LogGroup 'Emojies' { - Write-Host ($emojies | Format-Table | Out-String) - } - $emojies | Should -Not -BeNullOrEmpty - } - It 'Get-GitHubEmoji - Downloads all emojis' { - Get-GitHubEmoji -Path $Home - LogGroup 'Emojies' { - $emojies = Get-ChildItem -Path $Home -File - Write-Host ($emojies | Format-Table | Out-String) - } - $emojies | Should -Not -BeNullOrEmpty - } - } -} diff --git a/tests/GitHub.Tests.ps1 b/tests/GitHub.Tests.ps1 index c3ef277d8..d7afd6bc6 100644 --- a/tests/GitHub.Tests.ps1 +++ b/tests/GitHub.Tests.ps1 @@ -15,6 +15,111 @@ [CmdletBinding()] param() +Describe 'Auth' { + $authCases = . "$PSScriptRoot/Data/AuthCases.ps1" + + Context 'As using on ' -ForEach $authCases { + AfterAll { + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent + } + + It 'Connect-GitHubAccount - Connects using the provided credentials' { + $context = Connect-GitHubAccount @connectParams -PassThru -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } + $context | Should -Not -BeNullOrEmpty + } + + It 'Connect-GitHubAccount - Connects using the provided credentials - Double' { + $context = Connect-GitHubAccount @connectParams -PassThru -Silent + $context = Connect-GitHubAccount @connectParams -PassThru -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } + $context | Should -Not -BeNullOrEmpty + } + + It 'Connect-GitHubAccount - Connects using the provided credentials - Relog' { + Disconnect-GitHub -Silent + $context = Connect-GitHubAccount @connectParams -PassThru -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } + $context | Should -Not -BeNullOrEmpty + } + + It 'Switch-GitHubContext - Sets the default context' { + $context = Get-GitHubContext + Switch-GitHubContext -Context $context + $context = Get-GitHubContext + $context | Should -Not -BeNullOrEmpty + } + + # Tests for APP goes here + if ($AuthType -eq 'APP') { + It 'Connect-GitHubAccount - Connects using the provided credentials + AutoloadInstallations' { + $context = Connect-GitHubAccount @connectParams -PassThru -Silent -AutoloadInstallations + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } + $context | Should -Not -BeNullOrEmpty + } + + It 'Connect-GitHubApp - Connects as a GitHub App to ' { + $contexts = Connect-GitHubApp -PassThru -Silent + LogGroup 'Contexts' { + Write-Host ($contexts | Format-List | Out-String) + } + $contexts | Should -Not -BeNullOrEmpty + } + + It 'Connect-GitHubApp - Connects as a GitHub App to ' { + $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } + $context | Should -Not -BeNullOrEmpty + } + } + + # Tests for runners goes here + if ($Type -eq 'GitHub Actions') {} + + # Tests for IAT UAT and PAT goes here + It 'Connect-GitHubAccount - Connects to GitHub CLI on runners' { + [string]::IsNullOrEmpty($(gh auth token)) | Should -Be $false + } + It 'Get-GitHubViewer - Gets the logged in context' { + $viewer = Get-GitHubViewer + LogGroup 'Viewer' { + Write-Host ($viewer | Format-List | Out-String) + } + $viewer | Should -Not -BeNullOrEmpty + } + + It 'GetGitHubContext - Gets the default context' { + $context = Get-GitHubContext + LogGroup 'Default context' { + Write-Host ($viewer | Format-List | Out-String) + } + } + + It 'GetGitHubContext - List all contexts' { + $contexts = Get-GitHubContext -ListAvailable + LogGroup 'Contexts' { + Write-Host ($contexts | Format-List | Out-String) + } + $contexts.count | Should -BeGreaterOrEqual 1 + } + + It 'Disconnect-GitHubAccount - Disconnects all contexts' { + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent + (Get-GitHubContext -ListAvailable).count | Should -Be 0 + } + } +} + Describe 'GitHub' { Context 'Config' { It 'Get-GitHubConfig - Gets the module configuration' { @@ -249,3 +354,376 @@ line } } } + +Describe 'Apps' { + $authCases = . "$PSScriptRoot/Data/AuthCases.ps1" + + Context 'As using on ' -ForEach $authCases { + BeforeAll { + $context = Connect-GitHubAccount @connectParams -PassThru -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } + } + + AfterAll { + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent + } + + # Tests for APP goes here + if ($AuthType -eq 'APP') { + Context 'GitHub Apps' { + It 'Get-GitHubApp - Can get app details' { + $app = Get-GitHubApp + LogGroup 'App' { + Write-Host ($app | Format-Table | Out-String) + } + $app | Should -Not -BeNullOrEmpty + } + + It 'Get-GitHubAppJSONWebToken - Can get a JWT for the app' { + $jwt = Get-GitHubAppJSONWebToken @connectParams + LogGroup 'JWT' { + Write-Host ($jwt | Format-Table | Out-String) + } + $jwt | Should -Not -BeNullOrEmpty + } + + It 'Get-GitHubAppInstallation - Can get app installations' { + $installations = Get-GitHubAppInstallation + LogGroup 'Installations' { + Write-Host ($installations | Format-Table | Out-String) + } + $installations | Should -Not -BeNullOrEmpty + } + It 'New-GitHubAppInstallationAccessToken - Can get app installation access tokens' { + $installations = Get-GitHubAppInstallation + $installations | ForEach-Object { + $token = New-GitHubAppInstallationAccessToken -InstallationID $_.id + LogGroup 'Token' { + Write-Host ($token | Format-Table | Out-String) + } + $token | Should -Not -BeNullOrEmpty + } + } + } + + Context 'Webhooks' { + It 'Get-GitHubAppWebhookConfiguration - Can get the webhook configuration' { + $webhookConfig = Get-GitHubAppWebhookConfiguration + LogGroup 'Webhook config' { + Write-Host ($webhookConfig | Format-Table | Out-String) + } + $webhookConfig | Should -Not -BeNullOrEmpty + } + + It 'Update-GitHubAppWebhookConfiguration - Can update the webhook configuration' { + { Update-GitHubAppWebhookConfiguration -ContentType 'form' } | Should -Not -Throw + $webhookConfig = Get-GitHubAppWebhookConfiguration + LogGroup 'Webhook config - form' { + Write-Host ($webhookConfig | Format-Table | Out-String) + } + { Update-GitHubAppWebhookConfiguration -ContentType 'json' } | Should -Not -Throw + $webhookConfig = Get-GitHubAppWebhookConfiguration + LogGroup 'Webhook config - json' { + Write-Host ($webhookConfig | Format-Table | Out-String) + } + } + + It 'Get-GitHubAppWebhookDelivery - Can get webhook deliveries' { + $deliveries = Get-GitHubAppWebhookDelivery + LogGroup 'Deliveries' { + Write-Host ($deliveries | Format-Table | Out-String) + } + $deliveries | Should -Not -BeNullOrEmpty + } + + It 'Get-GitHubAppWebhookDelivery - Can redeliver a webhook delivery' { + $deliveries = Get-GitHubAppWebhookDelivery | Select-Object -First 1 + LogGroup 'Delivery - redeliver' { + Write-Host ($deliveries | Format-Table | Out-String) + } + { Invoke-GitHubAppWebhookReDelivery -ID $deliveries.id } | Should -Not -Throw + LogGroup 'Delivery - redeliver' { + Write-Host ($deliveries | Format-Table | Out-String) + } + } + } + It 'Connect-GitHubApp - Connects as a GitHub App to ' { + $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } + } + } + + # Tests for runners goes here + if ($Type -eq 'GitHub Actions') {} + + # Tests for IAT UAT and PAT goes here + } +} + +Describe 'API' { + $authCases = . "$PSScriptRoot/Data/AuthCases.ps1" + + Context 'As using on ' -ForEach $authCases { + BeforeAll { + $context = Connect-GitHubAccount @connectParams -PassThru -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } + $context | Should -Not -BeNullOrEmpty + } + AfterAll { + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent + } + + # Tests for APP goes here + if ($AuthType -eq 'APP') { + It 'Invoke-GitHubAPI - Gets the app details' { + { + $app = Invoke-GitHubAPI -ApiEndpoint '/app' + LogGroup 'App' { + Write-Host ($app | Format-Table | Out-String) + } + } | Should -Not -Throw + } + + It 'Connect-GitHubApp - Connects as a GitHub App to ' { + $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } + $context | Should -Not -BeNullOrEmpty + } + } + + # Tests for runners goes here + if ($Type -eq 'GitHub Actions') {} + + # Tests for IAT UAT and PAT goes here + Context 'API' { + It 'Invoke-GitHubAPI - Gets the rate limits directly using APIEndpoint' { + { + $rateLimit = Invoke-GitHubAPI -ApiEndpoint '/rate_limit' + LogGroup 'RateLimit' { + Write-Host ($rateLimit | Format-Table | Out-String) + } + } | Should -Not -Throw + } + + It 'Invoke-GitHubAPI - Gets the rate limits directly using Uri' { + { + $rateLimit = Invoke-GitHubAPI -Uri ($context.ApiBaseUri + '/rate_limit') + LogGroup 'RateLimit' { + Write-Host ($rateLimit | Format-Table | Out-String) + } + } | Should -Not -Throw + } + + It 'Invoke-GitHubGraphQLQuery - Gets the viewer' { + { + $viewer = Invoke-GitHubGraphQLQuery -Query 'query { viewer { login } }' + LogGroup 'Viewer' { + Write-Host ($viewer | Format-Table | Out-String) + } + } | Should -Not -Throw + } + } + + Context 'Meta' { + It 'Get-GitHubRoot - Gets the GitHub API Root' { + $root = Get-GitHubRoot + LogGroup 'Root' { + Write-Host ($root | Format-Table | Out-String) + } + $root | Should -Not -BeNullOrEmpty + } + It 'Get-GitHubApiVersion - Gets all API versions' { + $apiVersion = Get-GitHubApiVersion + LogGroup 'ApiVersion' { + Write-Host ($apiVersion | Format-Table | Out-String) + } + $apiVersion | Should -Not -BeNullOrEmpty + } + It 'Get-GitHubMeta - Gets GitHub meta information' { + $meta = Get-GitHubMeta + LogGroup 'Meta' { + Write-Host ($meta | Format-Table | Out-String) + } + $meta | Should -Not -BeNullOrEmpty + } + It 'Get-GitHubOctocat - Gets the Octocat' { + $octocat = Get-GitHubOctocat + LogGroup 'Octocat' { + Write-Host ($octocat | Format-Table | Out-String) + } + $octocat | Should -Not -BeNullOrEmpty + } + It 'Get-GitHubZen - Gets the Zen of GitHub' { + $zen = Get-GitHubZen + LogGroup 'Zen' { + Write-Host ($zen | Format-Table | Out-String) + } + $zen | Should -Not -BeNullOrEmpty + } + } + + Context 'Rate-Limit' { + It 'Get-GitHubRateLimit - Gets the rate limit status for the authenticated user' { + $rateLimit = Get-GitHubRateLimit + LogGroup 'RateLimit' { + Write-Host ($rateLimit | Format-Table | Out-String) + } + $rateLimit | Should -Not -BeNullOrEmpty + } + } + + Context 'License' { + It 'Get-GitHubLicense - Gets a list of all popular license templates' { + $licenseList = Get-GitHubLicense + LogGroup 'Licenses' { + Write-Host ($licenseList | Format-Table | Out-String) + } + $licenseList | Should -Not -BeNullOrEmpty + } + It 'Get-GitHubLicense - Gets a spesific license' { + $mitLicense = Get-GitHubLicense -Name 'mit' + LogGroup 'MIT License' { + Write-Host ($mitLicense | Format-Table | Out-String) + } + $mitLicense | Should -Not -BeNullOrEmpty + } + It 'Get-GitHubLicense - Gets a license from a repository' { + $githubLicense = Get-GitHubLicense -Owner 'PSModule' -Repository 'GitHub' + LogGroup 'GitHub License' { + Write-Host ($githubLicense | Format-Table | Out-String) + } + $githubLicense | Should -Not -BeNullOrEmpty + } + } + + Context 'GitIgnore' { + It 'Get-GitHubGitignore - Gets a list of all gitignore templates names' { + $gitIgnoreList = Get-GitHubGitignore + LogGroup 'GitIgnoreList' { + Write-Host ($gitIgnoreList | Format-Table | Out-String) + } + $gitIgnoreList | Should -Not -BeNullOrEmpty + } + It 'Get-GitHubGitignore - Gets a gitignore template' { + $vsGitIgnore = Get-GitHubGitignore -Name 'VisualStudio' + LogGroup 'Visual Studio GitIgnore' { + Write-Host ($vsGitIgnore | Format-Table | Out-String) + } + $vsGitIgnore | Should -Not -BeNullOrEmpty + } + } + + Context 'Markdown' { + It 'Get-GitHubMarkdown - Gets the rendered markdown for provided text' { + $markdown = Get-GitHubMarkdown -Text 'Hello, World!' + LogGroup 'Markdown' { + Write-Host ($markdown | Format-Table | Out-String) + } + $markdown | Should -Not -BeNullOrEmpty + } + It 'Get-GitHubMarkdown - Gets the rendered markdown for provided text using GitHub Formated Markdown' { + $gfmMarkdown = Get-GitHubMarkdown -Text 'Hello, World!' -Mode gfm + LogGroup 'GFM Markdown' { + Write-Host ($gfmMarkdown | Format-Table | Out-String) + } + $gfmMarkdown | Should -Not -BeNullOrEmpty + } + It 'Get-GitHubMarkdownRaw - Gets the raw rendered markdown for provided text' { + $rawMarkdown = Get-GitHubMarkdownRaw -Text 'Hello, World!' + LogGroup 'Raw Markdown' { + Write-Host ($rawMarkdown | Format-Table | Out-String) + } + $rawMarkdown | Should -Not -BeNullOrEmpty + } + } + + Context 'Git' { + It "Get-GitHubGitConfig gets the 'local' (default) Git configuration" { + $gitConfig = Get-GitHubGitConfig + LogGroup 'GitConfig' { + Write-Host ($gitConfig | Format-List | Out-String) + } + $gitConfig | Should -Not -BeNullOrEmpty + } + It "Get-GitHubGitConfig gets the 'global' Git configuration" { + git config --global advice.pushfetchfirst false + $gitConfig = Get-GitHubGitConfig -Scope 'global' + LogGroup 'GitConfig - Global' { + Write-Host ($gitConfig | Format-List | Out-String) + } + $gitConfig | Should -Not -BeNullOrEmpty + } + It "Get-GitHubGitConfig gets the 'system' Git configuration" { + $gitConfig = Get-GitHubGitConfig -Scope 'system' + LogGroup 'GitConfig - System' { + Write-Host ($gitConfig | Format-List | Out-String) + } + $gitConfig | Should -Not -BeNullOrEmpty + } + It 'Set-GitHubGitConfig sets the Git configuration' { + { Set-GitHubGitConfig } | Should -Not -Throw + $gitConfig = Get-GitHubGitConfig -Scope 'global' + LogGroup 'GitConfig - Global' { + Write-Host ($gitConfig | Format-List | Out-String) + } + $gitConfig | Should -Not -BeNullOrEmpty + $gitConfig.'user.name' | Should -Not -BeNullOrEmpty + $gitConfig.'user.email' | Should -Not -BeNullOrEmpty + } + } + } +} + +Describe 'Emojis' { + $authCases = . "$PSScriptRoot/Data/AuthCases.ps1" + + Context 'As using on ' -ForEach $authCases { + BeforeAll { + $context = Connect-GitHubAccount @connectParams -PassThru -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } + } + AfterAll { + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent + } + + # Tests for APP goes here + if ($AuthType -eq 'APP') { + It 'Connect-GitHubApp - Connects as a GitHub App to ' { + $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } + } + } + + # Tests for runners goes here + if ($Type -eq 'GitHub Actions') {} + + # Tests for IAT UAT and PAT goes here + It 'Get-GitHubEmoji - Gets a list of all emojis' { + $emojis = Get-GitHubEmoji + LogGroup 'emojis' { + Write-Host ($emojis | Format-Table | Out-String) + } + $emojis | Should -Not -BeNullOrEmpty + } + It 'Get-GitHubEmoji - Downloads all emojis' { + Get-GitHubEmoji -Path $Home + LogGroup 'emojis' { + $emojis = Get-ChildItem -Path $Home -File + Write-Host ($emojis | Format-Table | Out-String) + } + $emojis | Should -Not -BeNullOrEmpty + } + } +} From af7605429e14ef37f34315b369da59ac37569bcc Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 30 Mar 2025 15:47:36 +0200 Subject: [PATCH 205/210] =?UTF-8?q?=F0=9F=94=A7=20[Add]:=20Introduce=20tes?= =?UTF-8?q?ting=20framework=20files=20and=20configurations=20for=20user=20?= =?UTF-8?q?authentication=20scenarios?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/PSModule.yml | 13 + tests copy/Data/AuthCases.ps1 | 83 ++++ tests copy/Data/IssueForm.md | 19 + {tests => tests copy}/Environments.Tests.ps1 | 0 {tests => tests copy}/GitHub.Tests.ps1 | 0 {tests => tests copy}/Organizations.Tests.ps1 | 0 {tests => tests copy}/README.md | 0 {tests => tests copy}/Repositories.Tests.ps1 | 0 {tests => tests copy}/TEMPLATE.ps1 | 0 {tests => tests copy}/User.Tests.ps1 | 0 tests copy/Variables.Tests.ps1 | 428 ++++++++++++++++++ 11 files changed, 543 insertions(+) create mode 100644 tests copy/Data/AuthCases.ps1 create mode 100644 tests copy/Data/IssueForm.md rename {tests => tests copy}/Environments.Tests.ps1 (100%) rename {tests => tests copy}/GitHub.Tests.ps1 (100%) rename {tests => tests copy}/Organizations.Tests.ps1 (100%) rename {tests => tests copy}/README.md (100%) rename {tests => tests copy}/Repositories.Tests.ps1 (100%) rename {tests => tests copy}/TEMPLATE.ps1 (100%) rename {tests => tests copy}/User.Tests.ps1 (100%) create mode 100644 tests copy/Variables.Tests.ps1 diff --git a/.github/PSModule.yml b/.github/PSModule.yml index 6d578178e..554431a7d 100644 --- a/.github/PSModule.yml +++ b/.github/PSModule.yml @@ -1,3 +1,16 @@ Test: + SourceCode: + Skip: true + PSModule: + Skip: true + Module: + MacOS: + Skip: true + Windows: + Skip: true CodeCoverage: + Skip: true PercentTarget: 50 +Build: + Docs: + Skip: true diff --git a/tests copy/Data/AuthCases.ps1 b/tests copy/Data/AuthCases.ps1 new file mode 100644 index 000000000..63c7f1438 --- /dev/null +++ b/tests copy/Data/AuthCases.ps1 @@ -0,0 +1,83 @@ +@( + @{ + AuthType = 'PAT' + Type = 'a user' + Case = 'Fine-grained PAT token' + TokenType = 'USER_FG_PAT' + Target = 'it self (user account)' + Owner = 'psmodule-user' + OwnerType = 'user' + ConnectParams = @{ + Token = $env:TEST_USER_USER_FG_PAT + } + } + @{ + AuthType = 'PAT' + Type = 'a user' + Case = 'Fine-grained PAT token' + TokenType = 'ORG_FG_PAT' + Target = 'organization account' + Owner = 'psmodule-test-org2' + OwnerType = 'organization' + ConnectParams = @{ + Token = $env:TEST_USER_ORG_FG_PAT + } + } + @{ + AuthType = 'PAT' + Type = 'a user' + Case = 'Classic PAT token' + TokenType = 'PAT' + Target = 'user account' + Owner = 'psmodule-user' + OwnerType = 'user' + ConnectParams = @{ + Token = $env:TEST_USER_PAT + } + } + @{ + AuthType = 'IAT' + Type = 'GitHub Actions' + Case = 'GITHUB_TOKEN' + TokenType = 'GITHUB_TOKEN' + Target = 'this repository (GitHub)' + Owner = 'PSModule' + Repo = 'GitHub' + OwnerType = 'repository' + ConnectParams = @{ + Token = $env:GITHUB_TOKEN + } + } + @{ + AuthType = 'App' + Type = 'a GitHub App from an Enterprise' + Case = 'PEM + IAT' + TokenType = 'APP_ENT' + Target = 'organization account' + Owner = 'psmodule-test-org3' + OwnerType = 'organization' + ConnectParams = @{ + ClientID = $env:TEST_APP_ENT_CLIENT_ID + PrivateKey = $env:TEST_APP_ENT_PRIVATE_KEY + } + ConnectAppParams = @{ + Organization = 'psmodule-test-org3' + } + } + @{ + AuthType = 'App' + Type = 'a GitHub App from an Organization' + Case = 'PEM + IAT' + TokenType = 'APP_ORG' + Target = 'organization account' + Owner = 'psmodule-test-org' + OwnerType = 'organization' + ConnectParams = @{ + ClientID = $env:TEST_APP_ORG_CLIENT_ID + PrivateKey = $env:TEST_APP_ORG_PRIVATE_KEY + } + ConnectAppParams = @{ + Organization = 'psmodule-test-org' + } + } +) diff --git a/tests copy/Data/IssueForm.md b/tests copy/Data/IssueForm.md new file mode 100644 index 000000000..83b1b3967 --- /dev/null +++ b/tests copy/Data/IssueForm.md @@ -0,0 +1,19 @@ + +### Type with spaces + +Action + +### Multiline + +test +is multi + line + +### OS + +- [x] Windows +- [x] Linux +- [ ] macOS + diff --git a/tests/Environments.Tests.ps1 b/tests copy/Environments.Tests.ps1 similarity index 100% rename from tests/Environments.Tests.ps1 rename to tests copy/Environments.Tests.ps1 diff --git a/tests/GitHub.Tests.ps1 b/tests copy/GitHub.Tests.ps1 similarity index 100% rename from tests/GitHub.Tests.ps1 rename to tests copy/GitHub.Tests.ps1 diff --git a/tests/Organizations.Tests.ps1 b/tests copy/Organizations.Tests.ps1 similarity index 100% rename from tests/Organizations.Tests.ps1 rename to tests copy/Organizations.Tests.ps1 diff --git a/tests/README.md b/tests copy/README.md similarity index 100% rename from tests/README.md rename to tests copy/README.md diff --git a/tests/Repositories.Tests.ps1 b/tests copy/Repositories.Tests.ps1 similarity index 100% rename from tests/Repositories.Tests.ps1 rename to tests copy/Repositories.Tests.ps1 diff --git a/tests/TEMPLATE.ps1 b/tests copy/TEMPLATE.ps1 similarity index 100% rename from tests/TEMPLATE.ps1 rename to tests copy/TEMPLATE.ps1 diff --git a/tests/User.Tests.ps1 b/tests copy/User.Tests.ps1 similarity index 100% rename from tests/User.Tests.ps1 rename to tests copy/User.Tests.ps1 diff --git a/tests copy/Variables.Tests.ps1 b/tests copy/Variables.Tests.ps1 new file mode 100644 index 000000000..757d691ff --- /dev/null +++ b/tests copy/Variables.Tests.ps1 @@ -0,0 +1,428 @@ +#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 = 'Log outputs to GitHub Actions logs.' +)] +[CmdletBinding()] +param() + +BeforeAll { + $testName = 'VariableTest' + $os = $env:RUNNER_OS + $guid = [guid]::NewGuid().ToString() +} + +Describe 'Environments' { + $authCases = . "$PSScriptRoot/Data/AuthCases.ps1" + + Context 'As using on ' -ForEach $authCases { + BeforeAll { + $context = Connect-GitHubAccount @connectParams -PassThru -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } + if ($AuthType -eq 'APP') { + LogGroup 'Context - Installation' { + $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent + Write-Host ($context | Format-List | Out-String) + } + } + $repoName = "$testName-$os-$TokenType-$guid" + $variablePrefix = ("$testName`_$os`_$TokenType" -replace '-', '_').ToUpper() + $varName = ("$variablePrefix`_$guid" -replace '-', '_').ToUpper() + $environmentName = "$testName-$os-$TokenType-$guid" + + switch ($OwnerType) { + 'user' { + $repo = New-GitHubRepository -Name $repoName -AllowSquashMerge + $repo2 = New-GitHubRepository -Name "$repoName-2" -AllowSquashMerge + $repo3 = New-GitHubRepository -Name "$repoName-3" -AllowSquashMerge + } + 'organization' { + $repo = New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge + $repo2 = New-GitHubRepository -Owner $owner -Name "$repoName-2" -AllowSquashMerge + $repo3 = New-GitHubRepository -Owner $owner -Name "$repoName-3" -AllowSquashMerge + + LogGroup "Org variable - [$varName]" { + $params = @{ + Owner = $owner + Name = $varName + Value = 'organization' + Visibility = 'selected' + SelectedRepositories = $repo.id + } + $result = Set-GitHubVariable @params + Write-Host ($result | Select-Object * | Format-Table | Out-String) + } + } + } + LogGroup "Repository - [$repoName]" { + Write-Host ($repo | Format-List | Out-String) + Write-Host ($repo2 | Format-List | Out-String) + Write-Host ($repo3 | Format-List | Out-String) + } + } + + AfterAll { + switch ($OwnerType) { + 'user' { + Remove-GitHubRepository -Owner $owner -Name $repoName -Confirm:$false + } + 'organization' { + Get-GitHubVariable -Owner $owner | Remove-GitHubVariable + Remove-GitHubRepository -Owner $owner -Name $repoName -Confirm:$false + Remove-GitHubRepository -Owner $owner -Name "$repoName-2" -Confirm:$false + Remove-GitHubRepository -Owner $owner -Name "$repoName-3" -Confirm:$false + } + } + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent + } + + Context 'Organization' -Skip:($OwnerType -ne 'organization') { + BeforeAll { + $scope = @{ + Owner = $owner + } + } + It 'Set-GitHubVariable - should ensure existance of a organization variable' { + $name = "$variablePrefix`TestVariable" + LogGroup "Variable - [$name]" { + $param = @{ + Name = $name + Value = 'TestValue1234' + Visibility = 'private' + } + $result = Set-GitHubVariable @param @scope + Write-Host ($result | Select-Object * | Format-List | Out-String) + } + $result | Should -Not -BeNullOrEmpty + $result | Should -BeOfType [GitHubVariable] + $result.Name | Should -Be $name + $result.Value | Should -Be 'TestValue1234' + $result.Visibility | Should -Be 'private' + } + + It 'Set-GitHubVariable - should update an existing organization variable' { + $name = "$variablePrefix`TestVariable" + LogGroup "Variable - [$name]" { + $param = @{ + Name = $name + Value = 'TestValue123456789' + Visibility = 'all' + } + $result = Set-GitHubVariable @param @scope + Write-Host ($result | Select-Object * | Format-List | Out-String) + } + $result | Should -Not -BeNullOrEmpty + $result | Should -BeOfType [GitHubVariable] + $result.Name | Should -Be $name + $result.Value | Should -Be 'TestValue123456789' + $result.Visibility | Should -Be 'all' + } + + It 'Update-GitHubVariable - should update an existing organization variable' { + $name = "$variablePrefix`TestVariable" + LogGroup "Variable - [$name]" { + $param = @{ + Name = $name + Value = 'TestValue1234' + } + $result = Update-GitHubVariable @param @scope -PassThru + Write-Host ($result | Select-Object * | Format-List | Out-String) + } + $result | Should -Not -BeNullOrEmpty + $result | Should -BeOfType [GitHubVariable] + $result.Name | Should -Be $name + $result.Value | Should -Be 'TestValue1234' + $result.Visibility | Should -Be 'all' + } + + It 'New-GitHubVariable - should create a new organization variable' { + $name = "$variablePrefix`TestVariable2" + LogGroup "Variable - [$name]" { + $param = @{ + Name = $name + Value = 'TestValue123' + } + $result = New-GitHubVariable @param @scope + Write-Host ($result | Select-Object * | Format-List | Out-String) + } + $result | Should -Not -BeNullOrEmpty + $result | Should -BeOfType [GitHubVariable] + $result.Name | Should -Be $name + $result.Value | Should -Be 'TestValue123' + $result.Visibility | Should -Be 'private' + } + + It 'New-GitHubVariable - should throw if creating an organization variable that exists' { + $name = "$variablePrefix`TestVariable2" + LogGroup "Variable - [$name]" { + $param = @{ + Name = $name + Value = 'TestValue123' + } + { + $result = New-GitHubVariable @param @scope + Write-Host ($result | Select-Object * | Format-List | Out-String) + } | Should -Throw + } + } + + It 'Get-GitHubVariable' { + $result = Get-GitHubVariable @scope -Name "$variablePrefix*" + LogGroup 'Variables' { + Write-Host "$($result | Select-Object * | Format-List | Out-String)" + } + $result | Should -Not -BeNullOrEmpty + } + + It 'Remove-GitHubVariable' { + LogGroup 'Before remove' { + $before = Get-GitHubVariable @scope -Name "$variablePrefix*" + Write-Host "$($before | Format-List | Out-String)" + } + LogGroup 'Remove' { + $before | Remove-GitHubVariable + } + LogGroup 'After remove' { + $after = Get-GitHubVariable @scope -Name "$variablePrefix*" + Write-Host "$($after | Format-List | Out-String)" + } + $after.Count | Should -Be 0 + } + + Context 'SelectedRepository' { + BeforeEach { + LogGroup 'Sleep 15 seconds' { + Start-Sleep -Seconds 15 + } + } + It 'Get-GitHubVariableSelectedRepository - gets a list of selected repositories' { + LogGroup "SelectedRepositories - [$varName]" { + $result = Get-GitHubVariableSelectedRepository -Owner $owner -Name $varName + Write-Host "$($result | Select-Object * | Format-Table | Out-String)" + } + $result | Should -Not -BeNullOrEmpty + $result[0] | Should -BeOfType [GitHubRepository] + $result | Should -HaveCount 1 + } + It 'Add-GitHubVariableSelectedRepository - adds a repository to the list of selected repositories' { + { Add-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo2.id } | Should -Not -Throw + } + It 'Add-GitHubVariableSelectedRepository - adds a repository to the list of selected repositories - idempotency test' { + { Add-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo2.id } | Should -Not -Throw + } + It 'Add-GitHubVariableSelectedRepository - adds a repository to the list of selected repositories using pipeline' { + LogGroup 'Repo3' { + Write-Host "$($repo3 | Format-List | Out-String)" + } + { $repo3 | Add-GitHubVariableSelectedRepository -Owner $owner -Name $varName } | Should -Not -Throw + } + It 'Get-GitHubVariableSelectedRepository - gets 3 repositories' { + LogGroup "SelectedRepositories - [$varName]" { + $result = Get-GitHubVariableSelectedRepository -Owner $owner -Name $varName + Write-Host "$($result | Select-Object * | Format-Table | Out-String)" + } + $result | Should -Not -BeNullOrEmpty + $result[0] | Should -BeOfType [GitHubRepository] + $result | Should -HaveCount 3 + } + It 'Remove-GitHubVariableSelectedRepository - removes a repository from the list of selected repositories' { + { Remove-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo2.id } | Should -Not -Throw + } + It 'Remove-GitHubVariableSelectedRepository - removes a repository from the list of selected repositories - idempotency test' { + { Remove-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo2.id } | Should -Not -Throw + } + It 'Remove-GitHubVariableSelectedRepository - removes a repository from the list of selected repositories using pipeline' { + LogGroup 'Repo3' { + Write-Host "$($repo3 | Format-List | Out-String)" + } + { $repo3 | Remove-GitHubVariableSelectedRepository -Owner $owner -Name $varName } | Should -Not -Throw + } + It 'Get-GitHubVariableSelectedRepository - gets 1 repository' { + LogGroup "SelectedRepositories - [$varName]" { + $result = Get-GitHubVariableSelectedRepository -Owner $owner -Name $varName + Write-Host "$($result | Select-Object * | Format-Table | Out-String)" + } + $result | Should -Not -BeNullOrEmpty + $result[0] | Should -BeOfType [GitHubRepository] + $result | Should -HaveCount 1 + } + It 'Set-GitHubVariableSelectedRepository - should set the selected repositories for the variable' { + { Set-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo.id, $repo2.id, $repo3.id } | + Should -Not -Throw + } + It 'Set-GitHubVariableSelectedRepository - should set the selected repositories for the variable - idempotency test' { + { Set-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo.id, $repo2.id, $repo3.id } | + Should -Not -Throw + } + It 'Get-GitHubVariableSelectedRepository - gets 3 repository' { + $result = Get-GitHubVariableSelectedRepository -Owner $owner -Name $varName + LogGroup "SelectedRepositories - [$varName]" { + Write-Host "$($result | Select-Object * | Format-Table | Out-String)" + } + $result | Should -Not -BeNullOrEmpty + $result[0] | Should -BeOfType [GitHubRepository] + $result | Should -HaveCount 3 + } + } + } + + Context 'Repository' -Skip:($OwnerType -eq '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*" + LogGroup 'Variables' { + Write-Host "$($result | Select-Object * | Format-Table | Out-String)" + } + $result | Should -Not -BeNullOrEmpty + } + + It 'Get-GitHubVariable -IncludeInherited' { + $result = Get-GitHubVariable @scope -Name "*$os*" -IncludeInherited + LogGroup 'Variables' { + Write-Host "$($result | Select-Object * | Format-Table | Out-String)" + } + $result | Should -Not -BeNullOrEmpty + } + + It 'Remove-GitHubVariable' { + $before = Get-GitHubVariable @scope -Name "*$os*" + LogGroup 'Variables - Before' { + Write-Host "$($before | Format-Table | Out-String)" + } + $before | Remove-GitHubVariable + $after = Get-GitHubVariable @scope -Name "*$os*" + LogGroup 'Variables -After' { + Write-Host "$($after | Format-Table | Out-String)" + } + $after.Count | Should -Be 0 + } + } + + Context 'Environment' -Skip:($OwnerType -eq 'repository') { + BeforeAll { + $scope = @{ + Owner = $owner + Repository = $repoName + } + Set-GitHubVariable @scope -Name $varName -Value 'repository' + $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 + LogGroup 'Variables' { + Write-Host "$($result | Select-Object * | Format-Table | Out-String)" + } + $result | Should -Not -BeNullOrEmpty + } + + It 'Update-GitHubVariable' { + $param = @{ + Name = "$variablePrefix`TestVariable" + Value = 'TestValue1234' + } + $result = Update-GitHubVariable @param @scope -PassThru + LogGroup 'Variables' { + Write-Host "$($result | Select-Object * | Format-Table | Out-String)" + } + $result | Should -Not -BeNullOrEmpty + } + + It 'New-GitHubVariable' { + $param = @{ + Name = "$variablePrefix`TestVariable2" + Value = 'TestValue123' + } + $result = New-GitHubVariable @param @scope + LogGroup 'Variables' { + Write-Host "$($result | Select-Object * | Format-Table | Out-String)" + } + $result | Should -Not -BeNullOrEmpty + } + + It 'Get-GitHubVariable' { + $result = Get-GitHubVariable @scope -Name "*$os*" + LogGroup 'Variables' { + Write-Host "$($result | Select-Object * | Format-Table | Out-String)" + } + $result | Should -Not -BeNullOrEmpty + } + + It 'Get-GitHubVariable -IncludeInherited' { + $result = Get-GitHubVariable @scope -Name "*$os*" -IncludeInherited + LogGroup 'Variables' { + Write-Host "$($result | Select-Object * | Format-Table | Out-String)" + } + $result | Should -Not -BeNullOrEmpty + } + + It 'Remove-GitHubVariable' { + LogGroup 'Variables - Before' { + $before = Get-GitHubVariable @scope -Name "*$os*" + Write-Host "$($before | Format-Table | Out-String)" + } + $before | Remove-GitHubVariable + LogGroup 'Variables - After' { + $after = Get-GitHubVariable @scope -Name "*$os*" + Write-Host "$($after | Format-Table | Out-String)" + } + $after.Count | Should -Be 0 + } + } + } +} From d135aeac92b8fffac39d46e028ca1484368692fc Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 30 Mar 2025 16:17:07 +0200 Subject: [PATCH 206/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Move=20org?= =?UTF-8?q?anization=20variable=20setup=20to=20BeforeAll=20for=20improved?= =?UTF-8?q?=20test=20structure=20and=20clarity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 757d691ff..f74a27ac8 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -51,18 +51,6 @@ Describe 'Environments' { $repo = New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge $repo2 = New-GitHubRepository -Owner $owner -Name "$repoName-2" -AllowSquashMerge $repo3 = New-GitHubRepository -Owner $owner -Name "$repoName-3" -AllowSquashMerge - - LogGroup "Org variable - [$varName]" { - $params = @{ - Owner = $owner - Name = $varName - Value = 'organization' - Visibility = 'selected' - SelectedRepositories = $repo.id - } - $result = Set-GitHubVariable @params - Write-Host ($result | Select-Object * | Format-Table | Out-String) - } } } LogGroup "Repository - [$repoName]" { @@ -201,6 +189,19 @@ Describe 'Environments' { } Context 'SelectedRepository' { + BeforeAll { + LogGroup "Org variable - [$varName]" { + $params = @{ + Owner = $owner + Name = $varName + Value = 'organization' + Visibility = 'selected' + SelectedRepositories = $repo.id + } + $result = Set-GitHubVariable @params + Write-Host ($result | Select-Object * | Format-Table | Out-String) + } + } BeforeEach { LogGroup 'Sleep 15 seconds' { Start-Sleep -Seconds 15 From 5d2287c7311e298dc1cd91f204c0a5f525603a49 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 30 Mar 2025 16:45:38 +0200 Subject: [PATCH 207/210] =?UTF-8?q?=F0=9F=94=A7=20[Update]:=20Enable=20tes?= =?UTF-8?q?ting=20for=20MacOS=20and=20Windows=20in=20PSModule.yml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/PSModule.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/PSModule.yml b/.github/PSModule.yml index 554431a7d..f2f3ee24e 100644 --- a/.github/PSModule.yml +++ b/.github/PSModule.yml @@ -5,9 +5,9 @@ Test: Skip: true Module: MacOS: - Skip: true + Skip: false Windows: - Skip: true + Skip: false CodeCoverage: Skip: true PercentTarget: 50 From c9bc3548934ee562c30c8dcd939fcd0e940ba62b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 30 Mar 2025 16:50:25 +0200 Subject: [PATCH 208/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Consolidat?= =?UTF-8?q?e=20organization=20variable=20setup=20into=20a=20single=20log?= =?UTF-8?q?=20group=20for=20improved=20readability=20and=20structure=20in?= =?UTF-8?q?=20Variables.Tests.ps1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Variables.Tests.ps1 | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index f74a27ac8..c1ca2c444 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -51,6 +51,17 @@ Describe 'Environments' { $repo = New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge $repo2 = New-GitHubRepository -Owner $owner -Name "$repoName-2" -AllowSquashMerge $repo3 = New-GitHubRepository -Owner $owner -Name "$repoName-3" -AllowSquashMerge + LogGroup "Org variable - [$varName]" { + $params = @{ + Owner = $owner + Name = $varName + Value = 'organization' + Visibility = 'selected' + SelectedRepositories = $repo.id + } + $result = Set-GitHubVariable @params + Write-Host ($result | Select-Object * | Format-Table | Out-String) + } } } LogGroup "Repository - [$repoName]" { @@ -174,34 +185,22 @@ Describe 'Environments' { } It 'Remove-GitHubVariable' { + $testVarName = "$variablePrefix`TestVariable*" LogGroup 'Before remove' { - $before = Get-GitHubVariable @scope -Name "$variablePrefix*" + $before = Get-GitHubVariable @scope -Name $testVarName Write-Host "$($before | Format-List | Out-String)" } LogGroup 'Remove' { $before | Remove-GitHubVariable } LogGroup 'After remove' { - $after = Get-GitHubVariable @scope -Name "$variablePrefix*" + $after = Get-GitHubVariable @scope -Name $testVarName Write-Host "$($after | Format-List | Out-String)" } $after.Count | Should -Be 0 } Context 'SelectedRepository' { - BeforeAll { - LogGroup "Org variable - [$varName]" { - $params = @{ - Owner = $owner - Name = $varName - Value = 'organization' - Visibility = 'selected' - SelectedRepositories = $repo.id - } - $result = Set-GitHubVariable @params - Write-Host ($result | Select-Object * | Format-Table | Out-String) - } - } BeforeEach { LogGroup 'Sleep 15 seconds' { Start-Sleep -Seconds 15 From 4f4a2c55c0a55425aaceb4ccb62711aa04acf4bb Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 30 Mar 2025 18:13:17 +0200 Subject: [PATCH 209/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Remove=20o?= =?UTF-8?q?bsolete=20issue=20form=20and=20authentication=20cases,=20and=20?= =?UTF-8?q?add=20README=20and=20template=20for=20user=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/PSModule.yml | 13 - tests copy/Data/AuthCases.ps1 | 83 ---- tests copy/Data/IssueForm.md | 19 - tests copy/Variables.Tests.ps1 | 428 ------------------ {tests copy => tests}/Environments.Tests.ps1 | 0 {tests copy => tests}/GitHub.Tests.ps1 | 0 {tests copy => tests}/Organizations.Tests.ps1 | 0 {tests copy => tests}/README.md | 0 {tests copy => tests}/Repositories.Tests.ps1 | 0 {tests copy => tests}/TEMPLATE.ps1 | 0 {tests copy => tests}/User.Tests.ps1 | 0 11 files changed, 543 deletions(-) delete mode 100644 tests copy/Data/AuthCases.ps1 delete mode 100644 tests copy/Data/IssueForm.md delete mode 100644 tests copy/Variables.Tests.ps1 rename {tests copy => tests}/Environments.Tests.ps1 (100%) rename {tests copy => tests}/GitHub.Tests.ps1 (100%) rename {tests copy => tests}/Organizations.Tests.ps1 (100%) rename {tests copy => tests}/README.md (100%) rename {tests copy => tests}/Repositories.Tests.ps1 (100%) rename {tests copy => tests}/TEMPLATE.ps1 (100%) rename {tests copy => tests}/User.Tests.ps1 (100%) diff --git a/.github/PSModule.yml b/.github/PSModule.yml index f2f3ee24e..6d578178e 100644 --- a/.github/PSModule.yml +++ b/.github/PSModule.yml @@ -1,16 +1,3 @@ Test: - SourceCode: - Skip: true - PSModule: - Skip: true - Module: - MacOS: - Skip: false - Windows: - Skip: false CodeCoverage: - Skip: true PercentTarget: 50 -Build: - Docs: - Skip: true diff --git a/tests copy/Data/AuthCases.ps1 b/tests copy/Data/AuthCases.ps1 deleted file mode 100644 index 63c7f1438..000000000 --- a/tests copy/Data/AuthCases.ps1 +++ /dev/null @@ -1,83 +0,0 @@ -@( - @{ - AuthType = 'PAT' - Type = 'a user' - Case = 'Fine-grained PAT token' - TokenType = 'USER_FG_PAT' - Target = 'it self (user account)' - Owner = 'psmodule-user' - OwnerType = 'user' - ConnectParams = @{ - Token = $env:TEST_USER_USER_FG_PAT - } - } - @{ - AuthType = 'PAT' - Type = 'a user' - Case = 'Fine-grained PAT token' - TokenType = 'ORG_FG_PAT' - Target = 'organization account' - Owner = 'psmodule-test-org2' - OwnerType = 'organization' - ConnectParams = @{ - Token = $env:TEST_USER_ORG_FG_PAT - } - } - @{ - AuthType = 'PAT' - Type = 'a user' - Case = 'Classic PAT token' - TokenType = 'PAT' - Target = 'user account' - Owner = 'psmodule-user' - OwnerType = 'user' - ConnectParams = @{ - Token = $env:TEST_USER_PAT - } - } - @{ - AuthType = 'IAT' - Type = 'GitHub Actions' - Case = 'GITHUB_TOKEN' - TokenType = 'GITHUB_TOKEN' - Target = 'this repository (GitHub)' - Owner = 'PSModule' - Repo = 'GitHub' - OwnerType = 'repository' - ConnectParams = @{ - Token = $env:GITHUB_TOKEN - } - } - @{ - AuthType = 'App' - Type = 'a GitHub App from an Enterprise' - Case = 'PEM + IAT' - TokenType = 'APP_ENT' - Target = 'organization account' - Owner = 'psmodule-test-org3' - OwnerType = 'organization' - ConnectParams = @{ - ClientID = $env:TEST_APP_ENT_CLIENT_ID - PrivateKey = $env:TEST_APP_ENT_PRIVATE_KEY - } - ConnectAppParams = @{ - Organization = 'psmodule-test-org3' - } - } - @{ - AuthType = 'App' - Type = 'a GitHub App from an Organization' - Case = 'PEM + IAT' - TokenType = 'APP_ORG' - Target = 'organization account' - Owner = 'psmodule-test-org' - OwnerType = 'organization' - ConnectParams = @{ - ClientID = $env:TEST_APP_ORG_CLIENT_ID - PrivateKey = $env:TEST_APP_ORG_PRIVATE_KEY - } - ConnectAppParams = @{ - Organization = 'psmodule-test-org' - } - } -) diff --git a/tests copy/Data/IssueForm.md b/tests copy/Data/IssueForm.md deleted file mode 100644 index 83b1b3967..000000000 --- a/tests copy/Data/IssueForm.md +++ /dev/null @@ -1,19 +0,0 @@ - -### Type with spaces - -Action - -### Multiline - -test -is multi - line - -### OS - -- [x] Windows -- [x] Linux -- [ ] macOS - diff --git a/tests copy/Variables.Tests.ps1 b/tests copy/Variables.Tests.ps1 deleted file mode 100644 index 757d691ff..000000000 --- a/tests copy/Variables.Tests.ps1 +++ /dev/null @@ -1,428 +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 = 'Log outputs to GitHub Actions logs.' -)] -[CmdletBinding()] -param() - -BeforeAll { - $testName = 'VariableTest' - $os = $env:RUNNER_OS - $guid = [guid]::NewGuid().ToString() -} - -Describe 'Environments' { - $authCases = . "$PSScriptRoot/Data/AuthCases.ps1" - - Context 'As using on ' -ForEach $authCases { - BeforeAll { - $context = Connect-GitHubAccount @connectParams -PassThru -Silent - LogGroup 'Context' { - Write-Host ($context | Format-List | Out-String) - } - if ($AuthType -eq 'APP') { - LogGroup 'Context - Installation' { - $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent - Write-Host ($context | Format-List | Out-String) - } - } - $repoName = "$testName-$os-$TokenType-$guid" - $variablePrefix = ("$testName`_$os`_$TokenType" -replace '-', '_').ToUpper() - $varName = ("$variablePrefix`_$guid" -replace '-', '_').ToUpper() - $environmentName = "$testName-$os-$TokenType-$guid" - - switch ($OwnerType) { - 'user' { - $repo = New-GitHubRepository -Name $repoName -AllowSquashMerge - $repo2 = New-GitHubRepository -Name "$repoName-2" -AllowSquashMerge - $repo3 = New-GitHubRepository -Name "$repoName-3" -AllowSquashMerge - } - 'organization' { - $repo = New-GitHubRepository -Owner $owner -Name $repoName -AllowSquashMerge - $repo2 = New-GitHubRepository -Owner $owner -Name "$repoName-2" -AllowSquashMerge - $repo3 = New-GitHubRepository -Owner $owner -Name "$repoName-3" -AllowSquashMerge - - LogGroup "Org variable - [$varName]" { - $params = @{ - Owner = $owner - Name = $varName - Value = 'organization' - Visibility = 'selected' - SelectedRepositories = $repo.id - } - $result = Set-GitHubVariable @params - Write-Host ($result | Select-Object * | Format-Table | Out-String) - } - } - } - LogGroup "Repository - [$repoName]" { - Write-Host ($repo | Format-List | Out-String) - Write-Host ($repo2 | Format-List | Out-String) - Write-Host ($repo3 | Format-List | Out-String) - } - } - - AfterAll { - switch ($OwnerType) { - 'user' { - Remove-GitHubRepository -Owner $owner -Name $repoName -Confirm:$false - } - 'organization' { - Get-GitHubVariable -Owner $owner | Remove-GitHubVariable - Remove-GitHubRepository -Owner $owner -Name $repoName -Confirm:$false - Remove-GitHubRepository -Owner $owner -Name "$repoName-2" -Confirm:$false - Remove-GitHubRepository -Owner $owner -Name "$repoName-3" -Confirm:$false - } - } - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent - } - - Context 'Organization' -Skip:($OwnerType -ne 'organization') { - BeforeAll { - $scope = @{ - Owner = $owner - } - } - It 'Set-GitHubVariable - should ensure existance of a organization variable' { - $name = "$variablePrefix`TestVariable" - LogGroup "Variable - [$name]" { - $param = @{ - Name = $name - Value = 'TestValue1234' - Visibility = 'private' - } - $result = Set-GitHubVariable @param @scope - Write-Host ($result | Select-Object * | Format-List | Out-String) - } - $result | Should -Not -BeNullOrEmpty - $result | Should -BeOfType [GitHubVariable] - $result.Name | Should -Be $name - $result.Value | Should -Be 'TestValue1234' - $result.Visibility | Should -Be 'private' - } - - It 'Set-GitHubVariable - should update an existing organization variable' { - $name = "$variablePrefix`TestVariable" - LogGroup "Variable - [$name]" { - $param = @{ - Name = $name - Value = 'TestValue123456789' - Visibility = 'all' - } - $result = Set-GitHubVariable @param @scope - Write-Host ($result | Select-Object * | Format-List | Out-String) - } - $result | Should -Not -BeNullOrEmpty - $result | Should -BeOfType [GitHubVariable] - $result.Name | Should -Be $name - $result.Value | Should -Be 'TestValue123456789' - $result.Visibility | Should -Be 'all' - } - - It 'Update-GitHubVariable - should update an existing organization variable' { - $name = "$variablePrefix`TestVariable" - LogGroup "Variable - [$name]" { - $param = @{ - Name = $name - Value = 'TestValue1234' - } - $result = Update-GitHubVariable @param @scope -PassThru - Write-Host ($result | Select-Object * | Format-List | Out-String) - } - $result | Should -Not -BeNullOrEmpty - $result | Should -BeOfType [GitHubVariable] - $result.Name | Should -Be $name - $result.Value | Should -Be 'TestValue1234' - $result.Visibility | Should -Be 'all' - } - - It 'New-GitHubVariable - should create a new organization variable' { - $name = "$variablePrefix`TestVariable2" - LogGroup "Variable - [$name]" { - $param = @{ - Name = $name - Value = 'TestValue123' - } - $result = New-GitHubVariable @param @scope - Write-Host ($result | Select-Object * | Format-List | Out-String) - } - $result | Should -Not -BeNullOrEmpty - $result | Should -BeOfType [GitHubVariable] - $result.Name | Should -Be $name - $result.Value | Should -Be 'TestValue123' - $result.Visibility | Should -Be 'private' - } - - It 'New-GitHubVariable - should throw if creating an organization variable that exists' { - $name = "$variablePrefix`TestVariable2" - LogGroup "Variable - [$name]" { - $param = @{ - Name = $name - Value = 'TestValue123' - } - { - $result = New-GitHubVariable @param @scope - Write-Host ($result | Select-Object * | Format-List | Out-String) - } | Should -Throw - } - } - - It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope -Name "$variablePrefix*" - LogGroup 'Variables' { - Write-Host "$($result | Select-Object * | Format-List | Out-String)" - } - $result | Should -Not -BeNullOrEmpty - } - - It 'Remove-GitHubVariable' { - LogGroup 'Before remove' { - $before = Get-GitHubVariable @scope -Name "$variablePrefix*" - Write-Host "$($before | Format-List | Out-String)" - } - LogGroup 'Remove' { - $before | Remove-GitHubVariable - } - LogGroup 'After remove' { - $after = Get-GitHubVariable @scope -Name "$variablePrefix*" - Write-Host "$($after | Format-List | Out-String)" - } - $after.Count | Should -Be 0 - } - - Context 'SelectedRepository' { - BeforeEach { - LogGroup 'Sleep 15 seconds' { - Start-Sleep -Seconds 15 - } - } - It 'Get-GitHubVariableSelectedRepository - gets a list of selected repositories' { - LogGroup "SelectedRepositories - [$varName]" { - $result = Get-GitHubVariableSelectedRepository -Owner $owner -Name $varName - Write-Host "$($result | Select-Object * | Format-Table | Out-String)" - } - $result | Should -Not -BeNullOrEmpty - $result[0] | Should -BeOfType [GitHubRepository] - $result | Should -HaveCount 1 - } - It 'Add-GitHubVariableSelectedRepository - adds a repository to the list of selected repositories' { - { Add-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo2.id } | Should -Not -Throw - } - It 'Add-GitHubVariableSelectedRepository - adds a repository to the list of selected repositories - idempotency test' { - { Add-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo2.id } | Should -Not -Throw - } - It 'Add-GitHubVariableSelectedRepository - adds a repository to the list of selected repositories using pipeline' { - LogGroup 'Repo3' { - Write-Host "$($repo3 | Format-List | Out-String)" - } - { $repo3 | Add-GitHubVariableSelectedRepository -Owner $owner -Name $varName } | Should -Not -Throw - } - It 'Get-GitHubVariableSelectedRepository - gets 3 repositories' { - LogGroup "SelectedRepositories - [$varName]" { - $result = Get-GitHubVariableSelectedRepository -Owner $owner -Name $varName - Write-Host "$($result | Select-Object * | Format-Table | Out-String)" - } - $result | Should -Not -BeNullOrEmpty - $result[0] | Should -BeOfType [GitHubRepository] - $result | Should -HaveCount 3 - } - It 'Remove-GitHubVariableSelectedRepository - removes a repository from the list of selected repositories' { - { Remove-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo2.id } | Should -Not -Throw - } - It 'Remove-GitHubVariableSelectedRepository - removes a repository from the list of selected repositories - idempotency test' { - { Remove-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo2.id } | Should -Not -Throw - } - It 'Remove-GitHubVariableSelectedRepository - removes a repository from the list of selected repositories using pipeline' { - LogGroup 'Repo3' { - Write-Host "$($repo3 | Format-List | Out-String)" - } - { $repo3 | Remove-GitHubVariableSelectedRepository -Owner $owner -Name $varName } | Should -Not -Throw - } - It 'Get-GitHubVariableSelectedRepository - gets 1 repository' { - LogGroup "SelectedRepositories - [$varName]" { - $result = Get-GitHubVariableSelectedRepository -Owner $owner -Name $varName - Write-Host "$($result | Select-Object * | Format-Table | Out-String)" - } - $result | Should -Not -BeNullOrEmpty - $result[0] | Should -BeOfType [GitHubRepository] - $result | Should -HaveCount 1 - } - It 'Set-GitHubVariableSelectedRepository - should set the selected repositories for the variable' { - { Set-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo.id, $repo2.id, $repo3.id } | - Should -Not -Throw - } - It 'Set-GitHubVariableSelectedRepository - should set the selected repositories for the variable - idempotency test' { - { Set-GitHubVariableSelectedRepository -Owner $owner -Name $varName -RepositoryID $repo.id, $repo2.id, $repo3.id } | - Should -Not -Throw - } - It 'Get-GitHubVariableSelectedRepository - gets 3 repository' { - $result = Get-GitHubVariableSelectedRepository -Owner $owner -Name $varName - LogGroup "SelectedRepositories - [$varName]" { - Write-Host "$($result | Select-Object * | Format-Table | Out-String)" - } - $result | Should -Not -BeNullOrEmpty - $result[0] | Should -BeOfType [GitHubRepository] - $result | Should -HaveCount 3 - } - } - } - - Context 'Repository' -Skip:($OwnerType -eq '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*" - LogGroup 'Variables' { - Write-Host "$($result | Select-Object * | Format-Table | Out-String)" - } - $result | Should -Not -BeNullOrEmpty - } - - It 'Get-GitHubVariable -IncludeInherited' { - $result = Get-GitHubVariable @scope -Name "*$os*" -IncludeInherited - LogGroup 'Variables' { - Write-Host "$($result | Select-Object * | Format-Table | Out-String)" - } - $result | Should -Not -BeNullOrEmpty - } - - It 'Remove-GitHubVariable' { - $before = Get-GitHubVariable @scope -Name "*$os*" - LogGroup 'Variables - Before' { - Write-Host "$($before | Format-Table | Out-String)" - } - $before | Remove-GitHubVariable - $after = Get-GitHubVariable @scope -Name "*$os*" - LogGroup 'Variables -After' { - Write-Host "$($after | Format-Table | Out-String)" - } - $after.Count | Should -Be 0 - } - } - - Context 'Environment' -Skip:($OwnerType -eq 'repository') { - BeforeAll { - $scope = @{ - Owner = $owner - Repository = $repoName - } - Set-GitHubVariable @scope -Name $varName -Value 'repository' - $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 - LogGroup 'Variables' { - Write-Host "$($result | Select-Object * | Format-Table | Out-String)" - } - $result | Should -Not -BeNullOrEmpty - } - - It 'Update-GitHubVariable' { - $param = @{ - Name = "$variablePrefix`TestVariable" - Value = 'TestValue1234' - } - $result = Update-GitHubVariable @param @scope -PassThru - LogGroup 'Variables' { - Write-Host "$($result | Select-Object * | Format-Table | Out-String)" - } - $result | Should -Not -BeNullOrEmpty - } - - It 'New-GitHubVariable' { - $param = @{ - Name = "$variablePrefix`TestVariable2" - Value = 'TestValue123' - } - $result = New-GitHubVariable @param @scope - LogGroup 'Variables' { - Write-Host "$($result | Select-Object * | Format-Table | Out-String)" - } - $result | Should -Not -BeNullOrEmpty - } - - It 'Get-GitHubVariable' { - $result = Get-GitHubVariable @scope -Name "*$os*" - LogGroup 'Variables' { - Write-Host "$($result | Select-Object * | Format-Table | Out-String)" - } - $result | Should -Not -BeNullOrEmpty - } - - It 'Get-GitHubVariable -IncludeInherited' { - $result = Get-GitHubVariable @scope -Name "*$os*" -IncludeInherited - LogGroup 'Variables' { - Write-Host "$($result | Select-Object * | Format-Table | Out-String)" - } - $result | Should -Not -BeNullOrEmpty - } - - It 'Remove-GitHubVariable' { - LogGroup 'Variables - Before' { - $before = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($before | Format-Table | Out-String)" - } - $before | Remove-GitHubVariable - LogGroup 'Variables - After' { - $after = Get-GitHubVariable @scope -Name "*$os*" - Write-Host "$($after | Format-Table | Out-String)" - } - $after.Count | Should -Be 0 - } - } - } -} diff --git a/tests copy/Environments.Tests.ps1 b/tests/Environments.Tests.ps1 similarity index 100% rename from tests copy/Environments.Tests.ps1 rename to tests/Environments.Tests.ps1 diff --git a/tests copy/GitHub.Tests.ps1 b/tests/GitHub.Tests.ps1 similarity index 100% rename from tests copy/GitHub.Tests.ps1 rename to tests/GitHub.Tests.ps1 diff --git a/tests copy/Organizations.Tests.ps1 b/tests/Organizations.Tests.ps1 similarity index 100% rename from tests copy/Organizations.Tests.ps1 rename to tests/Organizations.Tests.ps1 diff --git a/tests copy/README.md b/tests/README.md similarity index 100% rename from tests copy/README.md rename to tests/README.md diff --git a/tests copy/Repositories.Tests.ps1 b/tests/Repositories.Tests.ps1 similarity index 100% rename from tests copy/Repositories.Tests.ps1 rename to tests/Repositories.Tests.ps1 diff --git a/tests copy/TEMPLATE.ps1 b/tests/TEMPLATE.ps1 similarity index 100% rename from tests copy/TEMPLATE.ps1 rename to tests/TEMPLATE.ps1 diff --git a/tests copy/User.Tests.ps1 b/tests/User.Tests.ps1 similarity index 100% rename from tests copy/User.Tests.ps1 rename to tests/User.Tests.ps1 From bdd2bbb86c0225f6ad70315187a5cadac29bf2ca Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 30 Mar 2025 19:18:26 +0200 Subject: [PATCH 210/210] =?UTF-8?q?=F0=9F=94=A7=20[Refactor]:=20Remove=20d?= =?UTF-8?q?ebug=20and=20verbose=20options=20from=20Process-PSModule.yml=20?= =?UTF-8?q?for=20cleaner=20workflow=20execution?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/Process-PSModule.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/Process-PSModule.yml b/.github/workflows/Process-PSModule.yml index eb49d367b..2fdfe0422 100644 --- a/.github/workflows/Process-PSModule.yml +++ b/.github/workflows/Process-PSModule.yml @@ -36,6 +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: - Debug: true - Verbose: true