GetCodespaceBillableOwner returns the billable owner and expected default values for codespaces created by the user for a given repository.
(ctx context.Context, nwo string)
| 763 | // GetCodespaceBillableOwner returns the billable owner and expected default values for |
| 764 | // codespaces created by the user for a given repository. |
| 765 | func (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. |
| 808 | type CreateCodespaceParams struct { |
nothing calls this directly
no test coverage detected