Skip to content

Define a common method, getAutoinitEnvVars.#10048

Merged
falahat merged 15 commits intomainfrom
getAutoinitEnvVars
Mar 13, 2026
Merged

Define a common method, getAutoinitEnvVars.#10048
falahat merged 15 commits intomainfrom
getAutoinitEnvVars

Conversation

@falahat
Copy link
Contributor

@falahat falahat commented Mar 9, 2026

Description

This simplifies some future changes and allows us to reuse getAutoinitEnvVars across our codebase.

Scenarios Tested

I did the same testing as #10049 (pr#10049)

I tested a source deploy of a nextjs app which included secrets, env vars, emulator-specific env vars, and testing for the admin sdk (load an image from google storage bucket.)

I deployed the backend (via source deploy) and verified it worked as expected.

I started an emulator and verified my local app and verified it worked as expected. apphosting.emulator.yaml was respected.

I also tested these scenarios to make sure the priority for the autoinit vars works correctly:
I set up a real time database so that the database url env var would be auto-injected.

  1. I tested running the emulator with no overrides, and it used the values from prod/default autoinjected values (i.e. for the database url)
  2. I ran the emulator, including the storage/database emulator and this correctly injected the FIREBASE_DATABASE_EMULATOR_HOST value, for example.
  3. I overrode FIREBASE_CONFIG in my apphosting.yaml and ran the emulator. It correctly used the values from this.

Sample Commands

firebase deploy
firebase emulators:start

This simplifies some future changes and allows us to reuse getAutoinitEnvVars across our codebase.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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 a new common utility function, getAutoinitEnvVars, to centralize the logic for constructing Firebase JS SDK auto-initialization environment variables. This refactoring simplifies existing code by removing redundant logic and promotes code reuse, making future modifications and additions related to environment variable handling more streamlined and less error-prone across the codebase.

Highlights

  • New Utility Function: Introduced getAutoinitEnvVars in src/apphosting/utils.ts to encapsulate the logic for generating Firebase JS SDK auto-initialization environment variables.
  • Code Refactoring: Replaced duplicated environment variable generation logic in src/emulator/apphosting/serve.ts with a call to the new getAutoinitEnvVars utility, improving code reuse and maintainability.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src/apphosting/utils.ts
    • Imported WebConfig type for use in the new function.
    • Added getAutoinitEnvVars function to generate Firebase auto-init environment variables based on a provided web app configuration.
  • src/emulator/apphosting/serve.ts
    • Imported the newly defined getAutoinitEnvVars utility function.
    • Refactored the environment variable injection logic, replacing an inline block with a call to getAutoinitEnvVars.
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
Contributor

@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 new helper function getAutoinitEnvVars to centralize the creation of JS SDK auto-initialization environment variables. This is a good refactoring that improves code reuse. I've suggested a small improvement to make the new function more concise and align better with the repository's style guide.

@falahat falahat marked this pull request as ready for review March 10, 2026 15:12
falahat added 6 commits March 11, 2026 10:52
Now, we clearly set the priority of env vars when creating environmentVariablesToInject

We calcualte autoinit env vars first, which means they will be overriden by emulator env vars or apphosting.yaml env vars.
@falahat falahat enabled auto-merge (squash) March 11, 2026 17:25
@falahat falahat disabled auto-merge March 11, 2026 21:10
@falahat falahat enabled auto-merge (squash) March 13, 2026 19:58
@falahat falahat merged commit 85eeecc into main Mar 13, 2026
47 checks passed
@falahat falahat deleted the getAutoinitEnvVars branch March 13, 2026 20:10
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.

3 participants