Skip to content

Commit a7cbcc5

Browse files
authoredMar 17, 2025··
🩹 [Patch]: Update environment functions documentation and remove unused environment class (#323)
## Description This pull request includes significant changes to the handling of GitHub environments in the PowerShell module. The most important changes involve the removal of the `Environment` class and its related classes, updates to the example outputs in several functions, and some adjustments to the function signatures. ### Removal of Classes: * [`src/classes/public/Environment/GitHubEnvironment.ps1`](diffhunk://#diff-c657e9b9cbcd747ecab0a2c2a667080554a022f31307be6ba5eb745cf70630bfL1-L68): Removed the `Environment`, `RequiredReviewers`, `BranchPolicy`, and `DeploymentBranchPolicy` classes, which were used to model GitHub environment data. ### Updates to Example Outputs: * [`src/functions/private/Environments/Get-GitHubEnvironmentByName.ps1`](diffhunk://#diff-281ec1cdd72ba78fe2f547115ac26085efe035f4c30b748e579a7b71c3de9882L16-R34): Updated the example output to reflect the new format of environment details, including additional fields like `id`, `node_id`, and `protection_rules`. * [`src/functions/private/Environments/Get-GitHubEnvironmentList.ps1`](diffhunk://#diff-b7e6a0698de85126a8c0bf19e78924ae225511ad39ea20b05b2fcf6d262e82efL13-R31): Updated the example output to show the new format for listing environments, including fields like `id`, `node_id`, `protection_rules`, and `deployment_branch_policy`. * [`src/functions/public/Environments/Get-GitHubEnvironment.ps1`](diffhunk://#diff-4ce9e4defaf029427d3215c1a0688b6bf11a705532e17295851e80b2e8948b0fL15-R54): Updated the example output to reflect the new format of environment details, similar to the changes made in `Get-GitHubEnvironmentByName`. ### Function Signature Adjustments: * [`src/functions/public/Environments/Remove-GitHubEnvironment.ps1`](diffhunk://#diff-7318eee8b888e260d6170db2abcae8cba8146173a0a7036f2756777ebc9fd5e8L13-R21): Changed the output type of the `Remove-GitHubEnvironment` function from `PSCustomObject` to `void`, indicating that it no longer returns an object. * [`src/functions/public/Environments/Set-GitHubEnvironment.ps1`](diffhunk://#diff-0d4fc874a278df0f48aba7cc73b05f002c068d4006e2acb0bdd24ab3eb6574e2L18-R40): Modified the example to use a hashtable for parameters, demonstrating a more complex usage scenario with additional fields like `Reviewers` and `DeploymentBranchPolicy`. ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [x] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas
1 parent dd5c57e commit a7cbcc5

File tree

6 files changed

+79
-103
lines changed

6 files changed

+79
-103
lines changed
 

‎src/classes/public/Environment/GitHubEnvironment.ps1

-68
This file was deleted.

‎src/functions/private/Environments/Get-GitHubEnvironmentByName.ps1

+15-6
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,25 @@ filter Get-GitHubEnvironmentByName {
1313
to use this function with a private repository.
1414
1515
.EXAMPLE
16-
Get-GitHubEnvironmentByName -Owner "my-org" -Repository "my-repo" -Name "production" -Context $GitHubContext
16+
Get-GitHubEnvironment -Owner 'PSModule' -Repository 'EnvironmentTest' -Name 'test'
1717
1818
Output:
19-
```powershell
20-
Name : production
21-
URL : https://github.com/my-org/my-repo/environments/production
22-
Protection : @{WaitTimer=0; Reviewers=@()}
19+
```pwsh
20+
id : 5944178128
21+
node_id : EN_kwDOOJqfM88AAAABYkz10A
22+
name : test
23+
url : https://api.github.com/repos/PSModule/EnvironmentTest/environments/test
24+
html_url : https://github.com/PSModule/EnvironmentTest/deployments/activity_log?environments_filter=test
25+
created_at : 3/16/2025 11:17:52 PM
26+
updated_at : 3/16/2025 11:17:52 PM
27+
can_admins_bypass : True
28+
protection_rules : {@{id=30352888; node_id=GA_kwDOOJqfM84BzyX4; type=required_reviewers; prevent_self_review=False;
29+
reviewers=System.Object[]}, @{id=30352889; node_id=GA_kwDOOJqfM84BzyX5; type=wait_timer; wait_timer=100},
30+
@{id=30352890; node_id=GA_kwDOOJqfM84BzyX6; type=branch_policy}}
31+
deployment_branch_policy : @{protected_branches=False; custom_branch_policies=True}
2332
```
2433
25-
Retrieves details of the "production" environment in the specified repository.
34+
Retrieves details of the "test" environment in the specified repository.
2635
2736
.OUTPUTS
2837
PSCustomObject

‎src/functions/private/Environments/Get-GitHubEnvironmentList.ps1

+15-5
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,25 @@ filter Get-GitHubEnvironmentList {
1010
to use this endpoint with a private repository.
1111
1212
.EXAMPLE
13-
Get-GitHubEnvironmentList -Owner 'octocat' -Repository 'Hello-World' -Context $GitHubContext
13+
Get-GitHubEnvironmentList -Owner 'PSModule' -Repository 'EnvironmentTest'
1414
1515
Output:
16-
```powershell
17-
Name : production
18-
Protection : @{required_reviewers=System.Object[]}
16+
```pwsh
17+
id : 5944178128
18+
node_id : EN_kwDOOJqfM88AAAABYkz10A
19+
name : test
20+
url : https://api.github.com/repos/PSModule/EnvironmentTest/environments/test
21+
html_url : https://github.com/PSModule/EnvironmentTest/deployments/activity_log?environments_filter=test
22+
created_at : 3/16/2025 11:17:52 PM
23+
updated_at : 3/16/2025 11:17:52 PM
24+
can_admins_bypass : True
25+
protection_rules : {@{id=30352888; node_id=GA_kwDOOJqfM84BzyX4; type=required_reviewers; prevent_self_review=False;
26+
reviewers=System.Object[]}, @{id=30352889; node_id=GA_kwDOOJqfM84BzyX5; type=wait_timer; wait_timer=100},
27+
@{id=30352890; node_id=GA_kwDOOJqfM84BzyX6; type=branch_policy}}
28+
deployment_branch_policy : @{protected_branches=False; custom_branch_policies=True}
1929
```
2030
21-
Retrieves the list of environments for the 'Hello-World' repository owned by 'octocat'.
31+
Lists all environments available in the "EnvironmentTest" repository owned by "PSModule".
2232
2333
.OUTPUTS
2434
PSCustomObject

‎src/functions/public/Environments/Get-GitHubEnvironment.ps1

+28-9
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,46 @@ filter Get-GitHubEnvironment {
1212
to use this function with a private repository.
1313
1414
.EXAMPLE
15-
Get-GitHubEnvironment -Owner "octocat" -Repository "Hello-World" -Name "production"
15+
Get-GitHubEnvironment -Owner 'PSModule' -Repository 'EnvironmentTest' -Name 'test'
1616
1717
Output:
1818
```pwsh
19-
Name : production
20-
URL : https://github.com/octocat/Hello-World/environments/production
21-
Protection : @{WaitTimer=0; Reviewers=@()}
19+
id : 5944178128
20+
node_id : EN_kwDOOJqfM88AAAABYkz10A
21+
name : test
22+
url : https://api.github.com/repos/PSModule/EnvironmentTest/environments/test
23+
html_url : https://github.com/PSModule/EnvironmentTest/deployments/activity_log?environments_filter=test
24+
created_at : 3/16/2025 11:17:52 PM
25+
updated_at : 3/16/2025 11:17:52 PM
26+
can_admins_bypass : True
27+
protection_rules : {@{id=30352888; node_id=GA_kwDOOJqfM84BzyX4; type=required_reviewers; prevent_self_review=False;
28+
reviewers=System.Object[]}, @{id=30352889; node_id=GA_kwDOOJqfM84BzyX5; type=wait_timer; wait_timer=100},
29+
@{id=30352890; node_id=GA_kwDOOJqfM84BzyX6; type=branch_policy}}
30+
deployment_branch_policy : @{protected_branches=False; custom_branch_policies=True}
2231
```
2332
24-
Retrieves details of the "production" environment in the specified repository.
33+
Retrieves details of the "test" environment in the specified repository.
2534
2635
.EXAMPLE
27-
Get-GitHubEnvironment -Owner "octocat" -Repository "Hello-World"
36+
Get-GitHubEnvironment -Owner 'PSModule' -Repository 'EnvironmentTest'
2837
2938
Output:
3039
```pwsh
31-
Name : production
32-
Protection : @{required_reviewers=System.Object[]}
40+
id : 5944178128
41+
node_id : EN_kwDOOJqfM88AAAABYkz10A
42+
name : test
43+
url : https://api.github.com/repos/PSModule/EnvironmentTest/environments/test
44+
html_url : https://github.com/PSModule/EnvironmentTest/deployments/activity_log?environments_filter=test
45+
created_at : 3/16/2025 11:17:52 PM
46+
updated_at : 3/16/2025 11:17:52 PM
47+
can_admins_bypass : True
48+
protection_rules : {@{id=30352888; node_id=GA_kwDOOJqfM84BzyX4; type=required_reviewers; prevent_self_review=False;
49+
reviewers=System.Object[]}, @{id=30352889; node_id=GA_kwDOOJqfM84BzyX5; type=wait_timer; wait_timer=100},
50+
@{id=30352890; node_id=GA_kwDOOJqfM84BzyX6; type=branch_policy}}
51+
deployment_branch_policy : @{protected_branches=False; custom_branch_policies=True}
3352
```
3453
35-
Lists all environments available in the "Hello-World" repository owned by "octocat".
54+
Lists all environments available in the "EnvironmentTest" repository owned by "PSModule".
3655
3756
.OUTPUTS
3857
PSCustomObject

‎src/functions/public/Environments/Remove-GitHubEnvironment.ps1

+1-12
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,15 @@ filter Remove-GitHubEnvironment {
1010
.EXAMPLE
1111
Remove-GitHubEnvironment -Owner 'PSModule' -Repository 'GitHub' -Name 'Production'
1212
13-
Output:
14-
```powershell
15-
Success: Environment 'Production' deleted from repository 'PSModule/GitHub'.
16-
```
17-
1813
Deletes the 'Production' environment from the 'PSModule/GitHub' repository.
1914
20-
.OUTPUTS
21-
PSCustomObject
22-
23-
.NOTES
24-
Returns the API response indicating success or failure of the deletion process.
25-
2615
.LINK
2716
https://psmodule.io/GitHub/Functions/Environments/Remove-GitHubEnvironment/
2817
2918
.LINK
3019
[Delete environments](https://docs.github.com/en/rest/deployments/environments?#delete-an-environment)
3120
#>
32-
[OutputType([pscustomobject])]
21+
[OutputType([void])]
3322
[CmdletBinding(SupportsShouldProcess)]
3423
param(
3524
# The name of the organization.

‎src/functions/public/Environments/Set-GitHubEnvironment.ps1

+20-3
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,29 @@ filter Set-GitHubEnvironment {
1515
OAuth app tokens and personal access tokens (classic) need the `repo` scope to use this endpoint.
1616
1717
.EXAMPLE
18-
Set-GitHubEnvironment -Owner "my-org" -Repository "my-repo" -Name "staging" -WaitTimer 30
18+
$params = @{
19+
Owner = "my-org"
20+
Repository = "my-repo"
21+
Name = "staging"
22+
WaitTimer = 30
23+
Reviewers = @{ type = $user.Type; id = $user.id }, @{ type = 'team'; id = $team.DatabaseID }
24+
DeploymentBranchPolicy = 'CustomBranchPolicies'
25+
Set-GitHubEnvironment @params
1926
2027
Output:
2128
```powershell
22-
StatusCode : 200
23-
ResponseBody : @{name=staging; wait_timer=30; deployment_branch_policy=}
29+
id : 5944178128
30+
node_id : EN_kwDOOJqfM88AAAABYkz10A
31+
name : test
32+
url : https://api.github.com/repos/PSModule/EnvironmentTest/environments/test
33+
html_url : https://github.com/PSModule/EnvironmentTest/deployments/activity_log?environments_filter=test
34+
created_at : 3/16/2025 11:17:52 PM
35+
updated_at : 3/16/2025 11:17:52 PM
36+
can_admins_bypass : True
37+
protection_rules : {@{id=30352888; node_id=GA_kwDOOJqfM84BzyX4; type=required_reviewers; prevent_self_review=False;
38+
reviewers=System.Object[]},@{id=30352889; node_id=GA_kwDOOJqfM84BzyX5; type=wait_timer; wait_timer=100},
39+
@{id=30352890; node_id=GA_kwDOOJqfM84BzyX6; type=branch_policy}}
40+
deployment_branch_policy : @{protected_branches=False; custom_branch_policies=True}
2441
```
2542
2643
Creates or updates the "staging" environment with a 30-minute wait timer.

0 commit comments

Comments
 (0)
Please sign in to comment.