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
After
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:
Created separate try/catch blocks for each API call in inputSiteName so as to enable better error handling and increased error message specificity
Moved utility functions defined in sites-create-template.ts into a src/utils/sites/create-template.ts utility file for better modularity and to enable separate mocking of the utility functions in integration tests
Authored new integration tests for changed functionality in tests/integration/commands/sites/sites-create-template.ts and updated imports for existing tests/integration/commands/sites/sites.ts. The new tests were moved into a separate file to enable different mock implementations for the different tests
Typed variable declarations and function signatures and calls, removing all ts-expect-errors in sites-create-template.ts
Made minor improvements for clarity to console output messages
For us to review and ship your PR efficiently, please perform the following steps:
[ ] Open a bug/issue before writing your code ๐งโ๐ป. This ensures we can discuss the changes and get feedback from everyone that should be involved. If you`re fixing a typo or something that`s on fire ๐ฅ (e.g. incident related), you can skip this step.
[ ] Read the contribution guidelines ๐. This ensures your code follows our style guide and
passes our tests.
[ ] Update or add tests (if any source code was changed or added) ๐งช
[ ] Update or add documentation (if features were changed or added) ๐
[ ] Make sure the status checks below are successful โ
A picture of a cute animal (not mandatory, but encouraged)
๐ 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 namePrevious 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
After
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 namednetlify-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 aCould not create repository: <error message>. Ensure your PAT grants permission to create repositories
messageCase: 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 andA site with that name already exists on your account
in the case of a site created on their accountOther changes include:
try/catch
blocks for each API call ininputSiteName
so as to enable better error handling and increased error message specificitysites-create-template.ts
into asrc/utils/sites/create-template.ts
utility file for better modularity and to enable separate mocking of the utility functions in integration teststests/integration/commands/sites/sites-create-template.ts
and updated imports for existingtests/integration/commands/sites/sites.ts
. The new tests were moved into a separate file to enable different mock implementations for the different teststs-expect-errors
insites-create-template.ts
For us to review and ship your PR efficiently, please perform the following steps:
A picture of a cute animal (not mandatory, but encouraged)