From 2b57084bd0351847ae9fd1cc6b5fd54cf071e189 Mon Sep 17 00:00:00 2001 From: Jeff Hubbard Date: Wed, 20 Apr 2022 11:52:32 -0700 Subject: [PATCH] PR feedback --- internal/codespaces/api/api.go | 7 +++++-- pkg/cmd/codespace/create.go | 19 ++++++++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/internal/codespaces/api/api.go b/internal/codespaces/api/api.go index b52f05e22..d43208e82 100644 --- a/internal/codespaces/api/api.go +++ b/internal/codespaces/api/api.go @@ -742,10 +742,13 @@ func (a *API) ListDevContainers(ctx context.Context, repoID int, branch string, perPage = limit } - listURL := fmt.Sprintf("%s/repositories/%d/codespaces/devcontainers?per_page=%d", a.githubAPI, repoID, perPage) + v := url.Values{} + v.Set("per_page", strconv.Itoa(perPage)) if branch != "" { - listURL += "&ref=" + branch + v.Set("ref", branch) } + listURL := fmt.Sprintf("%s/repositories/%d/codespaces/devcontainers?%s", a.githubAPI, repoID, v.Encode()) + for { req, err := http.NewRequest(http.MethodGet, listURL, nil) if err != nil { diff --git a/pkg/cmd/codespace/create.go b/pkg/cmd/codespace/create.go index 5bf2c3806..91d293658 100644 --- a/pkg/cmd/codespace/create.go +++ b/pkg/cmd/codespace/create.go @@ -15,6 +15,14 @@ import ( "github.com/spf13/cobra" ) +const ( + DEVCONTAINER_PROMPT_DEFAULT = "Default Codespaces configuration" +) + +var ( + DEFAULT_DEVCONTAINER_DEFINITIONS = []string{".devcontainer.json", ".devcontainer/devcontainer.json"} +) + type createOptions struct { repo string branch string @@ -57,8 +65,6 @@ func (a *App) Create(ctx context.Context, opts createOptions) error { vscsTarget := os.Getenv("VSCS_TARGET") vscsTargetUrl := os.Getenv("VSCS_TARGET_URL") - DEFAULT_DEVCONTAINER_DEFINITIONS := []string{".devcontainer.json", ".devcontainer/devcontainer.json"} - userInputs := struct { Repository string Branch string @@ -118,13 +124,13 @@ func (a *App) Create(ctx context.Context, opts createOptions) error { devContainerPath := opts.devContainerPath // now that we have repo+branch, we can list available devcontainer.json files (if any) - if len(opts.devContainerPath) < 1 { + if opts.devContainerPath == "" { a.StartProgressIndicatorWithLabel("Fetching devcontainer.json files") devcontainers, err := a.apiClient.ListDevContainers(ctx, repository.ID, branch, 100) + a.StopProgressIndicator() if err != nil { return fmt.Errorf("error getting devcontainer.json paths: %w", err) } - a.StopProgressIndicator() if len(devcontainers) > 0 { @@ -135,7 +141,7 @@ func (a *App) Create(ctx context.Context, opts createOptions) error { promptOptions := []string{} if !utils.StringInSlice(devcontainers[0].Path, DEFAULT_DEVCONTAINER_DEFINITIONS) { - promptOptions = []string{"Default Codespaces configuration"} + promptOptions = []string{DEVCONTAINER_PROMPT_DEFAULT} } for _, devcontainer := range devcontainers { @@ -156,7 +162,7 @@ func (a *App) Create(ctx context.Context, opts createOptions) error { } } - if devContainerPath == "Default Codespaces configuration" { + if devContainerPath == DEVCONTAINER_PROMPT_DEFAULT { // special arg allows users to opt out of devcontainer.json selection devContainerPath = "" } @@ -184,7 +190,6 @@ func (a *App) Create(ctx context.Context, opts createOptions) error { a.StartProgressIndicatorWithLabel("Creating codespace") codespace, err := a.apiClient.CreateCodespace(ctx, createParams) - a.StopProgressIndicator() if err != nil {