Skip to content

Commit

Permalink
Improve gh login
Browse files Browse the repository at this point in the history
Use `gh auth token` as a third source of GitHub token
  • Loading branch information
sbidoul committed May 1, 2024
1 parent 400ffa9 commit 59f75bd
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tools/github_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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. "
Expand Down

0 comments on commit 59f75bd

Please sign in to comment.