Repository navigation
refactor(hosting): use project-scoped endpoints for all Hosting API requests - #11229
Conversation
…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>
```
There was a problem hiding this comment.
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.
|
/joe-review |
### 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 ```
…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
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:createVersion,updateVersion,listVersions,cloneVersion, andcreateReleaseto accept an explicitproject: stringparameter and use/projects/${project}/sites/${site}/....project: string | number = "-"from channel APIs (getChannel,listChannels,createChannel,updateChannelTtl,deleteChannel), requiring callers to provide the project ID.src/commands/hosting-disable.ts:/projects/${projectId}/sites/${siteToDisable}/releasesusingneedProjectId(options).src/commands/hosting-clone.ts:"-"project wildcards; resolves source and target project IDs fromneedProjectId(options)or the[<project>:]<site>:<channel>target format.src/commands/hosting-channel-deploy.ts:projects/${projectId}/sites/${site}/versions/...).src/deploy/hosting/prepare.ts&src/deploy/hosting/release.ts:context.projectIdto all version and release lifecycle functions.src/hosting/runTags.ts:projecttolistVersions.src/commands/hosting-disable.spec.tsandsrc/commands/hosting-clone.spec.ts.src/hosting/api.spec.ts,src/deploy/hosting/prepare.spec.ts, andsrc/deploy/hosting/release.spec.ts.CHANGELOG.md: Added entry documenting project-scoped Hosting API calls.Scenarios Tested
npm run mocha:fast, 5,669 passing), covering:hosting:clone(same-project, cross-project, and invalid targets).hosting:disable.npm run lint:changed-files(0 errors) and Prettier checks.firebase deploy --only hostingdeploys with project-scoped version and release creation.firebase hosting:channel:create,firebase hosting:channel:list, andfirebase hosting:channel:deploysucceed with project-scoped endpoints.firebase hosting:clonesuccessfully clones channels and tags versions without using"-".firebase hosting:disablesuccessfully creates the disable release and halts traffic.Sample Commands