diff --git a/pkg/cmd/codespace/create.go b/pkg/cmd/codespace/create.go index fa484173d..d8b24d016 100644 --- a/pkg/cmd/codespace/create.go +++ b/pkg/cmd/codespace/create.go @@ -110,7 +110,7 @@ func newCreateCmd(app *App) *cobra.Command { createCmd.Flags().DurationVar(&opts.idleTimeout, "idle-timeout", 0, "allowed inactivity before codespace is stopped, e.g. \"10m\", \"1h\"") createCmd.Flags().Var(&opts.retentionPeriod, "retention-period", "allowed time after shutting down before the codespace is automatically deleted (maximum 30 days), e.g. \"1h\", \"72h\"") createCmd.Flags().StringVar(&opts.devContainerPath, "devcontainer-path", "", "path to the devcontainer.json file to use when creating codespace") - createCmd.Flags().StringVarP(&opts.displayName, "display-name", "d", "", "display name for the codespace") + createCmd.Flags().StringVarP(&opts.displayName, "display-name", "d", "", "display name for the codespace (48 characters or less)") return createCmd } @@ -282,6 +282,10 @@ func (a *App) Create(ctx context.Context, opts createOptions) error { } } + if len(opts.displayName) > 48 { // 48 is the max length of the display name in the API + return fmt.Errorf("error creating codespace: display name should contains 48 characters max or less") + } + createParams := &api.CreateCodespaceParams{ RepositoryID: repository.ID, Branch: branch, diff --git a/pkg/cmd/codespace/create_test.go b/pkg/cmd/codespace/create_test.go index ae85fc34a..bbb8d84d0 100644 --- a/pkg/cmd/codespace/create_test.go +++ b/pkg/cmd/codespace/create_test.go @@ -184,6 +184,25 @@ func TestApp_Create(t *testing.T) { wantStderr: " ✓ Codespaces usage for this repository is paid for by monalisa\n", wantErr: fmt.Errorf("error getting machine type: there is no such machine for the repository: %s\nAvailable machines: %v", "MEGA", []string{"GIGA", "TERA"}), }, + { + name: "create codespace with display name more than 48 characters results in error", + fields: fields{ + apiClient: apiCreateDefaults(&apiClientMock{ + CreateCodespaceFunc: func(ctx context.Context, params *api.CreateCodespaceParams) (*api.Codespace, error) { + return &api.Codespace{ + Name: "monalisa-dotfiles-abcd1234", + }, nil + }, + }), + }, + opts: createOptions{ + repo: "monalisa/dotfiles", + machine: "GIGA", + displayName: "this-is-very-long-display-name-with-49-characters", + }, + wantStderr: " ✓ Codespaces usage for this repository is paid for by monalisa\n", + wantErr: fmt.Errorf("error creating codespace: display name should contains 48 characters max or less"), + }, { name: "create codespace with devcontainer path results in selecting the correct machine type", fields: fields{