From 82aebfd9bb6ba3f57908368144bd7c221792bd0b Mon Sep 17 00:00:00 2001 From: Min RK Date: Sat, 8 Jul 2023 16:57:10 -0700 Subject: [PATCH] fix token retrieval from gh cli structure of `gh auth status` has changed `gh auth token` retrieves the token without any parsing and exits with nonzero if there is no token --- github_activity/github_activity.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/github_activity/github_activity.py b/github_activity/github_activity.py index d606c4f..ef073b8 100644 --- a/github_activity/github_activity.py +++ b/github_activity/github_activity.py @@ -7,6 +7,7 @@ import sys import urllib from pathlib import Path +from subprocess import CalledProcessError from subprocess import PIPE from subprocess import run from tempfile import TemporaryDirectory @@ -142,11 +143,13 @@ def get_activity( else: # Attempt to use the gh cli if installed try: - out = run(shlex.split("gh auth status -t"), capture_output=True) - lines = [ii for ii in out.stderr.decode().split("\n") if "Token:" in ii] - if lines: - print("Using GH access token stored via GH CLI.", file=sys.stderr) - auth = lines[0].split(": ")[-1].strip() + p = run(["gh", "auth", "token"], capture_output=True) + auth = p.stdout.strip() + except CalledProcessError: + print( + ("gh cli has no token. Login with `gh auth login`"), + file=sys.stderr, + ) except FileNotFoundError: print( (