From 7578ece5031ca83e8416c05aac0062a005ccb01e Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 27 Jun 2025 17:13:41 +0000 Subject: [PATCH] Update print_github_reviews.py to read token from ~/.github_token If GITHUB_TOKEN environment variable is not set and --token argument is not provided, the script will now attempt to read the GitHub token from the `~/.github_token` file. The order of precedence for token retrieval is: 1. --token command-line argument 2. GITHUB_TOKEN environment variable 3. ~/.github_token file --- scripts/print_github_reviews.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/scripts/print_github_reviews.py b/scripts/print_github_reviews.py index 880d3b3f9f..7c34c570a3 100755 --- a/scripts/print_github_reviews.py +++ b/scripts/print_github_reviews.py @@ -254,7 +254,7 @@ def parse_repo_url(url_string): "--token", type=str, default=os.environ.get("GITHUB_TOKEN"), - help="GitHub token. Can also be set via GITHUB_TOKEN env var." + help="GitHub token. Can also be set via GITHUB_TOKEN env var or from ~/.github_token." ) parser.add_argument( "--context-lines", @@ -289,9 +289,23 @@ def parse_repo_url(url_string): latest_line_comment_activity_dt = None processed_comments_count = 0 - if not args.token: - sys.stderr.write(f"Error: GitHub token not provided. Set GITHUB_TOKEN or use --token.{error_suffix}\n") + token = args.token + if not token: + try: + with open(os.path.expanduser("~/.github_token"), "r") as f: + token = f.read().strip() + if token: + sys.stderr.write("Using token from ~/.github_token\n") + except FileNotFoundError: + pass # File not found is fine, we'll check token next + except Exception as e: + sys.stderr.write(f"Warning: Could not read ~/.github_token: {e}\n") + + + if not token: + sys.stderr.write(f"Error: GitHub token not provided. Set GITHUB_TOKEN, use --token, or place it in ~/.github_token.{error_suffix}\n") sys.exit(1) + args.token = token # Ensure args.token is populated for the rest of the script final_owner = None final_repo = None