Skip to content

Commit dca1183

Browse files
🪲 [Fix]: Load existing config when starting a new session (#211)
## Description This pull request includes changes to the initialization process of the GitHub configuration. The main goal is to improve the handling of the GitHub configuration by ensuring it is properly initialized and loaded from defaults or context when necessary. * Fixes #210 Improvements to GitHub configuration initialization: * [`src/functions/private/Config/Initialize-GitHubConfig.ps1`](diffhunk://#diff-0bd6f61981cdae153b550552b394da11c794e8ad8ae819fbb7bb702022a02e5dL32-L50): Refactored the process block to better handle forced initialization and loading of the GitHub configuration from context or defaults. Added checks to avoid reinitializing if the configuration is already in memory. Changes to default configuration handling: * [`src/variables/private/Config.ps1`](diffhunk://#diff-24f682ffe9ba06c3a7c6620f5c550ddc9eac8bdfb1aefe07961c41cf1a5e9552L18-R18): Set the initial value of `Config` to `$null` instead of creating a new `GitHubConfig` instance. This ensures that the configuration is loaded properly during initialization. ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [x] 🪲 [Fix] - [ ] 🩹 [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 75040b9 commit dca1183

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

src/functions/private/Config/Initialize-GitHubConfig.ps1

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,34 @@
2929
}
3030

3131
process {
32-
Write-Debug "GitHubConfig ID: [$($script:GitHub.Config.ID)]"
33-
Write-Debug "Force: [$Force]"
34-
if (-not $script:GitHub.Config.ID -or $Force) {
35-
try {
36-
Write-Debug 'Attempt to load the stored GitHubConfig from ContextVault'
37-
$context = [GitHubConfig](Get-Context -ID $script:GitHub.Config.ID)
38-
if (-not $context -or $Force) {
39-
Write-Debug 'No stored config found. Loading GitHubConfig from defaults'
40-
$context = Set-Context -ID $script:GitHub.DefaultConfig.ID -Context $script:GitHub.DefaultConfig -PassThru
41-
}
32+
try {
33+
Write-Debug "Force: [$Force]"
34+
if ($Force) {
35+
Write-Debug 'Forcing initialization of GitHubConfig.'
36+
$context = Set-Context -ID $script:GitHub.DefaultConfig.ID -Context $script:GitHub.DefaultConfig -PassThru
37+
$script:GitHub.Config = [GitHubConfig]$context
38+
return
39+
}
40+
41+
Write-Debug "GitHubConfig ID: [$($script:GitHub.Config.ID)]"
42+
if ($null -ne $script:GitHub.Config) {
43+
Write-Debug 'GitHubConfig already initialized and available in memory.'
44+
return
45+
}
46+
47+
Write-Debug 'Attempt to load the stored GitHubConfig from ContextVault'
48+
$context = Get-Context -ID $script:GitHub.DefaultConfig.ID
49+
if ($context) {
4250
Write-Debug 'GitHubConfig loaded into memory.'
4351
$script:GitHub.Config = [GitHubConfig]$context
44-
} catch {
45-
Write-Error $_
46-
throw 'Failed to initialize GitHub config'
52+
return
4753
}
48-
} else {
49-
Write-Debug 'GitHubConfig already initialized and available in memory.'
54+
Write-Debug 'Initializing GitHubConfig from defaults'
55+
$context = Set-Context -ID $script:GitHub.DefaultConfig.ID -Context $script:GitHub.DefaultConfig -PassThru
56+
$script:GitHub.Config = [GitHubConfig]$context
57+
} catch {
58+
Write-Error $_
59+
throw 'Failed to initialize GitHub config'
5060
}
5161
}
5262

src/variables/private/Config.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515
OAuthAppClientID = '7204ae9b0580f2cb8288'
1616
DefaultContext = ''
1717
}
18-
Config = [GitHubConfig]::new()
18+
Config = $null
1919
}

0 commit comments

Comments
 (0)