MCPcopy Create free account
hub / github.com/cli/cli / EventsFeatures

Method EventsFeatures

internal/featuredetection/feature_detection.go:631–659  ·  view source on GitHub ↗

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

()

Source from the content-addressed store, hash-verified

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.
631func (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
661func resolveEnterpriseVersion(httpClient *http.Client, host string) (*version.Version, error) {
662 var metaResponse struct {

Callers

nothing calls this directly

Calls 8

clientMethod · 0.95
JoinPathFunction · 0.92
NewClientFromHTTPFunction · 0.92
WithHeaderFunction · 0.92
SetQueryMethod · 0.80
RequestWithContextMethod · 0.80
StringMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected