PR feedback

This commit is contained in:
Jeff Hubbard 2022-04-20 11:52:32 -07:00
parent 9fb6cf5423
commit 2b57084bd0
2 changed files with 17 additions and 9 deletions

View file

@ -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 {

View file

@ -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 {