Add GITHUB_TOKEN as another fallback option#148
Add GITHUB_TOKEN as another fallback option#148kevinbackhouse wants to merge 1 commit intoGitHubSecurityLab:mainfrom
Conversation
There was a problem hiding this comment.
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.") |
There was a problem hiding this comment.
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.") |
There was a problem hiding this comment.
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.