resolveCapiURL queries the GitHub API for the Copilot API endpoint URL.
(httpClient *http.Client, host string)
| 47 | |
| 48 | // resolveCapiURL queries the GitHub API for the Copilot API endpoint URL. |
| 49 | func resolveCapiURL(httpClient *http.Client, host string) (string, error) { |
| 50 | apiClient := api.NewClientFromHTTP(httpClient) |
| 51 | |
| 52 | var resp struct { |
| 53 | Viewer struct { |
| 54 | CopilotEndpoints struct { |
| 55 | Api string `graphql:"api"` |
| 56 | } `graphql:"copilotEndpoints"` |
| 57 | } `graphql:"viewer"` |
| 58 | } |
| 59 | |
| 60 | if err := apiClient.Query(host, "CopilotEndpoints", &resp, nil); err != nil { |
| 61 | return "", err |
| 62 | } |
| 63 | |
| 64 | if resp.Viewer.CopilotEndpoints.Api == "" { |
| 65 | return "", errors.New("empty Copilot API URL returned") |
| 66 | } |
| 67 | |
| 68 | return resp.Viewer.CopilotEndpoints.Api, nil |
| 69 | } |
| 70 | |
| 71 | func IsSessionID(s string) bool { |
| 72 | return sessionIDRegexp.MatchString(s) |