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

Method GetCodespacesPermissionsCheck

internal/codespaces/api/api.go:647–683  ·  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 int, branch string, devcontainerPath string)

Source from the content-addressed store, hash-verified

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 int, 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.
686type RepoSearchParameters struct {

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