GetCodespacesMachines returns the codespaces machines for the given repo, branch and location.
(ctx context.Context, repoID int64, branch, location string, devcontainerPath string)
| 659 | |
| 660 | // GetCodespacesMachines returns the codespaces machines for the given repo, branch and location. |
| 661 | func (a *API) GetCodespacesMachines(ctx context.Context, repoID int64, branch, location string, devcontainerPath string) ([]*Machine, error) { |
| 662 | u, err := safeurl.JoinPathWithHostPrefix(a.githubAPI, "repositories", strconv.FormatInt(repoID, 10), "codespaces", "machines") |
| 663 | if err != nil { |
| 664 | return nil, err |
| 665 | } |
| 666 | req, err := http.NewRequest(http.MethodGet, u.String(), nil) |
| 667 | if err != nil { |
| 668 | return nil, fmt.Errorf("error creating request: %w", err) |
| 669 | } |
| 670 | |
| 671 | q := req.URL.Query() |
| 672 | q.Add("location", location) |
| 673 | q.Add("ref", branch) |
| 674 | q.Add("devcontainer_path", devcontainerPath) |
| 675 | req.URL.RawQuery = q.Encode() |
| 676 | |
| 677 | a.setHeaders(req) |
| 678 | resp, err := a.do(ctx, req, "/repositories/*/codespaces/machines") |
| 679 | if err != nil { |
| 680 | return nil, fmt.Errorf("error making request: %w", err) |
| 681 | } |
| 682 | defer resp.Body.Close() |
| 683 | |
| 684 | if resp.StatusCode != http.StatusOK { |
| 685 | return nil, api.HandleHTTPError(resp) |
| 686 | } |
| 687 | |
| 688 | b, err := io.ReadAll(resp.Body) |
| 689 | if err != nil { |
| 690 | return nil, fmt.Errorf("error reading response body: %w", err) |
| 691 | } |
| 692 | |
| 693 | var response struct { |
| 694 | Machines []*Machine `json:"machines"` |
| 695 | } |
| 696 | if err := json.Unmarshal(b, &response); err != nil { |
| 697 | return nil, fmt.Errorf("error unmarshalling response: %w", err) |
| 698 | } |
| 699 | |
| 700 | return response.Machines, nil |
| 701 | } |
| 702 | |
| 703 | // GetCodespacesPermissionsCheck returns a bool indicating whether the user has accepted permissions for the given repo and devcontainer path. |
| 704 | func (a *API) GetCodespacesPermissionsCheck(ctx context.Context, repoID int64, branch string, devcontainerPath string) (bool, error) { |
nothing calls this directly
no test coverage detected