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)
| 584 | // StartCodespace starts a codespace for the user. |
| 585 | // If the codespace is already running, the returned error from the API is ignored. |
| 586 | func (a *API) StartCodespace(ctx context.Context, codespaceName string) error { |
| 587 | resp, err := a.withRetry(func() (*http.Response, error) { |
| 588 | u, err := safeurl.JoinPathWithHostPrefix(a.githubAPI, "user", "codespaces", codespaceName, "start") |
| 589 | if err != nil { |
| 590 | return nil, err |
| 591 | } |
| 592 | req, err := http.NewRequest( |
| 593 | http.MethodPost, |
| 594 | u.String(), |
| 595 | nil, |
| 596 | ) |
| 597 | if err != nil { |
| 598 | return nil, fmt.Errorf("error creating request: %w", err) |
| 599 | } |
| 600 | a.setHeaders(req) |
| 601 | return a.do(ctx, req, "/user/codespaces/*/start") |
| 602 | }) |
| 603 | if err != nil { |
| 604 | return fmt.Errorf("error making request: %w", err) |
| 605 | } |
| 606 | defer resp.Body.Close() |
| 607 | |
| 608 | if resp.StatusCode != http.StatusOK { |
| 609 | if resp.StatusCode == http.StatusConflict { |
| 610 | // 409 means the codespace is already running which we can safely ignore |
| 611 | return nil |
| 612 | } |
| 613 | return api.HandleHTTPError(resp) |
| 614 | } |
| 615 | |
| 616 | return nil |
| 617 | } |
| 618 | |
| 619 | func (a *API) StopCodespace(ctx context.Context, codespaceName string, orgName string, userName string) error { |
| 620 | var stopURL *safeurl.MutableSafeURL |
nothing calls this directly
no test coverage detected