Skip to content

Commit

Permalink
Fixing logic on API function to use correct syntax for type of token
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusStorhaug committed Sep 19, 2023
1 parent cb7a3c0 commit da9114d
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/GitHub/public/Core/Invoke-GitHubAPI.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit da9114d

Please sign in to comment.