Skip to content

Commit 2d3e1bd

Browse files
🩹 [Patch]: Bump Context to 5.0.3 (#194)
## Description - Bump `Context` to 5.0.3 - Reset vaults before tests. ## 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 c11742e commit 2d3e1bd

File tree

12 files changed

+105
-52
lines changed

12 files changed

+105
-52
lines changed

src/classes/public/Config/GitHubConfig.ps1

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,18 @@
1616

1717
# Simple parameterless constructor
1818
GitHubConfig() {}
19+
20+
# Creates a context object from a hashtable of key-vaule pairs.
21+
GitHubConfig([hashtable]$Properties) {
22+
foreach ($Property in $Properties.Keys) {
23+
$this.$Property = $Properties.$Property
24+
}
25+
}
26+
27+
# Creates a context object from a PSCustomObject.
28+
GitHubConfig([PSCustomObject]$Object) {
29+
$Object.PSObject.Properties | ForEach-Object {
30+
$this.($_.Name) = $_.Value
31+
}
32+
}
1933
}

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

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,49 @@
11
function Initialize-GitHubConfig {
22
<#
33
.SYNOPSIS
4+
Initialize the GitHub module configuration.
45
56
.DESCRIPTION
7+
Initialize the GitHub module configuration.
68
79
.EXAMPLE
810
Initialize-GitHubConfig
11+
12+
Initializes the GitHub module configuration.
13+
14+
.EXAMPLE
15+
Initialize-GitHubConfig -Force
16+
17+
Forces the initialization of the GitHub module configuration.
918
#>
1019
[OutputType([void])]
1120
[CmdletBinding()]
12-
param ()
21+
param (
22+
# Force the initialization of the GitHub config.
23+
[switch] $Force
24+
)
1325

1426
begin {
1527
$commandName = $MyInvocation.MyCommand.Name
1628
Write-Debug "[$commandName] - Start"
1729
}
1830

1931
process {
20-
try {
21-
$context = [GitHubConfig](Get-Context -ID $script:GitHub.Config.ID)
22-
if (-not $context) {
23-
$context = Set-Context -ID $script:GitHub.Config.ID -Context $script:GitHub.Config -PassThru
32+
Write-Verbose "GitHubConfig initialized: [$($script:GitHub.Initialized)]"
33+
Write-Verbose "Force: [$Force]"
34+
if (-not $script:GitHub.Initialized -or $Force) {
35+
try {
36+
$context = [GitHubConfig](Get-Context -ID $script:GitHub.Config.ID)
37+
if (-not $context -or $Force) {
38+
Write-Verbose "Loading GitHubConfig from defaults"
39+
$context = Set-Context -ID $script:GitHub.DefaultConfig.ID -Context $script:GitHub.DefaultConfig -PassThru
40+
}
41+
$script:GitHub.Config = [GitHubConfig]$context
42+
$script:GitHub.Initialized = $true
43+
} catch {
44+
Write-Error $_
45+
throw 'Failed to initialize GitHub config'
2446
}
25-
$script:GitHub.Config = [GitHubConfig]$context
26-
$script:GitHub.Initialized = $true
27-
} catch {
28-
Write-Error $_
29-
throw 'Failed to initialize GitHub config'
3047
}
3148
}
3249

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

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

33
function Get-GitHubContext {
44
<#
@@ -39,6 +39,7 @@ function Get-GitHubContext {
3939
begin {
4040
$commandName = $MyInvocation.MyCommand.Name
4141
Write-Verbose "[$commandName] - Start"
42+
$null = Get-GitHubConfig
4243
}
4344

4445
process {

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '5.0.1' }
1+
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '5.0.3' }
22

33
filter Remove-GitHubContext {
44
<#
@@ -29,14 +29,21 @@ filter Remove-GitHubContext {
2929
[string] $Context
3030
)
3131

32-
$commandName = $MyInvocation.MyCommand.Name
33-
Write-Verbose "[$commandName] - Start"
32+
begin {
33+
$commandName = $MyInvocation.MyCommand.Name
34+
Write-Verbose "[$commandName] - Start"
35+
$null = Get-GitHubConfig
36+
}
3437

35-
$ID = "$($script:GitHub.Config.ID)/$Context"
38+
process {
39+
$ID = "$($script:GitHub.Config.ID)/$Context"
3640

37-
if ($PSCmdlet.ShouldProcess('Remove-Secret', $context.Name)) {
38-
Remove-Context -ID $ID
41+
if ($PSCmdlet.ShouldProcess('Remove-Secret', $context.Name)) {
42+
Remove-Context -ID $ID
43+
}
3944
}
4045

41-
Write-Verbose "[$commandName] - End"
46+
end {
47+
Write-Verbose "[$commandName] - End"
48+
}
4249
}

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

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

33
function Set-GitHubContext {
44
<#
@@ -41,6 +41,7 @@ function Set-GitHubContext {
4141
begin {
4242
$commandName = $MyInvocation.MyCommand.Name
4343
Write-Verbose "[$commandName] - Start"
44+
$null = Get-GitHubConfig
4445
}
4546

4647
process {

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '5.0.1' }
1+
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '5.0.3' }
22

33
function Get-GitHubConfig {
44
<#
@@ -24,15 +24,7 @@ function Get-GitHubConfig {
2424
begin {
2525
$commandName = $MyInvocation.MyCommand.Name
2626
Write-Verbose "[$commandName] - Start"
27-
try {
28-
if (-not $script:GitHub.Initialized) {
29-
Initialize-GitHubConfig
30-
Write-Debug "Connected to context [$($script:GitHub.Config.ID)]"
31-
}
32-
} catch {
33-
Write-Error $_
34-
throw 'Failed to initialize secret vault'
35-
}
27+
Initialize-GitHubConfig
3628
}
3729

3830
process {

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '5.0.1' }
1+
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '5.0.3' }
22

33
function Remove-GitHubConfig {
44
<#
@@ -23,15 +23,7 @@ function Remove-GitHubConfig {
2323
begin {
2424
$commandName = $MyInvocation.MyCommand.Name
2525
Write-Verbose "[$commandName] - Start"
26-
try {
27-
if (-not $script:GitHub.Initialized) {
28-
Initialize-GitHubConfig
29-
Write-Debug "Connected to context [$($script:GitHub.Config.ID)]"
30-
}
31-
} catch {
32-
Write-Error $_
33-
throw 'Failed to initialize secret vault'
34-
}
26+
Initialize-GitHubConfig
3527
}
3628

3729
process {
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
function Reset-GitHubConfig {
2+
<#
3+
.SYNOPSIS
4+
Re-initializes the GitHub module configuration.
5+
6+
.DESCRIPTION
7+
Re-initializes the GitHub module configuration.
8+
9+
.EXAMPLE
10+
Reset-GitHubConfig
11+
12+
Re-initializes the GitHub module configuration.
13+
#>
14+
[OutputType([void])]
15+
[CmdletBinding(SupportsShouldProcess)]
16+
param ()
17+
18+
begin {
19+
$commandName = $MyInvocation.MyCommand.Name
20+
Write-Debug "[$commandName] - Start"
21+
}
22+
23+
process {
24+
try {
25+
if ($PSCmdlet.ShouldProcess('GitHubConfig', 'Reset')) {
26+
Initialize-GitHubConfig -Force
27+
}
28+
} catch {
29+
Write-Error $_
30+
throw 'Failed to reset GitHub module configuration.'
31+
}
32+
}
33+
34+
end {
35+
Write-Debug "[$commandName] - End"
36+
}
37+
}

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '5.0.1' }
1+
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '5.0.3' }
22

33
function Set-GitHubConfig {
44
<#
@@ -27,15 +27,7 @@ function Set-GitHubConfig {
2727
begin {
2828
$commandName = $MyInvocation.MyCommand.Name
2929
Write-Verbose "[$commandName] - Start"
30-
try {
31-
if (-not $script:GitHub.Initialized) {
32-
Initialize-GitHubConfig
33-
Write-Debug "Connected to context [$($script:GitHub.Config.ID)]"
34-
}
35-
} catch {
36-
Write-Error $_
37-
throw 'Failed to initialize secret vault'
38-
}
30+
Initialize-GitHubConfig
3931
}
4032

4133
process {

src/loader.ps1

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
Write-Verbose 'Initializing GitHub PowerShell module...'
33
Write-Verbose "Path: $scriptFilePath"
44

5-
Initialize-GitHubConfig
6-
75
switch ($script:GitHub.EnvironmentType) {
86
'GHA' {
97
Write-Verbose 'Detected running on a GitHub Actions runner, preparing environment...'

0 commit comments

Comments
 (0)