MCPcopy Index your code
hub / github.com/cli/cli / StartCodespace

Method StartCodespace

internal/codespaces/api/api.go:540–567  ·  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

538// StartCodespace starts a codespace for the user.
539// If the codespace is already running, the returned error from the API is ignored.
540func (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
569func (a *API) StopCodespace(ctx context.Context, codespaceName string, orgName string, userName string) error {
570 var stopURL string

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected