Skip to content

Commit 86a4706

Browse files
committed
Update startCreate to use new API endpoint
- Updates the signature of startCreate - Can't update API.CreateCodespace just yet until we support expanded access on the GET codespace endpoint which is used for polling
1 parent 05297b8 commit 86a4706

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

internal/codespaces/api/api.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -430,9 +430,7 @@ type CreateCodespaceParams struct {
430430
// CreateCodespace creates a codespace with the given parameters and returns a non-nil error if it
431431
// fails to create.
432432
func (a *API) CreateCodespace(ctx context.Context, params *CreateCodespaceParams) (*Codespace, error) {
433-
codespace, err := a.startCreate(
434-
ctx, params.User, params.RepositoryID, params.Machine, params.Branch, params.Location,
435-
)
433+
codespace, err := a.startCreate(ctx, params.RepositoryID, params.Machine, params.Branch, params.Location)
436434
if err != errProvisioningInProgress {
437435
return codespace, err
438436
}
@@ -475,7 +473,7 @@ type startCreateRequest struct {
475473
RepositoryID int `json:"repository_id"`
476474
Ref string `json:"ref"`
477475
Location string `json:"location"`
478-
SkuName string `json:"sku_name"`
476+
Machine string `json:"machine"`
479477
}
480478

481479
var errProvisioningInProgress = errors.New("provisioning in progress")
@@ -484,19 +482,19 @@ var errProvisioningInProgress = errors.New("provisioning in progress")
484482
// It may return success or an error, or errProvisioningInProgress indicating that the operation
485483
// did not complete before the GitHub API's time limit for RPCs (10s), in which case the caller
486484
// must poll the server to learn the outcome.
487-
func (a *API) startCreate(ctx context.Context, user string, repository int, sku, branch, location string) (*Codespace, error) {
488-
requestBody, err := json.Marshal(startCreateRequest{repository, branch, location, sku})
485+
func (a *API) startCreate(ctx context.Context, repoID int, machine, branch, location string) (*Codespace, error) {
486+
requestBody, err := json.Marshal(startCreateRequest{repoID, branch, location, machine})
489487
if err != nil {
490488
return nil, fmt.Errorf("error marshaling request: %w", err)
491489
}
492490

493-
req, err := http.NewRequest(http.MethodPost, a.githubAPI+"/vscs_internal/user/"+user+"/codespaces", bytes.NewBuffer(requestBody))
491+
req, err := http.NewRequest(http.MethodPost, a.githubAPI+"/user/codespaces", bytes.NewBuffer(requestBody))
494492
if err != nil {
495493
return nil, fmt.Errorf("error creating request: %w", err)
496494
}
497495

498496
a.setHeaders(req)
499-
resp, err := a.do(ctx, req, "/vscs_internal/user/*/codespaces")
497+
resp, err := a.do(ctx, req, "/user/codespaces")
500498
if err != nil {
501499
return nil, fmt.Errorf("error making request: %w", err)
502500
}

0 commit comments

Comments
 (0)