diff --git a/tools/github_login.py b/tools/github_login.py index 3e0d61ae..a811226c 100644 --- a/tools/github_login.py +++ b/tools/github_login.py @@ -5,6 +5,7 @@ import argparse import os import sys +import subprocess from getpass import getpass import github3 from .config import read_config, write_config @@ -20,6 +21,14 @@ def login(): else: config = read_config() token = config.get("GitHub", "token") + if not token: + try: + # attempt to get token from gh + token = subprocess.check_output( + ["gh", "auth", "token"], text=True + ).strip() + except subprocess.SubprocessError: + pass if not token: raise GitHubLoginError( "No token has been generated for this script. "