Skip to content

Commit

Permalink
Refactor Get-GitHubContext function to improve context retrieval logi…
Browse files Browse the repository at this point in the history
…c and set DefaultContext in configuration
  • Loading branch information
MariusStorhaug committed Nov 16, 2024
1 parent 6dbd208 commit 8b7927a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/functions/public/Auth/Context/Get-GitHubContext.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ function Get-GitHubContext {
return Get-Context -Name "$($script:Config.Name)/*" -AsPlainText
}

if (-not $Name) {
$defaultContext = Get-ContextSetting -Name 'DefaultContext' -
return Get-Context -Name $script:Config.Name
if ($Name) {
return Get-Context -Name "$($script:Config.Name)/$Name" -AsPlainText
}

Get-Context -Name $script:Config.Name
$defaultContext = Get-ContextSetting -Name 'DefaultContext' -Context $script:Config.Name -AsPlainText
Get-Context -Name "$($script:Config.Name)/$defaultContext"
}
3 changes: 2 additions & 1 deletion src/variables/private/Config.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
$script:Config = @{
Name = 'PSModule.GitHub' # $script:Config.Name
Name = 'PSModule.GitHub' # $script:Config.Name
DefaultContext = 'null'
}
8 changes: 4 additions & 4 deletions tools/dev/UserJourney.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Get-GitHubRepository -Context 'msx.ghe.com/MariusStorhaug'

Connect-GitHub -ClientID '<client_id>' -PrivateKey '<private_key>'
Get-GitHubOrganization
foreach (org) {
Connect-GitHub -Token ***********
Get-GitHubRepository
}
# foreach (org) {
# Connect-GitHub -Token ***********
# Get-GitHubRepository
# }

0 comments on commit 8b7927a

Please sign in to comment.