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

Method GetCodespaceBillableOwner

internal/codespaces/api/api.go:765–805  ·  view source on GitHub ↗

GetCodespaceBillableOwner returns the billable owner and expected default values for codespaces created by the user for a given repository.

(ctx context.Context, nwo string)

Source from the content-addressed store, hash-verified

763// GetCodespaceBillableOwner returns the billable owner and expected default values for
764// codespaces created by the user for a given repository.
765func (a *API) GetCodespaceBillableOwner(ctx context.Context, nwo string) (*User, error) {
766 req, err := http.NewRequest(http.MethodGet, a.githubAPI+"/repos/"+nwo+"/codespaces/new", nil)
767 if err != nil {
768 return nil, fmt.Errorf("error creating request: %w", err)
769 }
770
771 a.setHeaders(req)
772 resp, err := a.do(ctx, req, "/repos/*/codespaces/new")
773 if err != nil {
774 return nil, fmt.Errorf("error making request: %w", err)
775 }
776 defer resp.Body.Close()
777
778 if resp.StatusCode == http.StatusNotFound {
779 return nil, nil
780 } else if resp.StatusCode == http.StatusForbidden {
781 return nil, fmt.Errorf("you cannot create codespaces with that repository")
782 } else if resp.StatusCode != http.StatusOK {
783 return nil, api.HandleHTTPError(resp)
784 }
785
786 b, err := io.ReadAll(resp.Body)
787 if err != nil {
788 return nil, fmt.Errorf("error reading response body: %w", err)
789 }
790
791 var response struct {
792 BillableOwner User `json:"billable_owner"`
793 Defaults struct {
794 DevcontainerPath string `json:"devcontainer_path"`
795 Location string `json:"location"`
796 }
797 }
798 if err := json.Unmarshal(b, &response); err != nil {
799 return nil, fmt.Errorf("error unmarshalling response: %w", err)
800 }
801
802 // While this response contains further helpful information ahead of codespace creation,
803 // we're only referencing the billable owner today.
804 return &response.BillableOwner, nil
805}
806
807// CreateCodespaceParams are the required parameters for provisioning a Codespace.
808type CreateCodespaceParams struct {

Callers

nothing calls this directly

Calls 5

setHeadersMethod · 0.95
doMethod · 0.95
HandleHTTPErrorFunction · 0.92
ErrorfMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected