Skip to content

Commit a2e0254

Browse files
🩹 [Patch]: Add Get-GitHubContextInfo function to list available GitHub contexts (#229)
## Description This pull request introduces a new PowerShell function `Get-GitHubContextInfo`. The function is designed to list available GitHub contexts without retrieving the context data making it better suited to do lightweight queries about available contexts. ## 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 b50de3e commit a2e0254

File tree

9 files changed

+71
-12
lines changed

9 files changed

+71
-12
lines changed

src/functions/private/Auth/Context/Remove-GitHubContext.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '5.0.4' }
1+
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '5.0.5' }
22

33
filter Remove-GitHubContext {
44
<#

src/functions/private/Auth/Context/Set-GitHubContext.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '5.0.4' }
1+
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '5.0.5' }
22

33
function Set-GitHubContext {
44
<#

src/functions/public/Auth/Context/Get-GitHubContext.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '5.0.4' }
1+
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '5.0.5' }
22

33
function Get-GitHubContext {
44
<#
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '5.0.5' }
2+
3+
function Get-GitHubContextInfo {
4+
<#
5+
.SYNOPSIS
6+
Lists the available GitHub contexts without getting the context data.
7+
8+
.DESCRIPTION
9+
Lists the available GitHub contexts without getting the context data.
10+
11+
.EXAMPLE
12+
Get-GitHubContextInfo
13+
14+
Gets the current GitHub context.
15+
16+
.EXAMPLE
17+
Get-GitHubContextInfo -Name 'github.com*'
18+
19+
Gets the GitHub context that matches the name 'github.com*'.
20+
21+
.EXAMPLE
22+
Get-GitHubContextInfo -Name '*/Organization/*'
23+
24+
Gets the GitHub context that matches the name '*/Organization/*'.
25+
#>
26+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
27+
'PSAvoidUsingConvertToSecureStringWithPlainText', '',
28+
Justification = 'Encapsulated in a function. Never leaves as a plain text.'
29+
)]
30+
[OutputType([GitHubContext])]
31+
[CmdletBinding(DefaultParameterSetName = '__AllParameterSets')]
32+
param(
33+
# The name of the context to get.
34+
[Parameter()]
35+
[SupportsWildcards()]
36+
[string] $Name = '*'
37+
)
38+
39+
begin {
40+
$stackPath = Get-PSCallStackPath
41+
Write-Debug "[$stackPath] - Start"
42+
Initialize-GitHubConfig
43+
}
44+
45+
process {
46+
try {
47+
Get-ContextInfo -ID "$($script:GitHub.Config.ID)/$Name"
48+
} catch {
49+
throw $_
50+
}
51+
}
52+
53+
end {
54+
Write-Debug "[$stackPath] - End"
55+
}
56+
}

src/functions/public/Auth/Update-GitHubUserAccessToken.ps1

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
function Update-GitHubUserAccessToken {
1+
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '5.0.5' }
2+
3+
function Update-GitHubUserAccessToken {
24
<#
35
.SYNOPSIS
46
Updates the GitHub access token.
@@ -22,7 +24,8 @@
2224
[OutputType([securestring])]
2325
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Long links for documentation.')]
2426
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Justification = 'Is the CLI part of the module.')]
25-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '', Justification = 'The tokens are recieved as clear text. Mitigating exposure by removing variables and performing garbage collection.')]
27+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '',
28+
Justification = 'The tokens are recieved as clear text. Mitigating exposure by removing variables and performing garbage collection.')]
2629
[CmdletBinding(SupportsShouldProcess)]
2730
param(
2831
# The context to run the command in. Used to get the details for the API call.

src/functions/public/Config/Get-GitHubConfig.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '5.0.4' }
1+
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '5.0.5' }
22

33
function Get-GitHubConfig {
44
<#

src/functions/public/Config/Remove-GitHubConfig.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '5.0.4' }
1+
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '5.0.5' }
22

33
function Remove-GitHubConfig {
44
<#

src/functions/public/Config/Set-GitHubConfig.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '5.0.4' }
1+
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '5.0.5' }
22

33
function Set-GitHubConfig {
44
<#

tests/GitHub.Tests.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Describe 'GitHub' {
6262
PrivateKey = $env:TEST_APP_PRIVATE_KEY
6363
}
6464
{ Connect-GitHubAccount @params } | Should -Not -Throw
65-
$contexts = Get-GitHubContext -ListAvailable -Verbose:$false
65+
$contexts = Get-GitHubContextInfo -Verbose:$false
6666
Write-Verbose ($contexts | Out-String) -Verbose
6767
($contexts).Count | Should -Be 3
6868
}
@@ -72,16 +72,16 @@ Describe 'GitHub' {
7272
PrivateKey = $env:TEST_APP_PRIVATE_KEY
7373
}
7474
{ Connect-GitHubAccount @params -AutoloadInstallations } | Should -Not -Throw
75-
$contexts = Get-GitHubContext -ListAvailable -Verbose:$false
75+
$contexts = Get-GitHubContextInfo -Verbose:$false
7676
Write-Verbose ($contexts | Out-String) -Verbose
7777
($contexts).Count | Should -Be 7
7878
}
7979

8080
It 'Can disconnect a specific context' {
8181
{ Disconnect-GitHubAccount -Context 'github.com/psmodule-test-app/Organization/PSModule' -Silent } | Should -Not -Throw
82-
$contexts = Get-GitHubContext -ListAvailable -Verbose:$false
82+
$contexts = Get-GitHubContextInfo -Name 'github.com/psmodule-test-app/*' -Verbose:$false
8383
Write-Verbose ($contexts | Out-String) -Verbose
84-
($contexts).Count | Should -Be 6
84+
($contexts).Count | Should -Be 3
8585
Connect-GitHubAccount -ClientID $env:TEST_APP_CLIENT_ID -PrivateKey $env:TEST_APP_PRIVATE_KEY -AutoloadInstallations
8686
$contexts = Get-GitHubContext -ListAvailable -Verbose:$false
8787
Write-Verbose ($contexts | Out-String) -Verbose

0 commit comments

Comments
 (0)