(text: string)
| 36 | } |
| 37 | |
| 38 | export function parseGitHubAuthStatus(text: string): GitHubAuthStatus { |
| 39 | return Option.match(decodeGitHubAuthStatusJson(text), { |
| 40 | onNone: () => ({ parsed: false, accounts: [] }), |
| 41 | onSome: (status) => |
| 42 | ({ |
| 43 | parsed: true, |
| 44 | accounts: Object.values(status.hosts).flatMap((accounts) => |
| 45 | accounts.flatMap((account) => { |
| 46 | const host = nonEmptyString(account.host); |
| 47 | const login = nonEmptyString(account.login); |
| 48 | if (host === null || login === null) return []; |
| 49 | |
| 50 | return [ |
| 51 | { |
| 52 | host: host.toLowerCase(), |
| 53 | account: login, |
| 54 | authenticated: account.state === "success", |
| 55 | active: account.active, |
| 56 | error: account.error?.trim() || null, |
| 57 | }, |
| 58 | ]; |
| 59 | }), |
| 60 | ), |
| 61 | }) satisfies GitHubAuthStatus, |
| 62 | }); |
| 63 | } |
| 64 | |
| 65 | export function findAuthenticatedGitHubAccount( |
| 66 | accounts: ReadonlyArray<GitHubAuthStatusAccount>, |
no test coverage detected