Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions src/functions/public/Environments/Get-GitHubEnvironment.ps1
Original file line number Diff line number Diff line change
@@ -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"
}
}
72 changes: 72 additions & 0 deletions src/functions/public/Environments/Remove-GitHubEnvironment.ps1
Original file line number Diff line number Diff line change
@@ -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"
}
}
96 changes: 96 additions & 0 deletions src/functions/public/Environments/Set-GitHubEnvironment.ps1
Original file line number Diff line number Diff line change
@@ -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"
}
}
105 changes: 105 additions & 0 deletions src/functions/public/Variables/Get-GitHubVariable.ps1
Original file line number Diff line number Diff line change
@@ -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"
}
}
Loading