Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: follow standard pattern for auto-generated site names #5007

Merged
merged 9 commits into from
Oct 8, 2022

Conversation

tinfoil-knight
Copy link
Contributor

@tinfoil-knight tinfoil-knight commented Aug 28, 2022

🎉 Thanks for submitting a pull request! 🎉

Summary

Fixes #4630
Fixes #4653

The suggestions for auto-generated site names from the CLI don't follow the same pattern as they do when created from the Netlify App. These suggestions also use a very limited number of combinations which results in a user having a lot of site names being very similar & not being able to discern b/w them.

Additionally, the suggested site names can lead to invalid URLs as described here: #4653 (comment)

This PR fixes both the issue with standard names & site length. Also see #5007 (comment)


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)

@github-actions
Copy link

github-actions bot commented Aug 28, 2022

📊 Benchmark results

Comparing with 85f961d

Package size: 227 MB

⬇️ 0.05% decrease vs. 85f961d

^  224 MB  224 MB  224 MB  224 MB  224 MB  224 MB  224 MB  224 MB  224 MB  224 MB  224 MB  227 MB  227 MB 
│   ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
└───┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴──>
    T-12    T-11    T-10    T-9     T-8     T-7     T-6     T-5     T-4     T-3     T-2     T-1      T    
Legend

@tinfoil-knight
Copy link
Contributor Author

tinfoil-knight commented Aug 28, 2022

The longest possible site name suggestion is extraordinary-croquembouche-${suffix} where suffix is of length 6 making the maximum length 34.

For deploy previews, a 24 char hash is pre-pended (as per #4653 (comment)) which would make the max length 60 (34 + 24 + 2 for -- separator).

A suggestion should never cross the length of 37 characters (63 - (24 + 2))

In all cases, the URLs stay below the 63 char length which keeps everything functional.

@tinfoil-knight tinfoil-knight marked this pull request as ready for review August 28, 2022 13:06
@tinfoil-knight tinfoil-knight requested a review from danez August 28, 2022 13:06
@tinfoil-knight tinfoil-knight self-assigned this Aug 28, 2022
@tinfoil-knight tinfoil-knight added the type: bug code to address defects in shipped code label Aug 28, 2022
@danez
Copy link
Contributor

danez commented Aug 29, 2022

I have mixed feelings about this. I do not like the code duplication from the server-side. In case we ever decide to change the logic server-side this can create problems again.

What if instead of creating a name on the client we simply do not do this at all? If the API call createSiteInTeam is called without name then the server generates a name. This makes this way more simple and we do not have any code duplication. I quickly tried this by removing all autogeneration and it seems to work fine.

Do you see any problem with this?

Kapture 2022-08-29 at 14 09 31

@danez danez requested a review from a team August 29, 2022 12:14
@tinfoil-knight
Copy link
Contributor Author

tinfoil-knight commented Aug 29, 2022

What if instead of creating a name on the client we simply do not do this at all? If the API call createSiteInTeam is called without name then the server generates a name. This makes this way more simple and we do not have any code duplication. I quickly tried this by removing all autogeneration and it seems to work fine.

Do you see any problem with this?

Only issue with this is that it seems like the site name is going to be empty & there's no indication of what it's going to be.

Although, the Netlify UI also does the same thing (assign name without pre-indication).

I'll make the changes if you feel its necessary. Will need to update the CLI prompts a bit to indicate that an auto-generated name will be assigned.


Flow with auto-generated suggestion visible. (Current behaviour)

image

@danez
Copy link
Contributor

danez commented Aug 29, 2022

I personally feel this is okay if we add a message like leave empty for autogenerated name.

Ping @netlify/developer-experience-members What is your take on this? Any recommendations?

@whitep4nth3r
Copy link
Contributor

Something like Press enter to {generate a random site name} where 'Press enter' is the action, rather than 'Leave empty' which is an anti-action (kind of).

I left generate a random site name in curly brackets because I'm not sold on it.

@tinfoil-knight
Copy link
Contributor Author

tinfoil-knight commented Aug 30, 2022

@whitep4nth3r

How about Skip to let Netlify pick a name for your site ?

The prompt in the CLI would then be:

? Site name (you can change it later): Skip to let Netlify pick a name for your site

@whitep4nth3r
Copy link
Contributor

But how does someone Skip? That's not clear. I know we're getting deep into semantics and copy-writing and I'm not sure that's my area of expertise... but I'm not sure Skip instructs the user to press enter/return.

@tinfoil-knight
Copy link
Contributor Author

But how does someone Skip? That's not clear. I know we're getting deep into semantics and copy-writing and I'm not sure that's my area of expertise... but I'm not sure Skip instructs the user to press enter/return.

I didn't want to use Press enter because it seems like an action step without much choice. Skip seems like it offers a choice to let the user not think of the site name (which is the intended use of auto-generated names).

I do agree that Skip might be a bit unclear but pressing enter or return to skip a step is usual behaviour for many CLI utilities (from anecdotal experience) so I don't think this should be too confusing.

@whitep4nth3r
Copy link
Contributor

You know, I'm not sure we need a message if the auto-generated name is a suggestion like in the image above from @tinfoil-knight.

I just ran through setting up a new git repo via the GitHub CLI for inspiration. All (lighter contrast) prompts are e.g. (Y/n) or(.origin) where the default option is chosen when you press enter without being told.

Maybe we just need to show the auto generated name without an extra message. That feels more intuitive to me. What do you think?

image

@tinfoil-knight
Copy link
Contributor Author

tinfoil-knight commented Aug 30, 2022

Maybe we just need to show the auto generated name without an extra message. That feels more intuitive to me. What do you think?

@whitep4nth3r I like the auto-generated name option from a user's PoV but the issue with this is that it uses code that relies on internal server implementation (Netlify API) of how the site names are generated which makes it brittle which is why @danez suggested to avoid doing this in #5007 (comment)

@whitep4nth3r
Copy link
Contributor

Oh I see, that makes sense.

So the options are along the lines of:

  1. Site name (you can change it later): leave empty for autogenerated name
  2. Site name (you can change it later): skip to let Netlify pick a name for your site

I wonder whether we can get a bit of Netlify personality in here. Maybe I'm over-thinking it but there's maybe an opportunity to be a little quirky here given we can't show the auto-generated name.

Along the lines of....?

  1. Site name (you can change it later): pick for me
  2. Site name (you can change it later): I'm feeling lucky

Maybe we have an array of quirky strings to show a random one out of a selection each time? Am I going too far? 😅

@tinfoil-knight
Copy link
Contributor Author

Site name (you can change it later): pick for me sounds okay. I'd avoid going with an array of strings for consistency on the command line.

@danez I'll go forward with this & make changes to the flow to rely on the server for generating names if left empty.

@whitep4nth3r If you come up with any other ideas in the meantime, just let me know.

@tinfoil-knight tinfoil-knight marked this pull request as draft September 2, 2022 07:35
@tinfoil-knight
Copy link
Contributor Author

tinfoil-knight commented Sep 2, 2022

Change Summary

image

Edit: Everything below is outdated now since the default value that displayed Pick for me has been removed.


sites:create will no longer auto-suggest names & will just a Pick for me text. If left as it is, name will be selected by the server.

image


The sites:create-template command will now use the name of the template if the site name isn't available to create the Github Repository.

If a repository with the same name is already present, the user will get a well defined error.

The site name will be selected by the server if not provided.

The
image

Copy link
Contributor Author

@tinfoil-knight tinfoil-knight left a comment

Choose a reason for hiding this comment

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

@danez Let me know if any additional tests are required.

@tinfoil-knight tinfoil-knight marked this pull request as ready for review September 2, 2022 10:07
const { name: nameInput } = await inquirer.prompt([
{
type: 'input',
name: 'name',
message: 'Site name (you can change it later):',
default: siteSuggestion,
default: 'Pick for me',
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should be using the default property like this. We're assigning it a value that we know we won't use, just for the purpose of displaying something.

Instead, can we change message so that it reads something like Site name (leave blank for a random name; you can change it later), and we assign a value if the value is empty?

If we absolutely must use the current approach, let's please move the string to a constant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll change it. I find the current approach a bit "hacky" too.

@tinfoil-knight
Copy link
Contributor Author

Not sure as to what's happening with the failing tests here: https://github.com/netlify/cli/actions/runs/2993351770

@danez
Copy link
Contributor

danez commented Sep 5, 2022

I'm not working till end of September. So i can look then or someone else does. Sorry

@tinfoil-knight tinfoil-knight removed the request for review from danez September 5, 2022 20:03
@tinfoil-knight
Copy link
Contributor Author

tinfoil-knight commented Sep 30, 2022

@danez Can you take a look at the tests here now? They seem to be timing out. Still not sure what's causing this.

@danez
Copy link
Contributor

danez commented Oct 6, 2022

@tinfoil-knight I rebased on the current main branch and fixed the tests. It seems the tests match on the exact input line.

Copy link
Contributor

@danez danez left a comment

Choose a reason for hiding this comment

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

LGTM!

@tinfoil-knight
Copy link
Contributor Author

@tinfoil-knight I rebased on the current main branch and fixed the tests. It seems the tests match on the exact input line.

Thank you a lot for fixing the tests @danez.

@danez danez added type: bug code to address defects in shipped code and removed type: bug code to address defects in shipped code labels Oct 7, 2022
@verythorough
Copy link
Contributor

This is awesome! Here I was going to post a list of the words we use to generate the site names in Netlify, and I see y'all settled on a better solution. ✨

@danez danez added the automerge Add to Kodiak auto merge queue label Oct 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Add to Kodiak auto merge queue type: bug code to address defects in shipped code
Projects
None yet
5 participants