Skip to content

refactor(hosting): use project-scoped endpoints for all Hosting API requests - #11229

Merged
bkendall merged 6 commits into
mainfrom
bk-hosting-project-scope
Oct 6, 2026
Merged

bkendall merged 6 commits into
mainfrom
bk-hosting-project-scope

Conversation

@bkendall

@bkendall bkendall commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Description

Firebase Hosting API requests historically supported site-scoped paths (/v1beta1/sites/{site}/...) or project-scoped paths with a - wildcard (/v1beta1/projects/-/sites/{site}/...) due to global site uniqueness.

This change eliminates all site-scoped requests and - wildcard project identifiers across the codebase in favor of explicit project-scoped API calls (/v1beta1/projects/{project}/sites/{site}/...):

  • src/hosting/api.ts:
    • Updated createVersion, updateVersion, listVersions, cloneVersion, and createRelease to accept an explicit project: string parameter and use /projects/${project}/sites/${site}/....
    • Removed default fallback of project: string | number = "-" from channel APIs (getChannel, listChannels, createChannel, updateChannelTtl, deleteChannel), requiring callers to provide the project ID.
  • src/commands/hosting-disable.ts:
    • Scoped the release creation to /projects/${projectId}/sites/${siteToDisable}/releases using needProjectId(options).
  • src/commands/hosting-clone.ts:
    • Eliminated all "-" project wildcards; resolves source and target project IDs from needProjectId(options) or the [<project>:]<site>:<channel> target format.
  • src/commands/hosting-channel-deploy.ts:
    • Updated version string parsing to match the project-scoped resource name format (projects/${projectId}/sites/${site}/versions/...).
  • src/deploy/hosting/prepare.ts & src/deploy/hosting/release.ts:
    • Passed context.projectId to all version and release lifecycle functions.
  • src/hosting/runTags.ts:
    • Passed project to listVersions.
  • Tests:
    • Added new unit test suites: src/commands/hosting-disable.spec.ts and src/commands/hosting-clone.spec.ts.
    • Updated existing tests in src/hosting/api.spec.ts, src/deploy/hosting/prepare.spec.ts, and src/deploy/hosting/release.spec.ts.
  • CHANGELOG.md: Added entry documenting project-scoped Hosting API calls.

Scenarios Tested

  • Unit tests: Passed full fast test suite (npm run mocha:fast, 5,669 passing), covering:
    • Project-scoped version creation, clone, update, and release API helpers.
    • Project resolution and error handling for hosting:clone (same-project, cross-project, and invalid targets).
    • Project resolution and prompt confirmation for hosting:disable.
    • Deployment preparation and release flows.
  • Linting & Formatting: Passed npm run lint:changed-files (0 errors) and Prettier checks.
  • Manual Verification:
    • firebase deploy --only hosting deploys with project-scoped version and release creation.
    • firebase hosting:channel:create, firebase hosting:channel:list, and firebase hosting:channel:deploy succeed with project-scoped endpoints.
    • firebase hosting:clone successfully clones channels and tags versions without using "-".
    • firebase hosting:disable successfully creates the disable release and halts traffic.

Sample Commands

firebase deploy --only hosting --project <PROJECT_ID>
firebase hosting:channel:create <CHANNEL_ID> --project <PROJECT_ID>
firebase hosting:channel:deploy <CHANNEL_ID> --project <PROJECT_ID>
firebase hosting:clone <SITE_ID>:<SOURCE_CHANNEL> <SITE_ID>:<TARGET_CHANNEL> --project <PROJECT_ID>
firebase hosting:disable --site <SITE_ID> --project <PROJECT_ID>

…equests

### Description

Firebase Hosting API requests historically supported site-scoped paths (/v1beta1/sites/{site}/...) or project-scoped paths with a - wildcard (/v1beta1/projects/-/sites/{site}/...) due to global site uniqueness.

This change eliminates all site-scoped requests and - wildcard project identifiers across the codebase in favor of explicit project-scoped API calls (/v1beta1/projects/{project}/sites/{site}/...):

- **src/hosting/api.ts**:
  - Updated createVersion, updateVersion, listVersions, cloneVersion, and createRelease to accept an explicit project: string parameter and use /projects/${project}/sites/${site}/...
  - Removed default fallback of project: string | number = "-" from channel APIs (getChannel, listChannels, createChannel, updateChannelTtl, deleteChannel), requiring callers to provide the project ID.
- **src/commands/hosting-disable.ts**:
  - Scoped the release creation to /projects/${projectId}/sites/${siteToDisable}/releases using needProjectId(options).
- **src/commands/hosting-clone.ts**:
  - Eliminated all "-" project wildcards; resolves source and target project IDs from needProjectId(options) or the [<project>:]<site>:<channel> target format.
- **src/commands/hosting-channel-deploy.ts**:
  - Updated version string parsing to match the project-scoped resource name format (projects/${projectId}/sites/${site}/versions/...).
- **src/deploy/hosting/prepare.ts & src/deploy/hosting/release.ts**:
  - Passed context.projectId to all version and release lifecycle functions.
- **src/hosting/runTags.ts**:
  - Passed project to listVersions.
- **Tests**:
  - Added new unit test suites: src/commands/hosting-disable.spec.ts and src/commands/hosting-clone.spec.ts.
  - Updated existing tests in src/hosting/api.spec.ts, src/deploy/hosting/prepare.spec.ts, and src/deploy/hosting/release.spec.ts.
- **CHANGELOG.md**: Added entry documenting project-scoped Hosting API calls.

### Scenarios Tested

- **Unit tests**: Passed full fast test suite (npm run mocha:fast, 5,669 passing), covering:
  - Project-scoped version creation, clone, update, and release API helpers.
  - Project resolution and error handling for hosting:clone (same-project, cross-project, and invalid targets).
  - Project resolution and prompt confirmation for hosting:disable.
  - Deployment preparation and release flows.
- **Linting & Formatting**: Passed npm run lint:changed-files (0 errors) and prettier check.
- **Manual Verification**:
  - firebase deploy --only hosting deploys with project-scoped version and release creation.
  - firebase hosting:channel:create, firebase hosting:channel:list, and firebase hosting:channel:deploy succeed with project-scoped endpoints.
  - firebase hosting:clone successfully clones channels and tags versions without using "-".
  - firebase hosting:disable successfully creates the disable release and halts traffic.

### Sample Commands

```bash
firebase deploy --only hosting --project <PROJECT_ID>
firebase hosting:channel:create <CHANNEL_ID> --project <PROJECT_ID>
firebase hosting:channel:deploy <CHANNEL_ID> --project <PROJECT_ID>
firebase hosting:clone <SITE_ID>:<SOURCE_CHANNEL> <SITE_ID>:<TARGET_CHANNEL> --project <PROJECT_ID>
firebase hosting:disable --site <SITE_ID> --project <PROJECT_ID>
```

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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 updates Firebase Hosting API requests to be project-scoped, eliminating site-scoped requests and the use of "-" as a project identifier across various commands and API utilities. Key changes include refactoring API methods in src/hosting/api.ts to require a project parameter, updating the hosting:clone and hosting:disable commands, and adapting deployment and release processes to pass the project ID. Additionally, comprehensive unit tests have been added and updated to verify these project-scoped interactions. The review feedback recommends replacing the any type on the options parameter in the hosting:clone command with the proper Options type imported from ../options to align with the repository's TypeScript style guidelines.

Comment thread src/commands/hosting-clone.ts Resolved
Comment thread src/commands/hosting-clone.ts Resolved
@bkendall
bkendall requested a review from joehan October 2, 2026 22:18
@joehan

joehan commented Oct 2, 2026

Copy link
Copy Markdown
Member

/joe-review

@joehan joehan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM with some robo nits

Comment thread src/commands/hosting-clone.ts Resolved
Comment thread src/commands/hosting-clone.ts Resolved
@bkendall
bkendall enabled auto-merge (squash) October 6, 2026 22:00
@bkendall
bkendall merged commit 0c54cf8 into main Oct 6, 2026
50 of 51 checks passed
@bkendall
bkendall deleted the bk-hosting-project-scope branch October 6, 2026 22:12
bkendall added a commit that referenced this pull request Oct 13, 2026
### Description

In #11229, `hosting:clone` was updated to use project-scoped API requests and defaulted unspecified project IDs to `needProjectId(options)`. Because Firebase Hosting site IDs are globally unique, users previously cloned across projects without specifying the source project (e.g. `firebase hosting:clone site-a:live site-b:live --project=project-b`), which broke in 15.33.0 when `site-a` belonged to a different project than `--project`.

This change updates `hosting:clone` to implicitly look up the owning project for a site via `getSite("-", siteId)` when a project ID is not explicitly provided in the `[<project>:]<site>:<channel>` or `[<project>:]<site>@<version>` argument. Once resolved, all subsequent API operations (`getChannel`, `createChannel`, `cloneVersion`, `createRelease`, `addAuthDomains`) continue to use the resolved project ID on project-scoped endpoints.

Also updates the command help text and validation error messages to document the optional `<project>:` prefix.

Fixes #11247

### Scenarios Tested

- Unit tests in `src/commands/hosting-clone.spec.ts`:
  - Same-project channel and version cloning.
  - Explicit cross-project cloning (`<project>:<site>:<channel>`).
  - Implicit cross-project cloning when source site is in a different project than `--project` (#11247).
  - Implicit project resolution when `--project` is omitted.
  - Error handling when a site is not found (404).

### Sample Commands

```bash
firebase hosting:clone site-a:live site-b:live --project=project-b
firebase hosting:clone site-a:live site-b:live
firebase hosting:clone project-a:site-a:live project-b:site-b:live
```
bkendall added a commit that referenced this pull request Oct 13, 2026
…11275)

* fix(hosting): implicitly resolve site project IDs in hosting:clone

### Description

In #11229, `hosting:clone` was updated to use project-scoped API requests and defaulted unspecified project IDs to `needProjectId(options)`. Because Firebase Hosting site IDs are globally unique, users previously cloned across projects without specifying the source project (e.g. `firebase hosting:clone site-a:live site-b:live --project=project-b`), which broke in 15.33.0 when `site-a` belonged to a different project than `--project`.

This change updates `hosting:clone` to implicitly look up the owning project for a site via `getSite("-", siteId)` when a project ID is not explicitly provided in the `[<project>:]<site>:<channel>` or `[<project>:]<site>@<version>` argument. Once resolved, all subsequent API operations (`getChannel`, `createChannel`, `cloneVersion`, `createRelease`, `addAuthDomains`) continue to use the resolved project ID on project-scoped endpoints.

Also updates the command help text and validation error messages to document the optional `<project>:` prefix.

Fixes #11247

### Scenarios Tested

- Unit tests in `src/commands/hosting-clone.spec.ts`:
  - Same-project channel and version cloning.
  - Explicit cross-project cloning (`<project>:<site>:<channel>`).
  - Implicit cross-project cloning when source site is in a different project than `--project` (#11247).
  - Implicit project resolution when `--project` is omitted.
  - Error handling when a site is not found (404).

### Sample Commands

```bash
firebase hosting:clone site-a:live site-b:live --project=project-b
firebase hosting:clone site-a:live site-b:live
firebase hosting:clone project-a:site-a:live project-b:site-b:live
```

* fix(hosting): parallelize project resolution and preserve 404 error status
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