EventsFeatures checks whether event subscriptions are enabled for the authenticated account. Only github.com is supported, so GitHub Enterprise Server and GHE.com hosts report unavailable without making a request. A 403 response means they are not enabled for the account, and a 404 response means th
()
| 629 | // means they are not enabled for the account, and a 404 response means the host does not have the endpoint at all. Both |
| 630 | // are cached like a successful response when the detector caches results. |
| 631 | func (d *detector) EventsFeatures() (EventsFeatures, error) { |
| 632 | if ghauth.IsEnterprise(d.host) || ghauth.IsTenancy(d.host) { |
| 633 | return EventsFeatures{}, nil |
| 634 | } |
| 635 | |
| 636 | u, err := safeurl.JoinPath("event-subscriptions") |
| 637 | if err != nil { |
| 638 | return EventsFeatures{}, err |
| 639 | } |
| 640 | u.SetQuery("per_page", "1") |
| 641 | |
| 642 | ctx, cancel := context.WithTimeout(context.Background(), eventsFeatureDetectionTimeout) |
| 643 | defer cancel() |
| 644 | client := api.NewClientFromHTTP(d.client(http.StatusForbidden, http.StatusNotFound)) |
| 645 | // Unlike other detections, which inspect the schema, this one calls a real endpoint, so the header marks the request |
| 646 | // as feature detection. |
| 647 | resp, err := client.RequestWithContext(ctx, d.host, http.MethodGet, u.String(), nil, |
| 648 | api.WithHeader("gh-feature-detection", "true")) |
| 649 | if err != nil { |
| 650 | if httpErr, ok := errors.AsType[api.HTTPError](err); ok && |
| 651 | (httpErr.StatusCode == http.StatusForbidden || httpErr.StatusCode == http.StatusNotFound) { |
| 652 | return EventsFeatures{}, nil |
| 653 | } |
| 654 | return EventsFeatures{}, err |
| 655 | } |
| 656 | resp.Body.Close() |
| 657 | |
| 658 | return EventsFeatures{Subscriptions: true}, nil |
| 659 | } |
| 660 | |
| 661 | func resolveEnterpriseVersion(httpClient *http.Client, host string) (*version.Version, error) { |
| 662 | var metaResponse struct { |
nothing calls this directly
no test coverage detected