From f3be48215dff22c0db349641b16036ac75bbef42 Mon Sep 17 00:00:00 2001 From: Neil White Date: Wed, 8 Jan 2025 07:51:23 -0800 Subject: [PATCH 1/8] Added TLS 1.3 support for PS Core --- GitHubCore.ps1 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/GitHubCore.ps1 b/GitHubCore.ps1 index f869c4dc..e91642d9 100644 --- a/GitHubCore.ps1 +++ b/GitHubCore.ps1 @@ -315,7 +315,10 @@ function Invoke-GHRestMethod # Disable Progress Bar in function scope during Invoke-WebRequest $ProgressPreference = 'SilentlyContinue' - [Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12 + if ($PSVersionTable.PSVersion -lt 7.0.0) + { + [Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12 + } $result = Invoke-WebRequest @params @@ -582,7 +585,10 @@ function Invoke-GHRestMethod } finally { - [Net.ServicePointManager]::SecurityProtocol = $originalSecurityProtocol + if ($PSVersionTable.PSVersion -lt 7.0.0) + { + [Net.ServicePointManager]::SecurityProtocol = $originalSecurityProtocol + } } } From a53d6c1af2864deb75f1b5c529876c941f462b66 Mon Sep 17 00:00:00 2001 From: Neil White Date: Wed, 8 Jan 2025 08:44:12 -0800 Subject: [PATCH 2/8] Fixed PowerShell version comparison --- GitHubCore.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GitHubCore.ps1 b/GitHubCore.ps1 index e91642d9..0d036098 100644 --- a/GitHubCore.ps1 +++ b/GitHubCore.ps1 @@ -315,7 +315,7 @@ function Invoke-GHRestMethod # Disable Progress Bar in function scope during Invoke-WebRequest $ProgressPreference = 'SilentlyContinue' - if ($PSVersionTable.PSVersion -lt 7.0.0) + if ($PSVersionTable.PSVersion -lt [version]"7.0.0") { [Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12 } @@ -585,7 +585,7 @@ function Invoke-GHRestMethod } finally { - if ($PSVersionTable.PSVersion -lt 7.0.0) + if ($PSVersionTable.PSVersion -lt [version]"7.0.0") { [Net.ServicePointManager]::SecurityProtocol = $originalSecurityProtocol } From 6f1b15c2fd187729098543a1a2d4dab47ae1b050 Mon Sep 17 00:00:00 2001 From: Neil White Date: Wed, 8 Jan 2025 08:56:39 -0800 Subject: [PATCH 3/8] Changed double quotes to single-quotes Co-authored-by: Howard Wolosky --- GitHubCore.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GitHubCore.ps1 b/GitHubCore.ps1 index 0d036098..bbe2452c 100644 --- a/GitHubCore.ps1 +++ b/GitHubCore.ps1 @@ -585,7 +585,7 @@ function Invoke-GHRestMethod } finally { - if ($PSVersionTable.PSVersion -lt [version]"7.0.0") + if ($PSVersionTable.PSVersion -lt [Version]'7.0.0') { [Net.ServicePointManager]::SecurityProtocol = $originalSecurityProtocol } From e8356b1b79a5b68ffc805fc564f2e61262ee110d Mon Sep 17 00:00:00 2001 From: Neil White Date: Wed, 8 Jan 2025 08:57:04 -0800 Subject: [PATCH 4/8] Added proper spacing Co-authored-by: Howard Wolosky --- GitHubCore.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GitHubCore.ps1 b/GitHubCore.ps1 index bbe2452c..c8b0e11b 100644 --- a/GitHubCore.ps1 +++ b/GitHubCore.ps1 @@ -317,7 +317,7 @@ function Invoke-GHRestMethod if ($PSVersionTable.PSVersion -lt [version]"7.0.0") { - [Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12 + [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 } $result = Invoke-WebRequest @params From f42326dd187816d825dcd78100cf088892d390b5 Mon Sep 17 00:00:00 2001 From: Neil White Date: Wed, 22 Jan 2025 09:24:16 -0800 Subject: [PATCH 5/8] Implemented TLS 1.3 change. Fixed tests. --- GitHubCore.ps1 | 12 ++------ Helpers.ps1 | 32 +++++++++++++++++++++ Tests/GitHubBranches.tests.ps1 | 16 +++++------ Tests/GitHubCodespaces.tests.ps1 | 2 +- Tests/GitHubDeployments.tests.ps1 | 2 +- Tests/GitHubRepositories.tests.ps1 | 46 +++++++++++++++--------------- Tests/GitHubTeams.tests.ps1 | 4 +-- 7 files changed, 70 insertions(+), 44 deletions(-) diff --git a/GitHubCore.ps1 b/GitHubCore.ps1 index c8b0e11b..0c2abd9c 100644 --- a/GitHubCore.ps1 +++ b/GitHubCore.ps1 @@ -26,6 +26,7 @@ } Set-Variable -Scope Script -Option ReadOnly -Name ValidBodyContainingRequestMethods -Value ('Post', 'Patch', 'Put', 'Delete') +Set-Variable -Scope Script -Option ReadOnly -Name PreferredSecurityProtocolType -Value (Get-PreferredSecurityProtocolType) function Invoke-GHRestMethod { @@ -275,6 +276,7 @@ function Invoke-GHRestMethod } $originalSecurityProtocol = [Net.ServicePointManager]::SecurityProtocol + [Net.ServicePointManager]::SecurityProtocol = $PreferredSecurityProtocolType # When $Save is in use, we need to remember what file we're saving the result to. $outFile = [String]::Empty @@ -315,11 +317,6 @@ function Invoke-GHRestMethod # Disable Progress Bar in function scope during Invoke-WebRequest $ProgressPreference = 'SilentlyContinue' - if ($PSVersionTable.PSVersion -lt [version]"7.0.0") - { - [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 - } - $result = Invoke-WebRequest @params if ($Method -eq 'Delete') @@ -585,10 +582,7 @@ function Invoke-GHRestMethod } finally { - if ($PSVersionTable.PSVersion -lt [Version]'7.0.0') - { - [Net.ServicePointManager]::SecurityProtocol = $originalSecurityProtocol - } + [Net.ServicePointManager]::SecurityProtocol = $originalSecurityProtocol } } diff --git a/Helpers.ps1 b/Helpers.ps1 index 3a3023cd..00573ade 100644 --- a/Helpers.ps1 +++ b/Helpers.ps1 @@ -709,3 +709,35 @@ function New-ErrorRecord return $errorRecord } + +filter Get-PreferredSecurityProtocolType +{ + <# + .SYNOPSIS + Decides the security protocol to use when making a REST API call + + .DESCRIPTION + Decides to use TLS 1.3 if the user is running on PowerShell version 7.0 or higher, otherwise + uses TLS 1.2 if the user is running on Windows PowerShell. + + .NOTES + See https://learn.microsoft.com/en-us/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed#minimum-version + TLS Best Practices https://learn.microsoft.com/en-us/dotnet/framework/network-programming/tls + #> + [CmdletBinding()] + [OutputType([Net.SecurityProtocolType])] + param() + $dotNet47 = 460798 + if (($PSVersionTable.PSVersion -ge [version]'7.0.0') -or ( + (Get-ItemPropertyValue -LiteralPath 'HKLM:SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full' -Name Release) -ge $dotNet47) + ) + { + # .NET 4.7 (460798) is the first .NET version to respect the system default and supports TLS 1.3 out-of-box + return [Net.SecurityProtocolType]::SystemDefault + } + elseif (([Net.SecurityProtocolType] | Get-Member -MemberType Property -Static).Name -contains 'Tls13') + { + return [Net.SecurityProtocolType]::Tls13 + } + else { return [Net.SecurityProtocolType]::Tls12 } +} diff --git a/Tests/GitHubBranches.tests.ps1 b/Tests/GitHubBranches.tests.ps1 index b988166b..de8ebae7 100644 --- a/Tests/GitHubBranches.tests.ps1 +++ b/Tests/GitHubBranches.tests.ps1 @@ -322,7 +322,7 @@ Describe 'GitHubBranches\New-GitHubRepositoryBranch' { } AfterAll -ScriptBlock { - if (Get-Variable -Name repo -ErrorAction SilentlyContinue) + if (Get-Variable -Name repo -ErrorAction Ignore) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -408,7 +408,7 @@ Describe 'GitHubBranches\Remove-GitHubRepositoryBranch' { } AfterAll -ScriptBlock { - if (Get-Variable -Name repo -ErrorAction SilentlyContinue) + if (Get-Variable -Name repo -ErrorAction Ignore) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -470,7 +470,7 @@ Describe 'GitHubBranches\Get-GitHubRepositoryBranchProtectionRule' { } AfterAll -ScriptBlock { - if ($repo) + if (Get-Variable -Name repo -ErrorAction Ignore) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -723,7 +723,7 @@ Describe 'GitHubBranches\New-GitHubRepositoryBranchProtectionRule' { } AfterAll -ScriptBlock { - if ($repo) + if (Get-Variable -Name repo -ErrorAction Ignore) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -785,7 +785,7 @@ Describe 'GitHubBranches\Remove-GitHubRepositoryBranchProtectionRule' { } AfterAll -ScriptBlock { - if ($repo) + if (Get-Variable -Name repo -ErrorAction Ignore) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -975,7 +975,7 @@ Describe 'GitHubBranches\Get-GitHubRepositoryBranchPatternProtectionRule' { } AfterAll -ScriptBlock { - if (Get-Variable -Name repo -ErrorAction SilentlyContinue) + if (Get-Variable -Name repo -ErrorAction Ignore) { $repo | Remove-GitHubRepository -Force } @@ -1303,7 +1303,7 @@ Describe 'GitHubBranches\New-GitHubRepositoryBranchPatternProtectionRule' { } AfterAll -ScriptBlock { - if (Get-Variable -Name repo -ErrorAction SilentlyContinue) + if (Get-Variable -Name repo -ErrorAction Ignore) { $repo | Remove-GitHubRepository -Force } @@ -1364,7 +1364,7 @@ Describe 'GitHubBranches\Remove-GitHubRepositoryBranchPatternProtectionRule' { } AfterAll { - if (Get-Variable -Name repo -ErrorAction SilentlyContinue) + if (Get-Variable -Name repo -ErrorAction Ignore) { $repo | Remove-GitHubRepository -Force } diff --git a/Tests/GitHubCodespaces.tests.ps1 b/Tests/GitHubCodespaces.tests.ps1 index 57f6a663..06013490 100644 --- a/Tests/GitHubCodespaces.tests.ps1 +++ b/Tests/GitHubCodespaces.tests.ps1 @@ -435,7 +435,7 @@ Describe 'GitHubCodespaces\Stop-GitHubCodespace' { } AfterAll { - if (Get-Variable -Name repo -ErrorAction SilentlyContinue) + if (Get-Variable -Name repo -ErrorAction Ignore) { # Should delete any corresponding codespaces along with it $repo | Remove-GitHubRepository -Confirm:$false diff --git a/Tests/GitHubDeployments.tests.ps1 b/Tests/GitHubDeployments.tests.ps1 index 8a781db6..f0952b24 100644 --- a/Tests/GitHubDeployments.tests.ps1 +++ b/Tests/GitHubDeployments.tests.ps1 @@ -200,7 +200,7 @@ Describe 'GitHubDeployments\Remove-GitHubDeploymentEnvironment' { } AfterAll -ScriptBlock { - if ($repo) + if (Get-Variable -Name repo -ErrorAction Ignore) { $repo | Remove-GitHubRepository -Confirm:$false } diff --git a/Tests/GitHubRepositories.tests.ps1 b/Tests/GitHubRepositories.tests.ps1 index ee477fd7..59e96b29 100644 --- a/Tests/GitHubRepositories.tests.ps1 +++ b/Tests/GitHubRepositories.tests.ps1 @@ -60,7 +60,7 @@ Describe 'GitHubRepositories\New-GitHubRepository' { } AfterAll -ScriptBlock { - if ($repo) + if (Get-Variable -Name repo -ErrorAction Ignore) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -97,7 +97,7 @@ Describe 'GitHubRepositories\New-GitHubRepository' { } AfterAll -ScriptBlock { - if ($repo) + if (Get-Variable -Name repo -ErrorAction Ignore) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -162,7 +162,7 @@ Describe 'GitHubRepositories\New-GitHubRepository' { } AfterAll -ScriptBlock { - if ($repo) + if (Get-Variable -Name repo -ErrorAction Ignore) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -195,7 +195,7 @@ Describe 'GitHubRepositories\New-GitHubRepository' { } AfterAll -ScriptBlock { - if ($repo) + if (Get-Variable -Name repo -ErrorAction Ignore) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -227,7 +227,7 @@ Describe 'GitHubRepositories\New-GitHubRepository' { } AfterAll -ScriptBlock { - if ($repo) + if (Get-Variable -Name repo -ErrorAction Ignore) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -259,7 +259,7 @@ Describe 'GitHubRepositories\New-GitHubRepository' { } AfterAll -ScriptBlock { - if ($repo) + if (Get-Variable -Name repo -ErrorAction Ignore) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -291,7 +291,7 @@ Describe 'GitHubRepositories\New-GitHubRepository' { } AfterAll -ScriptBlock { - if ($repo) + if (Get-Variable -Name repo -ErrorAction Ignore) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -323,7 +323,7 @@ Describe 'GitHubRepositories\New-GitHubRepository' { } AfterAll -ScriptBlock { - if ($repo) + if (Get-Variable -Name repo -ErrorAction Ignore) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -355,7 +355,7 @@ Describe 'GitHubRepositories\New-GitHubRepository' { } AfterAll -ScriptBlock { - if ($repo) + if (Get-Variable -Name repo -ErrorAction Ignore) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -387,7 +387,7 @@ Describe 'GitHubRepositories\New-GitHubRepository' { } AfterAll -ScriptBlock { - if ($repo) + if (Get-Variable -Name repo -ErrorAction Ignore) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -419,7 +419,7 @@ Describe 'GitHubRepositories\New-GitHubRepository' { } AfterAll -ScriptBlock { - if ($repo) + if (Get-Variable -Name repo -ErrorAction Ignore) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -477,7 +477,7 @@ Describe 'GitHubRepositories\New-GitHubRepository' { } AfterAll -ScriptBlock { - if ($repo) + if (Get-Variable -Name repo -ErrorAction Ignore) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -515,7 +515,7 @@ Describe 'GitHubRepositories\New-GitHubRepository' { } AfterAll -ScriptBlock { - if ($repo) + if (Get-Variable -Name repo -ErrorAction Ignore) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -577,7 +577,7 @@ Describe 'GitHubRepositories\New-GitHubRepositoryFromTemplate' { } AfterAll { - if (Get-Variable -Name repo -ErrorAction SilentlyContinue) + if (Get-Variable -Name repo -ErrorAction Ignore) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -617,7 +617,7 @@ Describe 'GitHubRepositories\New-GitHubRepositoryFromTemplate' { } AfterAll { - if (Get-Variable -Name repo -ErrorAction SilentlyContinue) + if (Get-Variable -Name repo -ErrorAction Ignore) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -876,7 +876,7 @@ Describe 'GitHubRepositories\Get-GitHubRepository' { } AfterAll { - if (Get-Variable -Name repo -ErrorAction SilentlyContinue) + if (Get-Variable -Name repo -ErrorAction Ignore) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -1279,7 +1279,7 @@ Describe 'GitHubRepositories\Set-GitHubRepository' { } AfterAll -ScriptBlock { - if (Get-Variable -Name repo -ErrorAction SilentlyContinue) + if (Get-Variable -Name repo -ErrorAction Ignore) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -1310,7 +1310,7 @@ Describe 'GitHubRepositories\Set-GitHubRepository' { } AfterAll -ScriptBlock { - if ($repo) + if (Get-Variable -Name repo -ErrorAction Ignore) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -1905,7 +1905,7 @@ Describe 'GitHubRepositories\Get-GitHubRepositoryActionsPermission' { } AfterAll { - if (Get-Variable -Name repo -ErrorAction SilentlyContinue) + if (Get-Variable -Name repo -ErrorAction Ignore) { $repo | Remove-GitHubRepository -Force } @@ -1951,7 +1951,7 @@ Describe 'GitHubRepositories\Set-GitHubRepositoryActionsPermission' { } AfterAll { - if (Get-Variable -Name repo -ErrorAction SilentlyContinue) + if (Get-Variable -Name repo -ErrorAction Ignore) { $repo | Remove-GitHubRepository -Force } @@ -2096,7 +2096,7 @@ Describe 'GitHubRepositories\Get-GitHubRepositoryTeamPermission' { $team | Remove-GitHubTeam -Force } - if (Get-Variable -Name repo -ErrorAction SilentlyContinue) + if (Get-Variable -Name repo -ErrorAction Ignore) { $repo | Remove-GitHubRepository -Force } @@ -2230,7 +2230,7 @@ Describe 'GitHubRepositories\Set-GitHubRepositoryTeamPermission' { $team | Remove-GitHubTeam -Force } - if (Get-Variable -Name repo -ErrorAction SilentlyContinue) + if (Get-Variable -Name repo -ErrorAction Ignore) { $repo | Remove-GitHubRepository -Force } @@ -2384,7 +2384,7 @@ Describe 'GitHubRepositories\Remove-GitHubRepositoryTeamPermission' { $team | Remove-GitHubTeam -Force } - if (Get-Variable -Name repo -ErrorAction SilentlyContinue) + if (Get-Variable -Name repo -ErrorAction Ignore) { $repo | Remove-GitHubRepository -Force } diff --git a/Tests/GitHubTeams.tests.ps1 b/Tests/GitHubTeams.tests.ps1 index 67f34a8a..c8feacbe 100644 --- a/Tests/GitHubTeams.tests.ps1 +++ b/Tests/GitHubTeams.tests.ps1 @@ -196,7 +196,7 @@ Describe 'GitHubTeams\Get-GitHubTeam' { } AfterAll { - if (Get-Variable -Name repo -ErrorAction SilentlyContinue) + if (Get-Variable -Name repo -ErrorAction Ignore) { $repo | Remove-GitHubRepository -Force } @@ -350,7 +350,7 @@ Describe 'GitHubTeams\New-GitHubTeam' { } AfterAll { - if (Get-Variable -Name repo -ErrorAction SilentlyContinue) + if (Get-Variable -Name repo -ErrorAction Ignore) { $repo | Remove-GitHubRepository -Force } From 3f71e2167b4b9c583c6c1d531e3794815d6067c3 Mon Sep 17 00:00:00 2001 From: Neil White Date: Wed, 22 Jan 2025 09:26:30 -0800 Subject: [PATCH 6/8] Made repo variable retrieval call consistent --- Tests/GitHubBranches.tests.ps1 | 16 +++++------ Tests/GitHubCodespaces.tests.ps1 | 2 +- Tests/GitHubDeployments.tests.ps1 | 2 +- Tests/GitHubRepositories.tests.ps1 | 46 +++++++++++++++--------------- Tests/GitHubTeams.tests.ps1 | 4 +-- 5 files changed, 35 insertions(+), 35 deletions(-) diff --git a/Tests/GitHubBranches.tests.ps1 b/Tests/GitHubBranches.tests.ps1 index de8ebae7..c6535221 100644 --- a/Tests/GitHubBranches.tests.ps1 +++ b/Tests/GitHubBranches.tests.ps1 @@ -322,7 +322,7 @@ Describe 'GitHubBranches\New-GitHubRepositoryBranch' { } AfterAll -ScriptBlock { - if (Get-Variable -Name repo -ErrorAction Ignore) + if (Get-Variable -Name repo -ErrorAction SilentlyContinue) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -408,7 +408,7 @@ Describe 'GitHubBranches\Remove-GitHubRepositoryBranch' { } AfterAll -ScriptBlock { - if (Get-Variable -Name repo -ErrorAction Ignore) + if (Get-Variable -Name repo -ErrorAction SilentlyContinue) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -470,7 +470,7 @@ Describe 'GitHubBranches\Get-GitHubRepositoryBranchProtectionRule' { } AfterAll -ScriptBlock { - if (Get-Variable -Name repo -ErrorAction Ignore) + if (Get-Variable -Name repo -ErrorAction SilentlyContinue) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -723,7 +723,7 @@ Describe 'GitHubBranches\New-GitHubRepositoryBranchProtectionRule' { } AfterAll -ScriptBlock { - if (Get-Variable -Name repo -ErrorAction Ignore) + if (Get-Variable -Name repo -ErrorAction SilentlyContinue) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -785,7 +785,7 @@ Describe 'GitHubBranches\Remove-GitHubRepositoryBranchProtectionRule' { } AfterAll -ScriptBlock { - if (Get-Variable -Name repo -ErrorAction Ignore) + if (Get-Variable -Name repo -ErrorAction SilentlyContinue) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -975,7 +975,7 @@ Describe 'GitHubBranches\Get-GitHubRepositoryBranchPatternProtectionRule' { } AfterAll -ScriptBlock { - if (Get-Variable -Name repo -ErrorAction Ignore) + if (Get-Variable -Name repo -ErrorAction SilentlyContinue) { $repo | Remove-GitHubRepository -Force } @@ -1303,7 +1303,7 @@ Describe 'GitHubBranches\New-GitHubRepositoryBranchPatternProtectionRule' { } AfterAll -ScriptBlock { - if (Get-Variable -Name repo -ErrorAction Ignore) + if (Get-Variable -Name repo -ErrorAction SilentlyContinue) { $repo | Remove-GitHubRepository -Force } @@ -1364,7 +1364,7 @@ Describe 'GitHubBranches\Remove-GitHubRepositoryBranchPatternProtectionRule' { } AfterAll { - if (Get-Variable -Name repo -ErrorAction Ignore) + if (Get-Variable -Name repo -ErrorAction SilentlyContinue) { $repo | Remove-GitHubRepository -Force } diff --git a/Tests/GitHubCodespaces.tests.ps1 b/Tests/GitHubCodespaces.tests.ps1 index 06013490..57f6a663 100644 --- a/Tests/GitHubCodespaces.tests.ps1 +++ b/Tests/GitHubCodespaces.tests.ps1 @@ -435,7 +435,7 @@ Describe 'GitHubCodespaces\Stop-GitHubCodespace' { } AfterAll { - if (Get-Variable -Name repo -ErrorAction Ignore) + if (Get-Variable -Name repo -ErrorAction SilentlyContinue) { # Should delete any corresponding codespaces along with it $repo | Remove-GitHubRepository -Confirm:$false diff --git a/Tests/GitHubDeployments.tests.ps1 b/Tests/GitHubDeployments.tests.ps1 index f0952b24..17282761 100644 --- a/Tests/GitHubDeployments.tests.ps1 +++ b/Tests/GitHubDeployments.tests.ps1 @@ -200,7 +200,7 @@ Describe 'GitHubDeployments\Remove-GitHubDeploymentEnvironment' { } AfterAll -ScriptBlock { - if (Get-Variable -Name repo -ErrorAction Ignore) + if (Get-Variable -Name repo -ErrorAction SilentlyContinue) { $repo | Remove-GitHubRepository -Confirm:$false } diff --git a/Tests/GitHubRepositories.tests.ps1 b/Tests/GitHubRepositories.tests.ps1 index 59e96b29..95d619b0 100644 --- a/Tests/GitHubRepositories.tests.ps1 +++ b/Tests/GitHubRepositories.tests.ps1 @@ -60,7 +60,7 @@ Describe 'GitHubRepositories\New-GitHubRepository' { } AfterAll -ScriptBlock { - if (Get-Variable -Name repo -ErrorAction Ignore) + if (Get-Variable -Name repo -ErrorAction SilentlyContinue) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -97,7 +97,7 @@ Describe 'GitHubRepositories\New-GitHubRepository' { } AfterAll -ScriptBlock { - if (Get-Variable -Name repo -ErrorAction Ignore) + if (Get-Variable -Name repo -ErrorAction SilentlyContinue) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -162,7 +162,7 @@ Describe 'GitHubRepositories\New-GitHubRepository' { } AfterAll -ScriptBlock { - if (Get-Variable -Name repo -ErrorAction Ignore) + if (Get-Variable -Name repo -ErrorAction SilentlyContinue) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -195,7 +195,7 @@ Describe 'GitHubRepositories\New-GitHubRepository' { } AfterAll -ScriptBlock { - if (Get-Variable -Name repo -ErrorAction Ignore) + if (Get-Variable -Name repo -ErrorAction SilentlyContinue) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -227,7 +227,7 @@ Describe 'GitHubRepositories\New-GitHubRepository' { } AfterAll -ScriptBlock { - if (Get-Variable -Name repo -ErrorAction Ignore) + if (Get-Variable -Name repo -ErrorAction SilentlyContinue) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -259,7 +259,7 @@ Describe 'GitHubRepositories\New-GitHubRepository' { } AfterAll -ScriptBlock { - if (Get-Variable -Name repo -ErrorAction Ignore) + if (Get-Variable -Name repo -ErrorAction SilentlyContinue) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -291,7 +291,7 @@ Describe 'GitHubRepositories\New-GitHubRepository' { } AfterAll -ScriptBlock { - if (Get-Variable -Name repo -ErrorAction Ignore) + if (Get-Variable -Name repo -ErrorAction SilentlyContinue) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -323,7 +323,7 @@ Describe 'GitHubRepositories\New-GitHubRepository' { } AfterAll -ScriptBlock { - if (Get-Variable -Name repo -ErrorAction Ignore) + if (Get-Variable -Name repo -ErrorAction SilentlyContinue) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -355,7 +355,7 @@ Describe 'GitHubRepositories\New-GitHubRepository' { } AfterAll -ScriptBlock { - if (Get-Variable -Name repo -ErrorAction Ignore) + if (Get-Variable -Name repo -ErrorAction SilentlyContinue) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -387,7 +387,7 @@ Describe 'GitHubRepositories\New-GitHubRepository' { } AfterAll -ScriptBlock { - if (Get-Variable -Name repo -ErrorAction Ignore) + if (Get-Variable -Name repo -ErrorAction SilentlyContinue) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -419,7 +419,7 @@ Describe 'GitHubRepositories\New-GitHubRepository' { } AfterAll -ScriptBlock { - if (Get-Variable -Name repo -ErrorAction Ignore) + if (Get-Variable -Name repo -ErrorAction SilentlyContinue) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -477,7 +477,7 @@ Describe 'GitHubRepositories\New-GitHubRepository' { } AfterAll -ScriptBlock { - if (Get-Variable -Name repo -ErrorAction Ignore) + if (Get-Variable -Name repo -ErrorAction SilentlyContinue) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -515,7 +515,7 @@ Describe 'GitHubRepositories\New-GitHubRepository' { } AfterAll -ScriptBlock { - if (Get-Variable -Name repo -ErrorAction Ignore) + if (Get-Variable -Name repo -ErrorAction SilentlyContinue) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -577,7 +577,7 @@ Describe 'GitHubRepositories\New-GitHubRepositoryFromTemplate' { } AfterAll { - if (Get-Variable -Name repo -ErrorAction Ignore) + if (Get-Variable -Name repo -ErrorAction SilentlyContinue) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -617,7 +617,7 @@ Describe 'GitHubRepositories\New-GitHubRepositoryFromTemplate' { } AfterAll { - if (Get-Variable -Name repo -ErrorAction Ignore) + if (Get-Variable -Name repo -ErrorAction SilentlyContinue) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -876,7 +876,7 @@ Describe 'GitHubRepositories\Get-GitHubRepository' { } AfterAll { - if (Get-Variable -Name repo -ErrorAction Ignore) + if (Get-Variable -Name repo -ErrorAction SilentlyContinue) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -1279,7 +1279,7 @@ Describe 'GitHubRepositories\Set-GitHubRepository' { } AfterAll -ScriptBlock { - if (Get-Variable -Name repo -ErrorAction Ignore) + if (Get-Variable -Name repo -ErrorAction SilentlyContinue) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -1310,7 +1310,7 @@ Describe 'GitHubRepositories\Set-GitHubRepository' { } AfterAll -ScriptBlock { - if (Get-Variable -Name repo -ErrorAction Ignore) + if (Get-Variable -Name repo -ErrorAction SilentlyContinue) { Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } @@ -1905,7 +1905,7 @@ Describe 'GitHubRepositories\Get-GitHubRepositoryActionsPermission' { } AfterAll { - if (Get-Variable -Name repo -ErrorAction Ignore) + if (Get-Variable -Name repo -ErrorAction SilentlyContinue) { $repo | Remove-GitHubRepository -Force } @@ -1951,7 +1951,7 @@ Describe 'GitHubRepositories\Set-GitHubRepositoryActionsPermission' { } AfterAll { - if (Get-Variable -Name repo -ErrorAction Ignore) + if (Get-Variable -Name repo -ErrorAction SilentlyContinue) { $repo | Remove-GitHubRepository -Force } @@ -2096,7 +2096,7 @@ Describe 'GitHubRepositories\Get-GitHubRepositoryTeamPermission' { $team | Remove-GitHubTeam -Force } - if (Get-Variable -Name repo -ErrorAction Ignore) + if (Get-Variable -Name repo -ErrorAction SilentlyContinue) { $repo | Remove-GitHubRepository -Force } @@ -2230,7 +2230,7 @@ Describe 'GitHubRepositories\Set-GitHubRepositoryTeamPermission' { $team | Remove-GitHubTeam -Force } - if (Get-Variable -Name repo -ErrorAction Ignore) + if (Get-Variable -Name repo -ErrorAction SilentlyContinue) { $repo | Remove-GitHubRepository -Force } @@ -2384,7 +2384,7 @@ Describe 'GitHubRepositories\Remove-GitHubRepositoryTeamPermission' { $team | Remove-GitHubTeam -Force } - if (Get-Variable -Name repo -ErrorAction Ignore) + if (Get-Variable -Name repo -ErrorAction SilentlyContinue) { $repo | Remove-GitHubRepository -Force } diff --git a/Tests/GitHubTeams.tests.ps1 b/Tests/GitHubTeams.tests.ps1 index c8feacbe..67f34a8a 100644 --- a/Tests/GitHubTeams.tests.ps1 +++ b/Tests/GitHubTeams.tests.ps1 @@ -196,7 +196,7 @@ Describe 'GitHubTeams\Get-GitHubTeam' { } AfterAll { - if (Get-Variable -Name repo -ErrorAction Ignore) + if (Get-Variable -Name repo -ErrorAction SilentlyContinue) { $repo | Remove-GitHubRepository -Force } @@ -350,7 +350,7 @@ Describe 'GitHubTeams\New-GitHubTeam' { } AfterAll { - if (Get-Variable -Name repo -ErrorAction Ignore) + if (Get-Variable -Name repo -ErrorAction SilentlyContinue) { $repo | Remove-GitHubRepository -Force } From 32e93d91f5c0f2141cfd19dcb23b6858ecbc831c Mon Sep 17 00:00:00 2001 From: Neil White Date: Wed, 22 Jan 2025 09:39:09 -0800 Subject: [PATCH 7/8] Fixed variable missing error in test --- Tests/GitHubTeams.tests.ps1 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Tests/GitHubTeams.tests.ps1 b/Tests/GitHubTeams.tests.ps1 index 67f34a8a..2e4ffc38 100644 --- a/Tests/GitHubTeams.tests.ps1 +++ b/Tests/GitHubTeams.tests.ps1 @@ -954,7 +954,10 @@ Describe 'GitHubTeams\Get-GitHubTeamMember' { } AfterAll { - $team | Remove-GitHubTeam -Force + if (Get-Variable -Name team -ErrorAction SilentlyContinue) + { + $team | Remove-GitHubTeam -Force + } } Context 'Getting team members using TeamName' { From 0ef46ba1a13e327d569e3dd30838bb9f090c232a Mon Sep 17 00:00:00 2001 From: Neil White Date: Wed, 22 Jan 2025 09:47:38 -0800 Subject: [PATCH 8/8] Fixed more strict mode variable errors --- Tests/GitHubCodespaces.tests.ps1 | 10 +++++----- Tests/GitHubDeployments.tests.ps1 | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Tests/GitHubCodespaces.tests.ps1 b/Tests/GitHubCodespaces.tests.ps1 index 57f6a663..07486afc 100644 --- a/Tests/GitHubCodespaces.tests.ps1 +++ b/Tests/GitHubCodespaces.tests.ps1 @@ -209,7 +209,7 @@ Describe 'GitHubCodespaces\New-GitHubCodespace' { } AfterAll { - if ($codespace) + if (Get-Variable -Name codespace -ErrorAction SilentlyContinue) { Remove-GitHubCodespace -CodespaceName $codespace.name -Confirm:$false } @@ -249,7 +249,7 @@ Describe 'GitHubCodespaces\New-GitHubCodespace' { } AfterAll { - if ($codespace) + if (Get-Variable -Name codespace -ErrorAction SilentlyContinue) { Remove-GitHubCodespace -CodespaceName $codespace.name -Confirm:$false } @@ -289,7 +289,7 @@ Describe 'GitHubCodespaces\New-GitHubCodespace' { } AfterAll { - if ($codespace) + if (Get-Variable -Name codespace -ErrorAction SilentlyContinue) { Remove-GitHubCodespace -CodespaceName $codespace.name -Confirm:$false } @@ -329,7 +329,7 @@ Describe 'GitHubCodespaces\New-GitHubCodespace' { } AfterAll { - if ($codespace) + if (Get-Variable -Name codespace -ErrorAction SilentlyContinue) { Remove-GitHubCodespace -CodespaceName $codespace.name -Confirm:$false } @@ -357,7 +357,7 @@ Describe 'GitHubCodespaces\New-GitHubCodespace' { } AfterAll { - if ($codespace) + if (Get-Variable -Name codespace -ErrorAction SilentlyContinue) { Remove-GitHubCodespace -CodespaceName $codespace.name -Confirm:$false } diff --git a/Tests/GitHubDeployments.tests.ps1 b/Tests/GitHubDeployments.tests.ps1 index 17282761..79db0bc4 100644 --- a/Tests/GitHubDeployments.tests.ps1 +++ b/Tests/GitHubDeployments.tests.ps1 @@ -205,12 +205,12 @@ AfterAll -ScriptBlock { $repo | Remove-GitHubRepository -Confirm:$false } - if ($reviewerTeam1) + if (Get-Variable -Name reviewerTeam1 -ErrorAction SilentlyContinue) { $reviewerTeam1 | Remove-GitHubTeam -Confirm:$false } - if ($reviewerTeam2) + if (Get-Variable -Name reviewerTeam2 -ErrorAction SilentlyContinue) { $reviewerTeam2 | Remove-GitHubTeam -Confirm:$false }