diff --git a/src/classes/public/Environment/GitHubEnvironment.ps1 b/src/classes/public/Environment/GitHubEnvironment.ps1 deleted file mode 100644 index 54f9b3256..000000000 --- a/src/classes/public/Environment/GitHubEnvironment.ps1 +++ /dev/null @@ -1,68 +0,0 @@ -class RequiredReviewers { - [int]$Id - [string]$NodeId - [bool]$PreventSelfReview - [string]$Reviewers - - RequiredReviewers([psobject]$data) { - $this.Id = $data.id - $this.NodeId = $data.node_id - $this.PreventSelfReview = $data.prevent_self_review - $this.Reviewers = $data.reviewers - } -} - -class BranchPolicy { - [int]$Id - [string]$NodeId - - BranchPolicy([psobject]$data) { - $this.Id = $data.id - $this.NodeId = $data.node_id - } -} - -class DeploymentBranchPolicy { - [bool]$ProtectedBranches - [bool]$CustomBranchPolicies - - DeploymentBranchPolicy([psobject]$data) { - $this.ProtectedBranches = $data.protected_branches - $this.CustomBranchPolicies = $data.custom_branch_policies - } -} - -class Environment { - [long]$Id - [string]$NodeId - [string]$Name - [string]$Url - [string]$HtmlUrl - [datetime]$CreatedAt - [datetime]$UpdatedAt - [bool]$CanAdminsBypass - - [RequiredReviewers]$RequiredReviewers - [BranchPolicy]$BranchPolicy - [DeploymentBranchPolicy]$DeploymentBranchPolicy - - Environment([psobject]$data) { - $this.Id = $data.id - $this.NodeId = $data.node_id - $this.Name = $data.name - $this.Url = $data.url - $this.HtmlUrl = $data.html_url - $this.CreatedAt = [datetime]$data.created_at - $this.UpdatedAt = [datetime]$data.updated_at - $this.CanAdminsBypass = $data.can_admins_bypass - - foreach ($rule in $data.protection_rules) { - switch ($rule.type) { - 'required_reviewers' { $this.RequiredReviewers = [RequiredReviewers]::new($rule) } - 'branch_policy' { $this.BranchPolicy = [BranchPolicy]::new($rule) } - } - } - - $this.DeploymentBranchPolicy = [DeploymentBranchPolicy]::new($data.deployment_branch_policy) - } -} diff --git a/src/functions/private/Environments/Get-GitHubEnvironmentByName.ps1 b/src/functions/private/Environments/Get-GitHubEnvironmentByName.ps1 index 1d12b0a12..ab5286065 100644 --- a/src/functions/private/Environments/Get-GitHubEnvironmentByName.ps1 +++ b/src/functions/private/Environments/Get-GitHubEnvironmentByName.ps1 @@ -13,16 +13,25 @@ filter Get-GitHubEnvironmentByName { to use this function with a private repository. .EXAMPLE - Get-GitHubEnvironmentByName -Owner "my-org" -Repository "my-repo" -Name "production" -Context $GitHubContext + Get-GitHubEnvironment -Owner 'PSModule' -Repository 'EnvironmentTest' -Name 'test' Output: - ```powershell - Name : production - URL : https://github.com/my-org/my-repo/environments/production - Protection : @{WaitTimer=0; Reviewers=@()} + ```pwsh + id : 5944178128 + node_id : EN_kwDOOJqfM88AAAABYkz10A + name : test + url : https://api.github.com/repos/PSModule/EnvironmentTest/environments/test + html_url : https://github.com/PSModule/EnvironmentTest/deployments/activity_log?environments_filter=test + created_at : 3/16/2025 11:17:52 PM + updated_at : 3/16/2025 11:17:52 PM + can_admins_bypass : True + protection_rules : {@{id=30352888; node_id=GA_kwDOOJqfM84BzyX4; type=required_reviewers; prevent_self_review=False; + reviewers=System.Object[]}, @{id=30352889; node_id=GA_kwDOOJqfM84BzyX5; type=wait_timer; wait_timer=100}, + @{id=30352890; node_id=GA_kwDOOJqfM84BzyX6; type=branch_policy}} + deployment_branch_policy : @{protected_branches=False; custom_branch_policies=True} ``` - Retrieves details of the "production" environment in the specified repository. + Retrieves details of the "test" environment in the specified repository. .OUTPUTS PSCustomObject diff --git a/src/functions/private/Environments/Get-GitHubEnvironmentList.ps1 b/src/functions/private/Environments/Get-GitHubEnvironmentList.ps1 index 6db7d35de..e7238916b 100644 --- a/src/functions/private/Environments/Get-GitHubEnvironmentList.ps1 +++ b/src/functions/private/Environments/Get-GitHubEnvironmentList.ps1 @@ -10,15 +10,25 @@ filter Get-GitHubEnvironmentList { to use this endpoint with a private repository. .EXAMPLE - Get-GitHubEnvironmentList -Owner 'octocat' -Repository 'Hello-World' -Context $GitHubContext + Get-GitHubEnvironmentList -Owner 'PSModule' -Repository 'EnvironmentTest' Output: - ```powershell - Name : production - Protection : @{required_reviewers=System.Object[]} + ```pwsh + id : 5944178128 + node_id : EN_kwDOOJqfM88AAAABYkz10A + name : test + url : https://api.github.com/repos/PSModule/EnvironmentTest/environments/test + html_url : https://github.com/PSModule/EnvironmentTest/deployments/activity_log?environments_filter=test + created_at : 3/16/2025 11:17:52 PM + updated_at : 3/16/2025 11:17:52 PM + can_admins_bypass : True + protection_rules : {@{id=30352888; node_id=GA_kwDOOJqfM84BzyX4; type=required_reviewers; prevent_self_review=False; + reviewers=System.Object[]}, @{id=30352889; node_id=GA_kwDOOJqfM84BzyX5; type=wait_timer; wait_timer=100}, + @{id=30352890; node_id=GA_kwDOOJqfM84BzyX6; type=branch_policy}} + deployment_branch_policy : @{protected_branches=False; custom_branch_policies=True} ``` - Retrieves the list of environments for the 'Hello-World' repository owned by 'octocat'. + Lists all environments available in the "EnvironmentTest" repository owned by "PSModule". .OUTPUTS PSCustomObject diff --git a/src/functions/public/Environments/Get-GitHubEnvironment.ps1 b/src/functions/public/Environments/Get-GitHubEnvironment.ps1 index 6121ce071..c5b7b77ee 100644 --- a/src/functions/public/Environments/Get-GitHubEnvironment.ps1 +++ b/src/functions/public/Environments/Get-GitHubEnvironment.ps1 @@ -12,27 +12,46 @@ filter Get-GitHubEnvironment { to use this function with a private repository. .EXAMPLE - Get-GitHubEnvironment -Owner "octocat" -Repository "Hello-World" -Name "production" + Get-GitHubEnvironment -Owner 'PSModule' -Repository 'EnvironmentTest' -Name 'test' Output: ```pwsh - Name : production - URL : https://github.com/octocat/Hello-World/environments/production - Protection : @{WaitTimer=0; Reviewers=@()} + id : 5944178128 + node_id : EN_kwDOOJqfM88AAAABYkz10A + name : test + url : https://api.github.com/repos/PSModule/EnvironmentTest/environments/test + html_url : https://github.com/PSModule/EnvironmentTest/deployments/activity_log?environments_filter=test + created_at : 3/16/2025 11:17:52 PM + updated_at : 3/16/2025 11:17:52 PM + can_admins_bypass : True + protection_rules : {@{id=30352888; node_id=GA_kwDOOJqfM84BzyX4; type=required_reviewers; prevent_self_review=False; + reviewers=System.Object[]}, @{id=30352889; node_id=GA_kwDOOJqfM84BzyX5; type=wait_timer; wait_timer=100}, + @{id=30352890; node_id=GA_kwDOOJqfM84BzyX6; type=branch_policy}} + deployment_branch_policy : @{protected_branches=False; custom_branch_policies=True} ``` - Retrieves details of the "production" environment in the specified repository. + Retrieves details of the "test" environment in the specified repository. .EXAMPLE - Get-GitHubEnvironment -Owner "octocat" -Repository "Hello-World" + Get-GitHubEnvironment -Owner 'PSModule' -Repository 'EnvironmentTest' Output: ```pwsh - Name : production - Protection : @{required_reviewers=System.Object[]} + id : 5944178128 + node_id : EN_kwDOOJqfM88AAAABYkz10A + name : test + url : https://api.github.com/repos/PSModule/EnvironmentTest/environments/test + html_url : https://github.com/PSModule/EnvironmentTest/deployments/activity_log?environments_filter=test + created_at : 3/16/2025 11:17:52 PM + updated_at : 3/16/2025 11:17:52 PM + can_admins_bypass : True + protection_rules : {@{id=30352888; node_id=GA_kwDOOJqfM84BzyX4; type=required_reviewers; prevent_self_review=False; + reviewers=System.Object[]}, @{id=30352889; node_id=GA_kwDOOJqfM84BzyX5; type=wait_timer; wait_timer=100}, + @{id=30352890; node_id=GA_kwDOOJqfM84BzyX6; type=branch_policy}} + deployment_branch_policy : @{protected_branches=False; custom_branch_policies=True} ``` - Lists all environments available in the "Hello-World" repository owned by "octocat". + Lists all environments available in the "EnvironmentTest" repository owned by "PSModule". .OUTPUTS PSCustomObject diff --git a/src/functions/public/Environments/Remove-GitHubEnvironment.ps1 b/src/functions/public/Environments/Remove-GitHubEnvironment.ps1 index 91db6ff61..948831290 100644 --- a/src/functions/public/Environments/Remove-GitHubEnvironment.ps1 +++ b/src/functions/public/Environments/Remove-GitHubEnvironment.ps1 @@ -10,26 +10,15 @@ filter Remove-GitHubEnvironment { .EXAMPLE Remove-GitHubEnvironment -Owner 'PSModule' -Repository 'GitHub' -Name 'Production' - Output: - ```powershell - Success: Environment 'Production' deleted from repository 'PSModule/GitHub'. - ``` - Deletes the 'Production' environment from the 'PSModule/GitHub' repository. - .OUTPUTS - PSCustomObject - - .NOTES - Returns the API response indicating success or failure of the deletion process. - .LINK https://psmodule.io/GitHub/Functions/Environments/Remove-GitHubEnvironment/ .LINK [Delete environments](https://docs.github.com/en/rest/deployments/environments?#delete-an-environment) #> - [OutputType([pscustomobject])] + [OutputType([void])] [CmdletBinding(SupportsShouldProcess)] param( # The name of the organization. diff --git a/src/functions/public/Environments/Set-GitHubEnvironment.ps1 b/src/functions/public/Environments/Set-GitHubEnvironment.ps1 index e34eec4d4..f3925138a 100644 --- a/src/functions/public/Environments/Set-GitHubEnvironment.ps1 +++ b/src/functions/public/Environments/Set-GitHubEnvironment.ps1 @@ -15,12 +15,29 @@ filter Set-GitHubEnvironment { OAuth app tokens and personal access tokens (classic) need the `repo` scope to use this endpoint. .EXAMPLE - Set-GitHubEnvironment -Owner "my-org" -Repository "my-repo" -Name "staging" -WaitTimer 30 + $params = @{ + Owner = "my-org" + Repository = "my-repo" + Name = "staging" + WaitTimer = 30 + Reviewers = @{ type = $user.Type; id = $user.id }, @{ type = 'team'; id = $team.DatabaseID } + DeploymentBranchPolicy = 'CustomBranchPolicies' + Set-GitHubEnvironment @params Output: ```powershell - StatusCode : 200 - ResponseBody : @{name=staging; wait_timer=30; deployment_branch_policy=} + id : 5944178128 + node_id : EN_kwDOOJqfM88AAAABYkz10A + name : test + url : https://api.github.com/repos/PSModule/EnvironmentTest/environments/test + html_url : https://github.com/PSModule/EnvironmentTest/deployments/activity_log?environments_filter=test + created_at : 3/16/2025 11:17:52 PM + updated_at : 3/16/2025 11:17:52 PM + can_admins_bypass : True + protection_rules : {@{id=30352888; node_id=GA_kwDOOJqfM84BzyX4; type=required_reviewers; prevent_self_review=False; + reviewers=System.Object[]},@{id=30352889; node_id=GA_kwDOOJqfM84BzyX5; type=wait_timer; wait_timer=100}, + @{id=30352890; node_id=GA_kwDOOJqfM84BzyX6; type=branch_policy}} + deployment_branch_policy : @{protected_branches=False; custom_branch_policies=True} ``` Creates or updates the "staging" environment with a 30-minute wait timer.