Skip to content

feat(bin): gh-watch, a pull request poller for watcher hosts - #25

Open
ericboehs wants to merge 13 commits into
masterfrom
feat/gh-watch
Open

ericboehs wants to merge 13 commits into
masterfrom
feat/gh-watch

Conversation

@ericboehs

Copy link
Copy Markdown
Owner

Adds bin/gh-watch, a Ruby poller (stdlib plus gh) that reports new PR comments, reviews and state changes for watcher hosts.

  • Tokens only go to auth hosts over https, redirects aren't followed, and errors never carry the token; state is written 0600 and renamed into place.
  • since never advances after a partial read: open-PR paging, truncated connections and missing details fail the run instead.
  • Repo names of only dots are rejected, and the test API never receives the real gh token.
  • bin/h3 checks H3_TIMEOUT up front.

Tests: ruby test/gh-watch_test.rb (46 runs, 0 failures) against a fake API on loopback; bin/script-lint clean; parses on system Ruby 2.6. bin/shell-lint and bin/dotfiles-link-check fail on master already, on files this PR doesn't touch.

— 🤖 Opus 5.5, posting on behalf of @ericboehs

Polls one repo with a conditional REST request (ETag on the newest PR, so
a 304 costs nothing) and one GraphQL query only when something moved, CI
is pending, or five minutes have passed. Emits OPENED, MERGED, CLOSED,
COMMENT, REVIEW, PUSH and CI events as JSON Lines (--jsonl, state in
WATCHER_STATE_DIR, only state.json.next written) or as text (--once).

Auth comes from `gh auth token --hostname HOST` and is only sent over
https to that host's API; redirects are not followed. Any API failure
exits 2 with one "METHOD path -> status" line on stderr.
… API

A TCPServer fake of the REST and GraphQL endpoints plus a fake gh on
PATH; GH_WATCH_NOW pins the clock. An id fixture for acme/widgets pins
the event id formats. test/ is listed in .dotfiles-unmanaged since it
describes the repo rather than any machine.
- Remote-derived hosts must pass `gh auth status` and get no env tokens;
  enterprise env tokens never reach github.com. --jsonl with WATCHER_CWD
  but no WATCHER_REPO exits 2 instead of trusting the remote.
- Test hooks renamed to GHWATCH_TEST_API_BASE (loopback only) and
  GHWATCH_TEST_NOW, out of the host's GH_* passthrough.
- Events dropped by the cap set `backlog` so the next run queries even
  after a 304; runs with no PR query keep the old `since`.
- GraphQL split: a cheap heads query (50 newest open PRs, all on the
  five-minute refresh; unseen PRs keep their snapshot) and a batched
  nested query only for PRs updated since the last poll.
- Logins compare case-insensitively; CI events carry the PR author and
  are never demoted for being `me`.
- Unexpected data exits 2 with one line; nil guards in paging.
- MAX_PAGES truncation is a failure; the *.ghe.com api. fallback fires
  only on the first request with no cached base.
- Empty COMMENTED reviews that wrap inline comments are skipped; the
  issue CLOSED fixture no longer has closed_by.
- open_heads keeps paging between refreshes while hasNextPage and the
  last head's updatedAt is at or after the query window
- complete() fails when it stops at MAX_CONN with the oldest node still
  inside the window
- fetch_details fails when a batch's repository comes back nil
- owner/name (and --wake-team) reject . and .. so --repo ../.. cannot
  leave --state-dir
- with GHWATCH_TEST_API_BASE set, send GHWATCH_TEST_TOKEN or a fixed
  fake token and never ask gh for the real one

Tests cover each case against the loopback fake API; token_for's auth
rules are now tested in a subprocess with an explicit env.
A PR with more than MAX_CONN (100) comments, reviews, or review-thread
replies in the poll window raised instead of advancing `since`, so
every later poll hit the same limit and the repo never progressed.

On truncation, keep what was fetched, hold `since` at the oldest
fetched timestamp instead of letting it reach @now, set the backlog
flag so the next poll runs a full query, and warn loudly instead of
failing.

(Confirmed separately: the open-PR paging raise at full_query time is
self-healing — it only fires when refresh is false, and refresh forces
itself true at least every FULL_EVERY seconds regardless of prior
failures, so it doesn't wedge the same way.
EOF
)
- Require a non-empty UNTIL and slots >= 1 before honoring a
  ~/Library/Caches/heavy/slots override (0 slots or a missing UNTIL
  used to misbehave, e.g. BSD seq 1 0 running two slots instead of
  pausing).
- Clamp the effective slot count to at least 1 after the env and
  override are both applied.
- Accept an override file with no trailing newline (read's exit
  status after a complete EOF-terminated line was treated as a
  failure and the override was silently ignored).
- Reject an UNTIL more than 7 days out, and show "(override until X)"
  in the waiting message when an override is active.
- Validate HEAVY_SLOTS and HEAVY_MIN_IDLE are numeric on startup
  instead of looping forever with "integer expression expected".
- Cache idle() once per loop pass instead of sampling CPU twice (the
  gate check and the status line) every minute.
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.

1 participant