-
Notifications
You must be signed in to change notification settings - Fork 8k
feat(extension): resolve environment variables in extension configuration #7213
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
feat(extension): resolve environment variables in extension configuration #7213
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.
Summary of Changes
Hello @skal88, 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!
This pull request introduces the capability to resolve environment variables within extension configurations, mirroring the existing functionality for main settings. This enhancement allows users to leverage .env
files for sensitive or dynamic values in gemini-extension.json
files, improving security and configuration management. The change involved refactoring the environment variable resolution logic into a shared utility, ensuring consistency and maintainability across the codebase. It maintains backwards compatibility and includes robust testing to cover various use cases.
Highlights
- Environment Variable Resolution for Extensions: The core change enables environment variables (e.g.,
$API_KEY
,${DATABASE_URL}
) to be resolved withingemini-extension.json
files, bringing consistency with howsettings.json
handles them. This allows for more flexible and secure configuration of extensions. - Code Refactoring and Shared Utility: The common logic for resolving environment variables has been extracted into a new, dedicated utility module (
packages/cli/src/utils/envVarResolver.ts
). This promotes the DRY (Don't Repeat Yourself) principle, as both settings and extension configuration loading now utilize this shared, robust mechanism. - Backwards Compatibility and Graceful Handling: The implementation ensures that existing extension configurations without environment variables continue to function as before. Additionally, it gracefully handles cases where referenced environment variables are undefined, leaving their placeholders unchanged rather than replacing them with empty strings.
- Enhanced Test Coverage: Comprehensive unit tests have been added for the new
envVarResolver
utility, covering various string and object resolution scenarios. Furthermore, integration tests were added toextension.test.ts
to validate the end-to-end functionality of environment variable resolution within extension configurations.
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 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
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.
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 effectively refactors environment variable resolution into a shared utility and applies it to extension configurations, which is a great improvement for consistency. The changes are well-tested. However, I've found a critical robustness issue in the new utility that could lead to a stack overflow with certain inputs, and a high-severity issue regarding the use of an outdated keyword (var
) that should be updated to let
for better scoping and maintainability.
863d82b
to
0e7f3c2
Compare
Hello @scidomino Thank you for reaching out on my earlier #4521 . I still believe this functionality would be a great addition to the project, so I've decided to reopen it to see if we can get it included in a future version. It seems I don't have the permissions to add you as a reviewer, so I'm mentioning you here. If you have some time, I'd be grateful for your review. Thank you for your guidance! |
99197a5
to
b0143c8
Compare
b0143c8
to
23d361f
Compare
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.
…n' into feat/extension-env-var-resolution
Head branch was pushed to by a user without write access
You just need to run |
Head branch was pushed to by a user without write access
Done! 😃 Thanks @scidomino ! |
…s in extension configuration (google-gemini#7213)
…tion (google-gemini#7213) Co-authored-by: Tommaso Sciortino <[email protected]> Co-authored-by: Jacob Richman <[email protected]>
…tion (google-gemini#7213) Co-authored-by: Tommaso Sciortino <[email protected]> Co-authored-by: Jacob Richman <[email protected]>
TLDR
Resolve environment variables in extension configurations. Previously, variables like
$API_KEY
or${DATABASE_URL}
ingemini-extension.json
files were not being substituted with their actual values from.env
files, while the mainsettings.json
files had this functionality working correctly.Dive Deeper
This change extends the existing environment variable resolution mechanism to work consistently across both settings and extension configurations.
What was the problem?
$API_TOKEN
,${DB_URL}
) in extensiongemini-extension.json
files were not being resolved.env
files for extension configurations like they could for main settingsHow was it solved?
utils/envVarResolver.ts
)settings.ts
andextension.ts
now use the same underlying resolution logicTechnical implementation:
packages/cli/src/utils/envVarResolver.ts
withresolveEnvVarsInString
andresolveEnvVarsInObject
functionspackages/cli/src/config/settings.ts
to use the shared utility (removing duplicate code)packages/cli/src/config/extension.ts
to apply environment variable resolution during extension loading$VAR_NAME
and${VAR_NAME}
syntax consistentlyReviewer Test Plan
1. Test extension environment variable resolution:
Create test extension:
Create .gemini/extensions/test-env-ext/gemini-extension.json:
Create
.env
file in project root:Verify resolution:
Run gemini and use /mcp command
Verify in the output that:
API_KEY
shows secret-token-12345 (not $TEST_API_KEY)shows postgresql://user:pass@localhost:5432/testdb (not ${TEST_DB_URL})
DATABASE_URL
shows postgresql://user:pass@localhost:5432/testdb (not ${TEST_DB_URL})STATIC_VALUE
remains no-substitution-needed2. Test backwards compatibility:
Create extension without environment variables:
Verify: Extension loads normally and values remain unchanged.
Add to test extension:
Verify: Undefined variables remain as-is (not replaced with empty strings).
Testing Matrix
Linked issues / bugs
Fixes #4473