MCPcopy Create free account
hub / github.com/cli/cli / GetCodespacesPermissionsCheck

Method GetCodespacesPermissionsCheck

internal/codespaces/api/api.go:704–743  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

702
703// GetCodespacesPermissionsCheck returns a bool indicating whether the user has accepted permissions for the given repo and devcontainer path.
704func (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.
746type RepoSearchParameters struct {

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected