diff --git a/src/classes/public/Context/GitHubContext.ps1 b/src/classes/public/Context/GitHubContext.ps1 index 736d8fdb..e4117572 100644 --- a/src/classes/public/Context/GitHubContext.ps1 +++ b/src/classes/public/Context/GitHubContext.ps1 @@ -1,4 +1,4 @@ -class GitHubContext : Context { +class GitHubContext : Context { # The GitHub Context Name. # HostName/Username or HostName/AppSlug # github.com/Octocat @@ -18,7 +18,7 @@ class GitHubContext : Context { # The API base URI. # https://api.github.com - [uri] $ApiBaseUri + [string] $ApiBaseUri # The GitHub API version. # 2022-11-28 diff --git a/src/functions/private/Apps/Get-GitHubAppByName.ps1 b/src/functions/private/Apps/Get-GitHubAppByName.ps1 index 83ce4356..cf9ac29d 100644 --- a/src/functions/private/Apps/Get-GitHubAppByName.ps1 +++ b/src/functions/private/Apps/Get-GitHubAppByName.ps1 @@ -30,15 +30,25 @@ [object] $Context = (Get-GitHubContext) ) - $Context = Resolve-GitHubContext -Context $Context - - $inputObject = @{ - Context = $Context - APIEndpoint = "/apps/$AppSlug" - Method = 'GET' + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Verbose "[$commandName] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response + process { + $inputObject = @{ + Context = $Context + APIEndpoint = "/apps/$AppSlug" + Method = 'GET' + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } + end { + Write-Verbose "[$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..9055ec5e 100644 --- a/src/functions/public/Apps/GitHub Apps/Get-GitHubApp.ps1 +++ b/src/functions/public/Apps/GitHub Apps/Get-GitHubApp.ps1 @@ -40,7 +40,6 @@ ) $Context = Resolve-GitHubContext -Context $Context - Assert-GitHubContext -Context $Context -AuthType App switch ($PSCmdlet.ParameterSetName) { 'BySlug' { diff --git a/src/functions/public/Apps/GitHub Apps/Get-GitHubAppInstallation.ps1 b/src/functions/public/Apps/GitHub Apps/Get-GitHubAppInstallation.ps1 index fb8c1aef..79f05113 100644 --- a/src/functions/public/Apps/GitHub Apps/Get-GitHubAppInstallation.ps1 +++ b/src/functions/public/Apps/GitHub Apps/Get-GitHubAppInstallation.ps1 @@ -26,7 +26,6 @@ ) $Context = Resolve-GitHubContext -Context $Context - Assert-GitHubContext -Context $Context -AuthType App $inputObject = @{ Context = $Context diff --git a/src/functions/public/Apps/GitHub Apps/New-GitHubAppInstallationAccessToken.ps1 b/src/functions/public/Apps/GitHub Apps/New-GitHubAppInstallationAccessToken.ps1 index 34bf8658..d4d3667e 100644 --- a/src/functions/public/Apps/GitHub Apps/New-GitHubAppInstallationAccessToken.ps1 +++ b/src/functions/public/Apps/GitHub Apps/New-GitHubAppInstallationAccessToken.ps1 @@ -66,7 +66,6 @@ ) $Context = Resolve-GitHubContext -Context $Context - Assert-GitHubContext -Context $Context -AuthType App $inputObject = @{ Context = $Context diff --git a/src/functions/public/Apps/Webhooks/Get-GitHubAppWebhookConfiguration.ps1 b/src/functions/public/Apps/Webhooks/Get-GitHubAppWebhookConfiguration.ps1 index 163b65fd..64b8dbdf 100644 --- a/src/functions/public/Apps/Webhooks/Get-GitHubAppWebhookConfiguration.ps1 +++ b/src/functions/public/Apps/Webhooks/Get-GitHubAppWebhookConfiguration.ps1 @@ -27,7 +27,6 @@ ) $Context = Resolve-GitHubContext -Context $Context - Assert-GitHubContext -Context $Context -AuthType App $inputObject = @{ Context = $Context diff --git a/src/functions/public/Apps/Webhooks/Get-GitHubAppWebhookDelivery.ps1 b/src/functions/public/Apps/Webhooks/Get-GitHubAppWebhookDelivery.ps1 index e5a25609..b2ad5b3a 100644 --- a/src/functions/public/Apps/Webhooks/Get-GitHubAppWebhookDelivery.ps1 +++ b/src/functions/public/Apps/Webhooks/Get-GitHubAppWebhookDelivery.ps1 @@ -26,7 +26,6 @@ ) $Context = Resolve-GitHubContext -Context $Context - Assert-GitHubContext -Context $Context -AuthType App $inputObject = @{ Context = $Context diff --git a/src/functions/public/Auth/Connect-GitHubApp.ps1 b/src/functions/public/Auth/Connect-GitHubApp.ps1 index 0fa7235f..498ab089 100644 --- a/src/functions/public/Auth/Connect-GitHubApp.ps1 +++ b/src/functions/public/Auth/Connect-GitHubApp.ps1 @@ -1,4 +1,4 @@ -function Connect-GitHubApp { +function Connect-GitHubApp { <# .SYNOPSIS Connects to GitHub as a installation using a GitHub App. @@ -104,7 +104,7 @@ function Connect-GitHubApp { AuthType = [string]'IAT' TokenType = [string]'ghs' DisplayName = [string]$Context.DisplayName - ApiBaseUri = [uri]$Context.ApiBaseUri + ApiBaseUri = [string]$Context.ApiBaseUri ApiVersion = [string]$Context.ApiVersion HostName = [string]$Context.HostName ClientID = [string]$Context.ClientID @@ -113,18 +113,18 @@ function Connect-GitHubApp { Events = [string[]]$installation.events TargetType = [string]$installation.target_type Token = [securestring]$token.Token - TokenExpirationDate = [datetime]$token.ExpiresAt + TokenExpirationDate = [string]$token.ExpiresAt } switch ($installation.target_type) { 'User' { - $contextParams['TargetName'] = [string]$installation.account.login + $contextParams['TargetName'] = $installation.account.login } 'Organization' { - $contextParams['TargetName'] = [string]$installation.account.login + $contextParams['TargetName'] = $installation.account.login } 'Enterprise' { - $contextParams['TargetName'] = [string]$installation.account.slug + $contextParams['TargetName'] = $installation.account.slug } } Write-Verbose 'Logging in using a managed installation access token...' diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 index 01e0217c..cb420df5 100644 --- a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -52,7 +52,7 @@ function Set-GitHubContext { # Run functions to get info on the temporary context. try { Write-Verbose "Getting info on the context [$($contextObj['AuthType'])]." - switch -Regex ($contextObj['AuthType']) { + switch -Regex ($($contextObj['AuthType'])) { 'PAT|UAT|IAT' { $viewer = Get-GitHubViewer -Context $contextObj $viewer | Out-String -Stream | ForEach-Object { Write-Verbose $_ }