Skip to content

Conversation

@MatteoJoliveau
Copy link

EnvVarProvider now supports injecting a custom renaming strategy, which allows users to customise how environment variables are selected by transforming the requested flag key.

This PR

  • adds the Rename trait to EnvVarProvider, which allows users to inject custom strategies for transforming flag keys into the corresponding environment variable name.

How to test

Unit tests have been added. I tried to add a case to the Cucumber world, but I'm not familiar with that system, and I had issues injecting a generic R into the World.

@gemini-code-assist
Copy link

Summary of Changes

Hello @MatteoJoliveau, 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 significantly enhances the EnvVarProvider by introducing a flexible mechanism for transforming feature flag keys into environment variable names. By allowing the injection of custom renaming strategies via a new Rename trait, the provider can now adapt to diverse naming conventions without requiring direct modifications to its core logic. This change improves the provider's adaptability and extensibility for various use cases.

Highlights

  • Custom Renaming Strategy: The EnvVarProvider now supports injecting a custom renaming strategy, allowing users to define how feature flag keys are transformed into environment variable names. This provides greater flexibility in matching different naming conventions.
  • New Rename Trait: A new Rename trait has been introduced, defining a rename method that takes a flag key and returns a Cow<'a, str>. This trait is implemented by a default NoopRename (which performs no transformation) and also for closures, enabling easy custom renaming logic.
  • Generic EnvVarProvider: The EnvVarProvider has been made generic over the Rename trait, allowing it to accept and utilize any custom renaming strategy. The internal evaluate_environment_variable function now uses this injected strategy to determine the correct environment variable name.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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

  1. 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.

Copy link

@gemini-code-assist gemini-code-assist bot left a 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 flexible renaming mechanism for the EnvVarProvider by using a generic Rename trait. The implementation is well-designed, particularly the use of Cow for efficiency and the blanket implementation for closures, which makes the API very ergonomic. My review includes a few suggestions to improve code idiom and test clarity. Overall, this is a great addition.

evaluation_context: &EvaluationContext,
) -> EvaluationResult<ResolutionDetails<bool>> {
return evaluate_environment_variable(flag_key, evaluation_context);
return evaluate_environment_variable(&self.rename, flag_key, evaluation_context);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In Rust, the return keyword is typically omitted for the final expression of a function, as the last expression is implicitly returned. Removing it makes the code more idiomatic and aligns with common Rust style.

Suggested change
return evaluate_environment_variable(&self.rename, flag_key, evaluation_context);
evaluate_environment_variable(&self.rename, flag_key, evaluation_context)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I agree with this suggestion (and can add a commit fixing this if maintainers agree), I have to point out that this was not a change I introduced 😅

evaluation_context: &EvaluationContext,
) -> EvaluationResult<ResolutionDetails<f64>> {
return evaluate_environment_variable(flag_key, evaluation_context);
return evaluate_environment_variable(&self.rename, flag_key, evaluation_context);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In Rust, the return keyword is typically omitted for the final expression of a function. It's more idiomatic to rely on the implicit return.

Suggested change
return evaluate_environment_variable(&self.rename, flag_key, evaluation_context);
evaluate_environment_variable(&self.rename, flag_key, evaluation_context)

evaluation_context: &EvaluationContext,
) -> EvaluationResult<ResolutionDetails<String>> {
return evaluate_environment_variable(flag_key, evaluation_context);
return evaluate_environment_variable(&self.rename, flag_key, evaluation_context);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In Rust, the return keyword is typically omitted for the final expression of a function. It's more idiomatic to rely on the implicit return.

Suggested change
return evaluate_environment_variable(&self.rename, flag_key, evaluation_context);
evaluate_environment_variable(&self.rename, flag_key, evaluation_context)

@MatteoJoliveau MatteoJoliveau force-pushed the feature/env-var-renaming branch 3 times, most recently from 5d73a7c to 7983981 Compare October 27, 2025 14:22
EnvVarProvider now supports injecting a custom renaming
strategy, which allows users to customize how environment variables
are selected by transforming the requested flag key.

Signed-off-by: Matteo Joliveau <[email protected]>
@MatteoJoliveau MatteoJoliveau force-pushed the feature/env-var-renaming branch from 7983981 to f083099 Compare October 27, 2025 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant