X Tutup
Skip to content

Commit ef8dde4

Browse files
authored
Merge pull request cli#106 from github/jg/sku-params
ghcs create: pass branch for sku selection, pre-select if only one is returned
2 parents c0fbb7e + 2163aba commit ef8dde4

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

api/api.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,14 +327,15 @@ type SKU struct {
327327
DisplayName string `json:"display_name"`
328328
}
329329

330-
func (a *API) GetCodespacesSKUs(ctx context.Context, user *User, repository *Repository, location string) ([]*SKU, error) {
330+
func (a *API) GetCodespacesSKUs(ctx context.Context, user *User, repository *Repository, branch, location string) ([]*SKU, error) {
331331
req, err := http.NewRequest(http.MethodGet, githubAPI+"/vscs_internal/user/"+user.Login+"/skus", nil)
332332
if err != nil {
333333
return nil, fmt.Errorf("err creating request: %v", err)
334334
}
335335

336336
q := req.URL.Query()
337337
q.Add("location", location)
338+
q.Add("ref", branch)
338339
q.Add("repository_id", strconv.Itoa(repository.ID))
339340
req.URL.RawQuery = q.Encode()
340341

cmd/ghcs/create.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func create(opts *createOptions) error {
7777
return fmt.Errorf("error getting Codespace user: %v", userResult.Err)
7878
}
7979

80-
machine, err := getMachineName(ctx, opts.machine, userResult.User, repository, locationResult.Location, apiClient)
80+
machine, err := getMachineName(ctx, opts.machine, userResult.User, repository, branch, locationResult.Location, apiClient)
8181
if err != nil {
8282
return fmt.Errorf("error getting machine type: %v", err)
8383
}
@@ -225,8 +225,8 @@ func getBranchName(branch string) (string, error) {
225225
}
226226

227227
// getMachineName prompts the user to select the machine type, or validates the machine if non-empty.
228-
func getMachineName(ctx context.Context, machine string, user *api.User, repo *api.Repository, location string, apiClient *api.API) (string, error) {
229-
skus, err := apiClient.GetCodespacesSKUs(ctx, user, repo, location)
228+
func getMachineName(ctx context.Context, machine string, user *api.User, repo *api.Repository, branch, location string, apiClient *api.API) (string, error) {
229+
skus, err := apiClient.GetCodespacesSKUs(ctx, user, repo, branch, location)
230230
if err != nil {
231231
return "", fmt.Errorf("error getting Codespace SKUs: %v", err)
232232
}
@@ -250,6 +250,10 @@ func getMachineName(ctx context.Context, machine string, user *api.User, repo *a
250250
return "", nil
251251
}
252252

253+
if len(skus) == 1 {
254+
return skus[0].Name, nil // VS Code does not prompt for SKU if there is only one, this makes us consistent with that behavior
255+
}
256+
253257
skuNames := make([]string, 0, len(skus))
254258
skuByName := make(map[string]*api.SKU)
255259
for _, sku := range skus {

0 commit comments

Comments
 (0)
X Tutup