Skip to content

🩹 [Patch]: Update environment functions documentation and remove unused environment class #323

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2025
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
68 changes: 0 additions & 68 deletions src/classes/public/Environment/GitHubEnvironment.ps1

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 28 additions & 9 deletions src/functions/public/Environments/Get-GitHubEnvironment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 1 addition & 12 deletions src/functions/public/Environments/Remove-GitHubEnvironment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
23 changes: 20 additions & 3 deletions src/functions/public/Environments/Set-GitHubEnvironment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down