Skip to content

feat: set branch as alias on deploy command#8111

Merged
eduardoboucas merged 6 commits intomainfrom
fet/alias-branch-deploy
Mar 27, 2026
Merged

feat: set branch as alias on deploy command#8111
eduardoboucas merged 6 commits intomainfrom
fet/alias-branch-deploy

Conversation

@eduardoboucas
Copy link
Copy Markdown
Member

No description provided.

@eduardoboucas eduardoboucas requested a review from a team as a code owner March 27, 2026 12:31
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 27, 2026

📊 Benchmark results

Comparing with e95762d

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

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 27, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 48f9a335-64a9-43e7-9752-67b29eec9c3d

📥 Commits

Reviewing files that changed from the base of the PR and between 571b076 and bd329d6.

📒 Files selected for processing (1)
  • tests/integration/commands/deploy/deploy.test.ts

📝 Walkthrough

Summary by CodeRabbit

Release Notes

  • New Features

    • The --alias command-line option now properly propagates branch information to the build system, ensuring consistent deployment metadata throughout the entire build and deployment workflow.
  • Tests

    • Added integration tests verifying that --alias values are correctly propagated to build environment hooks and deployment API calls.

Walkthrough

This pull request adds support for propagating the --alias CLI option through the build system to the Netlify API. The change modifies getRunBuildOptions in src/lib/build.ts to accept an alias parameter and set the branch field in the returned object accordingly. A new integration test verifies that the alias value flows correctly through both the build plugin's environment (via process.env.BRANCH) and the deploy API request body's branch field.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive No description was provided by the author, making it impossible to assess whether it relates to the changeset. Add a pull request description explaining the purpose and context of setting branch as alias in the deploy command.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main change: setting the branch field to the alias value in the deploy command.
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 fet/alias-branch-deploy

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

Copy link
Copy Markdown

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

🧹 Nitpick comments (1)
src/lib/build.ts (1)

179-196: Logic looks correct; consider trimming the comment to focus on "why".

The branch computation logic is sound. However, per coding guidelines, the comment includes portions that describe what the code does (e.g., "use the alias as the branch name", "we leave it undefined") which the variable names and ternary already convey. The valuable parts are the business reasons.

✏️ Suggested comment refinement
-  // For non-production contexts, use the alias as the branch name so that
-  // branch-aware steps (e.g. DB setup) can create isolated resources for this
-  // deploy. In production, we leave it undefined so that `@netlify/config`
-  // resolves it from git as usual.
+  // Enables branch-aware steps (e.g. DB setup) to create isolated resources.
+  // Production leaves branch to `@netlify/config` to resolve from git.
   const isProductionContext = !context || context === 'production'
   const branch = isProductionContext ? undefined : alias || branchOption

As per coding guidelines: "Never write comments on what the code does; make the code clean and self-explanatory instead."

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

In `@src/lib/build.ts` around lines 179 - 196, The comment above the branch
computation is overly descriptive of what the code already expresses; update it
to a concise "why" only. Replace the multi-sentence explanation around
isProductionContext and branch with a short line that explains the business
intent (e.g., that non-production contexts use an override to isolate resources
while production leaves branch resolution to git/@netlify/config), and remove
the parts that restate the ternary logic using the identifiers
isProductionContext, context, alias, and branchOption.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/lib/build.ts`:
- Around line 179-196: The comment above the branch computation is overly
descriptive of what the code already expresses; update it to a concise "why"
only. Replace the multi-sentence explanation around isProductionContext and
branch with a short line that explains the business intent (e.g., that
non-production contexts use an override to isolate resources while production
leaves branch resolution to git/@netlify/config), and remove the parts that
restate the ternary logic using the identifiers isProductionContext, context,
alias, and branchOption.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cc592bf4-7aac-460d-898c-24b95fea20b2

📥 Commits

Reviewing files that changed from the base of the PR and between 42a46bf and f6c9945.

📒 Files selected for processing (1)
  • src/lib/build.ts

Copy link
Copy Markdown

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/unit/lib/build.test.ts`:
- Line 33: The test reveals RunBuildOptions missing a declared branch property
while the implementation returns branch: alias; update the type RunBuildOptions
to include an optional or required branch: string (or adjust the implementation
to stop returning branch) so the runtime shape matches the type. Locate the
RunBuildOptions type definition and add branch: string (or branch?: string)
accordingly, and ensure functions like the build runner that currently set
branch: alias (the code returning branch) conform to the updated type so tests
no longer need type assertions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c9916ae8-3f6b-4aec-8d1f-8aef98028550

📥 Commits

Reviewing files that changed from the base of the PR and between f6c9945 and 0aef9f1.

📒 Files selected for processing (2)
  • src/lib/build.ts
  • tests/unit/lib/build.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/lib/build.ts

options: { alias: 'custom-alias' },
})

expect(result.branch).toBe('custom-alias')
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Check RunBuildOptions type definition and getRunBuildOptions implementation

# Find RunBuildOptions type definition
ast-grep --pattern 'type RunBuildOptions = $_'
ast-grep --pattern 'interface RunBuildOptions { $$$ }'

# Check the getRunBuildOptions function return statement
rg -n "RunBuildOptions" --type ts -C 5 src/lib/build.ts

# Check if branch is being set in the implementation
rg -n "branch" --type ts src/lib/build.ts

Repository: netlify/cli

Length of output: 2432


🏁 Script executed:

cd tests/unit/lib && wc -l build.test.ts

Repository: netlify/cli

Length of output: 71


🏁 Script executed:

head -n 50 tests/unit/lib/build.test.ts | tail -n +25

Repository: netlify/cli

Length of output: 715


🏁 Script executed:

sed -n '135,210p' src/lib/build.ts

Repository: netlify/cli

Length of output: 2177


🏁 Script executed:

rg -n "import.*build" src/lib/build.ts | head -20

Repository: netlify/cli

Length of output: 156


🏁 Script executed:

rg -n "from '@netlify/build'" src/lib/build.ts

Repository: netlify/cli

Length of output: 156


🏁 Script executed:

rg -A 5 '@netlify/build' package.json

Repository: netlify/cli

Length of output: 302


🏁 Script executed:

# Also check if there's a tsconfig.build.json to understand compilation setup
cat tsconfig.build.json 2>/dev/null | head -30

Repository: netlify/cli

Length of output: 265


Update RunBuildOptions type to include the branch property.

The implementation returns branch: alias but the RunBuildOptions type does not declare this property. The test must use a type assertion workaround to access it. Either extend the type definition to include branch, or adjust the implementation to match the declared type.

🧰 Tools
🪛 GitHub Check: typecheck

[failure] 33-33:
Property 'branch' does not exist on type 'RunBuildOptions'.

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

In `@tests/unit/lib/build.test.ts` at line 33, The test reveals RunBuildOptions
missing a declared branch property while the implementation returns branch:
alias; update the type RunBuildOptions to include an optional or required
branch: string (or adjust the implementation to stop returning branch) so the
runtime shape matches the type. Locate the RunBuildOptions type definition and
add branch: string (or branch?: string) accordingly, and ensure functions like
the build runner that currently set branch: alias (the code returning branch)
conform to the updated type so tests no longer need type assertions.

@serhalp
Copy link
Copy Markdown
Member

serhalp commented Mar 27, 2026

What's the intent of this change @eduardoboucas? I believe alias and branch are intentionally distinct concepts, aren't they?

https://cli.netlify.com/commands/deploy/#deploy states:

alias (string) - Specifies the alias for deployment, the string at the beginning of the deploy subdomain. Useful for creating predictable deployment URLs. Avoid setting an alias string to the same value as a deployed branch. alias doesn’t create a branch deploy and can’t be used in conjunction with the branch subdomain feature. Maximum 37 characters.

context (string) - Specify a deploy context for environment variables read during the build (“production”, “deploy-preview”, “branch-deploy”, “dev”) or branch:your-branch where your-branch is the name of a branch (default: dev)

@eduardoboucas eduardoboucas enabled auto-merge (squash) March 27, 2026 17:10
@eduardoboucas eduardoboucas merged commit c08644e into main Mar 27, 2026
71 checks passed
@eduardoboucas eduardoboucas deleted the fet/alias-branch-deploy branch March 27, 2026 18:10
eduardoboucas pushed a commit that referenced this pull request Mar 27, 2026
🤖 I have created a release *beep* *boop*
---


## [24.8.0](v24.7.0...v24.8.0)
(2026-03-27)


### Features

* set `branch` as `alias` on `deploy` command
([#8111](#8111))
([c08644e](c08644e))


### Bug Fixes

* **deps:** bump node-forge from 1.3.2 to 1.4.0
([#8114](#8114))
([3fc2aec](3fc2aec))
* **deps:** bump yaml from 2.8.1 to 2.8.3
([#8101](#8101))
([e95762d](e95762d))

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

4 participants