Skip to content

Commit

Permalink
🪲 [Fix]: Connect-GitHubAccount - Get Token (#122)
Browse files Browse the repository at this point in the history
## Description

- Fix an issue where the `Connect-GitHubAccount` would get object
instead of value.

## Type of change

<!-- Use the check-boxes [x] on the options that are relevant. -->

- [ ] 📖 [Docs]
- [x] 🪲 [Fix]
- [ ] 🩹 [Patch]
- [ ] ⚠️ [Security fix]
- [ ] 🚀 [Feature]
- [ ] 🌟 [Breaking change]

## Checklist

<!-- Use the check-boxes [x] on the options that are relevant. -->

- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
  • Loading branch information
MariusStorhaug authored Aug 17, 2024
1 parent 1f9a870 commit 8bf53d9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/private/Commands/Initialize-RunnerEnvironment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
Set-GitHubEnv -Name 'GITHUB_REPOSITORY_NAME' -Value $env:GITHUB_REPOSITORY_NAME

# Autologon if a token is present in environment variables
$tokenVar = Get-ChildItem -Path 'Env:' | Where-Object Name -In 'GH_TOKEN', 'GITHUB_TOKEN' | Select-Object -First 1
Write-Verbose (Get-ChildItem -Path 'Env:' | Where-Object Name -In 'GH_TOKEN', 'GITHUB_TOKEN' | Out-String)
$tokenVar = Get-ChildItem -Path 'Env:' | Where-Object Name -In 'GH_TOKEN', 'GITHUB_TOKEN' | Select-Object -First 1 -ExpandProperty Value
$tokenVarPresent = $tokenVar.count -gt 0 -and -not [string]::IsNullOrEmpty($tokenVar)
if ($tokenVarPresent) {
Connect-GitHubAccount -Repo $env:GITHUB_REPOSITORY_NAME -Owner $env:GITHUB_REPOSITORY_OWNER
Expand Down
6 changes: 3 additions & 3 deletions src/public/Auth/Connect-GitHubAccount.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
$envVars = Get-ChildItem -Path 'Env:'
Write-Debug 'Environment variables:'
Write-Debug ($envVars | Format-Table -AutoSize | Out-String)
$gitHubToken = $envVars | Where-Object Name -In 'GH_TOKEN', 'GITHUB_TOKEN' | Select-Object -First 1
$gitHubToken = $envVars | Where-Object Name -In 'GH_TOKEN', 'GITHUB_TOKEN' | Select-Object -First 1 -ExpandProperty Value
Write-Debug "GitHub token: [$gitHubToken]"
$gitHubTokenPresent = $gitHubToken.count -gt 0 -and -not [string]::IsNullOrEmpty($gitHubToken)
Write-Debug "GitHub token present: [$gitHubTokenPresent]"
Expand Down Expand Up @@ -202,9 +202,9 @@
'sPAT' {
Write-Verbose 'Logging in using GitHub access token...'
Reset-GitHubConfig -Scope 'Auth'
$prefix = $gitHubToken.Value -replace '_.*$', '_*'
$prefix = $gitHubToken -replace '_.*$', '_*'
$settings = @{
AccessToken = ConvertTo-SecureString -AsPlainText $gitHubToken.Value
AccessToken = ConvertTo-SecureString -AsPlainText $gitHubToken
AccessTokenType = $prefix
ApiBaseUri = 'https://api.github.com'
ApiVersion = '2022-11-28'
Expand Down

0 comments on commit 8bf53d9

Please sign in to comment.