From da9114d927411db29fc9d9bff18edd42a4920b98 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 20 Sep 2023 00:16:29 +0200 Subject: [PATCH] Fixing logic on API function to use correct syntax for type of token --- src/GitHub/public/Core/Invoke-GitHubAPI.ps1 | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/GitHub/public/Core/Invoke-GitHubAPI.ps1 b/src/GitHub/public/Core/Invoke-GitHubAPI.ps1 index d7d34bf50..3ff02732c 100644 --- a/src/GitHub/public/Core/Invoke-GitHubAPI.ps1 +++ b/src/GitHub/public/Core/Invoke-GitHubAPI.ps1 @@ -27,12 +27,23 @@ [switch] $UseWebRequest ) + if ([string]::IsNullOrEmpty($Token)) { + throw 'Token is required' + } + + if ($Token.StartsWith('ghp_')) { + $authorization = "token $Token" + } + if ($Token.StartsWith('ghu_')) { + $authorization = "Bearer $Token" + } + $APICall = @{ Uri = "$script:APIBaseURI$($APIEndpoint.Replace('\', '/').Replace('//', '/'))" Method = $Method Body = [string]::IsNullOrEmpty($Data) ? ($Body | ConvertTo-Json -Depth 100) : $Data Headers = @{ - Authorization = "token $Token" + Authorization = $authorization 'Content-Type' = $ContentType 'X-GitHub-Api-Version' = $Version }