Repository navigation
Event streaming (1/11): Add a server-sent events reader and an Event Subscriptions API client - #15071
Merged
Merged
Conversation
Co-authored-by: Copilot <[email protected]> Copilot-Session: bbce5a7f-103c-4e67-99c9-2d6dc3f6a02b
Co-authored-by: Copilot <[email protected]> Copilot-Session: bbce5a7f-103c-4e67-99c9-2d6dc3f6a02b
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Split-CRLF handling can block SSE reads despite buffered frame data, and subscription requests fail to propagate cancellation and deadlines.
2 open issues
1 file not reviewed
pkg/cmd/event/client/client_mock.go: Generated file
What changed in this PR
Adds the shared foundations for the event-streaming stack tracked in #15070: a server-sent events reader and a client for GitHub’s preview Event Subscriptions API. This layer adds no user-facing commands.
Changes:
- Parse event frames, preserve event IDs, and report heartbeat comments.
- Support subscription management, paginated listing, and live streams with host checks and classified API errors.
- Add reader and client tests, subscription JSON export support, and a generated client mock.
| File | Description |
|---|---|
| pkg/cmd/event/client/types.go | Defines subscription data and selectable JSON export fields. |
| pkg/cmd/event/client/client.go | Implements subscription operations, stream access, and error mapping. |
| pkg/cmd/event/client/client_test.go | Tests API operations, pagination, response handling, and host rejection. |
| pkg/cmd/event/client/client_mock.go | Provides the generated EventClient mock for command tests. |
| internal/eventstream/sse.go | Implements frame parsing, line splitting, and heartbeat callbacks. |
| internal/eventstream/sse_test.go | Tests parsing rules, fragmented input, line limits, and read errors. |
Review effort: Balanced
| } | ||
|
|
||
| var sub Subscription | ||
| if err := c.api.REST(c.host, http.MethodGet, path.String(), nil, &sub); err != nil { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
2 of 6 tasks
BagToad
approved these changes
Nov 17, 2026
This was referenced Nov 18, 2026
Merged
|
|
||
| import ( | ||
| "bytes" | ||
| "context" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Layer 1 of 11 in the stack tracked by #15070.
Description
GitHub's Event Subscriptions API (in preview, github.com only) lets a client subscribe to events on a resource, such as a pull request being reviewed or merged, and receive them over a server-sent events (SSE) stream instead of polling. This is the first PR in a stack that adds
gh eventcommands on top of that API. It adds no commands yet; it adds the two building blocks they share.internal/eventstreamis a small SSE frame reader. Go has no SSE parser in the standard library, and the format is simple enough that a dependency is not worth it.FrameReaderfollows the parsing and interpretation rules of the WHATWG HTML spec (section 9.2), including multi-linedata, the carried-over last event ID, CR, LF, and CRLF line endings, and comment lines (heartbeats), which it reports through an optional callback. It ignoresretry, since reconnect timing is the caller's decision. Lines are capped at 64 KiB, which is far above any event the API sends, so a broken or hostile stream cannot grow the buffer without bound.pkg/cmd/event/clientwraps the API behind anEventClientinterface (with a generatedmoqmock): create, get, list (followingLinkpagination), and delete subscriptions, and open a subscription's event stream. It maps the API's responses to sentinel errors the commands can act on: an unsupported host, a missing resource or subscription, an account not enrolled in the preview, and the subscription limit.SupportedHostreports that only github.com serves the API, so commands can fail before sending a request to GitHub Enterprise Server or GHE.com.How did you test this change?
This PR has no user-facing surface on its own, so I exercised it through the commands added later in the stack. With a
ghbuilt from the complete stack, I ran the live smoke check from the evals PR against a sandbox pull request on github.com. It created a subscription, attached to its stream, and observed three review events (two change requests and an approval) as a second account submitted them, then created, viewed, listed, and deleted a separate subscription. Every request went through this client and every event through this reader.Key points
pkg/cmd/event/client, next to its commands, rather than inapi/, because the API is in preview and only these commands use it. It reusesgh's HTTP client, so authentication, host handling, and debug logging behave as elsewhere.422without field errors is treated as the subscription limit, since that is the only such response the API sends today.Notes for reviewers
Stack, bottom to top (this is 1 of 11, based on
trunk):babakks/event-client,babakks/event-listen,babakks/event-sub-list,babakks/event-sub-create,babakks/event-sub-view,babakks/event-sub-delete,babakks/event-hints,babakks/event-evals,babakks/event-listen-flush,babakks/event-listen-deleted-sub,babakks/event-check-suite.Start with
internal/eventstream/sse.go; the comments marked "Spec:" point at the rule each branch implements. Then readpkg/cmd/event/client/client.go, especially the error mapping in each method.client_mock.gois generated.Authorship and follow-up
Who wrote this:
Who answers review comments: