From b6ec92f0691bff3301fd7f26144a1aa6acfaa2a9 Mon Sep 17 00:00:00 2001 From: Arturo Date: Thu, 4 Sep 2025 15:36:33 +0000 Subject: [PATCH] Add support for GITHUB_TOKEN environment variable Add support for GITHUB_TOKEN environment variable in authentication chain, providing compatibility with GitHub CLI and other GitHub tools. Environment variable is checked after config file but before git credential helper fallback. Priority order: 1. Command line argument (--github-oauth) 2. Config file (~/.revupconfig) 3. Environment variable (GITHUB_TOKEN) [NEW] 4. Git credential helper 5. Error if none found Features: - Maintains all existing functionality and fallbacks - Proper token redaction in logs for security - Clear debug messaging showing which method was used - Updated error message to mention environment variable option This change improves user experience by allowing the same environment variable used by gh and other GitHub tools, reducing setup friction. Branch: main Topic: env-token-support --- revup/revup.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/revup/revup.py b/revup/revup.py index 03f92a8..eac4415 100755 --- a/revup/revup.py +++ b/revup/revup.py @@ -150,19 +150,27 @@ async def github_connection( ) if not args.github_oauth: - args.github_oauth = await git_ctx.credential( - protocol="https", - host=args.github_url, - path=f"{fork_info.owner}/{fork_info.name}.git", - ) - if args.github_oauth != "": + # Try environment variables first + args.github_oauth = os.environ.get("GITHUB_TOKEN") + if args.github_oauth: logs.redact({args.github_oauth: ""}) - logging.debug("Used credential from git-credential {}".format(args.github_oauth)) + logging.debug("Used GitHub token from environment variable") + else: + # Fall back to git credential helper + args.github_oauth = await git_ctx.credential( + protocol="https", + host=args.github_url, + path=f"{fork_info.owner}/{fork_info.name}.git", + ) + if args.github_oauth: + logs.redact({args.github_oauth: ""}) + logging.debug("Used credential from git-credential") if not args.github_oauth: raise RevupUsageException( "No Github OAuth token found! " - "Login with 'gh auth login' " + "Set the GITHUB_TOKEN environment variable, " + "login with 'gh auth login', " "or make one at https://github.com/settings/tokens/new " "(revup needs full repo permissions) " "then set it with `revup config github_oauth`."