GetCodespaceBillableOwner returns the billable owner and expected default values for codespaces created by the user for a given repository.
(ctx context.Context, nwo string)
| 826 | // GetCodespaceBillableOwner returns the billable owner and expected default values for |
| 827 | // codespaces created by the user for a given repository. |
| 828 | func (a *API) GetCodespaceBillableOwner(ctx context.Context, nwo string) (*User, error) { |
| 829 | owner, name, err := safeurl.RepoPartsFromNWO(nwo) |
| 830 | if err != nil { |
| 831 | return nil, err |
| 832 | } |
| 833 | u, err := safeurl.JoinPathWithHostPrefix(a.githubAPI, "repos", owner, name, "codespaces", "new") |
| 834 | if err != nil { |
| 835 | return nil, err |
| 836 | } |
| 837 | req, err := http.NewRequest(http.MethodGet, u.String(), nil) |
| 838 | if err != nil { |
| 839 | return nil, fmt.Errorf("error creating request: %w", err) |
| 840 | } |
| 841 | |
| 842 | a.setHeaders(req) |
| 843 | resp, err := a.do(ctx, req, "/repos/*/codespaces/new") |
| 844 | if err != nil { |
| 845 | return nil, fmt.Errorf("error making request: %w", err) |
| 846 | } |
| 847 | defer resp.Body.Close() |
| 848 | |
| 849 | if resp.StatusCode == http.StatusNotFound { |
| 850 | return nil, nil |
| 851 | } else if resp.StatusCode == http.StatusForbidden { |
| 852 | return nil, fmt.Errorf("you cannot create codespaces with that repository") |
| 853 | } else if resp.StatusCode != http.StatusOK { |
| 854 | return nil, api.HandleHTTPError(resp) |
| 855 | } |
| 856 | |
| 857 | b, err := io.ReadAll(resp.Body) |
| 858 | if err != nil { |
| 859 | return nil, fmt.Errorf("error reading response body: %w", err) |
| 860 | } |
| 861 | |
| 862 | var response struct { |
| 863 | BillableOwner User `json:"billable_owner"` |
| 864 | Defaults struct { |
| 865 | DevcontainerPath string `json:"devcontainer_path"` |
| 866 | Location string `json:"location"` |
| 867 | } |
| 868 | } |
| 869 | if err := json.Unmarshal(b, &response); err != nil { |
| 870 | return nil, fmt.Errorf("error unmarshalling response: %w", err) |
| 871 | } |
| 872 | |
| 873 | // While this response contains further helpful information ahead of codespace creation, |
| 874 | // we're only referencing the billable owner today. |
| 875 | return &response.BillableOwner, nil |
| 876 | } |
| 877 | |
| 878 | // CreateCodespaceParams are the required parameters for provisioning a Codespace. |
| 879 | type CreateCodespaceParams struct { |
nothing calls this directly
no test coverage detected