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

Method GetCodespacesMachines

internal/codespaces/api/api.go:607–644  ·  view source on GitHub ↗

GetCodespacesMachines returns the codespaces machines for the given repo, branch and location.

(ctx context.Context, repoID int64, branch, location string, devcontainerPath string)

Source from the content-addressed store, hash-verified

605
606// GetCodespacesMachines returns the codespaces machines for the given repo, branch and location.
607func (a *API) GetCodespacesMachines(ctx context.Context, repoID int64, branch, location string, devcontainerPath string) ([]*Machine, error) {
608 reqURL := fmt.Sprintf("%s/repositories/%d/codespaces/machines", a.githubAPI, repoID)
609 req, err := http.NewRequest(http.MethodGet, reqURL, nil)
610 if err != nil {
611 return nil, fmt.Errorf("error creating request: %w", err)
612 }
613
614 q := req.URL.Query()
615 q.Add("location", location)
616 q.Add("ref", branch)
617 q.Add("devcontainer_path", devcontainerPath)
618 req.URL.RawQuery = q.Encode()
619
620 a.setHeaders(req)
621 resp, err := a.do(ctx, req, "/repositories/*/codespaces/machines")
622 if err != nil {
623 return nil, fmt.Errorf("error making request: %w", err)
624 }
625 defer resp.Body.Close()
626
627 if resp.StatusCode != http.StatusOK {
628 return nil, api.HandleHTTPError(resp)
629 }
630
631 b, err := io.ReadAll(resp.Body)
632 if err != nil {
633 return nil, fmt.Errorf("error reading response body: %w", err)
634 }
635
636 var response struct {
637 Machines []*Machine `json:"machines"`
638 }
639 if err := json.Unmarshal(b, &response); err != nil {
640 return nil, fmt.Errorf("error unmarshalling response: %w", err)
641 }
642
643 return response.Machines, nil
644}
645
646// GetCodespacesPermissionsCheck returns a bool indicating whether the user has accepted permissions for the given repo and devcontainer path.
647func (a *API) GetCodespacesPermissionsCheck(ctx context.Context, repoID int64, branch string, devcontainerPath string) (bool, error) {

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected