Repository navigation
Show gh event listen hints only when event subscriptions are enabled - #15223
Conversation
Callers that cached feature detection results each built a cached HTTP client before creating the detector. NewCachedDetector takes the TTL directly, so callers only decide how long results are cached and the caching mechanism stays inside the detector. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: bbce5a7f-103c-4e67-99c9-2d6dc3f6a02b
NewCachedHTTPClientWithStatuses returns a cached client that also caches responses with the given status codes, such as 403, which are not cached by default. It relies on the X-GH-CACHE-STATUSES header supported by the go-gh cache, so go-gh is bumped accordingly. Without statuses, the header is not sent and the client behaves like NewCachedHTTPClient. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: bbce5a7f-103c-4e67-99c9-2d6dc3f6a02b
The detector now keeps the client it was given along with the cache TTL, and builds the client for each detection request through a private client method. This lets a detection method ask for extra cacheable status codes without callers knowing about the caching mechanism. Detectors created with NewDetector still do not cache. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: bbce5a7f-103c-4e67-99c9-2d6dc3f6a02b
EventsFeatures probes the event subscriptions endpoint to find out whether the authenticated account can use event subscriptions. A 403 means they are not enabled for the account, and a 404 means the host does not have the endpoint, so both report the feature as unavailable and are cached like a successful response when the detector caches. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: bbce5a7f-103c-4e67-99c9-2d6dc3f6a02b
The `gh event listen` hints shown to agents by `gh api`, `gh pr create`, `gh pr view`, `gh run view` and `gh run watch` now check event subscriptions access through feature detection, so accounts without access no longer see them. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: bbce5a7f-103c-4e67-99c9-2d6dc3f6a02b
Feature detection decides whether event subscriptions are enabled, so the hints no longer check the host. For an absolute API URL, `gh api` takes the pull request host from the URL. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: bbce5a7f-103c-4e67-99c9-2d6dc3f6a02b
The API decides whether event subscriptions are available, so the client no longer refuses GitHub Enterprise Server and GHE.com hosts before sending a request. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: bbce5a7f-103c-4e67-99c9-2d6dc3f6a02b
Also documents how feature detection decides whether the listen hints are shown. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: bbce5a7f-103c-4e67-99c9-2d6dc3f6a02b
GitHub Enterprise Server answers the event stream request with a 415, since it rejects the text/event-stream Accept header before it finds that the route does not exist. Report it as ErrUnsupportedHost instead of a bare HTTP error. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: bbce5a7f-103c-4e67-99c9-2d6dc3f6a02b
A host without the Event Subscriptions API answers 404, which cannot be told apart from a missing resource or subscription without another request. Name the host as a possible cause in the not found errors, and in the error of listing subscriptions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: bbce5a7f-103c-4e67-99c9-2d6dc3f6a02b
|
@iancanderson could you have a look at this one? 🙏 In particular, the help text and documentation changes are all in 466ce58 ( |
There was a problem hiding this comment.
🟡 Changes recommended
Absolute pull request URLs on configured API gateways are not mapped back to the logical GitHub host, causing incorrect feature detection and suppressed or misnamed hints.
1 open issue
What changed in this PR
This PR gates agent-facing gh event listen hints on cached account capability detection rather than a fixed host restriction.
Changes:
- Adds event-subscription detection with a three-second timeout and 24-hour caching, including 403 and 404 responses.
- Updates hints, host handling, and unsupported-host errors across API, pull request, run, and event commands.
- Updates tests, documentation, and the go-gh dependency for status-aware caching.
| File | Description |
|---|---|
| skills/gh/SKILL.md | Removes github.com-only wording. |
| pkg/cmd/workflow/run/run.go | Uses cached detector constructor. |
| pkg/cmd/run/watch/watch.go | Gates hints on capability detection. |
| pkg/cmd/run/watch/watch_test.go | Updates hint fixtures. |
| pkg/cmd/run/view/view.go | Wires detection into hints. |
| pkg/cmd/run/view/view_test.go | Updates hint expectations and mocks. |
| pkg/cmd/run/view/hint.go | Creates cached hint detector. |
| pkg/cmd/repo/list/list.go | Uses cached detector constructor. |
| pkg/cmd/repo/edit/edit.go | Uses cached detector constructor. |
| pkg/cmd/release/list/list.go | Uses cached detector constructor. |
| pkg/cmd/project/item-list/item_list.go | Uses cached detector constructor. |
| pkg/cmd/pr/view/view.go | Supplies hint client and updates help. |
| pkg/cmd/pr/view/view_test.go | Updates hint expectations and mocks. |
| pkg/cmd/pr/view/hint.go | Gates hints on capability detection. |
| pkg/cmd/pr/status/status.go | Uses cached detector constructor. |
| pkg/cmd/pr/shared/templates.go | Uses cached detector constructor. |
| pkg/cmd/pr/shared/finder.go | Uses cached detector constructor. |
| pkg/cmd/pr/pr.go | Removes host restriction from help. |
| pkg/cmd/pr/list/list.go | Uses cached detector constructor. |
| pkg/cmd/pr/edit/edit.go | Uses cached detector constructor. |
| pkg/cmd/pr/create/create.go | Passes detector to hints. |
| pkg/cmd/pr/create/create_test.go | Updates hint expectations. |
| pkg/cmd/pr/checks/checks.go | Uses cached detector constructor. |
| pkg/cmd/issue/view/view.go | Uses cached detector constructor. |
| pkg/cmd/issue/list/list.go | Uses cached detector constructor. |
| pkg/cmd/issue/edit/edit.go | Uses cached detector constructor. |
| pkg/cmd/issue/create/create.go | Uses cached detector constructor. |
| pkg/cmd/event/subscription/view/view_test.go | Updates missing-subscription expectations. |
| pkg/cmd/event/subscription/list/list.go | Explains possible unsupported-host 404s. |
| pkg/cmd/event/subscription/list/list_test.go | Covers unsupported-host messaging. |
| pkg/cmd/event/subscription/delete/delete_test.go | Updates missing-subscription expectations. |
| pkg/cmd/event/subscription/create/create.go | Expands resource-not-found explanation. |
| pkg/cmd/event/subscription/create/create_test.go | Updates error expectations. |
| pkg/cmd/event/shared/subscription.go | Adds host-support context to errors. |
| pkg/cmd/event/shared/hint.go | Replaces host checks with capability detection. |
| pkg/cmd/event/shared/hint_test.go | Covers enabled and disabled hints. |
| pkg/cmd/event/listen/listen.go | Updates help and host-related errors. |
| pkg/cmd/event/listen/listen_test.go | Updates error expectations. |
| pkg/cmd/event/event.go | Describes account-based preview access. |
| pkg/cmd/event/client/client.go | Removes host restriction and handles 415 responses. |
| pkg/cmd/event/client/client_test.go | Updates host-support coverage. |
| pkg/cmd/api/hint.go | Resolves absolute URL hosts and gates hints. |
| pkg/cmd/api/api.go | Supplies hint detector dependencies. |
| pkg/cmd/api/api_test.go | Covers additional API URL hosts. |
| internal/featuredetection/feature_detection.go | Adds cached construction and event detection. |
| internal/featuredetection/feature_detection_test.go | Tests cache headers and event detection. |
| internal/featuredetection/detector_mock.go | Adds event capability mocks. |
| go.sum | Updates go-gh checksums. |
| go.mod | Pins go-gh status-aware caching support. |
| docs/event-listen-preview.md | Documents capability gating and caching. |
| api/http_client.go | Adds configurable cached response statuses. |
| api/http_client_test.go | Tests cache-status headers. |
| api/client.go | Defines cache-status header constant. |
Review effort: Balanced
| return | ||
| } | ||
| host, requestPath = "github.com", u.Path | ||
| host, requestPath = ghauth.NormalizeHostname(u.Hostname()), strings.TrimPrefix(u.Path, "/api/v3") |
There was a problem hiding this comment.
Thanks, but I don't think this applies. api_host is meant to be a transparent gateway: the configured host stays the identity for login, git remotes, web URLs and so on, and only API traffic is rerouted behind the scenes (see docs/api-host.md). Users aren't expected to address the gateway directly, so passing a gateway URL like https://api-gateway.example.net/repos/OWNER/REPO/pulls/1 to gh api isn't an intended input.
In practice, the absolute URLs an agent passes here come from API responses (e.g. an event's api_url). The gateway just forwards requests and doesn't rewrite payloads, so those URLs point at the real API host (api.github.com or api.example.ghe.com), which already resolves to the right host via NormalizeHostname. Feature detection for that host then goes through the gateway as usual.
|
|
||
| Do not re-read the PR without a new event; the listener tells you when to look. | ||
|
|
||
| The command creates a subscription for the PR and event types, or reuses an existing one for the same set, and reconnects on its own if the stream drops. Events during a reconnect are lost, so each time the listener reports that it is listening again, read the state once. Subscriptions expire after 24 hours, and each account can hold a limited number at a time, so reuse the same set of event types rather than creating variations. To attach another listener to an existing subscription, pass its ID with `--subscription`. `--jq` and `--template` format each event, for example `--jq '.data.api_url'`. Events are only available on github.com, and this preview needs a user account enabled for the Event Subscriptions API. |
There was a problem hiding this comment.
Events are only available on github.com, and this
Did you remove this phrase so that the docs here are more evergreen/durable and don't rely on the state of the rollout? Because this still stands today - GHES and GHE.com won't be able to use the API.
That being said, this is still kind of covered with "This preview needs a user account enabled for the Event Subscriptions API.", in the sense that no user accounts on GHE.com are currently enabled for this, for example. So I think this is all fine 👍
Revert the host-restriction removal across the event client, commands, discovery hints, help text, and documentation, and short-circuit EventsFeatures for GitHub Enterprise Server and GHE.com hosts without making an HTTP request.

Description
When
ghdetects that an agent is calling it,gh pr create,gh pr view,gh run view,gh run watchandgh apiprint a hint on stderr suggestinggh event listeninstead of polling. The Event Streams API behindgh eventis in preview and only enabled for some accounts, but the hint was shown to every agent on github.com. Agents on accounts without access followed the hint and got a 403.This PR shows the hints only when feature detection says event subscriptions are enabled for the account:
EventsFeaturessendsGET /event-subscriptions?per_page=1with agh-feature-detection: trueheader. A 200 means event subscriptions are enabled. A 403 (not enabled for the account) or a 404 (the host does not have the endpoint) means they are not. Any other failure, including the 3 second timeout, also hides the hint.NewCachedHTTPClientWithStatusesopts into those statuses through theX-GH-CACHE-STATUSESheader added in feat(api): allow requests to opt into caching extra response statuses go-gh#335.EventsFeaturesreports them unavailable without sending a request, and the hints andgh eventcommands keep refusing those hosts as before.docs/event-listen-preview.mddescribes how feature detection gates the hints.How did you test this change?
I ran a build of this branch against github.com, with an account that has event subscriptions enabled, and against a GitHub Enterprise Server 3.23 host, which does not have the API. Unless stated otherwise,
ghran as an agent caller (COPILOT_CLIset), with an empty cache directory andGH_DEBUG=apito see the requests. The GHES host and repository are shown as<ghes-host>andOWNER/REPO.I ran these scenarios before
Restore github.com host restriction for event streaming, which does not change the github.com paths they exercise. I have not rerun the GitHub Enterprise Server scenarios against that commit, and I left out the scenarios for behavior it reverts.Feature detection and caching
Hints
gh eventon github.comI did not exercise the
gh run viewandgh run watchhints end to end, because no pull request run was in progress at the time.Key points
gh-feature-detection: trueheader marks the request as feature detection rather than data retrieval.Notes for reviewers
The first four commits are in
internal/featuredetectionandapi: aNewCachedDetectorconstructor,NewCachedHTTPClientWithStatuses, detection clients built from a cache TTL, andEventsFeatures. The next commit wires the hints to the detector. The commits after it that lifted the host restriction are reverted byRestore github.com host restriction for event streaming, so from there on the overall diff is easier to review than the individual commits.cli/go-gh#335 adds the
X-GH-CACHE-STATUSESheader this PR relies on to cache 403 and 404 responses, released in go-gh v2.17.1.Authorship and follow-up
Who wrote this:
Who answers review comments: