diff --git a/src/functions/private/Apps/Get-GitHubAppByName.ps1 b/src/functions/private/Apps/Get-GitHubAppByName.ps1 index cf9ac29d..e0c461cd 100644 --- a/src/functions/private/Apps/Get-GitHubAppByName.ps1 +++ b/src/functions/private/Apps/Get-GitHubAppByName.ps1 @@ -32,23 +32,27 @@ begin { $commandName = $MyInvocation.MyCommand.Name - Write-Verbose "[$commandName] - Start" + Write-Debug "[$commandName] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { - $inputObject = @{ - Context = $Context - APIEndpoint = "/apps/$AppSlug" - Method = 'GET' - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + try { + $inputObject = @{ + Context = $Context + APIEndpoint = "/apps/$AppSlug" + Method = 'GET' + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ } } end { - Write-Verbose "[$commandName] - End" + Write-Debug "[$commandName] - End" } } diff --git a/src/functions/private/Apps/Get-GitHubAuthenticatedApp.ps1 b/src/functions/private/Apps/Get-GitHubAuthenticatedApp.ps1 index cf0fb44b..f14ced4a 100644 --- a/src/functions/private/Apps/Get-GitHubAuthenticatedApp.ps1 +++ b/src/functions/private/Apps/Get-GitHubAuthenticatedApp.ps1 @@ -29,15 +29,31 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - - $inputObject = @{ - Context = $Context - APIEndpoint = '/app' - Method = 'GET' + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType App } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + process { + try { + $Context = Resolve-GitHubContext -Context $Context + + $inputObject = @{ + Context = $Context + APIEndpoint = '/app' + Method = 'GET' + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ + } + } + end { + Write-Debug "[$commandName] - End" } } diff --git a/src/functions/public/Auth/Assert-GitHubContext.ps1 b/src/functions/private/Auth/Context/Assert-GitHubContext.ps1 similarity index 92% rename from src/functions/public/Auth/Assert-GitHubContext.ps1 rename to src/functions/private/Auth/Context/Assert-GitHubContext.ps1 index ffa46dd3..e101876b 100644 --- a/src/functions/public/Auth/Assert-GitHubContext.ps1 +++ b/src/functions/private/Auth/Context/Assert-GitHubContext.ps1 @@ -27,7 +27,7 @@ begin { $commandName = $MyInvocation.MyCommand.Name - Write-Verbose "[$commandName] - Start" + Write-Debug "[$commandName] - Start" } process { @@ -39,6 +39,6 @@ } end { - Write-Verbose "[$commandName] - End" + Write-Debug "[$commandName] - End" } } diff --git a/src/functions/public/Auth/Context/Remove-GitHubContext.ps1 b/src/functions/private/Auth/Context/Remove-GitHubContext.ps1 similarity index 92% rename from src/functions/public/Auth/Context/Remove-GitHubContext.ps1 rename to src/functions/private/Auth/Context/Remove-GitHubContext.ps1 index abe5a116..653633f8 100644 --- a/src/functions/public/Auth/Context/Remove-GitHubContext.ps1 +++ b/src/functions/private/Auth/Context/Remove-GitHubContext.ps1 @@ -31,7 +31,7 @@ filter Remove-GitHubContext { begin { $commandName = $MyInvocation.MyCommand.Name - Write-Verbose "[$commandName] - Start" + Write-Debug "[$commandName] - Start" $null = Get-GitHubConfig } @@ -44,6 +44,6 @@ filter Remove-GitHubContext { } end { - Write-Verbose "[$commandName] - End" + Write-Debug "[$commandName] - End" } } diff --git a/src/functions/private/Auth/Context/Resolve-GitHubContext.ps1 b/src/functions/private/Auth/Context/Resolve-GitHubContext.ps1 index 1302d806..7bdf2fba 100644 --- a/src/functions/private/Auth/Context/Resolve-GitHubContext.ps1 +++ b/src/functions/private/Auth/Context/Resolve-GitHubContext.ps1 @@ -31,37 +31,41 @@ begin { $commandName = $MyInvocation.MyCommand.Name - Write-Verbose "[$commandName] - Start" + Write-Debug "[$commandName] - Start" Initialize-GitHubConfig } process { - if ($Context -is [string]) { - $contextName = $Context - Write-Verbose "Getting context: [$contextName]" - $Context = Get-GitHubContext -Context $contextName - } + try { + if ($Context -is [string]) { + $contextName = $Context + Write-Debug "Getting context: [$contextName]" + $Context = Get-GitHubContext -Context $contextName + } - if (-not $Context) { - throw "Please provide a valid context or log in using 'Connect-GitHub'." - } + if (-not $Context) { + throw "Please provide a valid context or log in using 'Connect-GitHub'." + } - # switch ($Context.Type) { - # 'App' { - # $availableContexts = Get-GitHubContext -ListAvailable | - # Where-Object { $_.Type -eq 'Installation' -and $_.ClientID -eq $Context.ClientID } - # $params = Get-FunctionParameter -Scope 2 - # Write-Verbose 'Resolving parameters used in called function' - # Write-Verbose ($params | Out-String) - # if ($params.Keys -in 'Owner', 'Organization') { - # $Context = $availableContexts | Where-Object { $_.Owner -eq $params.Owner } - # } - # } - # } + # switch ($Context.Type) { + # 'App' { + # $availableContexts = Get-GitHubContext -ListAvailable | + # Where-Object { $_.Type -eq 'Installation' -and $_.ClientID -eq $Context.ClientID } + # $params = Get-FunctionParameter -Scope 2 + # Write-Debug 'Resolving parameters used in called function' + # Write-Debug ($params | Out-String) + # if ($params.Keys -in 'Owner', 'Organization') { + # $Context = $availableContexts | Where-Object { $_.Owner -eq $params.Owner } + # } + # } + # } + } catch { + throw $_ + } } end { - Write-Verbose "[$commandName] - End" + Write-Debug "[$commandName] - End" Write-Output $Context } } diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/private/Auth/Context/Set-GitHubContext.ps1 similarity index 87% rename from src/functions/public/Auth/Context/Set-GitHubContext.ps1 rename to src/functions/private/Auth/Context/Set-GitHubContext.ps1 index cb420df5..e80fa14e 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/private/Auth/Context/Set-GitHubContext.ps1 @@ -40,22 +40,22 @@ function Set-GitHubContext { begin { $commandName = $MyInvocation.MyCommand.Name - Write-Verbose "[$commandName] - Start" + Write-Debug "[$commandName] - Start" $null = Get-GitHubConfig $contextObj = @{} + $Context } process { - Write-Verbose 'Context:' - $contextObj | Out-String -Stream | ForEach-Object { Write-Verbose $_ } + Write-Debug 'Context:' + $contextObj | Out-String -Stream | ForEach-Object { Write-Debug $_ } # Run functions to get info on the temporary context. try { - Write-Verbose "Getting info on the context [$($contextObj['AuthType'])]." + Write-Debug "Getting info on the context [$($contextObj['AuthType'])]." switch -Regex ($($contextObj['AuthType'])) { 'PAT|UAT|IAT' { $viewer = Get-GitHubViewer -Context $contextObj - $viewer | Out-String -Stream | ForEach-Object { Write-Verbose $_ } + $viewer | Out-String -Stream | ForEach-Object { Write-Debug $_ } if ([string]::IsNullOrEmpty($contextObj['DisplayName'])) { $contextObj['DisplayName'] = [string]$viewer.name } @@ -94,12 +94,12 @@ function Set-GitHubContext { $owner = $gitHubEvent.repository.owner.login $repo = $gitHubEvent.repository.name $gh_sender = $gitHubEvent.sender.login # sender is an automatic variable in Powershell - Write-Verbose "Enterprise: $enterprise" - Write-Verbose "Organization: $organization" - Write-Verbose "Repository: $repo" - Write-Verbose "Repository Owner: $owner" - Write-Verbose "Repository Owner Type: $targetType" - Write-Verbose "Sender: $gh_sender" + Write-Debug "Enterprise: $enterprise" + Write-Debug "Organization: $organization" + Write-Debug "Repository: $repo" + Write-Debug "Repository Owner: $owner" + Write-Debug "Repository Owner Type: $targetType" + Write-Debug "Sender: $gh_sender" if ([string]::IsNullOrEmpty($contextObj['Enterprise'])) { $contextObj['Enterprise'] = [string]$enterprise } @@ -139,11 +139,11 @@ function Set-GitHubContext { throw 'Failed to get info on the context. Unknown logon type.' } } - Write-Verbose "Found [$($contextObj['Type'])] with login: [$($contextObj['Name'])]" - $contextObj | Out-String -Stream | ForEach-Object { Write-Verbose $_ } - Write-Verbose '----------------------------------------------------' + Write-Debug "Found [$($contextObj['Type'])] with login: [$($contextObj['Name'])]" + $contextObj | Out-String -Stream | ForEach-Object { Write-Debug $_ } + Write-Debug '----------------------------------------------------' if ($PSCmdlet.ShouldProcess('Context', 'Set')) { - Write-Verbose "Saving context: [$($script:GitHub.Config.ID)/$($contextObj['Name'])]" + Write-Debug "Saving context: [$($script:GitHub.Config.ID)/$($contextObj['Name'])]" Set-Context -ID "$($script:GitHub.Config.ID)/$($contextObj['Name'])" -Context $contextObj if ($Default) { Set-GitHubDefaultContext -Context $contextObj['Name'] @@ -164,6 +164,6 @@ function Set-GitHubContext { } end { - Write-Verbose "[$commandName] - End" + Write-Debug "[$commandName] - End" } } diff --git a/src/functions/private/Auth/DeviceFlow/Invoke-GitHubDeviceFlowLogin.ps1 b/src/functions/private/Auth/DeviceFlow/Invoke-GitHubDeviceFlowLogin.ps1 index e4b349d3..c2ea74ae 100644 --- a/src/functions/private/Auth/DeviceFlow/Invoke-GitHubDeviceFlowLogin.ps1 +++ b/src/functions/private/Auth/DeviceFlow/Invoke-GitHubDeviceFlowLogin.ps1 @@ -41,25 +41,40 @@ [securestring] $RefreshToken ) - do { - if ($RefreshToken) { - $tokenResponse = Wait-GitHubAccessToken -ClientID $ClientID -RefreshToken $RefreshToken -HostName $HostName - } else { - $deviceCodeResponse = Request-GitHubDeviceCode -ClientID $ClientID -Scope $Scope -HostName $HostName + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + } - $deviceCode = $deviceCodeResponse.device_code - $interval = $deviceCodeResponse.interval - $userCode = $deviceCodeResponse.user_code - $verificationUri = $deviceCodeResponse.verification_uri + process { + try { + do { + if ($RefreshToken) { + $tokenResponse = Wait-GitHubAccessToken -ClientID $ClientID -RefreshToken $RefreshToken -HostName $HostName + } else { + $deviceCodeResponse = Request-GitHubDeviceCode -ClientID $ClientID -Scope $Scope -HostName $HostName - Write-Host '! ' -ForegroundColor DarkYellow -NoNewline - Write-Host "We added the code to your clipboard: [$userCode]" - $userCode | Set-Clipboard - Read-Host "Press Enter to open $HostName in your browser..." - Start-Process $verificationUri + $deviceCode = $deviceCodeResponse.device_code + $interval = $deviceCodeResponse.interval + $userCode = $deviceCodeResponse.user_code + $verificationUri = $deviceCodeResponse.verification_uri - $tokenResponse = Wait-GitHubAccessToken -DeviceCode $deviceCode -ClientID $ClientID -Interval $interval -HostName $HostName + Write-Host '! ' -ForegroundColor DarkYellow -NoNewline + Write-Host "We added the code to your clipboard: [$userCode]" + $userCode | Set-Clipboard + Read-Host "Press Enter to open $HostName in your browser..." + Start-Process $verificationUri + + $tokenResponse = Wait-GitHubAccessToken -DeviceCode $deviceCode -ClientID $ClientID -Interval $interval -HostName $HostName + } + } while ($tokenResponse.error) + $tokenResponse + } catch { + throw $_ } - } while ($tokenResponse.error) - $tokenResponse + } + + end { + Write-Debug "[$commandName] - End" + } } diff --git a/src/functions/private/Auth/DeviceFlow/Request-GitHubAccessToken.ps1 b/src/functions/private/Auth/DeviceFlow/Request-GitHubAccessToken.ps1 index c193c81d..289f7de7 100644 --- a/src/functions/private/Auth/DeviceFlow/Request-GitHubAccessToken.ps1 +++ b/src/functions/private/Auth/DeviceFlow/Request-GitHubAccessToken.ps1 @@ -42,40 +42,51 @@ [string] $HostName ) - $body = @{ - 'client_id' = $ClientID + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" } - if ($PSBoundParameters.ContainsKey('RefreshToken')) { - $body += @{ - 'refresh_token' = (ConvertFrom-SecureString $RefreshToken -AsPlainText) - 'grant_type' = 'refresh_token' + process { + $body = @{ + 'client_id' = $ClientID } - } - if ($PSBoundParameters.ContainsKey('DeviceCode')) { - $body += @{ - 'device_code' = $DeviceCode - 'grant_type' = 'urn:ietf:params:oauth:grant-type:device_code' + if ($PSBoundParameters.ContainsKey('RefreshToken')) { + $body += @{ + 'refresh_token' = (ConvertFrom-SecureString $RefreshToken -AsPlainText) + 'grant_type' = 'refresh_token' + } } - } - $RESTParams = @{ - Uri = "https://$HostName/login/oauth/access_token" - Method = 'POST' - Body = $body - Headers = @{ 'Accept' = 'application/json' } - } + if ($PSBoundParameters.ContainsKey('DeviceCode')) { + $body += @{ + 'device_code' = $DeviceCode + 'grant_type' = 'urn:ietf:params:oauth:grant-type:device_code' + } + } - try { - Write-Debug ($RESTParams.GetEnumerator() | Out-String) + $RESTParams = @{ + Uri = "https://$HostName/login/oauth/access_token" + Method = 'POST' + Body = $body + Headers = @{ 'Accept' = 'application/json' } + } - $tokenResponse = Invoke-RestMethod @RESTParams -Verbose:$false + try { + Write-Debug ($RESTParams.GetEnumerator() | Out-String) + + $tokenResponse = Invoke-RestMethod @RESTParams -Verbose:$false + + Write-Debug ($tokenResponse | ConvertTo-Json | Out-String) + return $tokenResponse + } catch { + Write-Error $_ + throw $_ + } + } - Write-Debug ($tokenResponse | ConvertTo-Json | Out-String) - return $tokenResponse - } catch { - Write-Error $_ - throw $_ + end { + Write-Debug "[$commandName] - End" } } diff --git a/src/functions/private/Auth/DeviceFlow/Request-GitHubDeviceCode.ps1 b/src/functions/private/Auth/DeviceFlow/Request-GitHubDeviceCode.ps1 index 28280f0a..117297cf 100644 --- a/src/functions/private/Auth/DeviceFlow/Request-GitHubDeviceCode.ps1 +++ b/src/functions/private/Auth/DeviceFlow/Request-GitHubDeviceCode.ps1 @@ -34,29 +34,40 @@ [string] $HostName ) - $headers = @{ - Accept = 'application/json' + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" } - $body = @{ - client_id = $ClientID - scope = $Scope - } + process { + $headers = @{ + Accept = 'application/json' + } - $RESTParams = @{ - Uri = "https://$HostName/login/device/code" - Method = 'POST' - Body = $body - Headers = $headers - } + $body = @{ + client_id = $ClientID + scope = $Scope + } + + $RESTParams = @{ + Uri = "https://$HostName/login/device/code" + Method = 'POST' + Body = $body + Headers = $headers + } - try { - Write-Debug ($RESTParams.GetEnumerator() | Out-String) + try { + Write-Debug ($RESTParams.GetEnumerator() | Out-String) + + $deviceCodeResponse = Invoke-RestMethod @RESTParams -Verbose:$false + return $deviceCodeResponse + } catch { + Write-Error $_ + throw $_ + } + } - $deviceCodeResponse = Invoke-RestMethod @RESTParams -Verbose:$false - return $deviceCodeResponse - } catch { - Write-Error $_ - throw $_ + end { + Write-Debug "[$commandName] - End" } } diff --git a/src/functions/private/Auth/DeviceFlow/Test-GitHubAccessTokenRefreshRequired.ps1 b/src/functions/private/Auth/DeviceFlow/Test-GitHubAccessTokenRefreshRequired.ps1 index bba2179d..e2d04b00 100644 --- a/src/functions/private/Auth/DeviceFlow/Test-GitHubAccessTokenRefreshRequired.ps1 +++ b/src/functions/private/Auth/DeviceFlow/Test-GitHubAccessTokenRefreshRequired.ps1 @@ -20,10 +20,24 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - $tokenExpirationDate = $Context.TokenExpirationDate - $currentDateTime = Get-Date - $remainingDuration = [datetime]$tokenExpirationDate - $currentDateTime + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + } - $remainingDuration.TotalHours -lt $script:GitHub.Config.AccessTokenGracePeriodInHours + process { + try { + $tokenExpirationDate = $Context.TokenExpirationDate + $currentDateTime = Get-Date + $remainingDuration = [datetime]$tokenExpirationDate - $currentDateTime + $remainingDuration.TotalHours -lt $script:GitHub.Config.AccessTokenGracePeriodInHours + } catch { + throw $_ + } + } + + end { + Write-Debug "[$commandName] - End" + } } diff --git a/src/functions/private/Auth/DeviceFlow/Wait-GitHubAccessToken.ps1 b/src/functions/private/Auth/DeviceFlow/Wait-GitHubAccessToken.ps1 index 74d60286..a02490a3 100644 --- a/src/functions/private/Auth/DeviceFlow/Wait-GitHubAccessToken.ps1 +++ b/src/functions/private/Auth/DeviceFlow/Wait-GitHubAccessToken.ps1 @@ -49,68 +49,83 @@ [int] $Interval = 5 ) - do { - if ($RefreshToken) { - $response = Request-GitHubAccessToken -ClientID $ClientID -RefreshToken $RefreshToken -HostName $HostName - } else { - $response = Request-GitHubAccessToken -ClientID $ClientID -DeviceCode $DeviceCode -HostName $HostName - } - if ($response.error) { - switch ($response.error) { - 'authorization_pending' { - # The user has not yet entered the code. - # Wait, then poll again. - Write-Debug $response.error_description - Start-Sleep -Seconds $interval - continue - } - 'slow_down' { - # The app polled too fast. - # Wait for the interval plus 5 seconds, then poll again. - Write-Debug $response.error_description - Start-Sleep -Seconds ($interval + 5) - continue - } - 'expired_token' { - # The 'device_code' expired, and the process needs to restart. - Write-Error $response.error_description - exit 1 - } - 'unsupported_grant_type' { - # The 'grant_type' is not supported. - Write-Error $response.error_description - exit 1 - } - 'incorrect_client_credentials' { - # The 'client_id' is not valid. - Write-Error $response.error_description - exit 1 - } - 'incorrect_device_code' { - # The 'device_code' is not valid. - Write-Error $response.error_description - exit 2 - } - 'access_denied' { - # The user cancelled the process. Stop polling. - Write-Error $response.error_description - exit 1 - } - 'device_flow_disabled' { - # The GitHub App does not support the Device Flow. - Write-Error $response.error_description - exit 1 + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + } + + process { + try { + do { + if ($RefreshToken) { + $response = Request-GitHubAccessToken -ClientID $ClientID -RefreshToken $RefreshToken -HostName $HostName + } else { + $response = Request-GitHubAccessToken -ClientID $ClientID -DeviceCode $DeviceCode -HostName $HostName } - default { - # The response contains an access token. Stop polling. - Write-Error 'Unknown error:' - Write-Error $response.error - Write-Error $response.error_description - Write-Error $response.error_uri - break + if ($response.error) { + switch ($response.error) { + 'authorization_pending' { + # The user has not yet entered the code. + # Wait, then poll again. + Write-Debug $response.error_description + Start-Sleep -Seconds $interval + continue + } + 'slow_down' { + # The app polled too fast. + # Wait for the interval plus 5 seconds, then poll again. + Write-Debug $response.error_description + Start-Sleep -Seconds ($interval + 5) + continue + } + 'expired_token' { + # The 'device_code' expired, and the process needs to restart. + Write-Error $response.error_description + exit 1 + } + 'unsupported_grant_type' { + # The 'grant_type' is not supported. + Write-Error $response.error_description + exit 1 + } + 'incorrect_client_credentials' { + # The 'client_id' is not valid. + Write-Error $response.error_description + exit 1 + } + 'incorrect_device_code' { + # The 'device_code' is not valid. + Write-Error $response.error_description + exit 2 + } + 'access_denied' { + # The user cancelled the process. Stop polling. + Write-Error $response.error_description + exit 1 + } + 'device_flow_disabled' { + # The GitHub App does not support the Device Flow. + Write-Error $response.error_description + exit 1 + } + default { + # The response contains an access token. Stop polling. + Write-Error 'Unknown error:' + Write-Error $response.error + Write-Error $response.error_description + Write-Error $response.error_uri + break + } + } } - } + } until ($response.access_token) + $response + } catch { + throw $_ } - } until ($response.access_token) - $response + } + + end { + Write-Debug "[$commandName] - End" + } } diff --git a/src/functions/private/Commands/ConvertFrom-GitHubOutput.ps1 b/src/functions/private/Commands/ConvertFrom-GitHubOutput.ps1 index f267a7d4..4d0c00ec 100644 --- a/src/functions/private/Commands/ConvertFrom-GitHubOutput.ps1 +++ b/src/functions/private/Commands/ConvertFrom-GitHubOutput.ps1 @@ -49,6 +49,8 @@ ) begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" $lines = @() } @@ -128,8 +130,10 @@ $i++ } if ($AsHashtable) { - return $result + $result + } else { + [PSCustomObject]$result } - [PSCustomObject]$result + Write-Debug "[$commandName] - End" } } diff --git a/src/functions/private/Commands/ConvertTo-GitHubOutput.ps1 b/src/functions/private/Commands/ConvertTo-GitHubOutput.ps1 index 0b9d7236..a2016556 100644 --- a/src/functions/private/Commands/ConvertTo-GitHubOutput.ps1 +++ b/src/functions/private/Commands/ConvertTo-GitHubOutput.ps1 @@ -46,32 +46,47 @@ [object] $InputObject ) - $outputLines = @() - - if ($InputObject -is [hashtable]) { - $InputObject = [PSCustomObject]$InputObject + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" } - foreach ($property in $InputObject.PSObject.Properties) { - $key = $property.Name - $value = $property.Value + process { + try { + $outputLines = @() - # Convert hashtable or PSCustomObject to compressed JSON - if ($value -is [hashtable] -or $value -is [PSCustomObject]) { - $value = $value | ConvertTo-Json -Compress - } + if ($InputObject -is [hashtable]) { + $InputObject = [PSCustomObject]$InputObject + } + + foreach ($property in $InputObject.PSObject.Properties) { + $key = $property.Name + $value = $property.Value - if ($value -is [string] -and $value.Contains("`n")) { - # Multi-line value - $guid = [Guid]::NewGuid().ToString() - $EOFMarker = "EOF_$guid" - $outputLines += "$key<<$EOFMarker" - $outputLines += $value - $outputLines += $EOFMarker - } else { - # Single-line value - $outputLines += "$key=$value" + # Convert hashtable or PSCustomObject to compressed JSON + if ($value -is [hashtable] -or $value -is [PSCustomObject]) { + $value = $value | ConvertTo-Json -Compress + } + + if ($value -is [string] -and $value.Contains("`n")) { + # Multi-line value + $guid = [Guid]::NewGuid().ToString() + $EOFMarker = "EOF_$guid" + $outputLines += "$key<<$EOFMarker" + $outputLines += $value + $outputLines += $EOFMarker + } else { + # Single-line value + $outputLines += "$key=$value" + } + } + $outputLines + } catch { + throw $_ } } - $outputLines + + end { + Write-Debug "[$commandName] - End" + } } diff --git a/src/functions/private/Config/Initialize-GitHubConfig.ps1 b/src/functions/private/Config/Initialize-GitHubConfig.ps1 index 4bbc8bab..e99769f9 100644 --- a/src/functions/private/Config/Initialize-GitHubConfig.ps1 +++ b/src/functions/private/Config/Initialize-GitHubConfig.ps1 @@ -29,24 +29,24 @@ } process { - Write-Verbose "GitHubConfig ID: [$($script:GitHub.Config.ID)]" - Write-Verbose "Force: [$Force]" + Write-Debug "GitHubConfig ID: [$($script:GitHub.Config.ID)]" + Write-Debug "Force: [$Force]" if (-not $script:GitHub.Config.ID -or $Force) { try { - Write-Verbose 'Attempt to load the stored GitHubConfig from ContextVault' + Write-Debug 'Attempt to load the stored GitHubConfig from ContextVault' $context = [GitHubConfig](Get-Context -ID $script:GitHub.Config.ID) if (-not $context -or $Force) { - Write-Verbose 'No stored config found. Loading GitHubConfig from defaults' + Write-Debug 'No stored config found. Loading GitHubConfig from defaults' $context = Set-Context -ID $script:GitHub.DefaultConfig.ID -Context $script:GitHub.DefaultConfig -PassThru } - Write-Verbose 'GitHubConfig loaded into memory.' + Write-Debug 'GitHubConfig loaded into memory.' $script:GitHub.Config = [GitHubConfig]$context } catch { Write-Error $_ throw 'Failed to initialize GitHub config' } } else { - Write-Verbose 'GitHubConfig already initialized and available in memory.' + Write-Debug 'GitHubConfig already initialized and available in memory.' } } diff --git a/src/functions/private/Gitignore/Get-GitHubGitignoreByName.ps1 b/src/functions/private/Gitignore/Get-GitHubGitignoreByName.ps1 index 777cb263..f5371d92 100644 --- a/src/functions/private/Gitignore/Get-GitHubGitignoreByName.ps1 +++ b/src/functions/private/Gitignore/Get-GitHubGitignoreByName.ps1 @@ -28,19 +28,30 @@ ) begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { - $inputObject = @{ - Context = $Context - APIEndpoint = "/gitignore/templates/$Name" - Accept = 'application/vnd.github.raw+json' - Method = 'GET' + try { + $inputObject = @{ + Context = $Context + APIEndpoint = "/gitignore/templates/$Name" + Accept = 'application/vnd.github.raw+json' + Method = 'GET' + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ } + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + end { + Write-Debug "[$commandName] - End" } } diff --git a/src/functions/private/Gitignore/Get-GitHubGitignoreList.ps1 b/src/functions/private/Gitignore/Get-GitHubGitignoreList.ps1 index 1f522c51..9dc4690f 100644 --- a/src/functions/private/Gitignore/Get-GitHubGitignoreList.ps1 +++ b/src/functions/private/Gitignore/Get-GitHubGitignoreList.ps1 @@ -26,18 +26,29 @@ ) begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { - $inputObject = @{ - Context = $Context - APIEndpoint = '/gitignore/templates' - Method = 'GET' + try { + $inputObject = @{ + Context = $Context + APIEndpoint = '/gitignore/templates' + Method = 'GET' + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ } + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + end { + Write-Debug "[$commandName] - End" } } diff --git a/src/functions/private/License/Get-GitHubLicenseByName.ps1 b/src/functions/private/License/Get-GitHubLicenseByName.ps1 index e14974dd..847534ad 100644 --- a/src/functions/private/License/Get-GitHubLicenseByName.ps1 +++ b/src/functions/private/License/Get-GitHubLicenseByName.ps1 @@ -31,19 +31,30 @@ ) begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { - $inputObject = @{ - Context = $Context - APIEndpoint = "/licenses/$Name" - Accept = 'application/vnd.github+json' - Method = 'GET' + try { + $inputObject = @{ + Context = $Context + APIEndpoint = "/licenses/$Name" + Accept = 'application/vnd.github+json' + Method = 'GET' + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ } + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + end { + Write-Debug "[$commandName] - End" } } diff --git a/src/functions/private/License/Get-GitHubLicenseList.ps1 b/src/functions/private/License/Get-GitHubLicenseList.ps1 index 6cefaf8b..d351783a 100644 --- a/src/functions/private/License/Get-GitHubLicenseList.ps1 +++ b/src/functions/private/License/Get-GitHubLicenseList.ps1 @@ -25,14 +25,30 @@ [string] $Context ) - $inputObject = @{ - Context = $Context - APIEndpoint = '/licenses' - Method = 'GET' + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + process { + try { + $inputObject = @{ + Context = $Context + APIEndpoint = '/licenses' + Method = 'GET' + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ + } } + end { + Write-Debug "[$commandName] - End" + } } diff --git a/src/functions/private/License/Get-GitHubRepositoryLicense.ps1 b/src/functions/private/License/Get-GitHubRepositoryLicense.ps1 index 351daa60..7883c464 100644 --- a/src/functions/private/License/Get-GitHubRepositoryLicense.ps1 +++ b/src/functions/private/License/Get-GitHubRepositoryLicense.ps1 @@ -34,29 +34,43 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner : [$($Context.Owner)]" + if ([string]::IsNullOrEmpty($Owner)) { + $Owner = $Context.Owner + } + Write-Debug "Owner : [$($Context.Owner)]" - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo + if ([string]::IsNullOrEmpty($Repo)) { + $Repo = $Context.Repo + } + Write-Debug "Repo : [$($Context.Repo)]" } - Write-Debug "Repo : [$($Context.Repo)]" - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/license" - Accept = 'application/vnd.github+json' - Method = 'GET' - } + process { + try { + $inputObject = @{ + Context = $Context + APIEndpoint = "/repos/$Owner/$Repo/license" + Accept = 'application/vnd.github+json' + Method = 'GET' + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - $Response = $_.Response - $rawContent = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($Response.content)) - $Response | Add-Member -NotePropertyName 'raw_content' -NotePropertyValue $rawContent -Force - $Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + $Response = $_.Response + $rawContent = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($Response.content)) + $Response | Add-Member -NotePropertyName 'raw_content' -NotePropertyValue $rawContent -Force + $Response + } + } catch { + throw $_ + } + } + end { + Write-Debug "[$commandName] - End" } } diff --git a/src/functions/private/Organization/Blocking/Block-GitHubUserByOrganization.ps1 b/src/functions/private/Organization/Blocking/Block-GitHubUserByOrganization.ps1 index e57d6334..9fc809f1 100644 --- a/src/functions/private/Organization/Blocking/Block-GitHubUserByOrganization.ps1 +++ b/src/functions/private/Organization/Blocking/Block-GitHubUserByOrganization.ps1 @@ -44,24 +44,36 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - - $inputObject = @{ - Context = $Context - APIEndpoint = "/orgs/$Organization/blocks/$Username" - Method = 'PUT' + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } - try { - $null = (Invoke-GitHubAPI @inputObject) - # Should we check if user is already blocked and return true if so? - return $true - } catch { - if ($_.Exception.Response.StatusCode.Value__ -eq 422) { - return $false - } else { - Write-Error $_.Exception.Response - throw $_ + process { + $inputObject = @{ + Context = $Context + APIEndpoint = "/orgs/$Organization/blocks/$Username" + Method = 'PUT' + } + + try { + $null = (Invoke-GitHubAPI @inputObject) + # Should we check if user is already blocked and return true if so? + return $true + } catch { + if ($_.Exception.Response.StatusCode.Value__ -eq 422) { + return $false + } else { + Write-Error $_.Exception.Response + throw $_ + } } } + + end { + Write-Debug "[$commandName] - End" + } } + diff --git a/src/functions/private/Organization/Blocking/Get-GitHubBlockedUserByOrganization.ps1 b/src/functions/private/Organization/Blocking/Get-GitHubBlockedUserByOrganization.ps1 index bdcac202..5d21ed3c 100644 --- a/src/functions/private/Organization/Blocking/Get-GitHubBlockedUserByOrganization.ps1 +++ b/src/functions/private/Organization/Blocking/Get-GitHubBlockedUserByOrganization.ps1 @@ -35,20 +35,34 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - - $body = @{ - per_page = $PerPage + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } - $inputObject = @{ - Context = $Context - APIEndpoint = "/orgs/$Organization/blocks" - Method = 'GET' - Body = $body - } + process { + try { + $body = @{ + per_page = $PerPage + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + $inputObject = @{ + Context = $Context + APIEndpoint = "/orgs/$Organization/blocks" + Method = 'GET' + Body = $body + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ + } + } + end { + Write-Debug "[$commandName] - End" } } diff --git a/src/functions/private/Organization/Blocking/Test-GitHubBlockedUserByOrganization.ps1 b/src/functions/private/Organization/Blocking/Test-GitHubBlockedUserByOrganization.ps1 index b838e199..a13f8777 100644 --- a/src/functions/private/Organization/Blocking/Test-GitHubBlockedUserByOrganization.ps1 +++ b/src/functions/private/Organization/Blocking/Test-GitHubBlockedUserByOrganization.ps1 @@ -43,21 +43,33 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - - $inputObject = @{ - Context = $Context - APIEndpoint = "/orgs/$Organization/blocks/$Username" - Method = 'GET' + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } - try { - (Invoke-GitHubAPI @inputObject).StatusCode -eq 204 - } catch { - if ($_.Exception.Response.StatusCode.Value__ -eq 404) { - return $false - } else { - throw $_ + process { + $inputObject = @{ + Context = $Context + APIEndpoint = "/orgs/$Organization/blocks/$Username" + Method = 'GET' + } + + try { + (Invoke-GitHubAPI @inputObject).StatusCode -eq 204 + } catch { + if ($_.Exception.Response.StatusCode.Value__ -eq 404) { + return $false + } else { + throw $_ + } } } + + end { + Write-Debug "[$commandName] - End" + } } + diff --git a/src/functions/private/Organization/Blocking/Unblock-GitHubUserByOrganization.ps1 b/src/functions/private/Organization/Blocking/Unblock-GitHubUserByOrganization.ps1 index 18314fb3..95b20730 100644 --- a/src/functions/private/Organization/Blocking/Unblock-GitHubUserByOrganization.ps1 +++ b/src/functions/private/Organization/Blocking/Unblock-GitHubUserByOrganization.ps1 @@ -44,19 +44,30 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + } + + process { + $inputObject = @{ + Context = $Context + APIEndpoint = "/orgs/$Organization/blocks/$Username" + Method = 'DELETE' + } - $inputObject = @{ - Context = $Context - APIEndpoint = "/orgs/$Organization/blocks/$Username" - Method = 'DELETE' + try { + $null = (Invoke-GitHubAPI @inputObject) + return $true + } catch { + Write-Error $_.Exception.Response + throw $_ + } } - try { - $null = (Invoke-GitHubAPI @inputObject) - return $true - } catch { - Write-Error $_.Exception.Response - throw $_ + end { + Write-Debug "[$commandName] - End" } } diff --git a/src/functions/private/Organization/Get-GitHubAllOrganization.ps1 b/src/functions/private/Organization/Get-GitHubAllOrganization.ps1 index 2c5f4fb5..d42d8f5b 100644 --- a/src/functions/private/Organization/Get-GitHubAllOrganization.ps1 +++ b/src/functions/private/Organization/Get-GitHubAllOrganization.ps1 @@ -37,22 +37,35 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - - $body = @{ - since = $Since - per_page = $PerPage + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } - $inputObject = @{ - Context = $Context - APIEndpoint = '/organizations' - Method = 'GET' - Body = $body - } + process { + try { + $body = @{ + since = $Since + per_page = $PerPage + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + $inputObject = @{ + Context = $Context + APIEndpoint = '/organizations' + Method = 'GET' + Body = $body + } + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ + } + } + end { + Write-Debug "[$commandName] - End" + } } diff --git a/src/functions/private/Organization/Get-GitHubMyOrganization.ps1 b/src/functions/private/Organization/Get-GitHubMyOrganization.ps1 index 1a514936..4290e6cc 100644 --- a/src/functions/private/Organization/Get-GitHubMyOrganization.ps1 +++ b/src/functions/private/Organization/Get-GitHubMyOrganization.ps1 @@ -36,20 +36,35 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - - $body = @{ - per_page = $PerPage + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } - $inputObject = @{ - Context = $Context - APIEndpoint = '/user/orgs' - Method = 'GET' - Body = $body + process { + try { + $body = @{ + per_page = $PerPage + } + + $inputObject = @{ + Context = $Context + APIEndpoint = '/user/orgs' + Method = 'GET' + Body = $body + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ + } } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + end { + Write-Debug "[$commandName] - End" } } diff --git a/src/functions/private/Organization/Get-GitHubOrganizationByName.ps1 b/src/functions/private/Organization/Get-GitHubOrganizationByName.ps1 index b7826882..424cb923 100644 --- a/src/functions/private/Organization/Get-GitHubOrganizationByName.ps1 +++ b/src/functions/private/Organization/Get-GitHubOrganizationByName.ps1 @@ -42,15 +42,29 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - - $inputObject = @{ - Context = $Context - APIEndpoint = "/orgs/$Organization" - Method = 'GET' + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + process { + try { + $inputObject = @{ + Context = $Context + APIEndpoint = "/orgs/$Organization" + Method = 'GET' + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ + } + } + end { + Write-Debug "[$commandName] - End" } } diff --git a/src/functions/private/Organization/Get-GitHubUserOrganization.ps1 b/src/functions/private/Organization/Get-GitHubUserOrganization.ps1 index a3544e76..e4bdc5c6 100644 --- a/src/functions/private/Organization/Get-GitHubUserOrganization.ps1 +++ b/src/functions/private/Organization/Get-GitHubUserOrganization.ps1 @@ -38,20 +38,34 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - - $body = @{ - per_page = $PerPage + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } - $inputObject = @{ - Context = $Context - APIEndpoint = "/users/$Username/orgs" - Method = 'GET' - Body = $body - } + process { + try { + $body = @{ + per_page = $PerPage + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + $inputObject = @{ + Context = $Context + APIEndpoint = "/users/$Username/orgs" + Method = 'GET' + Body = $body + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ + } + } + end { + Write-Debug "[$commandName] - End" } } diff --git a/src/functions/private/Releases/Assets/Get-GitHubReleaseAssetByID.ps1 b/src/functions/private/Releases/Assets/Get-GitHubReleaseAssetByID.ps1 index 6bcbbf6d..07ae996f 100644 --- a/src/functions/private/Releases/Assets/Get-GitHubReleaseAssetByID.ps1 +++ b/src/functions/private/Releases/Assets/Get-GitHubReleaseAssetByID.ps1 @@ -39,25 +39,40 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + if ([string]::IsNullOrEmpty($Owner)) { + $Owner = $Context.Owner + } + Write-Debug "Owner : [$($Context.Owner)]" - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner + if ([string]::IsNullOrEmpty($Repo)) { + $Repo = $Context.Repo + } + Write-Debug "Repo : [$($Context.Repo)]" } - Write-Debug "Owner : [$($Context.Owner)]" - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo : [$($Context.Repo)]" + process { + try { + + $inputObject = @{ + Context = $Context + APIEndpoint = "/repos/$Owner/$Repo/releases/assets/$ID" + Method = 'GET' + } - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/releases/assets/$ID" - Method = 'GET' + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ + } } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + end { + Write-Debug "[$commandName] - End" } } diff --git a/src/functions/private/Releases/Assets/Get-GitHubReleaseAssetByReleaseID.ps1 b/src/functions/private/Releases/Assets/Get-GitHubReleaseAssetByReleaseID.ps1 index 3fa1252a..782f71f7 100644 --- a/src/functions/private/Releases/Assets/Get-GitHubReleaseAssetByReleaseID.ps1 +++ b/src/functions/private/Releases/Assets/Get-GitHubReleaseAssetByReleaseID.ps1 @@ -44,29 +44,43 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner : [$($Context.Owner)]" + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + if ([string]::IsNullOrEmpty($Owner)) { + $Owner = $Context.Owner + } + Write-Debug "Owner : [$($Context.Owner)]" - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo + if ([string]::IsNullOrEmpty($Repo)) { + $Repo = $Context.Repo + } + Write-Debug "Repo : [$($Context.Repo)]" } - Write-Debug "Repo : [$($Context.Repo)]" - $body = @{ - per_page = $PerPage - } + process { + try { + $body = @{ + per_page = $PerPage + } - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/releases/$ID/assets" - Method = 'GET' - Body = $body - } + $inputObject = @{ + Context = $Context + APIEndpoint = "/repos/$Owner/$Repo/releases/$ID/assets" + Method = 'GET' + Body = $body + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ + } + } + end { + Write-Debug "[$commandName] - End" } } diff --git a/src/functions/private/Releases/Releases/Get-GitHubReleaseAll.ps1 b/src/functions/private/Releases/Releases/Get-GitHubReleaseAll.ps1 index e1305754..f90945c1 100644 --- a/src/functions/private/Releases/Releases/Get-GitHubReleaseAll.ps1 +++ b/src/functions/private/Releases/Releases/Get-GitHubReleaseAll.ps1 @@ -38,31 +38,43 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + if ([string]::IsNullOrEmpty($Owner)) { + $Owner = $Context.Owner + } + Write-Debug "Owner : [$($Context.Owner)]" - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner + if ([string]::IsNullOrEmpty($Repo)) { + $Repo = $Context.Repo + } + Write-Debug "Repo : [$($Context.Repo)]" } - Write-Debug "Owner : [$($Context.Owner)]" - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo : [$($Context.Repo)]" + process { + try { + $body = @{ + per_page = $PerPage + } - $body = @{ - per_page = $PerPage - } + $inputObject = @{ + Context = $Context + APIEndpoint = "/repos/$Owner/$Repo/releases" + Method = 'GET' + Body = $body + } - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/releases" - Method = 'GET' - Body = $body + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ + } } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + end { + Write-Debug "[$commandName] - End" } - } diff --git a/src/functions/private/Releases/Releases/Get-GitHubReleaseByID.ps1 b/src/functions/private/Releases/Releases/Get-GitHubReleaseByID.ps1 index c80412ba..73ff06d8 100644 --- a/src/functions/private/Releases/Releases/Get-GitHubReleaseByID.ps1 +++ b/src/functions/private/Releases/Releases/Get-GitHubReleaseByID.ps1 @@ -37,26 +37,39 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + if ([string]::IsNullOrEmpty($Owner)) { + $Owner = $Context.Owner + } + Write-Debug "Owner : [$($Context.Owner)]" - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner + if ([string]::IsNullOrEmpty($Repo)) { + $Repo = $Context.Repo + } + Write-Debug "Repo : [$($Context.Repo)]" } - Write-Debug "Owner : [$($Context.Owner)]" - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo : [$($Context.Repo)]" + process { + try { + $inputObject = @{ + Context = $Context + APIEndpoint = "/repos/$Owner/$Repo/releases/$ID" + Method = 'GET' + } - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/releases/$ID" - Method = 'GET' + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ + } } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + end { + Write-Debug "[$commandName] - End" } - } diff --git a/src/functions/private/Releases/Releases/Get-GitHubReleaseByTagName.ps1 b/src/functions/private/Releases/Releases/Get-GitHubReleaseByTagName.ps1 index e6befa41..4ba2856a 100644 --- a/src/functions/private/Releases/Releases/Get-GitHubReleaseByTagName.ps1 +++ b/src/functions/private/Releases/Releases/Get-GitHubReleaseByTagName.ps1 @@ -36,26 +36,39 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + if ([string]::IsNullOrEmpty($Owner)) { + $Owner = $Context.Owner + } + Write-Debug "Owner : [$($Context.Owner)]" - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner + if ([string]::IsNullOrEmpty($Repo)) { + $Repo = $Context.Repo + } + Write-Debug "Repo : [$($Context.Repo)]" } - Write-Debug "Owner : [$($Context.Owner)]" - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo : [$($Context.Repo)]" + process { + try { + $inputObject = @{ + Context = $Context + APIEndpoint = "/repos/$Owner/$Repo/releases/tags/$Tag" + Method = 'GET' + } - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/releases/tags/$Tag" - Method = 'GET' + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ + } } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + end { + Write-Debug "[$commandName] - End" } - } diff --git a/src/functions/private/Releases/Releases/Get-GitHubReleaseLatest.ps1 b/src/functions/private/Releases/Releases/Get-GitHubReleaseLatest.ps1 index 738f6fb5..631912de 100644 --- a/src/functions/private/Releases/Releases/Get-GitHubReleaseLatest.ps1 +++ b/src/functions/private/Releases/Releases/Get-GitHubReleaseLatest.ps1 @@ -33,25 +33,39 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + if ([string]::IsNullOrEmpty($Owner)) { + $Owner = $Context.Owner + } + Write-Debug "Owner : [$($Context.Owner)]" - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner + if ([string]::IsNullOrEmpty($Repo)) { + $Repo = $Context.Repo + } + Write-Debug "Repo : [$($Context.Repo)]" } - Write-Debug "Owner : [$($Context.Owner)]" - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo : [$($Context.Repo)]" + process { + try { + $inputObject = @{ + Context = $Context + APIEndpoint = "/repos/$Owner/$Repo/releases/latest" + Method = 'GET' + } - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/releases/latest" - Method = 'GET' + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ + } } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + end { + Write-Debug "[$commandName] - End" } } diff --git a/src/functions/private/Repositories/Autolinks/Get-GitHubRepositoryAutolinkById.ps1 b/src/functions/private/Repositories/Autolinks/Get-GitHubRepositoryAutolinkById.ps1 index 1557c4ce..58bbabf5 100644 --- a/src/functions/private/Repositories/Autolinks/Get-GitHubRepositoryAutolinkById.ps1 +++ b/src/functions/private/Repositories/Autolinks/Get-GitHubRepositoryAutolinkById.ps1 @@ -40,25 +40,39 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + if ([string]::IsNullOrEmpty($Owner)) { + $Owner = $Context.Owner + } + Write-Debug "Owner : [$($Context.Owner)]" - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner + if ([string]::IsNullOrEmpty($Repo)) { + $Repo = $Context.Repo + } + Write-Debug "Repo : [$($Context.Repo)]" } - Write-Debug "Owner : [$($Context.Owner)]" - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo : [$($Context.Repo)]" + process { + try { + $inputObject = @{ + Context = $Context + APIEndpoint = "/repos/$Owner/$Repo/autolinks/$AutolinkId" + Method = 'GET' + } - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/autolinks/$AutolinkId" - Method = 'GET' + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ + } } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + end { + Write-Debug "[$commandName] - End" } } diff --git a/src/functions/private/Repositories/Autolinks/Get-GitHubRepositoryAutolinkList.ps1 b/src/functions/private/Repositories/Autolinks/Get-GitHubRepositoryAutolinkList.ps1 index 92a44ed3..97d45991 100644 --- a/src/functions/private/Repositories/Autolinks/Get-GitHubRepositoryAutolinkList.ps1 +++ b/src/functions/private/Repositories/Autolinks/Get-GitHubRepositoryAutolinkList.ps1 @@ -34,25 +34,39 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + if ([string]::IsNullOrEmpty($Owner)) { + $Owner = $Context.Owner + } + Write-Debug "Owner : [$($Context.Owner)]" - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner + if ([string]::IsNullOrEmpty($Repo)) { + $Repo = $Context.Repo + } + Write-Debug "Repo : [$($Context.Repo)]" } - Write-Debug "Owner : [$($Context.Owner)]" - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo : [$($Context.Repo)]" + process { + try { + $inputObject = @{ + Context = $Context + APIEndpoint = "/repos/$Owner/$Repo/autolinks" + Method = 'GET' + } - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/autolinks" - Method = 'GET' + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ + } } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + end { + Write-Debug "[$commandName] - End" } } diff --git a/src/functions/private/Repositories/Fork/New-GitHubRepositoryAsFork.ps1 b/src/functions/private/Repositories/Fork/New-GitHubRepositoryAsFork.ps1 index 3538e5ac..999b4155 100644 --- a/src/functions/private/Repositories/Fork/New-GitHubRepositoryAsFork.ps1 +++ b/src/functions/private/Repositories/Fork/New-GitHubRepositoryAsFork.ps1 @@ -68,38 +68,53 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - - if ([string]::IsNullorEmpty($Name)) { - $Name = $Repo - } - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner : [$($Context.Owner)]" + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + if ([string]::IsNullOrEmpty($Owner)) { + $Owner = $Context.Owner + } + Write-Debug "Owner : [$($Context.Owner)]" - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo : [$($Context.Repo)]" + if ([string]::IsNullOrEmpty($Repo)) { + $Repo = $Context.Repo + } + Write-Debug "Repo : [$($Context.Repo)]" - $body = @{ - organization = $Organization - name = $Name - default_branch_only = $DefaultBranchOnly + if ([string]::IsNullorEmpty($Name)) { + $Name = $Repo + } + Write-Debug "Name : [$Name]" } - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/forks" - Method = 'POST' - Body = $body + process { + try { + $body = @{ + organization = $Organization + name = $Name + default_branch_only = $DefaultBranchOnly + } + + $inputObject = @{ + Context = $Context + APIEndpoint = "/repos/$Owner/$Repo/forks" + Method = 'POST' + Body = $body + } + + if ($PSCmdlet.ShouldProcess("Repository [$Organization/$Name] as fork of [$Owner/$Repo]", 'Create')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } + } catch { + throw $_ + } } - if ($PSCmdlet.ShouldProcess("Repository [$Organization/$Name] as fork of [$Owner/$Repo]", 'Create')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + end { + Write-Debug "[$commandName] - End" } } diff --git a/src/functions/private/Repositories/Repositories/Get-GitHubMyRepositories.ps1 b/src/functions/private/Repositories/Repositories/Get-GitHubMyRepositories.ps1 index 169fc58f..5b31eab4 100644 --- a/src/functions/private/Repositories/Repositories/Get-GitHubMyRepositories.ps1 +++ b/src/functions/private/Repositories/Repositories/Get-GitHubMyRepositories.ps1 @@ -113,34 +113,48 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - - $body = @{ - type = $Type - sort = $Sort - direction = $Direction - per_page = $PerPage + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } - if ($PSBoundParameters.ContainsKey('Affiliation')) { - $body['affiliation'] = $Affiliation -join ',' - } - if ($PSBoundParameters.ContainsKey('Since')) { - $body['since'] = $Since.ToString('yyyy-MM-ddTHH:mm:ssZ') - } - if ($PSBoundParameters.ContainsKey('Before')) { - $body['before'] = $Before.ToString('yyyy-MM-ddTHH:mm:ssZ') - } - - $inputObject = @{ - Context = $Context - APIEndpoint = '/user/repos' - Method = 'GET' - body = $body + process { + try { + $body = @{ + type = $Type + sort = $Sort + direction = $Direction + per_page = $PerPage + } + + if ($PSBoundParameters.ContainsKey('Affiliation')) { + $body['affiliation'] = $Affiliation -join ',' + } + if ($PSBoundParameters.ContainsKey('Since')) { + $body['since'] = $Since.ToString('yyyy-MM-ddTHH:mm:ssZ') + } + if ($PSBoundParameters.ContainsKey('Before')) { + $body['before'] = $Before.ToString('yyyy-MM-ddTHH:mm:ssZ') + } + + $inputObject = @{ + Context = $Context + APIEndpoint = '/user/repos' + Method = 'GET' + body = $body + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ + } } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + end { + Write-Debug "[$commandName] - End" } - } diff --git a/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryByName.ps1 b/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryByName.ps1 index 1d0f92d5..ec2fdaf8 100644 --- a/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryByName.ps1 +++ b/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryByName.ps1 @@ -36,26 +36,40 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + if ([string]::IsNullOrEmpty($Owner)) { + $Owner = $Context.Owner + } + Write-Debug "Owner : [$($Context.Owner)]" - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner + if ([string]::IsNullOrEmpty($Repo)) { + $Repo = $Context.Repo + } + Write-Debug "Repo : [$($Context.Repo)]" } - Write-Debug "Owner : [$($Context.Owner)]" - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo : [$($Context.Repo)]" + process { + try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo" - Method = 'GET' - } + $inputObject = @{ + Context = $Context + APIEndpoint = "/repos/$Owner/$Repo" + Method = 'GET' + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ + } } + end { + Write-Debug "[$commandName] - End" + } } diff --git a/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryListByID.ps1 b/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryListByID.ps1 index c145124c..9de7f033 100644 --- a/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryListByID.ps1 +++ b/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryListByID.ps1 @@ -33,21 +33,35 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - - $body = @{ - since = $Since + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } - $inputObject = @{ - Context = $Context - APIEndpoint = '/repositories' - Method = 'GET' - Body = $body - } + process { + try { + $body = @{ + since = $Since + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + $inputObject = @{ + Context = $Context + APIEndpoint = '/repositories' + Method = 'GET' + Body = $body + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ + } } + end { + Write-Debug "[$commandName] - End" + } } diff --git a/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryListByOrg.ps1 b/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryListByOrg.ps1 index e8ad3ed6..abdb2f8e 100644 --- a/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryListByOrg.ps1 +++ b/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryListByOrg.ps1 @@ -62,28 +62,42 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner : [$($Context.Owner)]" - - $body = @{ - sort = $Sort - type = $Type - direction = $Direction - per_page = $PerPage + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + if ([string]::IsNullOrEmpty($Owner)) { + $Owner = $Context.Owner + } + Write-Debug "Owner : [$($Context.Owner)]" } - $inputObject = @{ - Context = $Context - APIEndpoint = "/orgs/$Owner/repos" - Method = 'GET' - Body = $body + process { + try { + $body = @{ + sort = $Sort + type = $Type + direction = $Direction + per_page = $PerPage + } + + $inputObject = @{ + Context = $Context + APIEndpoint = "/orgs/$Owner/repos" + Method = 'GET' + Body = $body + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ + } } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + end { + Write-Debug "[$commandName] - End" } } diff --git a/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryListByUser.ps1 b/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryListByUser.ps1 index 3aa6a7e5..c03a934a 100644 --- a/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryListByUser.ps1 +++ b/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryListByUser.ps1 @@ -64,23 +64,47 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - - $body = @{ - sort = $Sort - type = $Type - direction = $Direction - per_page = $PerPage + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + if ([string]::IsNullOrEmpty($Owner)) { + $Owner = $Context.Owner + } + Write-Debug "Owner : [$($Context.Owner)]" + + if ([string]::IsNullOrEmpty($Repo)) { + $Repo = $Context.Repo + } + Write-Debug "Repo : [$($Context.Repo)]" } - $inputObject = @{ - Context = $Context - APIEndpoint = "/users/$Username/repos" - Method = 'GET' - Body = $body + process { + try { + $body = @{ + sort = $Sort + type = $Type + direction = $Direction + per_page = $PerPage + } + + $inputObject = @{ + Context = $Context + APIEndpoint = "/users/$Username/repos" + Method = 'GET' + Body = $body + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ + } } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + end { + Write-Debug "[$commandName] - End" } } diff --git a/src/functions/private/Repositories/Repositories/New-GitHubRepositoryFromTemplate.ps1 b/src/functions/private/Repositories/Repositories/New-GitHubRepositoryFromTemplate.ps1 index f58e8e89..133ee341 100644 --- a/src/functions/private/Repositories/Repositories/New-GitHubRepositoryFromTemplate.ps1 +++ b/src/functions/private/Repositories/Repositories/New-GitHubRepositoryFromTemplate.ps1 @@ -78,36 +78,45 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner : [$($Context.Owner)]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo : [$($Context.Repo)]" - - $body = @{ - owner = $Owner - name = $Name - description = $Description - include_all_branches = $IncludeAllBranches - private = $Private + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + if ([string]::IsNullOrEmpty($Owner)) { + $Owner = $Context.Owner + } + Write-Debug "Owner : [$($Context.Owner)]" } - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$TemplateOwner/$TemplateRepo/generate" - Method = 'POST' - Body = $body + process { + try { + $body = @{ + owner = $Owner + name = $Name + description = $Description + include_all_branches = $IncludeAllBranches + private = $Private + } + + $inputObject = @{ + Context = $Context + APIEndpoint = "/repos/$TemplateOwner/$TemplateRepo/generate" + Method = 'POST' + Body = $body + } + + if ($PSCmdlet.ShouldProcess("Repository [$Owner/$Name] from template [$TemplateOwner/$TemplateRepo]", 'Create')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } + } catch { + throw $_ + } } - if ($PSCmdlet.ShouldProcess("Repository [$Owner/$Name] from template [$TemplateOwner/$TemplateRepo]", 'Create')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + end { + Write-Debug "[$commandName] - End" } } diff --git a/src/functions/private/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 b/src/functions/private/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 index f5366ca7..4990d1c4 100644 --- a/src/functions/private/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 +++ b/src/functions/private/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 @@ -212,7 +212,10 @@ filter New-GitHubRepositoryOrg { } begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT $GitignoreTemplate = $PSBoundParameters['GitignoreTemplate'] $LicenseTemplate = $PSBoundParameters['LicenseTemplate'] if ([string]::IsNullOrEmpty($Owner)) { @@ -222,50 +225,49 @@ filter New-GitHubRepositoryOrg { } process { - $PSCmdlet.MyInvocation.MyCommand.Parameters.GetEnumerator() | ForEach-Object { - $paramName = $_.Key - $paramDefaultValue = Get-Variable -Name $paramName -ValueOnly -ErrorAction SilentlyContinue - $providedValue = $PSBoundParameters[$paramName] - Write-Debug "[$paramName]" - Write-Debug " - Default: [$paramDefaultValue]" - Write-Debug " - Provided: [$providedValue]" - if (-not $PSBoundParameters.ContainsKey($paramName) -and ($null -ne $paramDefaultValue)) { - Write-Debug ' - Using default value' - $PSBoundParameters[$paramName] = $paramDefaultValue - } else { - Write-Debug ' - Using provided value' + try { + $body = @{ + name = $Name + description = $Description + homepage = $Homepage + visibility = $Visibility + has_issues = $HasIssues + has_projects = $HasProjects + has_wiki = $HasWiki + has_downloads = $HasDownloads + is_template = $IsTemplate + team_id = $TeamId + auto_init = $AutoInit + allow_squash_merge = $AllowSquashMerge + allow_merge_commit = $AllowMergeCommit + allow_rebase_merge = $AllowRebaseMerge + allow_auto_merge = $AllowAutoMerge + delete_branch_on_merge = $DeleteBranchOnMerge + squash_merge_commit_title = $SquashMergeCommitTitle + squash_merge_commit_message = $SquashMergeCommitMessage + merge_commit_title = $MergeCommitTitle + merge_commit_message = $MergeCommitMessage + private = $Visibility -eq 'private' } - } - $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntry -Hashtable $body -RemoveNames 'Owner' -RemoveTypes 'SwitchParameter' - - $body['private'] = $Visibility -eq 'private' - $body['has_issues'] = if ($HasIssues.IsPresent) { $HasIssues } else { $false } - $body['has_wiki'] = if ($HasWiki.IsPresent) { $HasWiki } else { $false } - $body['has_projects'] = if ($HasProjects.IsPresent) { $HasProjects } else { $false } - $body['has_downloads'] = if ($HasDownloads.IsPresent) { $HasDownloads } else { $false } - $body['is_template'] = if ($IsTemplate.IsPresent) { $IsTemplate } else { $false } - $body['auto_init'] = if ($AutoInit.IsPresent) { $AutoInit } else { $false } - $body['allow_squash_merge'] = if ($AllowSquashMerge.IsPresent) { $AllowSquashMerge } else { $false } - $body['allow_merge_commit'] = if ($AllowMergeCommit.IsPresent) { $AllowMergeCommit } else { $false } - $body['allow_rebase_merge'] = if ($AllowRebaseMerge.IsPresent) { $AllowRebaseMerge } else { $false } - $body['allow_auto_merge'] = if ($AllowAutoMerge.IsPresent) { $AllowAutoMerge } else { $false } - $body['delete_branch_on_merge'] = if ($DeleteBranchOnMerge.IsPresent) { $DeleteBranchOnMerge } else { $false } - - Remove-HashtableEntry -Hashtable $body -NullOrEmptyValues - - $inputObject = @{ - Context = $Context - APIEndpoint = "/orgs/$Owner/repos" - Method = 'POST' - Body = $body - } + $inputObject = @{ + Context = $Context + APIEndpoint = "/orgs/$Owner/repos" + Method = 'POST' + Body = $body + } - if ($PSCmdlet.ShouldProcess("Repository in organization $Owner", 'Create')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + if ($PSCmdlet.ShouldProcess("Repository in organization $Owner", 'Create')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } + } catch { + throw $_ } } + + end { + Write-Debug "[$commandName] - End" + } } diff --git a/src/functions/private/Repositories/Repositories/New-GitHubRepositoryUser.ps1 b/src/functions/private/Repositories/Repositories/New-GitHubRepositoryUser.ps1 index a8346ea2..1954e21a 100644 --- a/src/functions/private/Repositories/Repositories/New-GitHubRepositoryUser.ps1 +++ b/src/functions/private/Repositories/Repositories/New-GitHubRepositoryUser.ps1 @@ -206,57 +206,58 @@ filter New-GitHubRepositoryUser { } begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT $GitignoreTemplate = $PSBoundParameters['GitignoreTemplate'] $LicenseTemplate = $PSBoundParameters['LicenseTemplate'] } process { - - $PSCmdlet.MyInvocation.MyCommand.Parameters.GetEnumerator() | ForEach-Object { - $paramName = $_.Key - $paramDefaultValue = Get-Variable -Name $paramName -ValueOnly -ErrorAction SilentlyContinue - $providedValue = $PSBoundParameters[$paramName] - Write-Debug "[$paramName]" - Write-Debug " - Default: [$paramDefaultValue]" - Write-Debug " - Provided: [$providedValue]" - if (-not $PSBoundParameters.ContainsKey($paramName) -and ($null -ne $paramDefaultValue)) { - Write-Debug ' - Using default value' - $PSBoundParameters[$paramName] = $paramDefaultValue - } else { - Write-Debug ' - Using provided value' + try { + $body = @{ + name = $Name + description = $Description + homepage = $Homepage + visibility = $Visibility + has_issues = $HasIssues + has_projects = $HasProjects + has_wiki = $HasWiki + has_downloads = $HasDownloads + is_template = $IsTemplate + team_id = $TeamId + auto_init = $AutoInit + allow_squash_merge = $AllowSquashMerge + allow_merge_commit = $AllowMergeCommit + allow_rebase_merge = $AllowRebaseMerge + allow_auto_merge = $AllowAutoMerge + delete_branch_on_merge = $DeleteBranchOnMerge + squash_merge_commit_title = $SquashMergeCommitTitle + squash_merge_commit_message = $SquashMergeCommitMessage + merge_commit_title = $MergeCommitTitle + merge_commit_message = $MergeCommitMessage + private = $Visibility -eq 'private' } - } - $body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case - Remove-HashtableEntry -Hashtable $body -RemoveNames 'visibility' -RemoveTypes 'SwitchParameter' - - $body['private'] = $Visibility -eq 'private' - $body['has_issues'] = if ($HasIssues.IsPresent) { $HasIssues } else { $false } - $body['has_wiki'] = if ($HasWiki.IsPresent) { $HasWiki } else { $false } - $body['has_projects'] = if ($HasProjects.IsPresent) { $HasProjects } else { $false } - $body['has_downloads'] = if ($HasDownloads.IsPresent) { $HasDownloads } else { $false } - $body['is_template'] = if ($IsTemplate.IsPresent) { $IsTemplate } else { $false } - $body['auto_init'] = if ($AutoInit.IsPresent) { $AutoInit } else { $false } - $body['allow_squash_merge'] = if ($AllowSquashMerge.IsPresent) { $AllowSquashMerge } else { $false } - $body['allow_merge_commit'] = if ($AllowMergeCommit.IsPresent) { $AllowMergeCommit } else { $false } - $body['allow_rebase_merge'] = if ($AllowRebaseMerge.IsPresent) { $AllowRebaseMerge } else { $false } - $body['allow_auto_merge'] = if ($AllowAutoMerge.IsPresent) { $AllowAutoMerge } else { $false } - $body['delete_branch_on_merge'] = if ($DeleteBranchOnMerge.IsPresent) { $DeleteBranchOnMerge } else { $false } - - Remove-HashtableEntry -Hashtable $body -NullOrEmptyValues - - $inputObject = @{ - Context = $Context - APIEndpoint = '/user/repos' - Method = 'POST' - Body = $body - } + $inputObject = @{ + Context = $Context + APIEndpoint = '/user/repos' + Method = 'POST' + Body = $body + } - if ($PSCmdlet.ShouldProcess('Repository for user', 'Create')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + if ($PSCmdlet.ShouldProcess('Repository for user', 'Create')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } } + } catch { + throw $_ } } + + end { + Write-Debug "[$commandName] - End" + } } diff --git a/src/functions/private/Users/Blocking/Block-GitHubUserByUser.ps1 b/src/functions/private/Users/Blocking/Block-GitHubUserByUser.ps1 index 1958b385..3c75e766 100644 --- a/src/functions/private/Users/Blocking/Block-GitHubUserByUser.ps1 +++ b/src/functions/private/Users/Blocking/Block-GitHubUserByUser.ps1 @@ -33,24 +33,35 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - - $inputObject = @{ - Context = $Context - APIEndpoint = "/user/blocks/$Username" - Method = 'PUT' + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } - try { - $null = (Invoke-GitHubAPI @inputObject) - # Should we check if user is already blocked and return true if so? - return $true - } catch { - if ($_.Exception.Response.StatusCode.Value__ -eq 422) { - return $false - } else { - Write-Error $_.Exception.Response - throw $_ + process { + $inputObject = @{ + Context = $Context + APIEndpoint = "/user/blocks/$Username" + Method = 'PUT' + } + + try { + $null = (Invoke-GitHubAPI @inputObject) + # Should we check if user is already blocked and return true if so? + return $true + } catch { + if ($_.Exception.Response.StatusCode.Value__ -eq 422) { + return $false + } else { + Write-Error $_.Exception.Response + throw $_ + } } } + + end { + Write-Debug "[$commandName] - End" + } } diff --git a/src/functions/private/Users/Blocking/Get-GitHubBlockedUserByUser.ps1 b/src/functions/private/Users/Blocking/Get-GitHubBlockedUserByUser.ps1 index 070070e3..5516d13a 100644 --- a/src/functions/private/Users/Blocking/Get-GitHubBlockedUserByUser.ps1 +++ b/src/functions/private/Users/Blocking/Get-GitHubBlockedUserByUser.ps1 @@ -28,21 +28,35 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - - $body = @{ - per_page = $PerPage + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } - $inputObject = @{ - Context = $Context - APIEndpoint = '/user/blocks' - Method = 'GET' - Body = $body + process { + try { + $body = @{ + per_page = $PerPage + } + + $inputObject = @{ + Context = $Context + APIEndpoint = '/user/blocks' + Method = 'GET' + Body = $body + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ + } } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + end { + Write-Debug "[$commandName] - End" } - } diff --git a/src/functions/private/Users/Blocking/Test-GitHubBlockedUserByUser.ps1 b/src/functions/private/Users/Blocking/Test-GitHubBlockedUserByUser.ps1 index d524f20c..c5cdaf37 100644 --- a/src/functions/private/Users/Blocking/Test-GitHubBlockedUserByUser.ps1 +++ b/src/functions/private/Users/Blocking/Test-GitHubBlockedUserByUser.ps1 @@ -40,27 +40,41 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - - $body = @{ - per_page = $PerPage + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } - $inputObject = @{ - Context = $Context - APIEndpoint = "/user/blocks/$Username" - Method = 'GET' - Body = $body - } + process { + try { + $body = @{ + per_page = $PerPage + } - try { - (Invoke-GitHubAPI @inputObject).StatusCode -eq 204 - } catch { - if ($_.Exception.Response.StatusCode.Value__ -eq 404) { - return $false - } else { + $inputObject = @{ + Context = $Context + APIEndpoint = "/user/blocks/$Username" + Method = 'GET' + Body = $body + } + + try { + (Invoke-GitHubAPI @inputObject).StatusCode -eq 204 + } catch { + if ($_.Exception.Response.StatusCode.Value__ -eq 404) { + return $false + } else { + throw $_ + } + } + } catch { throw $_ } } + end { + Write-Debug "[$commandName] - End" + } } diff --git a/src/functions/private/Users/Blocking/Unblock-GitHubUserByUser.ps1 b/src/functions/private/Users/Blocking/Unblock-GitHubUserByUser.ps1 index 55e11c29..169a3495 100644 --- a/src/functions/private/Users/Blocking/Unblock-GitHubUserByUser.ps1 +++ b/src/functions/private/Users/Blocking/Unblock-GitHubUserByUser.ps1 @@ -33,19 +33,34 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + } + + process { + try { + $inputObject = @{ + Context = $Context + APIEndpoint = "/user/blocks/$Username" + Method = 'DELETE' + } - $inputObject = @{ - Context = $Context - APIEndpoint = "/user/blocks/$Username" - Method = 'DELETE' + try { + $null = (Invoke-GitHubAPI @inputObject) + return $true + } catch { + Write-Error $_.Exception.Response + throw $_ + } + } catch { + throw $_ + } } - try { - $null = (Invoke-GitHubAPI @inputObject) - return $true - } catch { - Write-Error $_.Exception.Response - throw $_ + end { + Write-Debug "[$commandName] - End" } } diff --git a/src/functions/private/Users/Emails/Get-GitHubUserAllEmail.ps1 b/src/functions/private/Users/Emails/Get-GitHubUserAllEmail.ps1 index 3920bc53..b4457472 100644 --- a/src/functions/private/Users/Emails/Get-GitHubUserAllEmail.ps1 +++ b/src/functions/private/Users/Emails/Get-GitHubUserAllEmail.ps1 @@ -30,20 +30,34 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - - $body = @{ - per_page = $PerPage - } - $inputObject = @{ - Context = $Context - APIEndpoint = '/user/emails' - Method = 'GET' - Body = $body + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + process { + try { + $body = @{ + per_page = $PerPage + } + $inputObject = @{ + Context = $Context + APIEndpoint = '/user/emails' + Method = 'GET' + Body = $body + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ + } } + end { + Write-Debug "[$commandName] - End" + } } diff --git a/src/functions/private/Users/Emails/Get-GitHubUserPublicEmail.ps1 b/src/functions/private/Users/Emails/Get-GitHubUserPublicEmail.ps1 index 8c2deebf..f5f282ff 100644 --- a/src/functions/private/Users/Emails/Get-GitHubUserPublicEmail.ps1 +++ b/src/functions/private/Users/Emails/Get-GitHubUserPublicEmail.ps1 @@ -32,21 +32,35 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - - $body = @{ - per_page = $PerPage + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } - $inputObject = @{ - Context = $Context - APIEndpoint = '/user/public_emails' - Method = 'GET' - Body = $body - } + process { + try { + $body = @{ + per_page = $PerPage + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + $inputObject = @{ + Context = $Context + APIEndpoint = '/user/public_emails' + Method = 'GET' + Body = $body + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ + } } + end { + Write-Debug "[$commandName] - End" + } } diff --git a/src/functions/private/Users/Followers/Get-GitHubUserFollowersOfUser.ps1 b/src/functions/private/Users/Followers/Get-GitHubUserFollowersOfUser.ps1 index dbf9efaa..305c9aab 100644 --- a/src/functions/private/Users/Followers/Get-GitHubUserFollowersOfUser.ps1 +++ b/src/functions/private/Users/Followers/Get-GitHubUserFollowersOfUser.ps1 @@ -38,21 +38,35 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - - $body = @{ - per_page = $PerPage + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } - $inputObject = @{ - Context = $Context - APIEndpoint = "/users/$Username/followers" - Method = 'GET' - Body = $body - } + process { + try { + $body = @{ + per_page = $PerPage + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + $inputObject = @{ + Context = $Context + APIEndpoint = "/users/$Username/followers" + Method = 'GET' + Body = $body + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ + } } + end { + Write-Debug "[$commandName] - End" + } } diff --git a/src/functions/private/Users/Followers/Get-GitHubUserFollowingMe.ps1 b/src/functions/private/Users/Followers/Get-GitHubUserFollowingMe.ps1 index e229a5ad..362c1386 100644 --- a/src/functions/private/Users/Followers/Get-GitHubUserFollowingMe.ps1 +++ b/src/functions/private/Users/Followers/Get-GitHubUserFollowingMe.ps1 @@ -29,21 +29,35 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - - $body = @{ - per_page = $PerPage + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } - $inputObject = @{ - Context = $Context - APIEndpoint = '/user/following' - Method = 'GET' - Body = $body + process { + try { + $body = @{ + per_page = $PerPage + } + + $inputObject = @{ + Context = $Context + APIEndpoint = '/user/following' + Method = 'GET' + Body = $body + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ + } } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + end { + Write-Debug "[$commandName] - End" } - } diff --git a/src/functions/private/Users/Followers/Get-GitHubUserFollowingUser.ps1 b/src/functions/private/Users/Followers/Get-GitHubUserFollowingUser.ps1 index 66dff1aa..91aa7815 100644 --- a/src/functions/private/Users/Followers/Get-GitHubUserFollowingUser.ps1 +++ b/src/functions/private/Users/Followers/Get-GitHubUserFollowingUser.ps1 @@ -38,21 +38,35 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - - $body = @{ - per_page = $PerPage + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } - $inputObject = @{ - Context = $Context - APIEndpoint = "/users/$Username/following" - Method = 'GET' - Body = $body - } + process { + try { + $body = @{ + per_page = $PerPage + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + $inputObject = @{ + Context = $Context + APIEndpoint = "/users/$Username/following" + Method = 'GET' + Body = $body + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ + } } + end { + Write-Debug "[$commandName] - End" + } } diff --git a/src/functions/private/Users/Followers/Get-GitHubUserMyFollowers.ps1 b/src/functions/private/Users/Followers/Get-GitHubUserMyFollowers.ps1 index e11bf920..8245c08d 100644 --- a/src/functions/private/Users/Followers/Get-GitHubUserMyFollowers.ps1 +++ b/src/functions/private/Users/Followers/Get-GitHubUserMyFollowers.ps1 @@ -30,21 +30,35 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - - $body = @{ - per_page = $PerPage + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } - $inputObject = @{ - Context = $Context - APIEndpoint = '/user/followers' - Method = 'GET' - Body = $body - } + process { + try { + $body = @{ + per_page = $PerPage + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + $inputObject = @{ + Context = $Context + APIEndpoint = '/user/followers' + Method = 'GET' + Body = $body + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ + } } + end { + Write-Debug "[$commandName] - End" + } } diff --git a/src/functions/private/Users/Followers/Test-GitHubUserFollowedByMe.ps1 b/src/functions/private/Users/Followers/Test-GitHubUserFollowedByMe.ps1 index 2f3cf828..3a9a48a1 100644 --- a/src/functions/private/Users/Followers/Test-GitHubUserFollowedByMe.ps1 +++ b/src/functions/private/Users/Followers/Test-GitHubUserFollowedByMe.ps1 @@ -32,22 +32,33 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - - $inputObject = @{ - Context = $Context - APIEndpoint = "/user/following/$Username" - Method = 'GET' + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } - try { - $null = (Invoke-GitHubAPI @inputObject) - return $true - } catch { - if ($_.Exception.Response.StatusCode.Value__ -eq 404) { - return $false - } else { - throw $_ + process { + $inputObject = @{ + Context = $Context + APIEndpoint = "/user/following/$Username" + Method = 'GET' + } + + try { + $null = (Invoke-GitHubAPI @inputObject) + return $true + } catch { + if ($_.Exception.Response.StatusCode.Value__ -eq 404) { + return $false + } else { + throw $_ + } } } + + end { + Write-Debug "[$commandName] - End" + } } diff --git a/src/functions/private/Users/Followers/Test-GitHubUserFollowedByUser.ps1 b/src/functions/private/Users/Followers/Test-GitHubUserFollowedByUser.ps1 index 49bde7d9..81a84a88 100644 --- a/src/functions/private/Users/Followers/Test-GitHubUserFollowedByUser.ps1 +++ b/src/functions/private/Users/Followers/Test-GitHubUserFollowedByUser.ps1 @@ -38,22 +38,33 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - - $inputObject = @{ - Context = $Context - APIEndpoint = "/users/$Username/following/$Follows" - Method = 'GET' + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } - try { - $null = (Invoke-GitHubAPI @inputObject) - return $true - } catch { - if ($_.Exception.Response.StatusCode.Value__ -eq 404) { - return $false - } else { - throw $_ + process { + $inputObject = @{ + Context = $Context + APIEndpoint = "/users/$Username/following/$Follows" + Method = 'GET' + } + + try { + $null = (Invoke-GitHubAPI @inputObject) + return $true + } catch { + if ($_.Exception.Response.StatusCode.Value__ -eq 404) { + return $false + } else { + throw $_ + } } } + + end { + Write-Debug "[$commandName] - End" + } } diff --git a/src/functions/private/Users/GPG-Keys/Get-GitHubUserGpgKeyForUser.ps1 b/src/functions/private/Users/GPG-Keys/Get-GitHubUserGpgKeyForUser.ps1 index e137fb97..9dba33c4 100644 --- a/src/functions/private/Users/GPG-Keys/Get-GitHubUserGpgKeyForUser.ps1 +++ b/src/functions/private/Users/GPG-Keys/Get-GitHubUserGpgKeyForUser.ps1 @@ -36,21 +36,35 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - - $body = @{ - per_page = $PerPage + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } - $inputObject = @{ - Context = $Context - APIEndpoint = "/users/$Username/gpg_keys" - Method = 'GET' - Body = $body - } + process { + try { + $body = @{ + per_page = $PerPage + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + $inputObject = @{ + Context = $Context + APIEndpoint = "/users/$Username/gpg_keys" + Method = 'GET' + Body = $body + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ + } } + end { + Write-Debug "[$commandName] - End" + } } diff --git a/src/functions/private/Users/GPG-Keys/Get-GitHubUserMyGpgKey.ps1 b/src/functions/private/Users/GPG-Keys/Get-GitHubUserMyGpgKey.ps1 index 45fdbe31..6f119bb6 100644 --- a/src/functions/private/Users/GPG-Keys/Get-GitHubUserMyGpgKey.ps1 +++ b/src/functions/private/Users/GPG-Keys/Get-GitHubUserMyGpgKey.ps1 @@ -31,21 +31,35 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - - $body = @{ - per_page = $PerPage + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } - $inputObject = @{ - Context = $Context - APIEndpoint = '/user/gpg_keys' - Method = 'GET' - Body = $body - } + process { + try { + $body = @{ + per_page = $PerPage + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + $inputObject = @{ + Context = $Context + APIEndpoint = '/user/gpg_keys' + Method = 'GET' + Body = $body + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ + } } + end { + Write-Debug "[$commandName] - End" + } } diff --git a/src/functions/private/Users/GPG-Keys/Get-GitHubUserMyGpgKeyById.ps1 b/src/functions/private/Users/GPG-Keys/Get-GitHubUserMyGpgKeyById.ps1 index 5f88b848..14ba121f 100644 --- a/src/functions/private/Users/GPG-Keys/Get-GitHubUserMyGpgKeyById.ps1 +++ b/src/functions/private/Users/GPG-Keys/Get-GitHubUserMyGpgKeyById.ps1 @@ -33,16 +33,30 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - - $inputObject = @{ - Context = $Context - APIEndpoint = "/user/gpg_keys/$ID" - Method = 'GET' + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + process { + try { + $inputObject = @{ + Context = $Context + APIEndpoint = "/user/gpg_keys/$ID" + Method = 'GET' + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ + } } + end { + Write-Debug "[$commandName] - End" + } } diff --git a/src/functions/private/Users/Get-GitHubAllUser.ps1 b/src/functions/private/Users/Get-GitHubAllUser.ps1 index 45512ae1..c85e6284 100644 --- a/src/functions/private/Users/Get-GitHubAllUser.ps1 +++ b/src/functions/private/Users/Get-GitHubAllUser.ps1 @@ -36,22 +36,36 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - - $body = @{ - since = $Since - per_page = $PerPage + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } - $inputObject = @{ - Context = $Context - APIEndpoint = '/users' - Method = 'GET' - Body = $body - } + process { + try { + $body = @{ + since = $Since + per_page = $PerPage + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + $inputObject = @{ + Context = $Context + APIEndpoint = '/users' + Method = 'GET' + Body = $body + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ + } } + end { + Write-Debug "[$commandName] - End" + } } diff --git a/src/functions/private/Users/Get-GitHubMyUser.ps1 b/src/functions/private/Users/Get-GitHubMyUser.ps1 index 31fca26d..9287be3f 100644 --- a/src/functions/private/Users/Get-GitHubMyUser.ps1 +++ b/src/functions/private/Users/Get-GitHubMyUser.ps1 @@ -26,16 +26,30 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - - $inputObject = @{ - Context = $Context - APIEndpoint = '/user' - Method = 'GET' + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + process { + try { + $inputObject = @{ + Context = $Context + APIEndpoint = '/user' + Method = 'GET' + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ + } } + end { + Write-Debug "[$commandName] - End" + } } diff --git a/src/functions/private/Users/Get-GitHubUserByName.ps1 b/src/functions/private/Users/Get-GitHubUserByName.ps1 index 23fbcf0a..4eda5148 100644 --- a/src/functions/private/Users/Get-GitHubUserByName.ps1 +++ b/src/functions/private/Users/Get-GitHubUserByName.ps1 @@ -44,16 +44,30 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - - $inputObject = @{ - Context = $Context - APIEndpoint = "/users/$Username" - Method = 'GET' + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + process { + try { + $inputObject = @{ + Context = $Context + APIEndpoint = "/users/$Username" + Method = 'GET' + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ + } } + end { + Write-Debug "[$commandName] - End" + } } diff --git a/src/functions/private/Users/Keys/Get-GitHubUserKeyForUser.ps1 b/src/functions/private/Users/Keys/Get-GitHubUserKeyForUser.ps1 index 387d0286..ba37c431 100644 --- a/src/functions/private/Users/Keys/Get-GitHubUserKeyForUser.ps1 +++ b/src/functions/private/Users/Keys/Get-GitHubUserKeyForUser.ps1 @@ -36,21 +36,35 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - - $body = @{ - per_page = $PerPage + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } - $inputObject = @{ - Context = $Context - APIEndpoint = "/users/$Username/keys" - Method = 'GET' - Body = $body - } + process { + try { + $body = @{ + per_page = $PerPage + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + $inputObject = @{ + Context = $Context + APIEndpoint = "/users/$Username/keys" + Method = 'GET' + Body = $body + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ + } } + end { + Write-Debug "[$commandName] - End" + } } diff --git a/src/functions/private/Users/Keys/Get-GitHubUserMyKey.ps1 b/src/functions/private/Users/Keys/Get-GitHubUserMyKey.ps1 index 6ac7cc4f..4af14278 100644 --- a/src/functions/private/Users/Keys/Get-GitHubUserMyKey.ps1 +++ b/src/functions/private/Users/Keys/Get-GitHubUserMyKey.ps1 @@ -31,21 +31,35 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - - $body = @{ - per_page = $PerPage + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } - $inputObject = @{ - Context = $Context - APIEndpoint = '/user/keys' - Method = 'GET' - Body = $body - } + process { + try { + $body = @{ + per_page = $PerPage + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + $inputObject = @{ + Context = $Context + APIEndpoint = '/user/keys' + Method = 'GET' + Body = $body + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ + } } + end { + Write-Debug "[$commandName] - End" + } } diff --git a/src/functions/private/Users/Keys/Get-GitHubUserMyKeyById.ps1 b/src/functions/private/Users/Keys/Get-GitHubUserMyKeyById.ps1 index 708366a6..38c66b58 100644 --- a/src/functions/private/Users/Keys/Get-GitHubUserMyKeyById.ps1 +++ b/src/functions/private/Users/Keys/Get-GitHubUserMyKeyById.ps1 @@ -33,16 +33,30 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - - $inputObject = @{ - Context = $Context - APIEndpoint = "/user/keys/$ID" - Method = 'GET' + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + process { + try { + $inputObject = @{ + Context = $Context + APIEndpoint = "/user/keys/$ID" + Method = 'GET' + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ + } } + end { + Write-Debug "[$commandName] - End" + } } diff --git a/src/functions/private/Users/SSH-Signing-Keys/Get-GitHubUserMySigningKey.ps1 b/src/functions/private/Users/SSH-Signing-Keys/Get-GitHubUserMySigningKey.ps1 index be19c95c..77d4120a 100644 --- a/src/functions/private/Users/SSH-Signing-Keys/Get-GitHubUserMySigningKey.ps1 +++ b/src/functions/private/Users/SSH-Signing-Keys/Get-GitHubUserMySigningKey.ps1 @@ -31,21 +31,35 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - - $body = @{ - per_page = $PerPage + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } - $inputObject = @{ - Context = $Context - APIEndpoint = '/user/ssh_signing_keys' - Method = 'GET' - Body = $body - } + process { + try { + $body = @{ + per_page = $PerPage + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + $inputObject = @{ + Context = $Context + APIEndpoint = '/user/ssh_signing_keys' + Method = 'GET' + Body = $body + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ + } } + end { + Write-Debug "[$commandName] - End" + } } diff --git a/src/functions/private/Users/SSH-Signing-Keys/Get-GitHubUserMySigningKeyById.ps1 b/src/functions/private/Users/SSH-Signing-Keys/Get-GitHubUserMySigningKeyById.ps1 index 3fb5d79a..b95bca44 100644 --- a/src/functions/private/Users/SSH-Signing-Keys/Get-GitHubUserMySigningKeyById.ps1 +++ b/src/functions/private/Users/SSH-Signing-Keys/Get-GitHubUserMySigningKeyById.ps1 @@ -34,16 +34,30 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - - $inputObject = @{ - Context = $Context - APIEndpoint = "/user/ssh_signing_keys/$ID" - Method = 'GET' + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + process { + try { + $inputObject = @{ + Context = $Context + APIEndpoint = "/user/ssh_signing_keys/$ID" + Method = 'GET' + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ + } } + end { + Write-Debug "[$commandName] - End" + } } diff --git a/src/functions/private/Users/SSH-Signing-Keys/Get-GitHubUserSigningKeyForUser.ps1 b/src/functions/private/Users/SSH-Signing-Keys/Get-GitHubUserSigningKeyForUser.ps1 index 742388a2..4f577e54 100644 --- a/src/functions/private/Users/SSH-Signing-Keys/Get-GitHubUserSigningKeyForUser.ps1 +++ b/src/functions/private/Users/SSH-Signing-Keys/Get-GitHubUserSigningKeyForUser.ps1 @@ -36,21 +36,35 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - - $body = @{ - per_page = $PerPage + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } - $inputObject = @{ - Context = $Context - APIEndpoint = "/users/$Username/ssh_signing_keys" - Method = 'GET' - Body = $body - } + process { + try { + $body = @{ + per_page = $PerPage + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + $inputObject = @{ + Context = $Context + APIEndpoint = "/users/$Username/ssh_signing_keys" + Method = 'GET' + Body = $body + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ + } } + end { + Write-Debug "[$commandName] - End" + } } diff --git a/src/functions/private/Users/Social-Accounts/Get-GitHubMyUserSocials.ps1 b/src/functions/private/Users/Social-Accounts/Get-GitHubMyUserSocials.ps1 index b888f2ae..aad55ccd 100644 --- a/src/functions/private/Users/Social-Accounts/Get-GitHubMyUserSocials.ps1 +++ b/src/functions/private/Users/Social-Accounts/Get-GitHubMyUserSocials.ps1 @@ -29,21 +29,35 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - - $body = @{ - per_page = $PerPage + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } - $inputObject = @{ - Context = $Context - APIEndpoint = '/user/social_accounts' - Method = 'GET' - Body = $body + process { + try { + $body = @{ + per_page = $PerPage + } + + $inputObject = @{ + Context = $Context + APIEndpoint = '/user/social_accounts' + Method = 'GET' + Body = $body + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ + } } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + end { + Write-Debug "[$commandName] - End" } - } diff --git a/src/functions/private/Users/Social-Accounts/Get-GitHubUserSocialsByName.ps1 b/src/functions/private/Users/Social-Accounts/Get-GitHubUserSocialsByName.ps1 index 9289d985..48a78c86 100644 --- a/src/functions/private/Users/Social-Accounts/Get-GitHubUserSocialsByName.ps1 +++ b/src/functions/private/Users/Social-Accounts/Get-GitHubUserSocialsByName.ps1 @@ -32,16 +32,30 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - - $inputObject = @{ - Context = $Context - APIEndpoint = "/users/$Username/social_accounts" - Method = 'GET' + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + process { + try { + $inputObject = @{ + Context = $Context + APIEndpoint = "/users/$Username/social_accounts" + Method = 'GET' + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ + } } + end { + Write-Debug "[$commandName] - End" + } } diff --git a/src/functions/public/Actions/Disable-GitHubWorkflow.ps1 b/src/functions/public/Actions/Disable-GitHubWorkflow.ps1 index 781d94c2..707afc2e 100644 --- a/src/functions/public/Actions/Disable-GitHubWorkflow.ps1 +++ b/src/functions/public/Actions/Disable-GitHubWorkflow.ps1 @@ -26,24 +26,37 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + if ([string]::IsNullOrEmpty($Owner)) { + $Owner = $Context.Owner + } + Write-Debug "Owner : [$($Context.Owner)]" + + if ([string]::IsNullOrEmpty($Repo)) { + $Repo = $Context.Repo + } + Write-Debug "Repo : [$($Context.Repo)]" } - Write-Debug "Owner : [$($Context.Owner)]" - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo + process { + try { + $inputObject = @{ + Context = $Context + APIEndpoint = "/repos/$Owner/$Repo/actions/workflows/$ID/disable" + Method = 'PUT' + } + + $null = Invoke-GitHubAPI @inputObject + } catch { + throw $_ + } } - Write-Debug "Repo : [$($Context.Repo)]" - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/actions/workflows/$ID/disable" - Method = 'PUT' + end { + Write-Debug "[$commandName] - End" } - - $null = Invoke-GitHubAPI @inputObject - } diff --git a/src/functions/public/Actions/Enable-GitHubWorkflow.ps1 b/src/functions/public/Actions/Enable-GitHubWorkflow.ps1 index bea1ef5d..4d7fd43e 100644 --- a/src/functions/public/Actions/Enable-GitHubWorkflow.ps1 +++ b/src/functions/public/Actions/Enable-GitHubWorkflow.ps1 @@ -23,23 +23,37 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + if ([string]::IsNullOrEmpty($Owner)) { + $Owner = $Context.Owner + } + Write-Debug "Owner : [$($Context.Owner)]" + + if ([string]::IsNullOrEmpty($Repo)) { + $Repo = $Context.Repo + } + Write-Debug "Repo : [$($Context.Repo)]" } - Write-Debug "Owner : [$($Context.Owner)]" - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo + process { + try { + $inputObject = @{ + Context = $Context + APIEndpoint = "/repos/$Owner/$Repo/actions/workflows/$ID/enable" + Method = 'PUT' + } + + $null = Invoke-GitHubAPI @inputObject + } catch { + throw $_ + } } - Write-Debug "Repo : [$($Context.Repo)]" - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/actions/workflows/$ID/enable" - Method = 'PUT' + end { + Write-Debug "[$commandName] - End" } - - $null = Invoke-GitHubAPI @inputObject } diff --git a/src/functions/public/Actions/Get-GitHubWorkflow.ps1 b/src/functions/public/Actions/Get-GitHubWorkflow.ps1 index 3c687390..9cc9cbb5 100644 --- a/src/functions/public/Actions/Get-GitHubWorkflow.ps1 +++ b/src/functions/public/Actions/Get-GitHubWorkflow.ps1 @@ -40,31 +40,44 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner : [$($Context.Owner)]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + if ([string]::IsNullOrEmpty($Owner)) { + $Owner = $Context.Owner + } + Write-Debug "Owner : [$($Context.Owner)]" + + if ([string]::IsNullOrEmpty($Repo)) { + $Repo = $Context.Repo + } + Write-Debug "Repo : [$($Context.Repo)]" } - Write-Debug "Repo : [$($Context.Repo)]" - $body = @{ - per_page = $PerPage + process { + try { + $body = @{ + per_page = $PerPage + } + + $inputObject = @{ + Context = $Context + APIEndpoint = "/repos/$Owner/$Repo/actions/workflows" + Method = 'GET' + Body = $body + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response.workflows + } + } catch { + throw $_ + } } - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/actions/workflows" - Method = 'GET' - Body = $body + end { + Write-Debug "[$commandName] - End" } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response.workflows - } - } diff --git a/src/functions/public/Actions/Get-GitHubWorkflowRun.ps1 b/src/functions/public/Actions/Get-GitHubWorkflowRun.ps1 index cfe456e5..6ab37f93 100644 --- a/src/functions/public/Actions/Get-GitHubWorkflowRun.ps1 +++ b/src/functions/public/Actions/Get-GitHubWorkflowRun.ps1 @@ -1,5 +1,6 @@ filter Get-GitHubWorkflowRun { <# + TODO:Split into two private functions and a swtich statement to handle the parameter set. .NOTES [List workflow runs for a workflow](https://docs.github.com/rest/actions/workflow-runs?apiVersion=2022-11-28#list-workflow-runs-for-a-workflow) [List workflow runs for a repository](https://docs.github.com/rest/actions/workflow-runs?apiVersion=2022-11-28#list-workflow-runs-for-a-repository) @@ -30,41 +31,54 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + if ([string]::IsNullOrEmpty($Owner)) { + $Owner = $Context.Owner + } + Write-Debug "Owner : [$($Context.Owner)]" - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner + if ([string]::IsNullOrEmpty($Repo)) { + $Repo = $Context.Repo + } + Write-Debug "Repo : [$($Context.Repo)]" } - Write-Debug "Owner : [$($Context.Owner)]" - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo : [$($Context.Repo)]" + process { + try { + $body = @{ + per_page = $PerPage + } - $body = @{ - per_page = $PerPage - } + if ($Name) { + $ID = (Get-GitHubWorkflow -Owner $Owner -Repo $Repo -Name $Name).id + } - if ($Name) { - $ID = (Get-GitHubWorkflow -Owner $Owner -Repo $Repo -Name $Name).id - } + if ($ID) { + $Uri = "/repos/$Owner/$Repo/actions/workflows/$ID/runs" + } else { + $Uri = "/repos/$Owner/$Repo/actions/runs" + } - if ($ID) { - $Uri = "/repos/$Owner/$Repo/actions/workflows/$ID/runs" - } else { - $Uri = "/repos/$Owner/$Repo/actions/runs" - } + $inputObject = @{ + Context = $Context + APIEndpoint = $Uri + Method = 'GET' + Body = $body + } - $inputObject = @{ - Context = $Context - APIEndpoint = $Uri - Method = 'GET' - Body = $body + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response.workflow_runs + } + } catch { + throw $_ + } } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response.workflow_runs + end { + Write-Debug "[$commandName] - End" } - } diff --git a/src/functions/public/Actions/Get-GitHubWorkflowUsage.ps1 b/src/functions/public/Actions/Get-GitHubWorkflowUsage.ps1 index 2749659e..96a6bd8f 100644 --- a/src/functions/public/Actions/Get-GitHubWorkflowUsage.ps1 +++ b/src/functions/public/Actions/Get-GitHubWorkflowUsage.ps1 @@ -34,26 +34,40 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + if ([string]::IsNullOrEmpty($Owner)) { + $Owner = $Context.Owner + } + Write-Debug "Owner : [$($Context.Owner)]" - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner + if ([string]::IsNullOrEmpty($Repo)) { + $Repo = $Context.Repo + } + Write-Debug "Repo : [$($Context.Repo)]" } - Write-Debug "Owner : [$($Context.Owner)]" - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo : [$($Context.Repo)]" + process { + try { - $inputObject = @{ - Context = $Context - Method = 'GET' - APIEndpoint = "/repos/$Owner/$Repo/actions/workflows/$ID/timing" - } + $inputObject = @{ + Context = $Context + Method = 'GET' + APIEndpoint = "/repos/$Owner/$Repo/actions/workflows/$ID/timing" + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response.billable + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response.billable + } + } catch { + throw $_ + } } + end { + Write-Debug "[$commandName] - End" + } } diff --git a/src/functions/public/Actions/Remove-GitHubWorkflowRun.ps1 b/src/functions/public/Actions/Remove-GitHubWorkflowRun.ps1 index b8909886..bb4336ae 100644 --- a/src/functions/public/Actions/Remove-GitHubWorkflowRun.ps1 +++ b/src/functions/public/Actions/Remove-GitHubWorkflowRun.ps1 @@ -40,28 +40,41 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner : [$($Context.Owner)]" + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + if ([string]::IsNullOrEmpty($Owner)) { + $Owner = $Context.Owner + } + Write-Debug "Owner : [$($Context.Owner)]" - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo + if ([string]::IsNullOrEmpty($Repo)) { + $Repo = $Context.Repo + } + Write-Debug "Repo : [$($Context.Repo)]" } - Write-Debug "Repo : [$($Context.Repo)]" - $inputObject = @{ - Context = $Context - APIEndpoint = "repos/$Owner/$Repo/actions/runs/$RunID" - Method = 'DELETE' - } + process { + try { + $inputObject = @{ + Context = $Context + APIEndpoint = "repos/$Owner/$Repo/actions/runs/$RunID" + Method = 'DELETE' + } - if ($PSCmdlet.ShouldProcess("workflow run with ID [$RunID] in [$Owner/$Repo]", 'Delete')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + if ($PSCmdlet.ShouldProcess("workflow run with ID [$RunID] in [$Owner/$Repo]", 'Delete')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } + } catch { + throw $_ } } + end { + Write-Debug "[$commandName] - End" + } } diff --git a/src/functions/public/Actions/Start-GitHubWorkflow.ps1 b/src/functions/public/Actions/Start-GitHubWorkflow.ps1 index 96dfe00f..1cf704e1 100644 --- a/src/functions/public/Actions/Start-GitHubWorkflow.ps1 +++ b/src/functions/public/Actions/Start-GitHubWorkflow.ps1 @@ -52,34 +52,47 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + if ([string]::IsNullOrEmpty($Owner)) { + $Owner = $Context.Owner + } + Write-Debug "Owner : [$($Context.Owner)]" - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner + if ([string]::IsNullOrEmpty($Repo)) { + $Repo = $Context.Repo + } + Write-Debug "Repo : [$($Context.Repo)]" } - Write-Debug "Owner : [$($Context.Owner)]" - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo : [$($Context.Repo)]" + process { + try { + $body = @{ + ref = $Ref + inputs = $Inputs + } - $body = @{ - ref = $Ref - inputs = $Inputs - } + $inputObject = @{ + Context = $Context + APIEndpoint = "/repos/$Owner/$Repo/actions/workflows/$ID/dispatches" + Method = 'POST' + Body = $body + } - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/actions/workflows/$ID/dispatches" - Method = 'POST' - Body = $body - } - - if ($PSCmdlet.ShouldProcess("workflow with ID [$ID] in [$Owner/$Repo]", 'Start')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + if ($PSCmdlet.ShouldProcess("workflow with ID [$ID] in [$Owner/$Repo]", 'Start')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } + } catch { + throw $_ } } + end { + Write-Debug "[$commandName] - End" + } } diff --git a/src/functions/public/Actions/Start-GitHubWorkflowReRun.ps1 b/src/functions/public/Actions/Start-GitHubWorkflowReRun.ps1 index a5209b1b..7d2105e4 100644 --- a/src/functions/public/Actions/Start-GitHubWorkflowReRun.ps1 +++ b/src/functions/public/Actions/Start-GitHubWorkflowReRun.ps1 @@ -36,27 +36,41 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + if ([string]::IsNullOrEmpty($Owner)) { + $Owner = $Context.Owner + } + Write-Debug "Owner : [$($Context.Owner)]" - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner + if ([string]::IsNullOrEmpty($Repo)) { + $Repo = $Context.Repo + } + Write-Debug "Repo : [$($Context.Repo)]" } - Write-Debug "Owner : [$($Context.Owner)]" - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo : [$($Context.Repo)]" + process { + try { + $inputObject = @{ + Context = $Context + Method = 'POST' + APIEndpoint = "/repos/$Owner/$Repo/actions/runs/$ID/rerun" + } - $inputObject = @{ - Context = $Context - Method = 'POST' - APIEndpoint = "/repos/$Owner/$Repo/actions/runs/$ID/rerun" + if ($PSCmdlet.ShouldProcess("workflow with ID [$ID] in [$Owner/$Repo]", 'Re-run')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } + } catch { + throw $_ + } } - if ($PSCmdlet.ShouldProcess("workflow with ID [$ID] in [$Owner/$Repo]", 'Re-run')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + end { + Write-Debug "[$commandName] - End" } } diff --git a/src/functions/public/Actions/Stop-GitHubWorkflowRun.ps1 b/src/functions/public/Actions/Stop-GitHubWorkflowRun.ps1 index 2138de50..80bf356d 100644 --- a/src/functions/public/Actions/Stop-GitHubWorkflowRun.ps1 +++ b/src/functions/public/Actions/Stop-GitHubWorkflowRun.ps1 @@ -36,27 +36,41 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + if ([string]::IsNullOrEmpty($Owner)) { + $Owner = $Context.Owner + } + Write-Debug "Owner : [$($Context.Owner)]" - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner + if ([string]::IsNullOrEmpty($Repo)) { + $Repo = $Context.Repo + } + Write-Debug "Repo : [$($Context.Repo)]" } - Write-Debug "Owner : [$($Context.Owner)]" - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo : [$($Context.Repo)]" + process { + try { + $inputObject = @{ + Context = $Context + Method = 'POST' + APIEndpoint = "/repos/$Owner/$Repo/actions/runs/$ID/cancel" + } - $inputObject = @{ - Context = $Context - Method = 'POST' - APIEndpoint = "/repos/$Owner/$Repo/actions/runs/$ID/cancel" + if ($PSCmdlet.ShouldProcess("workflow run with ID [$ID] in [$Owner/$Repo]", 'Cancel/Stop')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } + } catch { + throw $_ + } } - if ($PSCmdlet.ShouldProcess("workflow run with ID [$ID] in [$Owner/$Repo]", 'Cancel/Stop')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + end { + Write-Debug "[$commandName] - End" } } diff --git a/src/functions/public/Apps/GitHub Apps/Get-GitHubApp.ps1 b/src/functions/public/Apps/GitHub Apps/Get-GitHubApp.ps1 index bbcd89b3..7c38e113 100644 --- a/src/functions/public/Apps/GitHub Apps/Get-GitHubApp.ps1 +++ b/src/functions/public/Apps/GitHub Apps/Get-GitHubApp.ps1 @@ -39,9 +39,6 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - Assert-GitHubContext -Context $Context -AuthType App - switch ($PSCmdlet.ParameterSetName) { 'BySlug' { Get-GitHubAppByName -AppSlug $AppSlug -Context $Context diff --git a/src/functions/public/Apps/GitHub Apps/Get-GitHubAppInstallation.ps1 b/src/functions/public/Apps/GitHub Apps/Get-GitHubAppInstallation.ps1 index fb8c1aef..4e9a9a86 100644 --- a/src/functions/public/Apps/GitHub Apps/Get-GitHubAppInstallation.ps1 +++ b/src/functions/public/Apps/GitHub Apps/Get-GitHubAppInstallation.ps1 @@ -25,16 +25,30 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - Assert-GitHubContext -Context $Context -AuthType App + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType APP + } - $inputObject = @{ - Context = $Context - APIEndpoint = '/app/installations' - Method = 'GET' + process { + try { + $inputObject = @{ + Context = $Context + APIEndpoint = '/app/installations' + Method = 'GET' + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ + } } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + end { + Write-Debug "[$commandName] - End" } } diff --git a/src/functions/public/Apps/GitHub Apps/New-GitHubAppInstallationAccessToken.ps1 b/src/functions/public/Apps/GitHub Apps/New-GitHubAppInstallationAccessToken.ps1 index 34bf8658..149706cf 100644 --- a/src/functions/public/Apps/GitHub Apps/New-GitHubAppInstallationAccessToken.ps1 +++ b/src/functions/public/Apps/GitHub Apps/New-GitHubAppInstallationAccessToken.ps1 @@ -65,21 +65,39 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - Assert-GitHubContext -Context $Context -AuthType App - - $inputObject = @{ - Context = $Context - APIEndpoint = "/app/installations/$InstallationID/access_tokens" - Method = 'Post' + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType APP } - Invoke-GitHubAPI @inputObject | ForEach-Object { - [pscustomobject]@{ - Token = $_.Response.token | ConvertTo-SecureString -AsPlainText -Force - ExpiresAt = $_.Response.expires_at.ToLocalTime() - Permissions = $_.Response.permissions - RepositorySelection = $_.Response.repository_selection + process { + try { + $inputObject = @{ + Context = $Context + APIEndpoint = "/app/installations/$InstallationID/access_tokens" + Method = 'Post' + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + [pscustomobject]@{ + Token = $_.Response.token | ConvertTo-SecureString -AsPlainText -Force + ExpiresAt = $_.Response.expires_at.ToLocalTime() + Permissions = $_.Response.permissions + RepositorySelection = $_.Response.repository_selection + } + } + } catch { + throw $_ } } + + end { + Write-Debug "[$commandName] - End" + } + + clean { + [System.GC]::Collect() + } } diff --git a/src/functions/public/Apps/Webhooks/Get-GitHubAppWebhookConfiguration.ps1 b/src/functions/public/Apps/Webhooks/Get-GitHubAppWebhookConfiguration.ps1 index 163b65fd..477d31ac 100644 --- a/src/functions/public/Apps/Webhooks/Get-GitHubAppWebhookConfiguration.ps1 +++ b/src/functions/public/Apps/Webhooks/Get-GitHubAppWebhookConfiguration.ps1 @@ -26,16 +26,31 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - Assert-GitHubContext -Context $Context -AuthType App + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType APP + } - $inputObject = @{ - Context = $Context - APIEndpoint = '/app/hook/config' - Method = 'GET' + process { + try { + $inputObject = @{ + Context = $Context + APIEndpoint = '/app/hook/config' + Method = 'GET' + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ + } } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + end { + Write-Debug "[$commandName] - End" } } + diff --git a/src/functions/public/Apps/Webhooks/Get-GitHubAppWebhookDelivery.ps1 b/src/functions/public/Apps/Webhooks/Get-GitHubAppWebhookDelivery.ps1 index e5a25609..14ff6896 100644 --- a/src/functions/public/Apps/Webhooks/Get-GitHubAppWebhookDelivery.ps1 +++ b/src/functions/public/Apps/Webhooks/Get-GitHubAppWebhookDelivery.ps1 @@ -25,16 +25,30 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - Assert-GitHubContext -Context $Context -AuthType App + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Debug "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType APP + } - $inputObject = @{ - Context = $Context - APIEndpoint = '/app/hook/deliveries' - Method = 'GET' + process { + try { + $inputObject = @{ + Context = $Context + APIEndpoint = '/app/hook/deliveries' + Method = 'GET' + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } catch { + throw $_ + } } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + end { + Write-Debug "[$commandName] - End" } } diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index ef228537..3d07d8f7 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -43,7 +43,6 @@ function Get-GitHubContext { } process { - switch ($PSCmdlet.ParameterSetName) { 'NamedContext' { Write-Verbose "NamedContext: [$Context]"