netlify / cli

Netlify Command Line Interface
http://cli.netlify.com
MIT License
1.58k stars 361 forks source link

fix: prevent redundant repos, add preliminary name checks, and improve error handling in sites:create-template #6908

Closed dylanspyer closed 3 weeks ago

dylanspyer commented 1 month ago

๐ŸŽ‰ Thanks for submitting a pull request! ๐ŸŽ‰

Summary

Fixes #6894

This PR makes several bug fixes and improvements across the sites:create-template command, including preventing redundant repo creation, adding preliminary name checks, improving error handling and error message specificity, adding modularity, and improving type safety.

Changes in user behavior include:

Case: When running sites:create-template, the user inputs a site name that is already taken and is prompted for a new name

Previous Behavior: A new redundant GitHub repo would be created for every unavailable site name the user inputs New Behavior: No redundant GitHub repos are created; at max one repo is created per call to sites:create-template

Before b4bugfix

After afterbugfix

Case: The user has created a site using a template and has opted for a random site name, and attempts to create another site from the same template and again opt for a random site name

Previous Behavior: User would continually be re-prompted for a new name and would not be able to use a random name. The random name option could only be used once per template. New Behavior: User can proceed with a random site name. If the first repository were named netlify-templates-angular-quickstart, the second and any created thereafter would be named netlify-templates-angular-quickstart-<8 random alphanumeric characters>

Case: The user authorizes with a GitHub PAT that does not grant permissions to create a repo

Previous Behavior: User would receive an undescriptive Warning: undefined.netlify.app already exists or a repository named undefined already exists on this account. Please try a different slug. message New Behavior: User receives a Could not create repository: <error message>. Ensure your PAT grants permission to create repositories message

Case: The user inputs a site name that is already taken by another Netlify user and then inputs a site name that already exists on their own account (but which responds with a 404 HTTP status)

Previous Behavior: The user would receive the same undescriptive error message for both cases: New Behavior: The user receives A site with that name is already taken in the case of a globally used site and A site with that name already exists on your account in the case of a site created on their account

Other changes include:


For us to review and ship your PR efficiently, please perform the following steps:

A picture of a cute animal (not mandatory, but encouraged) image