From 7fafee06f34cb638dbdc60a12f6670547021597c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Mar 2025 08:55:00 +0100 Subject: [PATCH 1/5] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Add=20error=20han?= =?UTF-8?q?dling=20in=20`Get-GitHubEnvironmentByName`=20and=20improve=20en?= =?UTF-8?q?vironment=20retrieval=20logic=20in=20`Get-GitHubEnvironment`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Get-GitHubEnvironmentByName.ps1 | 33 ++++++++++--------- .../Environments/Get-GitHubEnvironment.ps1 | 8 +++-- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/functions/private/Environments/Get-GitHubEnvironmentByName.ps1 b/src/functions/private/Environments/Get-GitHubEnvironmentByName.ps1 index 5669f5fee..dd5368509 100644 --- a/src/functions/private/Environments/Get-GitHubEnvironmentByName.ps1 +++ b/src/functions/private/Environments/Get-GitHubEnvironmentByName.ps1 @@ -86,23 +86,26 @@ filter Get-GitHubEnvironmentByName { Uri = $Context.ApiBaseUri + "/repos/$Owner/$Repository/environments/$encodedName" Context = $Context } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response | ForEach-Object { - [GitHubEnvironment]@{ - Name = $_.name - DatabaseID = $_.id - NodeID = $_.node_id - Url = $_.html_url - Owner = $Owner - Repository = $Repository - CreatedAt = $_.created_at - UpdatedAt = $_.updated_at - CanAdminsBypass = $_.can_admins_bypass - ProtectionRules = $_.protection_rules - DeploymentBranchPolicy = $_.deployment_branch_policy + try { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response | ForEach-Object { + [GitHubEnvironment]@{ + Name = $_.name + DatabaseID = $_.id + NodeID = $_.node_id + Url = $_.html_url + Owner = $Owner + Repository = $Repository + CreatedAt = $_.created_at + UpdatedAt = $_.updated_at + CanAdminsBypass = $_.can_admins_bypass + ProtectionRules = $_.protection_rules + DeploymentBranchPolicy = $_.deployment_branch_policy + } } } + } catch { + return } } diff --git a/src/functions/public/Environments/Get-GitHubEnvironment.ps1 b/src/functions/public/Environments/Get-GitHubEnvironment.ps1 index ef54ea8c3..f679a056c 100644 --- a/src/functions/public/Environments/Get-GitHubEnvironment.ps1 +++ b/src/functions/public/Environments/Get-GitHubEnvironment.ps1 @@ -104,8 +104,12 @@ filter Get-GitHubEnvironment { } process { - Get-GitHubEnvironmentList -Owner $Owner -Repository $Repository -PerPage $PerPage -Context $Context | - Where-Object { $_.Name -like $Name } + if ($Name.Contains('*')) { + Get-GitHubEnvironmentList -Owner $Owner -Repository $Repository -PerPage $PerPage -Context $Context | + Where-Object { $_.Name -like $Name } + } else { + Get-GitHubEnvironmentByName -Owner $Owner -Repository $Repository -Name $Name -Context $Context + } } end { From 4003dc86c7190514f131f201f4d1e94fd10ba8b3 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Mar 2025 09:24:42 +0100 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20tests=20?= =?UTF-8?q?for=20`Get-GitHubEnvironment`=20to=20use=20the=20renamed=20'Nam?= =?UTF-8?q?e'=20parameter=20and=20add=20checks=20for=20existing=20environm?= =?UTF-8?q?ents?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Environments.Tests.ps1 | 68 +++++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 24 deletions(-) diff --git a/tests/Environments.Tests.ps1 b/tests/Environments.Tests.ps1 index 0d69552ce..f39d176b7 100644 --- a/tests/Environments.Tests.ps1 +++ b/tests/Environments.Tests.ps1 @@ -36,7 +36,7 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) } It 'Get-GitHubEnvironment - retrieves a specific environment that does not exist yet' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo | Where-Object { $_.Name -eq $environmentName } + $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName $result | Should -BeNullOrEmpty } @@ -47,6 +47,12 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) $result.ProtectionRules.wait_timer | Should -Be 10 } + It 'Get-GitHubEnvironment - retrieves a specific environment that does exist' { + $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName + $result | Should -Not -BeNullOrEmpty + $result.Name | Should -Be $environmentName + } + It 'Set-GitHubEnvironment - creates an environment with a slash in the name' { $result = Set-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" $result | Should -Not -BeNullOrEmpty @@ -58,13 +64,12 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) { Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" | Remove-GitHubEnvironment -Confirm:$false } | Should -Not -Throw - Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" | Should -BeNullOrEmpty } - It 'Get-GitHubEnvironment - retrieves a specific environment' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName + It 'Get-GitHubEnvironment - retrieves a specific environment that does exist' { + $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" $result | Should -Not -BeNullOrEmpty - $result.Name | Should -Be $environmentName + $result.Name | Should -Be "$environmentName/$os" } It 'Get-GitHubEnvironment - lists all environments' { @@ -77,7 +82,7 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) } It 'Get-GitHubEnvironment - retrieves a specific environment that does not exist yet' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo | Where-Object { $_.Name -eq $environmentName } + $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName $result | Should -BeNullOrEmpty } } @@ -102,7 +107,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ } It 'Get-GitHubEnvironment - retrieves a specific environment that does not exist yet' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo | Where-Object { $_.Name -eq $environmentName } + $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName $result | Should -BeNullOrEmpty } @@ -113,6 +118,12 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ $result.ProtectionRules.wait_timer | Should -Be 10 } + It 'Get-GitHubEnvironment - retrieves a specific environment that does exist' { + $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName + $result | Should -Not -BeNullOrEmpty + $result.Name | Should -Be $environmentName + } + It 'Set-GitHubEnvironment - creates an environment with a slash in the name' { $result = Set-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" $result | Should -Not -BeNullOrEmpty @@ -123,13 +134,12 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ { Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" | Remove-GitHubEnvironment -Confirm:$false } | Should -Not -Throw - Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" | Should -BeNullOrEmpty } - It 'Get-GitHubEnvironment - retrieves a specific environment' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName + It 'Get-GitHubEnvironment - retrieves a specific environment that does exist' { + $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" $result | Should -Not -BeNullOrEmpty - $result.Name | Should -Be $environmentName + $result.Name | Should -Be "$environmentName/$os" } It 'Get-GitHubEnvironment - lists all environments' { @@ -142,7 +152,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ } It 'Get-GitHubEnvironment - retrieves a specific environment that does not exist yet' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo | Where-Object { $_.Name -eq $environmentName } + $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName $result | Should -BeNullOrEmpty } } @@ -172,7 +182,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { } It 'Get-GitHubEnvironment - retrieves a specific environment that does not exist yet' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo | Where-Object { $_.Name -eq $environmentName } + $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName $result | Should -BeNullOrEmpty } @@ -183,6 +193,12 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { $result.ProtectionRules.wait_timer | Should -Be 10 } + It 'Get-GitHubEnvironment - retrieves a specific environment that does exist' { + $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName + $result | Should -Not -BeNullOrEmpty + $result.Name | Should -Be $environmentName + } + It 'Set-GitHubEnvironment - creates an environment with a slash in the name' { $result = Set-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" $result | Should -Not -BeNullOrEmpty @@ -194,13 +210,12 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { { Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" | Remove-GitHubEnvironment -Confirm:$false } | Should -Not -Throw - Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" | Should -BeNullOrEmpty } - It 'Get-GitHubEnvironment - retrieves a specific environment' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName + It 'Get-GitHubEnvironment - retrieves a specific environment that does exist' { + $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" $result | Should -Not -BeNullOrEmpty - $result.Name | Should -Be $environmentName + $result.Name | Should -Be "$environmentName/$os" } It 'Get-GitHubEnvironment - lists all environments' { @@ -213,7 +228,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { } It 'Get-GitHubEnvironment - retrieves a specific environment that does not exist yet' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo | Where-Object { $_.Name -eq $environmentName } + $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName $result | Should -BeNullOrEmpty } } @@ -239,7 +254,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { } It 'Get-GitHubEnvironment - retrieves a specific environment that does not exist yet' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo | Where-Object { $_.Name -eq $environmentName } + $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName $result | Should -BeNullOrEmpty } @@ -250,6 +265,12 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { $result.ProtectionRules.wait_timer | Should -Be 10 } + It 'Get-GitHubEnvironment - retrieves a specific environment that does exist' { + $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName + $result | Should -Not -BeNullOrEmpty + $result.Name | Should -Be $environmentName + } + It 'Set-GitHubEnvironment - creates an environment with a slash in the name' { $result = Set-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" $result | Should -Not -BeNullOrEmpty @@ -261,13 +282,12 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { { Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" | Remove-GitHubEnvironment -Confirm:$false } | Should -Not -Throw - Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" | Should -BeNullOrEmpty } - It 'Get-GitHubEnvironment - retrieves a specific environment' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName + It 'Get-GitHubEnvironment - retrieves a specific environment that does exist' { + $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" $result | Should -Not -BeNullOrEmpty - $result.Name | Should -Be $environmentName + $result.Name | Should -Be "$environmentName/$os" } It 'Get-GitHubEnvironment - lists all environments' { @@ -280,7 +300,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { } It 'Get-GitHubEnvironment - retrieves a specific environment that does not exist yet' { - $result = Get-GitHubEnvironment -Owner $owner -Repository $repo | Where-Object { $_.Name -eq $environmentName } + $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName $result | Should -BeNullOrEmpty } } From 9f355b024ff89d658b23a5b128d4125c4d5deb49 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Mar 2025 09:39:47 +0100 Subject: [PATCH 3/5] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20tests=20?= =?UTF-8?q?for=20`Get-GitHubEnvironment`=20to=20ensure=20correct=20retriev?= =?UTF-8?q?al=20of=20environments=20with=20slashes=20in=20their=20names?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Environments.Tests.ps1 | 39 ++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/tests/Environments.Tests.ps1 b/tests/Environments.Tests.ps1 index f39d176b7..0c984c36a 100644 --- a/tests/Environments.Tests.ps1 +++ b/tests/Environments.Tests.ps1 @@ -57,7 +57,12 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) $result = Set-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be "$environmentName/$os" - Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" | Should -Not -BeNullOrEmpty + } + + It 'Get-GitHubEnvironment - retrieves a specific environment with a slash in the name that does exist' { + $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" + $result | Should -Not -BeNullOrEmpty + $result.Name | Should -Be "$environmentName/$os" } It 'Remove-GitHubEnvironment - deletes an environment with a slash in the name' { @@ -68,8 +73,7 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) It 'Get-GitHubEnvironment - retrieves a specific environment that does exist' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" - $result | Should -Not -BeNullOrEmpty - $result.Name | Should -Be "$environmentName/$os" + $result | Should -BeNullOrEmpty } It 'Get-GitHubEnvironment - lists all environments' { @@ -130,6 +134,12 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ $result.Name | Should -Be "$environmentName/$os" } + It 'Get-GitHubEnvironment - retrieves a specific environment with a slash in the name that does exist' { + $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" + $result | Should -Not -BeNullOrEmpty + $result.Name | Should -Be "$environmentName/$os" + } + It 'Remove-GitHubEnvironment - deletes an environment with a slash in the name' { { Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" | Remove-GitHubEnvironment -Confirm:$false @@ -138,8 +148,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ It 'Get-GitHubEnvironment - retrieves a specific environment that does exist' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" - $result | Should -Not -BeNullOrEmpty - $result.Name | Should -Be "$environmentName/$os" + $result | Should -BeNullOrEmpty } It 'Get-GitHubEnvironment - lists all environments' { @@ -203,7 +212,12 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { $result = Set-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be "$environmentName/$os" - Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" | Should -Not -BeNullOrEmpty + } + + It 'Get-GitHubEnvironment - retrieves a specific environment with a slash in the name that does exist' { + $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" + $result | Should -Not -BeNullOrEmpty + $result.Name | Should -Be "$environmentName/$os" } It 'Remove-GitHubEnvironment - deletes an environment with a slash in the name' { @@ -214,8 +228,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { It 'Get-GitHubEnvironment - retrieves a specific environment that does exist' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" - $result | Should -Not -BeNullOrEmpty - $result.Name | Should -Be "$environmentName/$os" + $result | Should -BeNullOrEmpty } It 'Get-GitHubEnvironment - lists all environments' { @@ -275,7 +288,12 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { $result = Set-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be "$environmentName/$os" - Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" | Should -Not -BeNullOrEmpty + } + + It 'Get-GitHubEnvironment - retrieves a specific environment with a slash in the name that does exist' { + $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" + $result | Should -Not -BeNullOrEmpty + $result.Name | Should -Be "$environmentName/$os" } It 'Remove-GitHubEnvironment - deletes an environment with a slash in the name' { @@ -286,8 +304,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { It 'Get-GitHubEnvironment - retrieves a specific environment that does exist' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" - $result | Should -Not -BeNullOrEmpty - $result.Name | Should -Be "$environmentName/$os" + $result | Should -BeNullOrEmpty } It 'Get-GitHubEnvironment - lists all environments' { From 4169d5646b44e1c67034467705f12947e81bb411 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Mar 2025 10:02:07 +0100 Subject: [PATCH 4/5] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20test=20d?= =?UTF-8?q?escriptions=20for=20`Get-GitHubEnvironment`=20to=20clarify=20ex?= =?UTF-8?q?pected=20behavior=20when=20no=20environments=20are=20retrieved?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Environments.Tests.ps1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/Environments.Tests.ps1 b/tests/Environments.Tests.ps1 index 0c984c36a..7c19c9be8 100644 --- a/tests/Environments.Tests.ps1 +++ b/tests/Environments.Tests.ps1 @@ -30,12 +30,12 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } Context 'Environments' { - It 'Get-GitHubEnvironment - lists all environments' { + It 'Get-GitHubEnvironment - lists all environments - retrieves none' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo $result | Should -BeNullOrEmpty } - It 'Get-GitHubEnvironment - retrieves a specific environment that does not exist yet' { + It 'Get-GitHubEnvironment - retrieves a specific environment that does not exist' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName $result | Should -BeNullOrEmpty } @@ -105,7 +105,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } Context 'Environments' { - It 'Get-GitHubEnvironment - lists all environments' { + It 'Get-GitHubEnvironment - lists all environments - retrieves none' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo $result | Should -BeNullOrEmpty } @@ -185,7 +185,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } Context 'Environments' { - It 'Get-GitHubEnvironment - lists all environments' { + It 'Get-GitHubEnvironment - lists all environments - retrieves none' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo $result | Should -BeNullOrEmpty } @@ -261,7 +261,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount } Context 'Environments' { - It 'Get-GitHubEnvironment - lists all environments' { + It 'Get-GitHubEnvironment - lists all environments - retrieves none' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo $result | Should -BeNullOrEmpty } From 92519045611f7b8df5b0baf17d84965113cce13e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Mar 2025 10:10:00 +0100 Subject: [PATCH 5/5] No code changes made; skipping commit. --- tests/Environments.Tests.ps1 | 241 ++++++++++++++--------------------- 1 file changed, 98 insertions(+), 143 deletions(-) diff --git a/tests/Environments.Tests.ps1 b/tests/Environments.Tests.ps1 index 7c19c9be8..0fd0a6ddf 100644 --- a/tests/Environments.Tests.ps1 +++ b/tests/Environments.Tests.ps1 @@ -17,306 +17,261 @@ BeforeAll { $os = $env:RUNNER_OS } -Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT)' { - BeforeAll { - Connect-GitHubAccount -Token $env:TEST_USER_USER_FG_PAT - $owner = 'psmodule-user' - $guid = [guid]::NewGuid().ToString() - $repo = "$repoSuffix-$guid" - New-GitHubRepository -Name $repo -AllowSquashMerge - } - AfterAll { - Remove-GitHubRepository -Owner $owner -Name $repo -Confirm:$false - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - Context 'Environments' { - It 'Get-GitHubEnvironment - lists all environments - retrieves none' { +Describe 'Environments' { + + Context 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT)' { + BeforeAll { + Connect-GitHubAccount -Token $env:TEST_USER_USER_FG_PAT + $owner = 'psmodule-user' + $guid = [guid]::NewGuid().ToString() + $repo = "$repoSuffix-$guid" + New-GitHubRepository -Name $repo -AllowSquashMerge + } + AfterAll { + Remove-GitHubRepository -Owner $owner -Name $repo -Confirm:$false + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount + } + It 'Get-GitHubEnvironment: should return an empty list when no environments exist' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo $result | Should -BeNullOrEmpty } - - It 'Get-GitHubEnvironment - retrieves a specific environment that does not exist' { + It 'Get-GitHubEnvironment: should return null when retrieving a non-existent environment' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName $result | Should -BeNullOrEmpty } - - It 'Set-GitHubEnvironment - creates an environment' { + It 'Set-GitHubEnvironment: should successfully create an environment with a wait timer of 10' { $result = Set-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName -WaitTimer 10 $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be $environmentName $result.ProtectionRules.wait_timer | Should -Be 10 } - - It 'Get-GitHubEnvironment - retrieves a specific environment that does exist' { + It 'Get-GitHubEnvironment: should retrieve the environment that was created' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be $environmentName } - - It 'Set-GitHubEnvironment - creates an environment with a slash in the name' { + It 'Set-GitHubEnvironment: should successfully create an environment with a slash in its name' { $result = Set-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be "$environmentName/$os" } - - It 'Get-GitHubEnvironment - retrieves a specific environment with a slash in the name that does exist' { + It 'Get-GitHubEnvironment: should retrieve the environment with a slash in its name' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be "$environmentName/$os" } - - It 'Remove-GitHubEnvironment - deletes an environment with a slash in the name' { + It 'Remove-GitHubEnvironment: should delete the environment with a slash in its name without errors' { { Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" | Remove-GitHubEnvironment -Confirm:$false } | Should -Not -Throw } - - It 'Get-GitHubEnvironment - retrieves a specific environment that does exist' { + It 'Get-GitHubEnvironment: should return null when retrieving the deleted environment with a slash in its name' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" $result | Should -BeNullOrEmpty } - - It 'Get-GitHubEnvironment - lists all environments' { + It 'Get-GitHubEnvironment: should list one remaining environment' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo $result.Count | Should -Be 1 } - - It 'Remove-GitHubEnvironment - deletes an environment' { + It 'Remove-GitHubEnvironment: should delete the remaining environment without errors' { { Remove-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName -Confirm:$false } | Should -Not -Throw } - - It 'Get-GitHubEnvironment - retrieves a specific environment that does not exist yet' { + It 'Get-GitHubEnvironment: should return null when retrieving an environment that does not exist' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName $result | Should -BeNullOrEmpty } } -} -Describe 'As a user - Fine-grained PAT token - organization account access (ORG_FG_PAT)' { - BeforeAll { - Connect-GitHubAccount -Token $env:TEST_USER_ORG_FG_PAT - $owner = 'psmodule-test-org2' - $guid = [guid]::NewGuid().ToString() - $repo = "$repoSuffix-$guid" - New-GitHubRepository -Owner $owner -Name $repo -AllowSquashMerge - } - AfterAll { - Remove-GitHubRepository -Owner $owner -Name $repo -Confirm:$false - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - Context 'Environments' { - It 'Get-GitHubEnvironment - lists all environments - retrieves none' { + Context 'As a user - Fine-grained PAT token - organization account access (ORG_FG_PAT)' { + BeforeAll { + Connect-GitHubAccount -Token $env:TEST_USER_ORG_FG_PAT + $owner = 'psmodule-test-org2' + $guid = [guid]::NewGuid().ToString() + $repo = "$repoSuffix-$guid" + New-GitHubRepository -Owner $owner -Name $repo -AllowSquashMerge + } + AfterAll { + Remove-GitHubRepository -Owner $owner -Name $repo -Confirm:$false + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount + } + It 'Get-GitHubEnvironment: should return an empty list when no environments exist' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo $result | Should -BeNullOrEmpty } - - It 'Get-GitHubEnvironment - retrieves a specific environment that does not exist yet' { + It 'Get-GitHubEnvironment: should return null when retrieving a non-existent environment' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName $result | Should -BeNullOrEmpty } - - It 'Set-GitHubEnvironment - creates an environment' { + It 'Set-GitHubEnvironment: should successfully create an environment with a wait timer of 10' { $result = Set-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName -WaitTimer 10 $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be $environmentName $result.ProtectionRules.wait_timer | Should -Be 10 } - - It 'Get-GitHubEnvironment - retrieves a specific environment that does exist' { + It 'Get-GitHubEnvironment: should retrieve the environment that was created' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be $environmentName } - - It 'Set-GitHubEnvironment - creates an environment with a slash in the name' { + It 'Set-GitHubEnvironment: should successfully create an environment with a slash in its name' { $result = Set-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be "$environmentName/$os" } - - It 'Get-GitHubEnvironment - retrieves a specific environment with a slash in the name that does exist' { + It 'Get-GitHubEnvironment: should retrieve the environment with a slash in its name' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be "$environmentName/$os" } - - It 'Remove-GitHubEnvironment - deletes an environment with a slash in the name' { + It 'Remove-GitHubEnvironment: should delete the environment with a slash in its name without errors' { { Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" | Remove-GitHubEnvironment -Confirm:$false } | Should -Not -Throw } - - It 'Get-GitHubEnvironment - retrieves a specific environment that does exist' { + It 'Get-GitHubEnvironment: should return null when retrieving the deleted environment with a slash in its name' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" $result | Should -BeNullOrEmpty } - - It 'Get-GitHubEnvironment - lists all environments' { + It 'Get-GitHubEnvironment: should list one remaining environment' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo $result.Count | Should -Be 1 } - - It 'Remove-GitHubEnvironment - deletes an environment' { + It 'Remove-GitHubEnvironment: should delete the remaining environment without errors' { { Remove-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName -Confirm:$false } | Should -Not -Throw } - - It 'Get-GitHubEnvironment - retrieves a specific environment that does not exist yet' { + It 'Get-GitHubEnvironment: should return null when retrieving an environment that does not exist' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName $result | Should -BeNullOrEmpty } } -} -Describe 'As a user - Classic PAT token (PAT)' -Skip {} + Context 'As a user - Classic PAT token (PAT)' -Skip {} -Describe 'As GitHub Actions (GHA)' -Skip {} + Context 'As GitHub Actions (GHA)' -Skip {} -Describe 'As a GitHub App - Enterprise (APP_ENT)' { - BeforeAll { - Connect-GitHubAccount -ClientID $env:TEST_APP_ENT_CLIENT_ID -PrivateKey $env:TEST_APP_ENT_PRIVATE_KEY - $owner = 'psmodule-test-org3' - $guid = [guid]::NewGuid().ToString() - $repo = "$repoSuffix-$guid" - Connect-GitHubApp -Organization $owner -Default - New-GitHubRepository -Owner $owner -Name $repo -AllowSquashMerge - } - AfterAll { - Remove-GitHubRepository -Owner $owner -Name $repo -Confirm:$false - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - Context 'Environments' { - It 'Get-GitHubEnvironment - lists all environments - retrieves none' { + Context 'As a GitHub App - Enterprise (APP_ENT)' { + BeforeAll { + Connect-GitHubAccount -ClientID $env:TEST_APP_ENT_CLIENT_ID -PrivateKey $env:TEST_APP_ENT_PRIVATE_KEY + $owner = 'psmodule-test-org3' + $guid = [guid]::NewGuid().ToString() + $repo = "$repoSuffix-$guid" + Connect-GitHubApp -Organization $owner -Default + New-GitHubRepository -Owner $owner -Name $repo -AllowSquashMerge + } + AfterAll { + Remove-GitHubRepository -Owner $owner -Name $repo -Confirm:$false + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount + } + It 'Get-GitHubEnvironment: should return an empty list when no environments exist' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo $result | Should -BeNullOrEmpty } - - It 'Get-GitHubEnvironment - retrieves a specific environment that does not exist yet' { + It 'Get-GitHubEnvironment: should return null when retrieving a non-existent environment' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName $result | Should -BeNullOrEmpty } - - It 'Set-GitHubEnvironment - creates an environment' { + It 'Set-GitHubEnvironment: should successfully create an environment with a wait timer of 10' { $result = Set-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName -WaitTimer 10 $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be $environmentName $result.ProtectionRules.wait_timer | Should -Be 10 } - - It 'Get-GitHubEnvironment - retrieves a specific environment that does exist' { + It 'Get-GitHubEnvironment: should retrieve the environment that was created' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be $environmentName } - - It 'Set-GitHubEnvironment - creates an environment with a slash in the name' { + It 'Set-GitHubEnvironment: should successfully create an environment with a slash in its name' { $result = Set-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be "$environmentName/$os" } - - It 'Get-GitHubEnvironment - retrieves a specific environment with a slash in the name that does exist' { + It 'Get-GitHubEnvironment: should retrieve the environment with a slash in its name' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be "$environmentName/$os" } - - It 'Remove-GitHubEnvironment - deletes an environment with a slash in the name' { + It 'Remove-GitHubEnvironment: should delete the environment with a slash in its name without errors' { { Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" | Remove-GitHubEnvironment -Confirm:$false } | Should -Not -Throw } - - It 'Get-GitHubEnvironment - retrieves a specific environment that does exist' { + It 'Get-GitHubEnvironment: should return null when retrieving the deleted environment with a slash in its name' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" $result | Should -BeNullOrEmpty } - - It 'Get-GitHubEnvironment - lists all environments' { + It 'Get-GitHubEnvironment: should list one remaining environment' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo $result.Count | Should -Be 1 } - - It 'Remove-GitHubEnvironment - deletes an environment' { + It 'Remove-GitHubEnvironment: should delete the remaining environment without errors' { { Remove-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName -Confirm:$false } | Should -Not -Throw } - - It 'Get-GitHubEnvironment - retrieves a specific environment that does not exist yet' { + It 'Get-GitHubEnvironment: should return null when retrieving an environment that does not exist' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName $result | Should -BeNullOrEmpty } } -} -Describe 'As a GitHub App - Organization (APP_ORG)' { - BeforeAll { - Connect-GitHubAccount -ClientID $env:TEST_APP_ORG_CLIENT_ID -PrivateKey $env:TEST_APP_ORG_PRIVATE_KEY - $owner = 'psmodule-test-org' - $guid = [guid]::NewGuid().ToString() - $repo = "$repoSuffix-$guid" - Connect-GitHubApp -Organization $owner -Default - New-GitHubRepository -Owner $owner -Name $repo -AllowSquashMerge - } - AfterAll { - Remove-GitHubRepository -Owner $owner -Name $repo -Confirm:$false - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount - } - Context 'Environments' { - It 'Get-GitHubEnvironment - lists all environments - retrieves none' { + Context 'As a GitHub App - Organization (APP_ORG)' { + BeforeAll { + Connect-GitHubAccount -ClientID $env:TEST_APP_ORG_CLIENT_ID -PrivateKey $env:TEST_APP_ORG_PRIVATE_KEY + $owner = 'psmodule-test-org' + $guid = [guid]::NewGuid().ToString() + $repo = "$repoSuffix-$guid" + Connect-GitHubApp -Organization $owner -Default + New-GitHubRepository -Owner $owner -Name $repo -AllowSquashMerge + } + AfterAll { + Remove-GitHubRepository -Owner $owner -Name $repo -Confirm:$false + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount + } + It 'Get-GitHubEnvironment: should return an empty list when no environments exist' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo $result | Should -BeNullOrEmpty } - - It 'Get-GitHubEnvironment - retrieves a specific environment that does not exist yet' { + It 'Get-GitHubEnvironment: should return null when retrieving a non-existent environment' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName $result | Should -BeNullOrEmpty } - - It 'Set-GitHubEnvironment - creates an environment' { + It 'Set-GitHubEnvironment: should successfully create an environment with a wait timer of 10' { $result = Set-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName -WaitTimer 10 $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be $environmentName $result.ProtectionRules.wait_timer | Should -Be 10 } - - It 'Get-GitHubEnvironment - retrieves a specific environment that does exist' { + It 'Get-GitHubEnvironment: should retrieve the environment that was created' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be $environmentName } - - It 'Set-GitHubEnvironment - creates an environment with a slash in the name' { + It 'Set-GitHubEnvironment: should successfully create an environment with a slash in its name' { $result = Set-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be "$environmentName/$os" } - - It 'Get-GitHubEnvironment - retrieves a specific environment with a slash in the name that does exist' { + It 'Get-GitHubEnvironment: should retrieve the environment with a slash in its name' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be "$environmentName/$os" } - - It 'Remove-GitHubEnvironment - deletes an environment with a slash in the name' { + It 'Remove-GitHubEnvironment: should delete the environment with a slash in its name without errors' { { Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" | Remove-GitHubEnvironment -Confirm:$false } | Should -Not -Throw } - - It 'Get-GitHubEnvironment - retrieves a specific environment that does exist' { + It 'Get-GitHubEnvironment: should return null when retrieving the deleted environment with a slash in its name' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name "$environmentName/$os" $result | Should -BeNullOrEmpty } - - It 'Get-GitHubEnvironment - lists all environments' { + It 'Get-GitHubEnvironment: should list one remaining environment' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo $result.Count | Should -Be 1 } - - It 'Remove-GitHubEnvironment - deletes an environment' { + It 'Remove-GitHubEnvironment: should delete the remaining environment without errors' { { Remove-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName -Confirm:$false } | Should -Not -Throw } - - It 'Get-GitHubEnvironment - retrieves a specific environment that does not exist yet' { + It 'Get-GitHubEnvironment: should return null when retrieving an environment that does not exist' { $result = Get-GitHubEnvironment -Owner $owner -Repository $repo -Name $environmentName $result | Should -BeNullOrEmpty }