-
Notifications
You must be signed in to change notification settings - Fork 10
Add GITHUB_TOKEN as another fallback option #148
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request adds GITHUB_TOKEN as a third fallback option for AI API authentication, while also fixing a critical bug where COPILOT_TOKEN was not being properly checked. The change enhances flexibility for users, particularly those running in GitHub Actions environments where GITHUB_TOKEN is automatically available.
Changes:
- Fixed missing check for COPILOT_TOKEN that would have prevented it from being used
- Added GITHUB_TOKEN as a third fallback option in the token resolution chain
- Updated the function docstring to document all three supported environment variables
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| token = os.getenv("GITHUB_TOKEN") | ||
| if token: | ||
| return token | ||
| raise RuntimeError("AI_API_TOKEN environment variable is not set.") |
Copilot
AI
Feb 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message at line 61 only mentions "AI_API_TOKEN environment variable is not set" but the function now accepts three different environment variables (AI_API_TOKEN, COPILOT_TOKEN, or GITHUB_TOKEN). The error message should be updated to reflect all three options to provide accurate guidance to users when none of them are set.
| raise RuntimeError("AI_API_TOKEN environment variable is not set.") | |
| raise RuntimeError( | |
| "No API token found. Please set one of: AI_API_TOKEN, COPILOT_TOKEN, or GITHUB_TOKEN." | |
| ) |
| def get_AI_token(): | ||
| """ | ||
| Get the token for the AI API from the environment. | ||
| The environment variable can be named either AI_API_TOKEN | ||
| or COPILOT_TOKEN. | ||
| The environment variable can be named either AI_API_TOKEN, | ||
| COPILOT_TOKEN, or GITHUB_TOKEN. | ||
| """ | ||
| token = os.getenv("AI_API_TOKEN") | ||
| if token: | ||
| return token | ||
| token = os.getenv("COPILOT_TOKEN") | ||
| if token: | ||
| return token | ||
| token = os.getenv("GITHUB_TOKEN") | ||
| if token: | ||
| return token | ||
| raise RuntimeError("AI_API_TOKEN environment variable is not set.") |
Copilot
AI
Feb 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new GITHUB_TOKEN fallback behavior and the fixed COPILOT_TOKEN check lack test coverage. Given that tests/test_api_endpoint_config.py contains comprehensive tests for the related get_AI_endpoint() function, similar tests should be added for get_AI_token() to verify the fallback chain works correctly (AI_API_TOKEN -> COPILOT_TOKEN -> GITHUB_TOKEN) and that the error is raised when none are set.
No description provided.