()
| 35 | } |
| 36 | |
| 37 | export function getGithubUser(): { name: string; email: string } | null { |
| 38 | try { |
| 39 | // Try getting basic user info first |
| 40 | const basicInfo = executeCommand('gh api user') |
| 41 | |
| 42 | const user = JSON.parse(basicInfo) as { name: string; email: string | null } |
| 43 | |
| 44 | let email = user.email |
| 45 | |
| 46 | // If email is private/null, try fetching from /user/emails |
| 47 | if (!email) { |
| 48 | try { |
| 49 | const emailsJson = executeCommand('gh api user/emails') |
| 50 | |
| 51 | const emails = JSON.parse(emailsJson) as Array<{ |
| 52 | email: string |
| 53 | primary: boolean |
| 54 | }> |
| 55 | |
| 56 | const primary = emails.find(e => e.primary) |
| 57 | |
| 58 | if (primary) { |
| 59 | email = primary.email |
| 60 | } |
| 61 | } catch { |
| 62 | // Ignore error if can't fetch emails, just fallback |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | if (user.name && email) { |
| 67 | return { name: user.name, email } |
| 68 | } |
| 69 | |
| 70 | return null |
| 71 | } catch (error) { |
| 72 | logger.error(`Failed to fetch GitHub user info.`) |
| 73 | logger.debug(`Error details: ${error}`) |
| 74 | |
| 75 | return null |
| 76 | } |
| 77 | } |
nothing calls this directly
no test coverage detected