Skip to main content
Post

Wait for pull request events with GitHub CLI

GitHub CLI 2.105.0 adds a preview of gh event, which lets you or an agent wait for a pull request to change instead of polling it in a loop.

Run gh event listen with a pull request URL and the event you want, such as a submitted review. It creates the subscription, opens the stream, and prints each event as a line of JSON. By default it exits after the first event, so it fits into scripts and agent loops. --count waits for several events, --follow keeps listening, and --timeout stops the wait. --jq or --template pulls out just the fields you need. For example, you can wait on a check suite finishing and print only .data.conclusion.

It can listen for submitted reviews, pull request state and head changes, merge conflicts, and completed check suites. Each event includes a data.api_url pointing to the resource that changed. If you'd rather manage subscriptions yourself, gh event subscription has create, list, view, and delete.

The CLI also nudges agents toward it. gh pr create, gh pr view, gh run view, gh run watch, and gh api now suggest gh event listen over polling.

The commands are in preview and may change. They need access to GitHub Event Streams, which is also in preview on GitHub.com and has a waitlist. You'll need GitHub CLI v2.105.0 or later.

Loading replies