refactor(desktop,shared,db): make trigger providers additive

Merged
SA
3mo ago
+688-473

Why

Adding a trigger provider meant editing six files GitHub had shaped: the sentence grammar, the menu table, the slot renderer, the card's option fetching, the matcher, and the dispatcher. Two agents adding Slack and Linear in parallel would collide on every one of them. This PR makes a provider one module plus registry lines, so those can proceed in parallel.

Zero behaviour change is the bar. Nothing user-visible should differ.

What

Desktop — providers/<name>/ owns a provider's config kind, icon, Add Trigger subtree, config factory and sentence renderer. Three things iterate TRIGGER_PROVIDERS instead of naming providers:

  • TriggerMenuItems renders the menu (single-leaf providers become the leaf; multi-leaf become a submenu)
  • flattenTriggerMenu builds the search index — same registry, so menu and search can't drift
  • TriggerSentence hands the row's state (set, mark, options, disabled) to whichever provider owns the config

Pickable values move to per-provider hooks composed by useProviderOptions; the card no longer knows what a repository is.

Shared — automation-matching splits the same way: shared primitives in core.ts, GitHub's matcher in github.ts, and triggerMatches(config, event, ctx) dispatching on config.kind. A kind with no matcher does not match — an event for a provider that can't yet evaluate it must not fire by default.

DB — doing this exposed that packages/db's hand-written TriggerConfig had drifted from the zod schema that validates every write (events: string[] vs event: string; an "org_members" actor the schema never had). The only thing keeping it from a runtime mismatch was an as never at the read site. DB types are now derived from the schema and that cast is gone.

To add a provider

  1. providers/<name>/ implementing TriggerProvider
  2. append to TRIGGER_PROVIDERS
  3. a case in triggerMatches
  4. if it has pickable values, its hook in useProviderOptions

Verified in the running app

  • menu lists the same 3 providers with icons; GitHub submenu has the same 11 entries
  • search still flattens to GitHub › PR review submitted › Approved
  • a comment trigger renders, configures and saves — Triggers saved, zero console errors
  • schedule row shows one clock (provider-supplied) not two
  • typecheck and lint pass with real exit codes

One intentional visual: the schedule row's clock now comes from the provider like every other row's icon, rather than ScheduleSentence drawing its own. Same pixel, one source.


Summary by cubic

Refactors triggers so providers are additive and registry-driven. Behavior is unchanged; an unknown persisted GitHub event that previously crashed the editor now renders as its raw name.

  • Desktop: providers/<name>/ owns a provider’s kind, icon, Add Trigger subtree, config factory, and sentence renderer. TriggerMenuItems, flattenTriggerMenu, and TriggerSentence iterate TRIGGER_PROVIDERS. Pickable values move to per-provider hooks composed by useProviderOptions, so TriggersCard no longer fetches repos/people directly. The schedule row’s clock icon now comes from the provider (same visual). Unknown GitHub events render as text to avoid an editor crash.
  • Shared/API: @superset/shared/automation-matching splits into core.ts (shared primitives) and provider modules; triggerMatches dispatches on config.kind. The GitHub webhook route uses triggerMatches with provider context. A kind with no matcher does not match.
  • DB: TriggerConfig and related types derive from the zod schema in @superset/shared, removing drift and unsafe casts.

Migration

  • Add a provider by implementing providers/<name>/ as a TriggerProvider, appending it to TRIGGER_PROVIDERS, adding its case to triggerMatches, and registering its options hook in useProviderOptions if needed. No data or user migration is required.

Summary by CodeRabbit

  • New Features
    • Added a unified automation trigger editor for schedule, GitHub, and webhook triggers.
    • Added provider-based trigger menus with icons, grouped options, and sentence-style configuration.
    • Added GitHub repository, branch, label, actor, and comment filters.
    • Added schedule defaults, timezone handling, and next-run information.
  • Bug Fixes
    • Improved trigger matching for scopes, actors, and text filters.
    • Invalid regular expressions now safely produce no match.
  • Style
    • Removed the unused clock icon from schedule controls.