Repository navigation
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request fixes an issue where firebase deploy --non-interactive fails for Functions parameters that have a default value. In non-interactive mode, parameters with defaults are now resolved to their default values instead of throwing an error, while parameters without defaults still trigger a failure. Comprehensive unit tests have been added to verify this behavior. The review feedback suggests a minor improvement to paramValueFromDefault to reduce nesting by removing unnecessary else statements after early returns, aligning with the repository's style guide.
| if (param.type === "string") { | ||
| return new ParamValue(String(resolvedDefault), false, { string: true }); | ||
| } else if (param.type === "int") { | ||
| return new ParamValue(String(resolvedDefault), false, { number: true }); | ||
| } else if (param.type === "boolean") { | ||
| return new ParamValue(String(resolvedDefault), false, { boolean: true }); | ||
| } else if (param.type === "list") { | ||
| return ParamValue.fromList(resolvedDefault as string[], param.delimiter); | ||
| } |
There was a problem hiding this comment.
According to the repository style guide, we should reduce nesting as much as possible. Since each conditional block in paramValueFromDefault returns early, we can remove the else keywords to flatten the control flow and improve readability.
if (param.type === "string") {
return new ParamValue(String(resolvedDefault), false, { string: true });
}
if (param.type === "int") {
return new ParamValue(String(resolvedDefault), false, { number: true });
}
if (param.type === "boolean") {
return new ParamValue(String(resolvedDefault), false, { boolean: true });
}
if (param.type === "list") {
return ParamValue.fromList(resolvedDefault as string[], param.delimiter);
}References
- Reduce nesting as much as possible: Code should avoid unnecessarily deep nesting or long periods of nesting. Use early returns, continue, and break statements in functions and loops to handle edge cases early and keep main logic flat. (link)
0992c31 to
e1b3f6a
Compare
In non-interactive mode, resolveParams failed for every param that was not set in a dotenv file, even when the param had a default. Resolve such params to their default instead (with the same CEL resolution and type check as the interactive path), and only report params that have no default. Interactive mode is unchanged. Fixes firebase#11523
bf00fd7 to
f31eeee
Compare
There was a problem hiding this comment.
@yeegz Thanks for the contribution! The approach looks right to me.
I've left a couple of small requests inline.
In non-interactive mode, report params with neither a dotenv value nor a default before resolving any default, so a default that refers to a missing param still gets the message that names it. Apply the same validationRegex and nonEmpty checks the prompt uses to the default, and update the resolveParams and promptParam doc comments.
|
Thanks @IzaakGough! Done in the latest commit:
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #11546 +/- ##
=======================================
Coverage ? 61.13%
=======================================
Files ? 870
Lines ? 51087
Branches ? 10313
=======================================
Hits ? 31234
Misses ? 18718
Partials ? 1135 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…ive-param-defaults # Conflicts: # CHANGELOG.md
…ive-param-defaults # Conflicts: # CHANGELOG.md
Description
Fixes #11523.
With
--non-interactive, a Functions param that wasn't in a.envfile failed the deploy even if it had adefault. As discussed on the issue, it now uses the default in that case. Params without a default still fail with the same error, which now lists only those params.Defaults go through the same CEL resolution and type check as the interactive prompt, so both modes give the same value. Interactive mode doesn't change.
Scenarios Tested
Added tests in
params.spec.ts:false, int, list and CEL defaults resolve without prompting.envvalue still beats the defaultThe new tests fail on
mainand pass with this change. The rest of the functions tests pass too.Sample Commands
firebase deploy --only functions --non-interactivewithdefineString('GREETING', { default: 'hello' })and no.envnow deploys withGREETING=hello.