From fc5352aa6882a20ccafc94c0bd17d1220a5d4b55 Mon Sep 17 00:00:00 2001 From: Paul Matthews <6736509+pmatthews05@users.noreply.github.com> Date: Thu, 13 Mar 2025 12:48:13 +0000 Subject: [PATCH 1/5] Added Repository Environments calls. --- .../Environments/Get-GitHubEnvironment.ps1 | 91 ++++++++++++++++++ .../Environments/Remove-GitHubEnvironment.ps1 | 72 ++++++++++++++ .../Environments/Set-GitHubEnvironment.ps1 | 95 +++++++++++++++++++ 3 files changed, 258 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 diff --git a/src/functions/public/Environments/Get-GitHubEnvironment.ps1 b/src/functions/public/Environments/Get-GitHubEnvironment.ps1 new file mode 100644 index 000000000..cf215c97c --- /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' -EnvironmentName '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(DefaultParameterSetName = '__AllParameterSets')] + 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] $EnvironmentName, + + [Parameter(ParameterSetName = '__AllParameterSets')] + [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/$EnvironmentName" + $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..8208f1c8d --- /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' -EnvironmentName '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] $EnvironmentName, + + # 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/$EnvironmentName" + Context = $Context + } + + if ($PSCmdlet.ShouldProcess("Environment [$EnvironmentName]", '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..2a8ad258b --- /dev/null +++ b/src/functions/public/Environments/Set-GitHubEnvironment.ps1 @@ -0,0 +1,95 @@ +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] $EnvironmentName, + + # 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 = $WaitTimer + prevent_self_review = $PreventSelfReview + reviewers = $Reviewers + deployment_branch_policy = $DeploymentBranchPolicy + } | Remove-HashtableEntry -NullOrEmptyValues + + $inputObject = @{ + Method = 'PUT' + APIEndpoint = "/repos/$Owner/$Repository/environments/$EnvironmentName" + Body = $body + Context = $Context + } + + if ($PSCmdlet.ShouldProcess("Environment [$EnvironmentName]", 'Set')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } + } + + end { + Write-Debug "[$stackPath] - End" + } +} \ No newline at end of file From 328e47be17f508456e6da1f9812769ac350630ff Mon Sep 17 00:00:00 2001 From: Paul Matthews <6736509+pmatthews05@users.noreply.github.com> Date: Thu, 13 Mar 2025 12:55:40 +0000 Subject: [PATCH 2/5] fix up for empty parameters --- .../public/Environments/Set-GitHubEnvironment.ps1 | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/functions/public/Environments/Set-GitHubEnvironment.ps1 b/src/functions/public/Environments/Set-GitHubEnvironment.ps1 index 2a8ad258b..5d93c6762 100644 --- a/src/functions/public/Environments/Set-GitHubEnvironment.ps1 +++ b/src/functions/public/Environments/Set-GitHubEnvironment.ps1 @@ -69,10 +69,10 @@ filter Set-GitHubEnvironment { process { $body = @{ - wait_timer = $WaitTimer - prevent_self_review = $PreventSelfReview - reviewers = $Reviewers - deployment_branch_policy = $DeploymentBranchPolicy + 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 = @{ @@ -80,7 +80,8 @@ filter Set-GitHubEnvironment { APIEndpoint = "/repos/$Owner/$Repository/environments/$EnvironmentName" Body = $body Context = $Context - } + } | Remove-HashtableEntry -NullOrEmptyValues + if ($PSCmdlet.ShouldProcess("Environment [$EnvironmentName]", 'Set')) { Invoke-GitHubAPI @inputObject | ForEach-Object { From f6715ba8da2ade5f0a23c198afd7a8c5ad213b89 Mon Sep 17 00:00:00 2001 From: Paul Matthews <6736509+pmatthews05@users.noreply.github.com> Date: Thu, 13 Mar 2025 14:26:43 +0000 Subject: [PATCH 3/5] Added Variables functions --- .../public/Variables/Get-GitHubVariable.ps1 | 105 +++++++++++ .../Variables/Remove-GitHubVariable.ps1 | 105 +++++++++++ .../public/Variables/Set-GitHubVariable.ps1 | 165 ++++++++++++++++++ 3 files changed, 375 insertions(+) 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/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..c83603b64 --- /dev/null +++ b/src/functions/public/Variables/Set-GitHubVariable.ps1 @@ -0,0 +1,165 @@ +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 a1a3a63a0398381058f850fef6cc907cac27afaf Mon Sep 17 00:00:00 2001 From: Paul Matthews <6736509+pmatthews05@users.noreply.github.com> Date: Thu, 13 Mar 2025 15:53:02 +0000 Subject: [PATCH 4/5] Update to invalid bracket. --- src/functions/public/Variables/Set-GitHubVariable.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/functions/public/Variables/Set-GitHubVariable.ps1 b/src/functions/public/Variables/Set-GitHubVariable.ps1 index c83603b64..4c1fb01cb 100644 --- a/src/functions/public/Variables/Set-GitHubVariable.ps1 +++ b/src/functions/public/Variables/Set-GitHubVariable.ps1 @@ -109,7 +109,7 @@ function Set-GitHubVariable { process { $getParams = $PSBoundParameters $getParams | Remove-HashtableEntry -NullOrEmptyValues -RemoveNames 'Value','Private','SelectedRepositoryIDs','Context' - $variableFound = Get-GitHubVariable @getParams -Name $Name } + $variableFound = Get-GitHubVariable @getParams -Name $Name $body = @{ name = $Name @@ -158,6 +158,7 @@ function Set-GitHubVariable { $result = Invoke-GitHubAPI @inputObject Write-Output $result.Response } + } end { Write-Debug "[$stackPath] - End" From a1fde9734702ca1c97e4195b3838df60aea43056 Mon Sep 17 00:00:00 2001 From: Paul Matthews <6736509+pmatthews05@users.noreply.github.com> Date: Thu, 13 Mar 2025 16:11:08 +0000 Subject: [PATCH 5/5] Updated after re-reading CodingStandards --- .../public/Environments/Get-GitHubEnvironment.ps1 | 10 +++++----- .../public/Environments/Remove-GitHubEnvironment.ps1 | 8 ++++---- .../public/Environments/Set-GitHubEnvironment.ps1 | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/functions/public/Environments/Get-GitHubEnvironment.ps1 b/src/functions/public/Environments/Get-GitHubEnvironment.ps1 index cf215c97c..027083c48 100644 --- a/src/functions/public/Environments/Get-GitHubEnvironment.ps1 +++ b/src/functions/public/Environments/Get-GitHubEnvironment.ps1 @@ -13,7 +13,7 @@ filter Get-GitHubEnvironment { Lists all environments for the 'PSModule/GitHub' repository. .EXAMPLE - Get-GitHubEnvironment -Owner 'PSModule' -Repository 'Github' -EnvironmentName 'Production' + Get-GitHubEnvironment -Owner 'PSModule' -Repository 'Github' -Name 'Production' Get the 'Production' environment for the 'PSModule/GitHub' repository. @@ -21,7 +21,7 @@ filter Get-GitHubEnvironment { [List environments](https://docs.github.com/en/rest/deployments/environments#list-environments) #> [OutputType([pscustomobject])] - [CmdletBinding(DefaultParameterSetName = '__AllParameterSets')] + [CmdletBinding()] param( # The name of the organization. [Parameter( @@ -44,9 +44,9 @@ filter Get-GitHubEnvironment { ParameterSetName = 'NamedEnv', ValueFromPipelineByPropertyName )] - [string] $EnvironmentName, + [string] $Name, - [Parameter(ParameterSetName = '__AllParameterSets')] + [Parameter()] [ValidateRange(0, 100)] [int] $PerPage, @@ -76,7 +76,7 @@ filter Get-GitHubEnvironment { } if ($PSCmdlet.ParameterSetName -eq 'NamedEnv') { - $inputObject.APIEndpoint = "/repos/$Owner/$Repository/environments/$EnvironmentName" + $inputObject.APIEndpoint = "/repos/$Owner/$Repository/environments/$Name" $inputObject.Remove('Body') } diff --git a/src/functions/public/Environments/Remove-GitHubEnvironment.ps1 b/src/functions/public/Environments/Remove-GitHubEnvironment.ps1 index 8208f1c8d..1864e01ba 100644 --- a/src/functions/public/Environments/Remove-GitHubEnvironment.ps1 +++ b/src/functions/public/Environments/Remove-GitHubEnvironment.ps1 @@ -7,7 +7,7 @@ filter Remove-GitHubEnvironment { Deletes an environment from a repository .EXAMPLE - Remove-GitHubEnvironment -Owner 'PSModule' -Repository 'GitHub' -EnvironmentName 'Production' + Remove-GitHubEnvironment -Owner 'PSModule' -Repository 'GitHub' -Name 'Production' Deletes the 'Production' environment from the 'PSModule/GitHub' repository. @@ -37,7 +37,7 @@ filter Remove-GitHubEnvironment { Mandatory, ValueFromPipelineByPropertyName )] - [string] $EnvironmentName, + [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. @@ -55,11 +55,11 @@ filter Remove-GitHubEnvironment { process { $inputObject = @{ Method = 'DELETE' - APIEndpoint = "/repos/$Owner/$Repository/environments/$EnvironmentName" + APIEndpoint = "/repos/$Owner/$Repository/environments/$Name" Context = $Context } - if ($PSCmdlet.ShouldProcess("Environment [$EnvironmentName]", 'DELETE')) { + if ($PSCmdlet.ShouldProcess("Environment [$Name]", 'DELETE')) { Invoke-GitHubAPI @inputObject | ForEach-Object { Write-Output $_.Response } diff --git a/src/functions/public/Environments/Set-GitHubEnvironment.ps1 b/src/functions/public/Environments/Set-GitHubEnvironment.ps1 index 5d93c6762..0f90b099f 100644 --- a/src/functions/public/Environments/Set-GitHubEnvironment.ps1 +++ b/src/functions/public/Environments/Set-GitHubEnvironment.ps1 @@ -31,7 +31,7 @@ filter Set-GitHubEnvironment { Mandatory, ValueFromPipelineByPropertyName )] - [string] $EnvironmentName, + [string] $Name, # The amount of time to delay a job after the job is initially triggered. The time (in minutes). [Parameter(ValueFromPipelineByPropertyName)] @@ -77,13 +77,13 @@ filter Set-GitHubEnvironment { $inputObject = @{ Method = 'PUT' - APIEndpoint = "/repos/$Owner/$Repository/environments/$EnvironmentName" + APIEndpoint = "/repos/$Owner/$Repository/environments/$Name" Body = $body Context = $Context } | Remove-HashtableEntry -NullOrEmptyValues - if ($PSCmdlet.ShouldProcess("Environment [$EnvironmentName]", 'Set')) { + if ($PSCmdlet.ShouldProcess("Environment [$Name]", 'Set')) { Invoke-GitHubAPI @inputObject | ForEach-Object { Write-Output $_.Response }