-
Notifications
You must be signed in to change notification settings - Fork 652
Add GITHUB_API_BASE_URL environment variable #174
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
Enable integration with self-hosted GitHub Enterprise servers by allowing custom API base URL configuration through environment variable.
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.
Hello @cacapouh, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
Summary of Changes
As gemini-code-assist, I've reviewed this pull request. The primary goal of this PR is to enhance the application's compatibility by allowing users to specify a custom GitHub API base URL. This is particularly useful for integrating with self-hosted GitHub Enterprise instances, which use a different API endpoint than the public https://api.github.com
. The change is implemented by introducing a new environment variable, GITHUB_API_BASE_URL
, which is then used in relevant API calls throughout the codebase, falling back to the default public URL if the variable is not set.
Highlights
- Environment Variable: Introduces the
GITHUB_API_BASE_URL
environment variable to allow users to specify their custom GitHub API endpoint. - API URL Configuration: Updates code in both the Python backend and Next.js frontend to read and utilize the
GITHUB_API_BASE_URL
environment variable for constructing GitHub API request URLs.
Changelog
- api/data_pipeline.py
- In the
get_github_file_content
function, the hardcoded GitHub API base URL (https://api.github.com
) is replaced with a value retrieved from theGITHUB_API_BASE_URL
environment variable usingos.getenv
, defaulting to the public API URL if the variable is not present (lines 446-447).
- In the
- src/app/[owner]/[repo]/page.tsx
- A new constant
apiBaseUrl
is introduced to read theGITHUB_API_BASE_URL
environment variable usingprocess.env
, defaulting to the public API URL (line 1060). - The API URL for fetching the repository tree (
/git/trees
) is updated to use the configurableapiBaseUrl
(line 1062). - The API URL for fetching the README (
/readme
) is updated to use the configurableapiBaseUrl
(line 1103).
- A new constant
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Env var sets the base,
GitHub Enterprise finds its place,
API calls flow.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
This pull request introduces a valuable feature by allowing the GitHub API base URL to be configured via the GITHUB_API_BASE_URL
environment variable, which is great for supporting GitHub Enterprise instances.
The implementation in the TypeScript file (page.tsx
) correctly handles the base URL construction. However, the Python implementation (data_pipeline.py
) has a critical issue in how it constructs the final API URL, potentially leading to incorrect URLs, especially in the default case or when the provided base URL includes a scheme. Additionally, both implementations could be made more robust against trailing slashes in the provided base URL.
I've provided specific suggestions to address these points. It would also be beneficial to document how the GITHUB_API_BASE_URL
environment variable should be formatted (e.g., including the scheme like https://my.ghe.server/api/v3
) for users of this feature.
Summary of Findings
- Critical URL Construction Bug in Python: The Python code in
api/data_pipeline.py
incorrectly prependshttps://
to theapi_base_url
when the default value or a user-provided value forGITHUB_API_BASE_URL
already contains the scheme. This results in malformed URLs likehttps://https://api.github.com/...
. - URL Robustness (Trailing Slashes): Both Python and TypeScript implementations could be improved to handle potential trailing slashes in the
GITHUB_API_BASE_URL
to prevent double slashes in the constructed API URLs (e.g.,...base//path/...
). - Environment Variable Usage in Next.js: The usage of
process.env.GITHUB_API_BASE_URL
insrc/app/[owner]/[repo]/page.tsx
is appropriate for React Server Components or server-side execution contexts in Next.js. This is not an issue but an observation confirming correct usage in its likely context.
Merge Readiness
This pull request introduces an important feature for GitHub Enterprise support. However, there's a critical issue in the Python code (api/data_pipeline.py
) related to API URL construction that needs to be addressed before merging. Additionally, a medium-severity improvement for handling trailing slashes in the base URL is suggested for both Python and TypeScript implementations.
I recommend that these changes, particularly the critical one, be made before this PR is merged. As an AI reviewer, I am not authorized to approve pull requests; please ensure further review and approval by team members.
api_base_url = os.getenv("GITHUB_API_BASE_URL", "https://api.github.com") | ||
api_url = f"https://{api_base_url}/repos/{owner}/{repo}/contents/{file_path}" |
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 current construction of api_url
has a couple of issues:
- Critical: If
GITHUB_API_BASE_URL
is not set,api_base_url
becomes"https://api.github.com"
. Then,api_url
becomesf"https://https://api.github.com/..."
, which is incorrect due to the doublehttps://
. - Medium: If
GITHUB_API_BASE_URL
is set by the user and already includes thehttps://
scheme (e.g.,"https://my.ghe.com/api/v3"
), the same doublehttps://
issue will occur. - Minor: If
GITHUB_API_BASE_URL
ends with a trailing slash (e.g.,"https://my.ghe.com/api/v3/"
), the resulting URL might have a double slash (e.g.,"...v3//repos/..."
), which is generally undesirable though often tolerated by servers.
Could we adjust the logic to ensure the GITHUB_API_BASE_URL
is expected to contain the scheme, and then we don't prepend https://
? Also, stripping any trailing slash from the base URL would make it more robust. For example:
api_base_url = os.getenv("GITHUB_API_BASE_URL", "https://api.github.com") | |
api_url = f"https://{api_base_url}/repos/{owner}/{repo}/contents/{file_path}" | |
raw_github_api_base_url = os.getenv("GITHUB_API_BASE_URL", "https://api.github.com") | |
# Ensure the base URL includes the scheme and remove any trailing slash for clean concatenation. | |
api_base_url = raw_github_api_base_url.rstrip('/') | |
api_url = f"{api_base_url}/repos/{owner}/{repo}/contents/{file_path}" |
@@ -1057,8 +1057,9 @@ IMPORTANT: | |||
let treeData = null; | |||
let apiErrorDetails = ''; | |||
|
|||
const apiBaseUrl = process.env.GITHUB_API_BASE_URL || 'https://api.github.com'; |
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 logic for apiBaseUrl
is good in that it expects the full base URL (including scheme) from process.env.GITHUB_API_BASE_URL
or defaults correctly.
To make it more robust, what do you think about ensuring that apiBaseUrl
doesn't have a trailing slash? If process.env.GITHUB_API_BASE_URL
is set to something like "https://my.ghe.com/api/v3/"
, the current concatenation apiUrl =
${apiBaseUrl}/repos/...would result in
"https://my.ghe.com/api/v3//repos/..."`. While many servers handle //
as /
, it's cleaner to avoid it.
Consider removing a potential trailing slash:
const apiBaseUrl = (process.env.GITHUB_API_BASE_URL || 'https://api.github.com').replace(/\/$/, '');
Enable integration with self-hosted GitHub Enterprise servers by allowing custom API base URL configuration through environment variable.
#96