Skip to content

fix: AX for env setting#8091

Merged
sean-roberts merged 3 commits intomainfrom
sr/env
Mar 25, 2026
Merged

fix: AX for env setting#8091
sean-roberts merged 3 commits intomainfrom
sr/env

Conversation

@sean-roberts
Copy link
Contributor

in ax testing, we see two things:

  • agents don't know redeploys are needed
  • they often try to pass a --site flag to specify the site to use even if it's not needed, this resulted in errors.

@sean-roberts sean-roberts requested a review from a team as a code owner March 25, 2026 16:11
@github-actions
Copy link

github-actions bot commented Mar 25, 2026

📊 Benchmark results

Comparing with f35bd4b

  • Dependency count: 1,059 (no change)
  • Package size: 354 MB ⬆️ 0.00% increase vs. f35bd4b
  • Number of ts-expect-error directives: 356 (no change)

@sean-roberts sean-roberts requested a review from a team as a code owner March 25, 2026 16:19
@coderabbitai
Copy link

coderabbitai bot commented Mar 25, 2026

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added --site flag to environment variable commands (env:get, env:import, env:list, env:set, env:unset) to target specific projects.
  • Improvements

    • Enhanced user guidance with messages reminding users that environment variable changes require a redeploy to take effect on deployed versions.
  • Documentation

    • Updated CLI documentation for env commands to reflect new available flags.

Walkthrough

The pull request extends multiple netlify env subcommands with a new --site flag to target specific projects by name or ID. A new utility function getSiteInfo is introduced to determine site information by validating the requested site ID against cached data, falling back to a fresh API lookup if needed. All environment variable command handlers (env:get, env:import, env:list, env:set, env:unset) are refactored to use this utility instead of directly accessing cached site info. Additionally, several commands gain redeploy reminder messages to inform users of deployment requirements. CLI documentation is updated to reflect the new flag additions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'fix: AX for env setting' is vague and does not clearly convey the specific changes made (adding --site flag support and redeploy messaging). Consider a more descriptive title like 'fix: add --site flag and redeploy messaging for env commands' to better communicate the actual changes to reviewers.
✅ Passed checks (2 passed)
Check name Status Explanation
Description check ✅ Passed The description addresses real issues observed during AX testing that motivated the changes: agents not knowing redeploys are needed and attempting to use --site flags that weren't supported.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sr/env

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (5)
src/commands/env/env-unset.ts (1)

71-81: ⚠️ Potential issue | 🟠 Major

Same issue: --site option not wired up.

The siteId at line 74 doesn't consider options.site.

Proposed fix
 export const envUnset = async (key: string, options: OptionValues, command: BaseCommand) => {
   const { context, force } = options
   const { api, cachedConfig, site } = command.netlify
-  const siteId = site.id
+  const siteId = options.site || site.id

   if (!siteId) {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/commands/env/env-unset.ts` around lines 71 - 81, The envUnset function
currently always uses command.netlify.site.id for siteId and ignores the CLI
--site option; update envUnset to prefer options.site when provided (e.g., use
options.site || command.netlify.site.id) so the function honors the --site flag
before falling back to command.netlify.site.id, and then use that computed
siteId when calling getSiteInfo and subsequent API calls.
src/commands/env/env-import.ts (1)

53-63: ⚠️ Potential issue | 🟠 Major

Same issue: --site option not wired up.

The siteId at line 55 doesn't consider options.site.

Proposed fix
 export const envImport = async (fileName: string, options: OptionValues, command: BaseCommand) => {
   const { api, cachedConfig, site } = command.netlify
-  const siteId = site.id
+  const siteId = options.site || site.id

   if (!siteId) {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/commands/env/env-import.ts` around lines 53 - 63, The envImport function
currently always reads siteId from command.netlify.site.id and ignores the CLI
--site option; update envImport so siteId is derived from the CLI option when
present (e.g. use options.site || site.id or the equivalent nullish coalescing)
before the existing falsy check, and ensure subsequent calls (like
getSiteInfo(api, siteId, cachedConfig)) use that computed siteId; reference the
envImport function, the siteId variable, the options.site value, and
command.netlify.site to locate where to apply the change.
src/commands/env/env-get.ts (1)

8-18: ⚠️ Potential issue | 🟠 Major

Same issue: --site option not wired up.

The siteId derivation at line 11 doesn't consider options.site.

Proposed fix
 export const envGet = async (name: string, options: OptionValues, command: BaseCommand) => {
   const { context, scope } = options
   const { api, cachedConfig, site } = command.netlify
-  const siteId = site.id
+  const siteId = options.site || site.id

   if (!siteId) {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/commands/env/env-get.ts` around lines 8 - 18, The envGet function
currently derives siteId from command.netlify.site.id without checking the CLI
--site option; change the siteId derivation to prefer options.site (e.g. const
siteId = options.site || site.id) so the --site flag is honored, then pass that
siteId into getSiteInfo(api, siteId, cachedConfig); update any related
null-check/log to use the new siteId variable and keep references to envGet,
getSiteInfo, and command.netlify consistent.
src/commands/env/env-set.ts (1)

111-119: ⚠️ Potential issue | 🟠 Major

Same issue: --site option not wired up.

Similar to env-list.ts, the siteId is derived from site.id without considering options.site. The fix should be applied consistently across all env commands.

Proposed fix
 export const envSet = async (key: string, value: string, options: OptionValues, command: BaseCommand) => {
   const { context, force, scope, secret } = options
   const { api, cachedConfig, site } = command.netlify
-  const siteId = site.id
+  const siteId = options.site || site.id
   if (!siteId) {
     log('No project id found, please run inside a project folder or `netlify link`')
     return false
   }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/commands/env/env-set.ts` around lines 111 - 119, The envSet handler
derives siteId from command.netlify.site.id and ignores the --site CLI flag;
update envSet to resolve siteId from options.site first (falling back to
command.netlify.site.id) before calling getSiteInfo so the --site option is
honored; modify the siteId assignment logic in envSet (and apply the same
pattern to other env command handlers) to use options.site when present and then
call getSiteInfo(api, siteId, cachedConfig).
src/commands/env/env-list.ts (1)

44-55: ⚠️ Potential issue | 🟠 Major

Wire up the --site option to determine the target site.

The --site flag is defined and documented but not used in the handler. Line 47 derives siteId only from site.id, so passing --site my-other-project has no effect.

Fix
 export const envList = async (options: OptionValues, command: BaseCommand) => {
   const { context, scope } = options
   const { api, cachedConfig, site } = command.netlify
-  const siteId = site.id
+  const siteId = options.site || site.id

   if (!siteId) {
     log('No project id found, please run inside a project folder or `netlify link`')
     return false
   }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/commands/env/env-list.ts` around lines 44 - 55, The handler envList
currently always uses command.netlify.site.id and ignores the --site flag;
update envList to prefer the CLI option value (options.site) when present and
fall back to command.netlify.site.id otherwise, i.e. compute siteId =
options.site || command.netlify.site?.id, validate it the same way as before,
and then pass that siteId into getSiteInfo(api, siteId, cachedConfig) so the
--site flag correctly targets the requested site.
🧹 Nitpick comments (1)
src/commands/env/env.ts (1)

22-22: Optional: centralize site option definitions to reduce drift.

The same option string/description is repeated in 5 places. A small helper (or shared constants) would keep future updates consistent.

♻️ Proposed refactor
+const SITE_OPTION_DESCRIPTION = 'A project name or ID to target'
+const SITE_OPTION_LONG = '--site <name-or-id>'
+const SITE_OPTION_SHORT_AND_LONG = '-s, --site <name-or-id>'
+
 export const createEnvCommand = (program: BaseCommand) => {
   program
     .command('env:get')
@@
-    .option('--site <name-or-id>', 'A project name or ID to target')
+    .option(SITE_OPTION_LONG, SITE_OPTION_DESCRIPTION)
@@
   program
     .command('env:import')
@@
-    .option('-s, --site <name-or-id>', 'A project name or ID to target')
+    .option(SITE_OPTION_SHORT_AND_LONG, SITE_OPTION_DESCRIPTION)
@@
   program
     .command('env:list')
@@
-    .option('--site <name-or-id>', 'A project name or ID to target')
+    .option(SITE_OPTION_LONG, SITE_OPTION_DESCRIPTION)
@@
   program
     .command('env:set')
@@
-    .option('--site <name-or-id>', 'A project name or ID to target')
+    .option(SITE_OPTION_LONG, SITE_OPTION_DESCRIPTION)
@@
   program
     .command('env:unset')
@@
-    .option('-s, --site <name-or-id>', 'A project name or ID to target')
+    .option(SITE_OPTION_SHORT_AND_LONG, SITE_OPTION_DESCRIPTION)

Also applies to: 49-49, 65-65, 96-96, 133-133

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/commands/env/env.ts` at line 22, Multiple commands repeat the same
.option('--site <name-or-id>', 'A project name or ID to target'); extract that
literal into a shared symbol and reuse it: add a constant (e.g.,
SITE_OPTION_FLAGS = "--site <name-or-id>" and SITE_OPTION_DESC = "A project name
or ID to target") or a small helper function addSiteOption(command) that calls
command.option(SITE_OPTION_FLAGS, SITE_OPTION_DESC), then replace the five
inline .option(...) occurrences with either command.option(SITE_OPTION_FLAGS,
SITE_OPTION_DESC) or addSiteOption(command) to centralize the definition and
avoid drift.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@src/commands/env/env-get.ts`:
- Around line 8-18: The envGet function currently derives siteId from
command.netlify.site.id without checking the CLI --site option; change the
siteId derivation to prefer options.site (e.g. const siteId = options.site ||
site.id) so the --site flag is honored, then pass that siteId into
getSiteInfo(api, siteId, cachedConfig); update any related null-check/log to use
the new siteId variable and keep references to envGet, getSiteInfo, and
command.netlify consistent.

In `@src/commands/env/env-import.ts`:
- Around line 53-63: The envImport function currently always reads siteId from
command.netlify.site.id and ignores the CLI --site option; update envImport so
siteId is derived from the CLI option when present (e.g. use options.site ||
site.id or the equivalent nullish coalescing) before the existing falsy check,
and ensure subsequent calls (like getSiteInfo(api, siteId, cachedConfig)) use
that computed siteId; reference the envImport function, the siteId variable, the
options.site value, and command.netlify.site to locate where to apply the
change.

In `@src/commands/env/env-list.ts`:
- Around line 44-55: The handler envList currently always uses
command.netlify.site.id and ignores the --site flag; update envList to prefer
the CLI option value (options.site) when present and fall back to
command.netlify.site.id otherwise, i.e. compute siteId = options.site ||
command.netlify.site?.id, validate it the same way as before, and then pass that
siteId into getSiteInfo(api, siteId, cachedConfig) so the --site flag correctly
targets the requested site.

In `@src/commands/env/env-set.ts`:
- Around line 111-119: The envSet handler derives siteId from
command.netlify.site.id and ignores the --site CLI flag; update envSet to
resolve siteId from options.site first (falling back to command.netlify.site.id)
before calling getSiteInfo so the --site option is honored; modify the siteId
assignment logic in envSet (and apply the same pattern to other env command
handlers) to use options.site when present and then call getSiteInfo(api,
siteId, cachedConfig).

In `@src/commands/env/env-unset.ts`:
- Around line 71-81: The envUnset function currently always uses
command.netlify.site.id for siteId and ignores the CLI --site option; update
envUnset to prefer options.site when provided (e.g., use options.site ||
command.netlify.site.id) so the function honors the --site flag before falling
back to command.netlify.site.id, and then use that computed siteId when calling
getSiteInfo and subsequent API calls.

---

Nitpick comments:
In `@src/commands/env/env.ts`:
- Line 22: Multiple commands repeat the same .option('--site <name-or-id>', 'A
project name or ID to target'); extract that literal into a shared symbol and
reuse it: add a constant (e.g., SITE_OPTION_FLAGS = "--site <name-or-id>" and
SITE_OPTION_DESC = "A project name or ID to target") or a small helper function
addSiteOption(command) that calls command.option(SITE_OPTION_FLAGS,
SITE_OPTION_DESC), then replace the five inline .option(...) occurrences with
either command.option(SITE_OPTION_FLAGS, SITE_OPTION_DESC) or
addSiteOption(command) to centralize the definition and avoid drift.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 68d3ec07-c0f5-4ae3-b316-501478c5f891

📥 Commits

Reviewing files that changed from the base of the PR and between f35bd4b and 38854d9.

⛔ Files ignored due to path filters (2)
  • tests/integration/commands/env/__snapshots__/env.test.ts.snap is excluded by !**/*.snap
  • tests/integration/commands/envelope/__snapshots__/envelope.test.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (9)
  • docs/commands/env.md
  • src/commands/env/env-clone.ts
  • src/commands/env/env-get.ts
  • src/commands/env/env-import.ts
  • src/commands/env/env-list.ts
  • src/commands/env/env-set.ts
  • src/commands/env/env-unset.ts
  • src/commands/env/env.ts
  • src/commands/env/utils.ts

@sean-roberts sean-roberts enabled auto-merge (squash) March 25, 2026 16:36
@sean-roberts sean-roberts merged commit d77ff79 into main Mar 25, 2026
71 checks passed
@sean-roberts sean-roberts deleted the sr/env branch March 25, 2026 16:37
eduardoboucas pushed a commit that referenced this pull request Mar 25, 2026
🤖 I have created a release *beep* *boop*
---


## [24.6.0](v24.5.1...v24.6.0)
(2026-03-25)


### Features

* log output to stderr on `deploy --json --verbose`
([#8090](#8090))
([13e973c](13e973c))


### Bug Fixes

* AX for env setting
([#8091](#8091))
([d77ff79](d77ff79))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: token-generator-app[bot] <82042599+token-generator-app[bot]@users.noreply.github.com>
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.

2 participants