Skip to content

Event streaming (4/11): Add gh event subscription create - #15074

Merged
BagToad merged 1 commit into
babakks/event-sub-listfrom
babakks/event-sub-create
Nov 17, 2026
Merged

BagToad merged 1 commit into
babakks/event-sub-listfrom
babakks/event-sub-create

Conversation

@babakks

@babakks babakks commented Nov 17, 2026

Copy link
Copy Markdown
Member

Layer 4 of 11 in the stack tracked by #15070.

Description

gh event listen --resource creates a subscription and listens in one step. Some callers want to create the subscription separately, for example to start several listeners on it with gh event listen --subscription ID, or to set it up before the work that needs it.

gh event subscription create --resource PR_URL --event TYPE[,TYPE...] [--json FIELDS]

It prints the subscription ID to stdout, so it can be captured in a script. On a terminal it also tells on stderr whether the subscription was created or an existing one was reused, and when it expires. Creation is idempotent: an active subscription for the same resource and event types is returned instead of a new one. --event takes the same full type names and completion as gh event listen. A missing or inaccessible resource and the subscription limit get the same messages as in gh event listen.

How did you test this change?

Recording of gh event subscription create on babakks#17: it prints the new ID on stdout and a "Created subscription" note on stderr, the subscription then appears in gh event subscription list, the same command again reports "Reused existing subscription", and --json prints the selected fields.

04-sub-create.mp4

With a gh built from the complete stack, I ran the live smoke check from the evals PR against a sandbox pull request on github.com. Among other steps, it ran gh event subscription create with a merge conflict event type and got a sub_... ID on stdout, saw the same ID, resource URL, and event types in gh event subscription view ID --json id,resourceUrl,eventTypes, found the ID in gh event subscription list --limit 100 --json id, ran gh event subscription delete ID, and then saw gh event subscription view ID fail because the subscription was gone.

Key points

  • Only the ID goes to stdout, and the created or reused note only to a terminal's stderr, so id=$(gh event subscription create ...) works without parsing.
  • Like gh event listen, the resource URL's host selects where the request goes; the API validates the resource itself.

Notes for reviewers

Stack, bottom to top (this is 4 of 11, based on babakks/event-sub-list): 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.

The whole change is pkg/cmd/event/subscription/create/create.go and its tests.

Authorship and follow-up

Who wrote this:

  • A human wrote it.
  • An agent wrote it under close human direction.
  • An agent wrote it independently, and no human has guided the implementation beyond the initial prompt.

Who answers review comments:

  • @babakks will read and reply directly. Name the account.
  • An agent will draft replies and @username will read them before they are posted.
  • Nobody has explicitly committed to replying.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: bbce5a7f-103c-4e67-99c9-2d6dc3f6a02b
@babakks
babakks requested a review from a team as a code owner November 17, 2026 17:11
@babakks
babakks requested review from niik and a balanced review from Copilot and removed request for a team November 17, 2026 17:11
@babakks
babakks added this pull request to stack #15082 November 17, 2026 17:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The tests omit mixed stdout/stderr TTY states, leaving command-substitution output and status-note gating on stderr’s TTY state unverified.

1 open issue
What changed in this PR

Adds gh event subscription create as layer 4 of the event-streaming stack, allowing subscriptions to be created or reused separately from listening.

Changes:

  • Registers the create command with resource and event flags, event completion, and JSON output.
  • Prints the subscription ID to stdout and created/reused status with expiry to terminal stderr.
  • Adds tests for flag validation, output formats, API errors, event normalization, and host selection.
File Description
pkg/​cmd/​event/​subscription/​subscription.go Registers the create subcommand.
pkg/​cmd/​event/​subscription/​create/​create.go Implements subscription creation and output handling using shared event helpers.
pkg/​cmd/​event/​subscription/​create/​create_test.go Tests command inputs, creation results, output, errors, and resource-host selection.

Review effort: Balanced

@babakks
babakks requested review from BagToad and removed request for niik November 17, 2026 17:15
@BagToad
BagToad merged commit 42d52b4 into trunk Nov 17, 2026
19 checks passed
@BagToad
BagToad deleted the babakks/event-sub-create branch November 17, 2026 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants