Skip to content

refactor(ctrl): migrate GitHub webhook onto pkg/webhook receiver#6427

Open
Flo4604 wants to merge 1 commit into
eng-2865-implement-control-plane-invoice-closing-webhookfrom
github-webhook-receiver
Open

refactor(ctrl): migrate GitHub webhook onto pkg/webhook receiver#6427
Flo4604 wants to merge 1 commit into
eng-2865-implement-control-plane-invoice-closing-webhookfrom
github-webhook-receiver

Conversation

@Flo4604

@Flo4604 Flo4604 commented Jun 11, 2026

Copy link
Copy Markdown
Member

Migrates ctrl-api's GitHub webhook from a hand-rolled http.Handler onto the
pkg/webhook receiver, making it the second consumer after Stripe.

  • Transport chores (method policing, body-size cap, HMAC verification,
    routing, metrics, retry semantics) move to pkg/webhook +
    verifiers/github; the handler file shrinks to business logic only.
  • push / pull_request keep their exact dispatch behavior: same payload
    parsing, same Restate ingress Send with the delivery id as idempotency
    key (now sourced from event.ID via X-GitHub-Delivery).
  • Deliberate skips (branch delete pushes, non-branch refs, same-repo PRs,
    uninteresting actions) now return webhook.ErrIgnore with a reason, so
    they 200 and surface as outcome=ignored in
    unkey_webhook_events_total{provider="github"} instead of being invisible.
  • create/delete/installation use the variadic On registration; everything
    else falls through to a Default handler that ignores with a logged
    reason, replacing the old "Unhandled event type" log line.
  • GitHub webhooks get transport metrics for the first time.

Behavior changes, both edge cases: malformed payloads on verified requests
now return 500 instead of 400 (GitHub does not auto-retry either way), and
unknown event types are logged through the receiver's ignored path rather
than a bespoke log line.

Verified: bazel test //svc/ctrl/api/... //pkg/webhook/... (the existing
webhook integration tests pass unchanged: push dispatch, fork PRs, deleted
branches, created branches, invalid signature 401).

@vercel

vercel Bot commented Jun 11, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
dashboard Ready Ready Preview, Comment Jun 19, 2026 9:22am
design Ready Ready Preview, Comment Jun 19, 2026 9:22am

Request Review

@Flo4604

Flo4604 commented Jun 11, 2026

Copy link
Copy Markdown
Member Author

This stack of pull requests is managed by jj-ryu.

@pullfrog pullfrog Bot 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.

✅ No new issues found.

Reviewed changes — since the prior pullfrog review at 2a02720, the source went through several byte-identical rebases (f1022af3f30dde8f4c46e); the only real deltas at the current head c9762cd are a webhook-registration argument-order flip and a test header addition.

  • On registration flipped to events-firstNewGitHubWebhook now calls On([]string{"push"}, webhook.Typed(s.handlePush)) (and likewise for pull_request and the lifecycle events) instead of the handler-first form. This matches the framework's actual signature On(eventTypes []string, fn HandlerFunc) and directly adopts the suggestion chronark raised on github_webhook.go:33.
  • Idempotency-key path now exercised in testssendWebhook sets X-GitHub-Delivery: delivery-test, so the integration tests now drive the deliveryID := event.ID branch that attaches WithIdempotencyKey to the Restate Send.

I confirmed run.go and BUILD.bazel are byte-for-byte identical to the last reviewed source, so the only behavior-relevant change is the registration flip, which I verified compiles correctly against pkg/webhook/receiver.go's On(eventTypes []string, fn HandlerFunc). The new delivery header strengthens coverage of the idempotency-key path; it is set but not asserted, which is fine — DeliveryId propagation isn't the subject of these tests.

The two documented behavior changes from the original review are unchanged, and chronark's open thread on argument order is now satisfied by the code (left for chronark to resolve). The separate "why not return a proper 400 on malformed payloads" question remains an author decision and is untouched by these commits.

Pullfrog  | View workflow run | Using Claude Opus𝕏

Comment on lines +33 to +40
On([]string{"push"}, webhook.Typed(s.handlePush)).
On([]string{"pull_request"}, webhook.Typed(s.handlePullRequest)).
// Branch lifecycle events carry no code to deploy; the first push of a
// new branch arrives as its own push event (created: true), which is
// what triggers preview deployments.
On([]string{"create", "delete", "installation"}, ignoreEvent).
// GitHub Apps receive every subscribed event type; anything without a
// handler is deliberately not deployment-relevant.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

clean af

@Flo4604 Flo4604 force-pushed the eng-2865-implement-control-plane-invoice-closing-webhook branch from 1fa2934 to bc0dadd Compare June 16, 2026 10:37
@Flo4604 Flo4604 force-pushed the github-webhook-receiver branch from aed0efd to c867d13 Compare June 16, 2026 10:37
@Flo4604 Flo4604 force-pushed the eng-2865-implement-control-plane-invoice-closing-webhook branch from bc0dadd to 370526b Compare June 16, 2026 13:28
@Flo4604 Flo4604 force-pushed the github-webhook-receiver branch from c867d13 to a04a0ba Compare June 16, 2026 13:28
@Flo4604 Flo4604 force-pushed the eng-2865-implement-control-plane-invoice-closing-webhook branch from 370526b to 8ade5dd Compare June 16, 2026 15:12
@Flo4604 Flo4604 force-pushed the github-webhook-receiver branch from a04a0ba to 1e4a713 Compare June 16, 2026 15:12
@Flo4604 Flo4604 force-pushed the eng-2865-implement-control-plane-invoice-closing-webhook branch from 8ade5dd to 7c6c4a2 Compare June 16, 2026 16:23
@Flo4604 Flo4604 force-pushed the github-webhook-receiver branch from 1e4a713 to 97856f9 Compare June 16, 2026 16:23
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