Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix token retrieval from gh cli #89

Merged
merged 1 commit into from
Jul 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions github_activity/github_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
(
Expand Down