Conversation
|
👋 @marcospassos
☝️ Lastly, the title for the commit will come from the pull request title. So please provide a descriptive title that summarizes the changes in 50 characters or less using the imperative mood. |
commit: |
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the API key creation flow to avoid prompting the user for environments that aren’t configured and centralizes environment-to-slug resolution.
- Extracts environment selection and slug lookup into
getEnvironmentandgetApplicationSlugmethods - Defaults to development if production isn’t configured
- Imports
ProjectConfigurationto type the new helpers
Comments suppressed due to low confidence (1)
src/application/cli/command/apiKey/create.ts:144
- Add unit tests for
getEnvironmentto cover: 1) automatic DEV fallback when production missing, 2) user prompt path when both environments exist.
return input.select({
| private getEnvironment( | ||
| configuration: ProjectConfiguration, | ||
| environment?: ApplicationEnvironment, | ||
| ): Promise<ApplicationEnvironment> { | ||
| if (environment !== undefined) { | ||
| return Promise.resolve(environment); | ||
| } | ||
|
|
||
| if (configuration.applications.production === undefined) { | ||
| return Promise.resolve(ApplicationEnvironment.DEVELOPMENT); | ||
| } | ||
|
|
||
| const {io: {input}} = this.config; | ||
|
|
||
| return input.select({ |
There was a problem hiding this comment.
[nitpick] Consider declaring this method as async rather than returning Promise.resolve(...), which improves readability and consistency with its asynchronous usage.
| private getEnvironment( | |
| configuration: ProjectConfiguration, | |
| environment?: ApplicationEnvironment, | |
| ): Promise<ApplicationEnvironment> { | |
| if (environment !== undefined) { | |
| return Promise.resolve(environment); | |
| } | |
| if (configuration.applications.production === undefined) { | |
| return Promise.resolve(ApplicationEnvironment.DEVELOPMENT); | |
| } | |
| const {io: {input}} = this.config; | |
| return input.select({ | |
| private async getEnvironment( | |
| configuration: ProjectConfiguration, | |
| environment?: ApplicationEnvironment, | |
| ): Promise<ApplicationEnvironment> { | |
| if (environment !== undefined) { | |
| return environment; | |
| } | |
| if (configuration.applications.production === undefined) { | |
| return ApplicationEnvironment.DEVELOPMENT; | |
| } | |
| const {io: {input}} = this.config; | |
| return await input.select({ |
| if (environment !== undefined) { | ||
| return Promise.resolve(environment); | ||
| } | ||
|
|
There was a problem hiding this comment.
If both production and development are undefined, this code will default to DEVELOPMENT and only later throw—consider adding a guard here to surface a clear error when no environments are configured.
| if (configuration.applications.production === undefined | |
| && configuration.applications.development === undefined) { | |
| throw new HelpfulError( | |
| 'No environments are configured in the project. Please configure at least one environment.', | |
| {reason: ErrorReason.INVALID_INPUT}, | |
| ); | |
| } |
Summary
This PR optimizes the API key creation flow to avoid prompting the user for environments that don’t exist.
Checklist