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)
| 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) { |
| 705 | u, err := safeurl.JoinPathWithHostPrefix(a.githubAPI, "repositories", strconv.FormatInt(repoID, 10), "codespaces", "permissions_check") |
| 706 | if err != nil { |
| 707 | return false, err |
| 708 | } |
| 709 | req, err := http.NewRequest(http.MethodGet, u.String(), nil) |
| 710 | if err != nil { |
| 711 | return false, fmt.Errorf("error creating request: %w", err) |
| 712 | } |
| 713 | |
| 714 | q := req.URL.Query() |
| 715 | q.Add("ref", branch) |
| 716 | q.Add("devcontainer_path", devcontainerPath) |
| 717 | req.URL.RawQuery = q.Encode() |
| 718 | |
| 719 | a.setHeaders(req) |
| 720 | resp, err := a.do(ctx, req, "/repositories/*/codespaces/permissions_check") |
| 721 | if err != nil { |
| 722 | return false, fmt.Errorf("error making request: %w", err) |
| 723 | } |
| 724 | defer resp.Body.Close() |
| 725 | |
| 726 | if resp.StatusCode != http.StatusOK { |
| 727 | return false, api.HandleHTTPError(resp) |
| 728 | } |
| 729 | |
| 730 | b, err := io.ReadAll(resp.Body) |
| 731 | if err != nil { |
| 732 | return false, fmt.Errorf("error reading response body: %w", err) |
| 733 | } |
| 734 | |
| 735 | var response struct { |
| 736 | Accepted bool `json:"accepted"` |
| 737 | } |
| 738 | if err := json.Unmarshal(b, &response); err != nil { |
| 739 | return false, fmt.Errorf("error unmarshalling response: %w", err) |
| 740 | } |
| 741 | |
| 742 | return response.Accepted, nil |
| 743 | } |
| 744 | |
| 745 | // RepoSearchParameters are the optional parameters for searching for repositories. |
| 746 | type RepoSearchParameters struct { |
nothing calls this directly
no test coverage detected