fix(doctor): drop --json authenticated for gh CLI compatibility
gh CLI 2.98+ removed the 'authenticated' field from 'gh auth status --json' (only 'hosts' remains), causing the command to exit 1 even when the user is authenticated. The doctor then falsely reports 'No GITHUB_TOKEN' despite the user being logged in via 'gh auth login'. Since the code only checks the return code (it never parses stdout), the '--json' flag is unnecessary. 'gh auth status' without it works across all gh versions and returns exit 0 when authenticated. Fixes: gh auth status --json authenticated → gh auth status
This commit is contained in:
@@ -294,9 +294,14 @@ def _check_state_db(should_fix: bool, f: Finding) -> None:
|
||||
|
||||
|
||||
def _gh_authenticated() -> bool:
|
||||
"""Check if gh CLI is authenticated via token file or device flow."""
|
||||
"""Check if gh CLI is authenticated via token file or device flow.
|
||||
|
||||
Plain ``gh auth status`` (exit code only): gh 2.98+ dropped the
|
||||
``authenticated`` JSON field, so ``--json authenticated`` exits 1 even
|
||||
when logged in, and the doctor falsely reported "No GITHUB_TOKEN".
|
||||
"""
|
||||
try:
|
||||
result = subprocess.run(["gh", "auth", "status", "--json", "authenticated"], capture_output=True, timeout=10)
|
||||
result = subprocess.run(["gh", "auth", "status"], capture_output=True, timeout=10)
|
||||
return result.returncode == 0
|
||||
except (FileNotFoundError, subprocess.TimeoutExpired):
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user