StartCodespace starts a codespace for the user. If the codespace is already running, the returned error from the API is ignored.
(ctx context.Context, codespaceName string)
| 538 | // StartCodespace starts a codespace for the user. |
| 539 | // If the codespace is already running, the returned error from the API is ignored. |
| 540 | func (a *API) StartCodespace(ctx context.Context, codespaceName string) error { |
| 541 | resp, err := a.withRetry(func() (*http.Response, error) { |
| 542 | req, err := http.NewRequest( |
| 543 | http.MethodPost, |
| 544 | a.githubAPI+"/user/codespaces/"+codespaceName+"/start", |
| 545 | nil, |
| 546 | ) |
| 547 | if err != nil { |
| 548 | return nil, fmt.Errorf("error creating request: %w", err) |
| 549 | } |
| 550 | a.setHeaders(req) |
| 551 | return a.do(ctx, req, "/user/codespaces/*/start") |
| 552 | }) |
| 553 | if err != nil { |
| 554 | return fmt.Errorf("error making request: %w", err) |
| 555 | } |
| 556 | defer resp.Body.Close() |
| 557 | |
| 558 | if resp.StatusCode != http.StatusOK { |
| 559 | if resp.StatusCode == http.StatusConflict { |
| 560 | // 409 means the codespace is already running which we can safely ignore |
| 561 | return nil |
| 562 | } |
| 563 | return api.HandleHTTPError(resp) |
| 564 | } |
| 565 | |
| 566 | return nil |
| 567 | } |
| 568 | |
| 569 | func (a *API) StopCodespace(ctx context.Context, codespaceName string, orgName string, userName string) error { |
| 570 | var stopURL string |
nothing calls this directly
no test coverage detected