Skip to content

Update print_github_reviews.py to read token from ~/.github_token #1752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions scripts/print_github_reviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down
Loading