MCPcopy Create free account
hub / github.com/cli/cli / StartCodespace

Method StartCodespace

internal/codespaces/api/api.go:586–617  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

584// StartCodespace starts a codespace for the user.
585// If the codespace is already running, the returned error from the API is ignored.
586func (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
619func (a *API) StopCodespace(ctx context.Context, codespaceName string, orgName string, userName string) error {
620 var stopURL *safeurl.MutableSafeURL

Callers

nothing calls this directly

Calls 8

withRetryMethod · 0.95
setHeadersMethod · 0.95
doMethod · 0.95
JoinPathWithHostPrefixFunction · 0.92
HandleHTTPErrorFunction · 0.92
StringMethod · 0.65
ErrorfMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected