Merge pull request #106 from github/jg/sku-params
ghcs create: pass branch for sku selection, pre-select if only one is returned
This commit is contained in:
commit
ef8dde4d2e
2 changed files with 9 additions and 4 deletions
|
|
@ -327,7 +327,7 @@ type SKU struct {
|
|||
DisplayName string `json:"display_name"`
|
||||
}
|
||||
|
||||
func (a *API) GetCodespacesSKUs(ctx context.Context, user *User, repository *Repository, location string) ([]*SKU, error) {
|
||||
func (a *API) GetCodespacesSKUs(ctx context.Context, user *User, repository *Repository, branch, location string) ([]*SKU, error) {
|
||||
req, err := http.NewRequest(http.MethodGet, githubAPI+"/vscs_internal/user/"+user.Login+"/skus", nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("err creating request: %v", err)
|
||||
|
|
@ -335,6 +335,7 @@ func (a *API) GetCodespacesSKUs(ctx context.Context, user *User, repository *Rep
|
|||
|
||||
q := req.URL.Query()
|
||||
q.Add("location", location)
|
||||
q.Add("ref", branch)
|
||||
q.Add("repository_id", strconv.Itoa(repository.ID))
|
||||
req.URL.RawQuery = q.Encode()
|
||||
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ func create(opts *createOptions) error {
|
|||
return fmt.Errorf("error getting Codespace user: %v", userResult.Err)
|
||||
}
|
||||
|
||||
machine, err := getMachineName(ctx, opts.machine, userResult.User, repository, locationResult.Location, apiClient)
|
||||
machine, err := getMachineName(ctx, opts.machine, userResult.User, repository, branch, locationResult.Location, apiClient)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error getting machine type: %v", err)
|
||||
}
|
||||
|
|
@ -225,8 +225,8 @@ func getBranchName(branch string) (string, error) {
|
|||
}
|
||||
|
||||
// getMachineName prompts the user to select the machine type, or validates the machine if non-empty.
|
||||
func getMachineName(ctx context.Context, machine string, user *api.User, repo *api.Repository, location string, apiClient *api.API) (string, error) {
|
||||
skus, err := apiClient.GetCodespacesSKUs(ctx, user, repo, location)
|
||||
func getMachineName(ctx context.Context, machine string, user *api.User, repo *api.Repository, branch, location string, apiClient *api.API) (string, error) {
|
||||
skus, err := apiClient.GetCodespacesSKUs(ctx, user, repo, branch, location)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error getting Codespace SKUs: %v", err)
|
||||
}
|
||||
|
|
@ -250,6 +250,10 @@ func getMachineName(ctx context.Context, machine string, user *api.User, repo *a
|
|||
return "", nil
|
||||
}
|
||||
|
||||
if len(skus) == 1 {
|
||||
return skus[0].Name, nil // VS Code does not prompt for SKU if there is only one, this makes us consistent with that behavior
|
||||
}
|
||||
|
||||
skuNames := make([]string, 0, len(skus))
|
||||
skuByName := make(map[string]*api.SKU)
|
||||
for _, sku := range skus {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue