diff --git a/src/functions/private/Auth/Context/Remove-GitHubContext.ps1 b/src/functions/private/Auth/Context/Remove-GitHubContext.ps1 index 72b5b4246..d3c5a8f37 100644 --- a/src/functions/private/Auth/Context/Remove-GitHubContext.ps1 +++ b/src/functions/private/Auth/Context/Remove-GitHubContext.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '5.0.4' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '5.0.5' } filter Remove-GitHubContext { <# diff --git a/src/functions/private/Auth/Context/Set-GitHubContext.ps1 b/src/functions/private/Auth/Context/Set-GitHubContext.ps1 index 902f7604a..fbba40931 100644 --- a/src/functions/private/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/private/Auth/Context/Set-GitHubContext.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '5.0.4' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '5.0.5' } function Set-GitHubContext { <# diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index f14da0dd1..87857b38f 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '5.0.4' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '5.0.5' } function Get-GitHubContext { <# diff --git a/src/functions/public/Auth/Context/Get-GitHubContextInfo.ps1 b/src/functions/public/Auth/Context/Get-GitHubContextInfo.ps1 new file mode 100644 index 000000000..cd43e4bfe --- /dev/null +++ b/src/functions/public/Auth/Context/Get-GitHubContextInfo.ps1 @@ -0,0 +1,56 @@ +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '5.0.5' } + +function Get-GitHubContextInfo { + <# + .SYNOPSIS + Lists the available GitHub contexts without getting the context data. + + .DESCRIPTION + Lists the available GitHub contexts without getting the context data. + + .EXAMPLE + Get-GitHubContextInfo + + Gets the current GitHub context. + + .EXAMPLE + Get-GitHubContextInfo -Name 'github.com*' + + Gets the GitHub context that matches the name 'github.com*'. + + .EXAMPLE + Get-GitHubContextInfo -Name '*/Organization/*' + + Gets the GitHub context that matches the name '*/Organization/*'. + #> + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidUsingConvertToSecureStringWithPlainText', '', + Justification = 'Encapsulated in a function. Never leaves as a plain text.' + )] + [OutputType([GitHubContext])] + [CmdletBinding(DefaultParameterSetName = '__AllParameterSets')] + param( + # The name of the context to get. + [Parameter()] + [SupportsWildcards()] + [string] $Name = '*' + ) + + begin { + $stackPath = Get-PSCallStackPath + Write-Debug "[$stackPath] - Start" + Initialize-GitHubConfig + } + + process { + try { + Get-ContextInfo -ID "$($script:GitHub.Config.ID)/$Name" + } catch { + throw $_ + } + } + + end { + Write-Debug "[$stackPath] - End" + } +} diff --git a/src/functions/public/Auth/Update-GitHubUserAccessToken.ps1 b/src/functions/public/Auth/Update-GitHubUserAccessToken.ps1 index 237b86f4d..bbce1c0c2 100644 --- a/src/functions/public/Auth/Update-GitHubUserAccessToken.ps1 +++ b/src/functions/public/Auth/Update-GitHubUserAccessToken.ps1 @@ -1,4 +1,6 @@ -function Update-GitHubUserAccessToken { +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '5.0.5' } + +function Update-GitHubUserAccessToken { <# .SYNOPSIS Updates the GitHub access token. @@ -22,7 +24,8 @@ [OutputType([securestring])] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Long links for documentation.')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Justification = 'Is the CLI part of the module.')] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '', Justification = 'The tokens are recieved as clear text. Mitigating exposure by removing variables and performing garbage collection.')] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '', + Justification = 'The tokens are recieved as clear text. Mitigating exposure by removing variables and performing garbage collection.')] [CmdletBinding(SupportsShouldProcess)] param( # The context to run the command in. Used to get the details for the API call. diff --git a/src/functions/public/Config/Get-GitHubConfig.ps1 b/src/functions/public/Config/Get-GitHubConfig.ps1 index 80ad7190b..0e09e7501 100644 --- a/src/functions/public/Config/Get-GitHubConfig.ps1 +++ b/src/functions/public/Config/Get-GitHubConfig.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '5.0.4' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '5.0.5' } function Get-GitHubConfig { <# diff --git a/src/functions/public/Config/Remove-GitHubConfig.ps1 b/src/functions/public/Config/Remove-GitHubConfig.ps1 index fc882ed6c..21da4986c 100644 --- a/src/functions/public/Config/Remove-GitHubConfig.ps1 +++ b/src/functions/public/Config/Remove-GitHubConfig.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '5.0.4' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '5.0.5' } function Remove-GitHubConfig { <# diff --git a/src/functions/public/Config/Set-GitHubConfig.ps1 b/src/functions/public/Config/Set-GitHubConfig.ps1 index feebfc01b..00cc7c744 100644 --- a/src/functions/public/Config/Set-GitHubConfig.ps1 +++ b/src/functions/public/Config/Set-GitHubConfig.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '5.0.4' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '5.0.5' } function Set-GitHubConfig { <# diff --git a/tests/GitHub.Tests.ps1 b/tests/GitHub.Tests.ps1 index a9568e5bd..192e0ccaa 100644 --- a/tests/GitHub.Tests.ps1 +++ b/tests/GitHub.Tests.ps1 @@ -62,7 +62,7 @@ Describe 'GitHub' { PrivateKey = $env:TEST_APP_PRIVATE_KEY } { Connect-GitHubAccount @params } | Should -Not -Throw - $contexts = Get-GitHubContext -ListAvailable -Verbose:$false + $contexts = Get-GitHubContextInfo -Verbose:$false Write-Verbose ($contexts | Out-String) -Verbose ($contexts).Count | Should -Be 3 } @@ -72,16 +72,16 @@ Describe 'GitHub' { PrivateKey = $env:TEST_APP_PRIVATE_KEY } { Connect-GitHubAccount @params -AutoloadInstallations } | Should -Not -Throw - $contexts = Get-GitHubContext -ListAvailable -Verbose:$false + $contexts = Get-GitHubContextInfo -Verbose:$false Write-Verbose ($contexts | Out-String) -Verbose ($contexts).Count | Should -Be 7 } It 'Can disconnect a specific context' { { Disconnect-GitHubAccount -Context 'github.com/psmodule-test-app/Organization/PSModule' -Silent } | Should -Not -Throw - $contexts = Get-GitHubContext -ListAvailable -Verbose:$false + $contexts = Get-GitHubContextInfo -Name 'github.com/psmodule-test-app/*' -Verbose:$false Write-Verbose ($contexts | Out-String) -Verbose - ($contexts).Count | Should -Be 6 + ($contexts).Count | Should -Be 3 Connect-GitHubAccount -ClientID $env:TEST_APP_CLIENT_ID -PrivateKey $env:TEST_APP_PRIVATE_KEY -AutoloadInstallations $contexts = Get-GitHubContext -ListAvailable -Verbose:$false Write-Verbose ($contexts | Out-String) -Verbose