GetCodespacesPermissionsCheck returns a bool indicating whether the user has accepted permissions for the given repo and devcontainer path.
(ctx context.Context, repoID int64, branch string, devcontainerPath string)
| 645 | |
| 646 | // GetCodespacesPermissionsCheck returns a bool indicating whether the user has accepted permissions for the given repo and devcontainer path. |
| 647 | func (a *API) GetCodespacesPermissionsCheck(ctx context.Context, repoID int64, branch string, devcontainerPath string) (bool, error) { |
| 648 | reqURL := fmt.Sprintf("%s/repositories/%d/codespaces/permissions_check", a.githubAPI, repoID) |
| 649 | req, err := http.NewRequest(http.MethodGet, reqURL, nil) |
| 650 | if err != nil { |
| 651 | return false, fmt.Errorf("error creating request: %w", err) |
| 652 | } |
| 653 | |
| 654 | q := req.URL.Query() |
| 655 | q.Add("ref", branch) |
| 656 | q.Add("devcontainer_path", devcontainerPath) |
| 657 | req.URL.RawQuery = q.Encode() |
| 658 | |
| 659 | a.setHeaders(req) |
| 660 | resp, err := a.do(ctx, req, "/repositories/*/codespaces/permissions_check") |
| 661 | if err != nil { |
| 662 | return false, fmt.Errorf("error making request: %w", err) |
| 663 | } |
| 664 | defer resp.Body.Close() |
| 665 | |
| 666 | if resp.StatusCode != http.StatusOK { |
| 667 | return false, api.HandleHTTPError(resp) |
| 668 | } |
| 669 | |
| 670 | b, err := io.ReadAll(resp.Body) |
| 671 | if err != nil { |
| 672 | return false, fmt.Errorf("error reading response body: %w", err) |
| 673 | } |
| 674 | |
| 675 | var response struct { |
| 676 | Accepted bool `json:"accepted"` |
| 677 | } |
| 678 | if err := json.Unmarshal(b, &response); err != nil { |
| 679 | return false, fmt.Errorf("error unmarshalling response: %w", err) |
| 680 | } |
| 681 | |
| 682 | return response.Accepted, nil |
| 683 | } |
| 684 | |
| 685 | // RepoSearchParameters are the optional parameters for searching for repositories. |
| 686 | type RepoSearchParameters struct { |
nothing calls this directly
no test coverage detected