Skip to content

refactor(githubevents): generic dispatch helper - #281

Merged
cbrgm merged 6 commits into
mainfrom
phase-3-generic-dispatch
Aug 12, 2026
Merged

refactor(githubevents): generic dispatch helper#281
cbrgm merged 6 commits into
mainfrom
phase-3-generic-dispatch

Conversation

@cbrgm

@cbrgm cbrgm commented Aug 12, 2026

Copy link
Copy Markdown
Owner

What

Collapse the ~500 copy-pasted concurrency loops into one hand-written generic helper.

  • new githubevents/dispatch.go with dispatch[T], the single implementation of the errgroup + panic-recovery + first-error-wins loop
  • generated handle* methods now call dispatch(...) instead of repeating ~27 lines each
  • characterization tests (githubevents/dispatch_test.go) lock the behavior through the public API before the refactor

Net: +722 / -5579 lines. Stacked on #280.

Why

The same errgroup/recover block was generated hundreds of times. One generic helper is far easier to reason about and test, and it only touches unexported internals so the public API is unchanged.

Behavior is preserved exactly, and i was deliberate about it: same errgroup first-error-wins semantics (not errors.Join, so if two callbacks fail only the first surfaces, like before), the exact "recovered from panic: %v" message, and all the guard / wrong-action errors verbatim. The characterization tests (panic recovery, fan-out count, error propagation, empty-action rejection, the Any path) were written to pass on the old code first, then kept passing after the refactor.

Testing

  • go test ./githubevents/ -run TestDispatch -v -> 5/5, unchanged before and after the refactor
  • make test green (incl. the 100+ generated per-event test files), make apidiff -> API compatible
  • grep -rl errgroup githubevents/ -> only dispatch.go + events.go (the bespoke handleError), no events_*.go

Checklist

  • Tests added/updated (dispatch_test.go characterization suite)
  • No breaking changes (unexported internals only, apidiff compatible)
  • Readable commit history (tests first, then the helper)
  • AI code review considered and comments resolved

cbrgm added 2 commits August 12, 2026 14:49
replace exec-based gofmt call in gen/format.go with go/format,
so the generator formats in-process instead of shelling out.
make format and make generate now run gofumpt -extra over
gen and githubevents, matching what golangci-lint expects.
repo was already gofumpt v0.7.0 clean, so no output diff.
@cbrgm
cbrgm force-pushed the phase-2-modern-go branch from 2c3a05e to b40c7ea Compare August 12, 2026 12:49
@cbrgm
cbrgm force-pushed the phase-3-generic-dispatch branch from 6aa9a45 to 8c76fbe Compare August 12, 2026 12:51
Base automatically changed from phase-2-modern-go to main August 12, 2026 12:51
@cbrgm
cbrgm enabled auto-merge (squash) August 12, 2026 12:52
@cbrgm
cbrgm merged commit 9522619 into main Aug 12, 2026
4 checks passed
@cbrgm
cbrgm deleted the phase-3-generic-dispatch branch August 12, 2026 12:52
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