|
70 | 70 |
|
71 | 71 | # Set the default repository to use in commands. |
72 | 72 | [Parameter()] |
73 | | - [string] $Repo |
| 73 | + [string] $Repo, |
| 74 | + |
| 75 | + # Suppresses the output of the function. |
| 76 | + [Parameter()] |
| 77 | + [switch] $Silent |
74 | 78 | ) |
75 | 79 |
|
76 | 80 | $envVars = Get-ChildItem -Path 'Env:' |
|
93 | 97 | $seconds = $accessTokenValidity.Seconds.ToString().PadLeft(2, '0') |
94 | 98 | $accessTokenValidityText = "$hours`:$minutes`:$seconds" |
95 | 99 | if ($accessTokenIsValid) { |
96 | | - if ($accessTokenValidity.TotalHours -gt 4) { |
97 | | - Write-Host '✓ ' -ForegroundColor Green -NoNewline |
98 | | - Write-Host "Access token is still valid for $accessTokenValidityText ..." |
| 100 | + if ($accessTokenValidity.TotalHours -gt $script:Auth.AccessTokenGracePeriodInHours) { |
| 101 | + if (-not $Silent) { |
| 102 | + Write-Host '✓ ' -ForegroundColor Green -NoNewline |
| 103 | + Write-Host "Access token is still valid for $accessTokenValidityText ..." |
| 104 | + } |
99 | 105 | break |
100 | 106 | } else { |
101 | | - Write-Host '⚠ ' -ForegroundColor Yellow -NoNewline |
102 | | - Write-Host "Access token remaining validity $accessTokenValidityText. Refreshing access token..." |
| 107 | + if (-not $Silent) { |
| 108 | + Write-Host '⚠ ' -ForegroundColor Yellow -NoNewline |
| 109 | + Write-Host "Access token remaining validity $accessTokenValidityText. Refreshing access token..." |
| 110 | + } |
103 | 111 | $tokenResponse = Invoke-GitHubDeviceFlowLogin -ClientID $clientID -RefreshToken (Get-GitHubConfig -Name RefreshToken) |
104 | 112 | } |
105 | 113 | } else { |
106 | 114 | $refreshTokenValidity = [datetime](Get-GitHubConfig -Name 'RefreshTokenExpirationDate') - (Get-Date) |
107 | 115 | $refreshTokenIsValid = $refreshTokenValidity.Seconds -gt 0 |
108 | 116 | if ($refreshTokenIsValid) { |
109 | | - Write-Host '⚠ ' -ForegroundColor Yellow -NoNewline |
110 | | - Write-Verbose 'Access token expired. Refreshing access token...' |
| 117 | + if (-not $Silent) { |
| 118 | + Write-Host '⚠ ' -ForegroundColor Yellow -NoNewline |
| 119 | + Write-Host 'Access token expired. Refreshing access token...' |
| 120 | + } |
111 | 121 | $tokenResponse = Invoke-GitHubDeviceFlowLogin -ClientID $clientID -RefreshToken (Get-GitHubConfig -Name RefreshToken) |
112 | 122 | } else { |
113 | 123 | Write-Verbose "Using $Mode authentication..." |
|
154 | 164 | $accessTokenValue = Read-Host -Prompt 'Enter your personal access token' -AsSecureString |
155 | 165 | $accessTokenType = (ConvertFrom-SecureString $accessTokenValue -AsPlainText) -replace '_.*$', '_*' |
156 | 166 | if ($accessTokenType -notmatch '^ghp_|^github_pat_') { |
157 | | - Write-Host '⚠ ' -ForegroundColor Yellow -NoNewline |
158 | | - Write-Host "Unexpected access token format: $accessTokenType" |
| 167 | + Write-Warning '⚠ ' -ForegroundColor Yellow -NoNewline |
| 168 | + Write-Warning "Unexpected access token format: $accessTokenType" |
159 | 169 | } |
160 | 170 | $settings = @{ |
161 | 171 | AccessToken = $accessTokenValue |
|
190 | 200 | $username = 'system' |
191 | 201 | } |
192 | 202 |
|
193 | | - Write-Host '✓ ' -ForegroundColor Green -NoNewline |
194 | | - Write-Host "Logged in as $username!" |
195 | | - |
| 203 | + if (-not $Silent) { |
| 204 | + Write-Host '✓ ' -ForegroundColor Green -NoNewline |
| 205 | + Write-Host "Logged in as $username!" |
| 206 | + } |
196 | 207 |
|
197 | 208 | $systemRepo = $envVars | Where-Object Name -EQ 'GITHUB_REPOSITORY' |
198 | 209 | $systemRepoPresent = $systemRepo.count -gt 0 |
|
0 commit comments