mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-04 09:13:08 +00:00
fix: improve gh auth detection to work with GH_TOKEN env var
Use gh api user to verify authentication instead of gh auth status, which can return non-zero even when GH_TOKEN is valid (due to stale config file entries). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -94,10 +94,19 @@ async function getGhStatus(): Promise<GhStatus> {
|
|||||||
// Version command failed
|
// Version command failed
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check authentication status
|
// Check authentication status by actually making an API call
|
||||||
|
// gh auth status can return non-zero even when GH_TOKEN is valid
|
||||||
|
try {
|
||||||
|
const { stdout } = await execAsync('gh api user --jq ".login"', { env: execEnv });
|
||||||
|
const user = stdout.trim();
|
||||||
|
if (user) {
|
||||||
|
status.authenticated = true;
|
||||||
|
status.user = user;
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// API call failed - try gh auth status as fallback
|
||||||
try {
|
try {
|
||||||
const { stdout } = await execAsync('gh auth status', { env: execEnv });
|
const { stdout } = await execAsync('gh auth status', { env: execEnv });
|
||||||
// If this succeeds without error, we're authenticated
|
|
||||||
status.authenticated = true;
|
status.authenticated = true;
|
||||||
|
|
||||||
// Try to extract username from output
|
// Try to extract username from output
|
||||||
@@ -107,10 +116,8 @@ async function getGhStatus(): Promise<GhStatus> {
|
|||||||
if (userMatch) {
|
if (userMatch) {
|
||||||
status.user = userMatch[1];
|
status.user = userMatch[1];
|
||||||
}
|
}
|
||||||
} catch (error: unknown) {
|
} catch {
|
||||||
// Auth status returns non-zero if not authenticated
|
// Auth status returns non-zero if not authenticated
|
||||||
const err = error as { stderr?: string };
|
|
||||||
if (err.stderr?.includes('not logged in')) {
|
|
||||||
status.authenticated = false;
|
status.authenticated = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user