()
| 21 | status: 'gh_not_authenticated'; |
| 22 | }; |
| 23 | async function checkLoginState(): Promise<CheckResult> { |
| 24 | if (!(await isSignedIn())) { |
| 25 | return { |
| 26 | status: 'not_signed_in' |
| 27 | }; |
| 28 | } |
| 29 | const ghStatus = await getGhAuthStatus(); |
| 30 | if (ghStatus === 'not_installed') { |
| 31 | return { |
| 32 | status: 'gh_not_installed' |
| 33 | }; |
| 34 | } |
| 35 | if (ghStatus === 'not_authenticated') { |
| 36 | return { |
| 37 | status: 'gh_not_authenticated' |
| 38 | }; |
| 39 | } |
| 40 | |
| 41 | // ghStatus === 'authenticated'. getGhAuthStatus spawns with stdout:'ignore' |
| 42 | // (telemetry-safe); spawn once more with stdout:'pipe' to read the token. |
| 43 | const { |
| 44 | stdout |
| 45 | } = await execa('gh', ['auth', 'token'], { |
| 46 | stdout: 'pipe', |
| 47 | stderr: 'ignore', |
| 48 | timeout: 5000, |
| 49 | reject: false |
| 50 | }); |
| 51 | const trimmed = stdout.trim(); |
| 52 | if (!trimmed) { |
| 53 | return { |
| 54 | status: 'gh_not_authenticated' |
| 55 | }; |
| 56 | } |
| 57 | return { |
| 58 | status: 'has_gh_token', |
| 59 | token: new RedactedGithubToken(trimmed) |
| 60 | }; |
| 61 | } |
| 62 | function errorMessage(err: ImportTokenError, codeUrl: string): string { |
| 63 | switch (err.kind) { |
| 64 | case 'not_signed_in': |
no test coverage detected