From 59f75bdd8c18a08ee78717151623456ddc782ece Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Wed, 1 May 2024 18:23:19 +0200 Subject: [PATCH] Improve gh login Use `gh auth token` as a third source of GitHub token --- tools/github_login.py | 9 +++++++++ 1 file changed, 9 insertions(+) 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. "