Skip to content

app/: GitHub's webhook (sc-8900) - #74

Closed
ndbroadbent wants to merge 28 commits into
laravel-stafffrom
laravel-webhooks
Closed

ndbroadbent wants to merge 28 commits into
laravel-stafffrom
laravel-webhooks

Conversation

@ndbroadbent

Copy link
Copy Markdown
Member

Part of sc-8900 (the forge side of the Laravel Rust port). Stacked on #70.

Ports POST /webhooks/github (the API host, outside the session and CSRF groups).

  • Signatures: X-Hub-Signature-256 is checked in constant time; an unsigned or wrongly signed delivery gets 401. Without GITHUB_WEBHOOK_SECRET the route answers 404.

  • Reading deliveries: ported as today's read_event. A fork's branch goes by its head label (octocat:main). Merges, closes, reopens, branch deletions (delete and push with deleted), installation and repository changes, member, membership, organization and team events are all read.

  • Domain events: once per linked project, through forge::events. features agreed this seam and handle the events with idempotent listeners:

    • PullRequestMerged { project_id, head, base, merge_commit }
    • BranchClosed { project_id, branch, why: "pull_request" | "branch_deleted" }
    • BranchReopened
    • RepositoryVisibilityChanged { project_id, private }

    Linked projects match by GitHub's repository ID, or by URL when the link has no ID yet. The response says {dispatched: n}.

  • Installations: attached to or detached from linked projects. A removal only applies to projects on the installation being removed. Each affected organization's GitHub-derived members are rechecked.

  • Access: member, membership and organization events recheck the people they name; team events recheck everyone in the installation's organizations. RecheckAccess (a queued job) asks the App for each person's permission on every linked repository, collaborators only as today, and applies it through auth::memberships::apply, the same path a sign-in takes. A person GitHub can't answer for is logged, and the others still update.

  • GitHub App client (forge::github_app): the JWT (GITHUB_APP_ID, GITHUB_APP_PRIVATE_KEY_BASE64), installation tokens, and collaborator permission by permanent user ID.

Not in this PR:

  • GitLab project hooks, which come with self-managed instances (sc-8634; GitLab is off until then).
  • The hourly forge sync, which comes next with its heartbeat.

Tests: app/tests/webhooks.rs covers signature refusal, merges reaching both projects (by ID and by URL), a fork's branch, a deleted branch, installation detach and attach (including another installation's removal leaving the project alone), and a collaborator change queueing a recheck. The JWT and permission calls aren't run in tests, to avoid committing a private key, even a test one; apply has its own tests. The whole app suite passes on docspring-dev, and clippy is clean.

@visualci-com

visualci-com Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

VisualCI

docspring/visualci · build #297 · 331 unchanged · no changes

This PR vs base: nothing since #261, across 2 builds

Updated as builds change. Agents can review with VisualCI's MCP tools.

ndbroadbent added a commit that referenced this pull request Dec 2, 2026
… (a pull request closed without merging, or the branch deleted) closes its builds waiting for review with today's warning; reopen_branch brings back the newest; both idempotent and fire BuildChanged; for the forge listeners once #74 lands
ndbroadbent added a commit that referenced this pull request Dec 2, 2026
… (a pull request closed without merging, or the branch deleted) closes its builds waiting for review with today's warning; reopen_branch brings back the newest; both idempotent and fire BuildChanged; for the forge listeners once #74 lands
ndbroadbent added a commit that referenced this pull request Dec 2, 2026
… (a pull request closed without merging, or the branch deleted) closes its builds waiting for review with today's warning; reopen_branch brings back the newest; both idempotent and fire BuildChanged; for the forge listeners once #74 lands
ndbroadbent added a commit that referenced this pull request Dec 2, 2026
… (a pull request closed without merging, or the branch deleted) closes its builds waiting for review with today's warning; reopen_branch brings back the newest; both idempotent and fire BuildChanged; for the forge listeners once #74 lands
ndbroadbent added a commit that referenced this pull request Dec 2, 2026
… (a pull request closed without merging, or the branch deleted) closes its builds waiting for review with today's warning; reopen_branch brings back the newest; both idempotent and fire BuildChanged; for the forge listeners once #74 lands
ndbroadbent added a commit that referenced this pull request Dec 2, 2026
… (a pull request closed without merging, or the branch deleted) closes its builds waiting for review with today's warning; reopen_branch brings back the newest; both idempotent and fire BuildChanged; for the forge listeners once #74 lands
…orted as is, the emails outbox (once per dedupe key and recipient; billing email or admins with their choices), DeliverEmails through Postmark (queued on each email, scheduled every five minutes; five attempts, then failed), a member's notice on MembershipChanged; emails table and users' email choices
…UALCI_EMAILS_HEARTBEAT_URL/TOKEN; fails when the oldest unsent email has waited over 30 minutes or delivery errored), and failed_unresolved_count for /status (emails_failed_unresolved, as today)
…claim lapses after 30 minutes, far longer than a 10-second send), so a slow run's batch is never sent twice; a crashed run's fifth attempt ends failed, never a sixth; a failed send waits five minutes for the next run; the membership notice's dedupe key is the change's time, fixed at dispatch, so a retried listener doesn't send it again
… within five minutes, constant-time), Team on checkout and active, Free on deletion, only the organization's own subscription and only newer events, packs and automatic reloads credited once per reference, billing problems shown and reloads paused; the plans; STRIPE_SECRET_KEY/STRIPE_WEBHOOK_SECRET
… for Team and for credit packs, Stripe's portal, automatic reloads, payment methods (list, add, default, remove) and invoices, admins only (a member 403, anyone else 404); the Stripe client and catalog (products, prices by lookup key, the portal configuration, the customer) on Laravel's HTTP client
…y, and a webhook event whose livemode doesn't match the key is refused; a subscription event's freshness check and its change happen in one transaction with the organization's row locked; a paid invoice no longer clears the two-subscriptions notice; payment method IDs are letters, digits and underscores only
…e (shown once, vcu_/vci_ plus 40 letters and digits, stored as SHA-256 with the first ten characters shown) and delete; project tokens by the project's admins (a member 403); a security notice when one is made
…en's id; a notice that can't be queued is logged, never losing a token that's already made
…gin (admins; 50 a day per organization, 3 a day per address, staff exempt), waiting for the invitee to accept or decline whether or not they have an account (recorded for their account when one exists); accepting never lowers a role; admins withdraw invitations, change roles and remove members, except where the forge decides the membership, and the organization keeps an admin; a removed member is told unless they left themselves
…aren't in (their tools are the admin MCP's, with its audit log); changing or removing a member locks the admin memberships first, so two admins demoting each other can't leave none; accepting re-reads the invitation FOR UPDATE (a withdrawn one or a second click is a 404) and tells the person they joined
…their organizations and roles, pending invitations, email choices, the heard-about question), email choices, an organization's billing email (admins), 'How did you hear about VisualCI?'; the team's email about each new sign-up through the outbox (reply-to the person), once answered or ten minutes after sign-up, every minute with a heartbeat (VISUALCI_SIGNUPS_HEARTBEAT) that fails when one waits over 40 minutes
…Auth application with its ID and secret), as today's; staff who aren't in an organization can't change its billing email; the sign-ups heartbeat fails when the database can't answer
…vice/code and /device/token for the CLI (device code stored hashed, ten minutes, one token once, claimed in one statement), GET/POST /api/ui/device/{code} for the person to approve or deny (codes read as typed); a security notice when the CLI signs in
…isualCI command-line sign-in' label, where and when it was asked for and 'only approve this if you just ran visualci login', with the name the CLI sent as a detail; at most ten codes per address in ten minutes (429); expired codes deleted daily (VISUALCI_DEVICE_PRUNE_HEARTBEAT); a poll within the interval gets slow_down; the code is claimed and its token made in one transaction; the client's address comes through TRUSTED_PROXIES
…ign-ups with how they heard about VisualCI, every email rendered with sample data, failed emails retried or dismissed; a 404 for anyone who isn't staff
…lugs checked (reserved words, lowercase letters, digits and dashes) and unique (409), names 1 to 100 characters, five a day except for staff (a new account's own organization doesn't count)
…ns::invite_to, orgs::create_org, tokens::make_project_token and remove_project_token, which the web routes now call too; callers check the person's role
…b-Signature-256, constant time); merges, closed and reopened pull requests (a fork's branch by its label), deleted branches and visibility changes dispatched to the domain once per linked project (by GitHub's repository ID, else URL) as forge::events; installations attach to and detach from linked projects (only from the installation being removed) and recheck their organizations' GitHub members; membership and team changes queue RecheckAccess, which asks the App for each person's permission on every linked repository and applies it as a sign-in does; the GitHub App client (JWT, installation tokens, collaborator permission)
…s collaborators once (affiliation=all; one installation token per installation for the run; the path looked up by GitHub's ID) and derives everyone's permission from that, keyed by repository ID; nothing changes unless every repository was read, and it stops when the rate limit is low; an installation is attached only after GitHub confirms it exists (a stale or redelivered 'created'); renamed and transferred repositories move their links by ID; a delivery naming a repository's ID backfills links that only had its URL; 'edited' takes the repository's own private flag; deliveries up to GitHub's 25 MB
@ndbroadbent
ndbroadbent changed the base branch from laravel-orgs to laravel-staff December 2, 2026 21:41
ndbroadbent added a commit that referenced this pull request Dec 2, 2026
… (a pull request closed without merging, or the branch deleted) closes its builds waiting for review with today's warning; reopen_branch brings back the newest; both idempotent and fire BuildChanged; for the forge listeners once #74 lands
ndbroadbent added a commit that referenced this pull request Dec 2, 2026
… (a pull request closed without merging, or the branch deleted) closes its builds waiting for review with today's warning; reopen_branch brings back the newest; both idempotent and fire BuildChanged; for the forge listeners once #74 lands (#85)
ndbroadbent added a commit that referenced this pull request Dec 2, 2026
…quest's approvals become the base branch's (record_merge), and closing or reopening a branch closes or brings back its builds waiting for review; each idempotent, with tests. forge/events.rs is subdomains' file from #74, byte for byte, so the rebase onto #74 applies cleanly
ndbroadbent added a commit that referenced this pull request Dec 2, 2026
…quest's approvals become the base branch's (record_merge), and closing or reopening a branch closes or brings back its builds waiting for review; each idempotent, with tests. forge/events.rs is subdomains' file from #74, byte for byte, so the rebase onto #74 applies cleanly (#93)
@ndbroadbent

Copy link
Copy Markdown
Member Author

Included in #87.

@ndbroadbent ndbroadbent closed this Dec 3, 2026
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