Skip to content

Commit

Permalink
Refactor Remove-GitHubConfig function to improve context handling and…
Browse files Browse the repository at this point in the history
… error management
  • Loading branch information
MariusStorhaug committed Dec 8, 2024
1 parent 232ace8 commit 00f8d9a
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/functions/public/Config/Remove-GitHubConfig.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,26 @@ function Remove-GitHubConfig {
[string] $Name
)

$commandName = $MyInvocation.MyCommand.Name
Write-Verbose "[$commandName] - Start"
begin {
$commandName = $MyInvocation.MyCommand.Name
Write-Verbose "[$commandName] - Start"
$moduleContext = Get-Context -ID $script:Config.Name
}

try {
if ($PSCmdlet.ShouldProcess('ContextSetting', 'Remove')) {
Remove-ContextSetting -Name $Name -ID $script:Config.Name
process {
try {
if ($PSCmdlet.ShouldProcess('ContextSetting', 'Remove')) {
$moduleContext.PSObject.Properties.Remove($Name)
}
} catch {
Write-Error $_
Write-Error (Get-PSCallStack | Format-Table | Out-String)
throw 'Failed to connect to GitHub.'
}
} catch {
Write-Error $_
Write-Error (Get-PSCallStack | Format-Table | Out-String)
throw 'Failed to connect to GitHub.'
Set-Context -ID $script:Config.Name -Context $moduleContext
}

Write-Verbose "[$commandName] - End"
end {
Write-Verbose "[$commandName] - End"
}
}

0 comments on commit 00f8d9a

Please sign in to comment.