File tree Expand file tree Collapse file tree 12 files changed +105
-52
lines changed Expand file tree Collapse file tree 12 files changed +105
-52
lines changed Original file line number Diff line number Diff line change 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}
Original file line number Diff line number Diff line change 11function 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
Original file line number Diff line number Diff line change 1- # Requires -Modules @ { ModuleName = ' Context' ; RequiredVersion = ' 5.0.1 ' }
1+ # Requires -Modules @ { ModuleName = ' Context' ; RequiredVersion = ' 5.0.3 ' }
22
33function 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 {
Original file line number Diff line number Diff line change 1- # Requires -Modules @ { ModuleName = ' Context' ; RequiredVersion = ' 5.0.1 ' }
1+ # Requires -Modules @ { ModuleName = ' Context' ; RequiredVersion = ' 5.0.3 ' }
22
33filter 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}
Original file line number Diff line number Diff line change 1- # Requires -Modules @ { ModuleName = ' Context' ; RequiredVersion = ' 5.0.1 ' }
1+ # Requires -Modules @ { ModuleName = ' Context' ; RequiredVersion = ' 5.0.3 ' }
22
33function 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 {
Original file line number Diff line number Diff line change 1- # Requires -Modules @ { ModuleName = ' Context' ; RequiredVersion = ' 5.0.1 ' }
1+ # Requires -Modules @ { ModuleName = ' Context' ; RequiredVersion = ' 5.0.3 ' }
22
33function 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 {
Original file line number Diff line number Diff line change 1- # Requires -Modules @ { ModuleName = ' Context' ; RequiredVersion = ' 5.0.1 ' }
1+ # Requires -Modules @ { ModuleName = ' Context' ; RequiredVersion = ' 5.0.3 ' }
22
33function 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 {
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 1- # Requires -Modules @ { ModuleName = ' Context' ; RequiredVersion = ' 5.0.1 ' }
1+ # Requires -Modules @ { ModuleName = ' Context' ; RequiredVersion = ' 5.0.3 ' }
22
33function 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 {
Original file line number Diff line number Diff line change 22Write-Verbose ' Initializing GitHub PowerShell module...'
33Write-Verbose " Path: $scriptFilePath "
44
5- Initialize-GitHubConfig
6-
75switch ($script :GitHub.EnvironmentType ) {
86 ' GHA' {
97 Write-Verbose ' Detected running on a GitHub Actions runner, preparing environment...'
You can’t perform that action at this time.
0 commit comments