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

Method GetCodespace

internal/codespaces/api/api.go:497–536  ·  view source on GitHub ↗

GetCodespace returns the user codespace based on the provided name. If the codespace is not found, an error is returned. If includeConnection is true, it will return the connection information for the codespace.

(ctx context.Context, codespaceName string, includeConnection bool)

Source from the content-addressed store, hash-verified

495// If the codespace is not found, an error is returned.
496// If includeConnection is true, it will return the connection information for the codespace.
497func (a *API) GetCodespace(ctx context.Context, codespaceName string, includeConnection bool) (*Codespace, error) {
498 resp, err := a.withRetry(func() (*http.Response, error) {
499 req, err := http.NewRequest(
500 http.MethodGet,
501 a.githubAPI+"/user/codespaces/"+codespaceName,
502 nil,
503 )
504 if err != nil {
505 return nil, fmt.Errorf("error creating request: %w", err)
506 }
507 if includeConnection {
508 q := req.URL.Query()
509 q.Add("internal", "true")
510 q.Add("refresh", "true")
511 req.URL.RawQuery = q.Encode()
512 }
513 a.setHeaders(req)
514 return a.do(ctx, req, "/user/codespaces/*")
515 })
516 if err != nil {
517 return nil, fmt.Errorf("error making request: %w", err)
518 }
519 defer resp.Body.Close()
520
521 if resp.StatusCode != http.StatusOK {
522 return nil, api.HandleHTTPError(resp)
523 }
524
525 b, err := io.ReadAll(resp.Body)
526 if err != nil {
527 return nil, fmt.Errorf("error reading response body: %w", err)
528 }
529
530 var response Codespace
531 if err := json.Unmarshal(b, &response); err != nil {
532 return nil, fmt.Errorf("error unmarshalling response: %w", err)
533 }
534
535 return &response, nil
536}
537
538// StartCodespace starts a codespace for the user.
539// If the codespace is already running, the returned error from the API is ignored.

Callers 3

CreateCodespaceMethod · 0.95
TestRetriesFunction · 0.95

Calls 8

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

Tested by 1

TestRetriesFunction · 0.76