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