feat(desktop,trpc): trigger editor

Merged
SA
3mo ago
+8668-320

Event triggers become reachable. The automation page now edits the whole trigger set rather than just a schedule, so a GitHub trigger can be created without hand-writing an API call.

No migration.

The sentence grammar is data

Each event names its own words and its own slots, because the filters genuinely differ:

Draft opened in [repos] by [anyone]
[Any comment] by [anyone] on a PR by [anyone] in [repos]
Push to [branches] in [repos] by [anyone]
Workflow failed in [repos]

A comment carries two independent people — who wrote it, and who opened the thing it's on — where a push carries neither. Keeping that as a table means the row renders one way and every event describes itself, rather than a growing pile of conditionals per event.

"Any" is a menu entry, not the empty state

An empty scope matches nothing, by design — that's what stops a half-built trigger firing on every repository. So the UI can't treat blank as "everything": choosing Any repo is its own deliberate act, and an unset chip is visibly marked as blocking Save.

Validation is the server's

describeTriggerProblems and summarizeTriggerProblems come from @superset/shared — the same functions the API rejects with. The form blocks Save on exactly what the server would refuse, instead of restating the rules and drifting.

Repositories keyed by id

The picker stores GitHub's numeric repoId, which is what the matcher compares against. A full name would stop matching the moment someone renames the repository.

What making types honest surfaced

automation.get now returns the trigger set with ids, so a save updates rows in place rather than replacing them — which would roll a webhook's key and reset a schedule's next run.

More usefully: the schedule projection was still typed sql<string> after the join became a left join. Making it honestly nullable surfaced eight places that assumed every automation has a schedule —

  • the list's schedule column and the row label
  • the next-run preview and its timezone tooltip
  • setEnabled's resume recompute
  • update's recurrence recompute and its trigger sync
  • setPrompt's response

Each would have crashed or displayed a schedule that doesn't exist, for exactly the automations this feature creates. Same class as the dtstart-as-string bug earlier: a type assertion the compiler kept believing.

Not in this PR

  • People pickers are empty. "Specific People" needs a member list, and me needs GitHub identities linked to users — it currently matches nobody rather than misfiring. Both are backlog A2/A3.
  • Branch and label pickers are free of options — they accept "any" but have nothing to enumerate until we sync branches and labels.
  • Slack, Sentry and Linear aren't in the Add Trigger menu yet; their schemas exist but nothing ingests them into automation_events.

Typecheck, lint and the full suite pass. Not yet verified against a running app — worth a CDP pass before merge.


Summary by cubic

Replaces the schedule-only autosave with a sentence-based trigger editor and explicit Save/Discard. Draft triggers no longer disappear; validation runs on Save and a successful save toasts while failures keep edits.

  • Adds a sentence-chip TriggersEditor with provider icons and searchable Add Trigger; shows per‑trigger “Next run …” inline and formats it in the schedule’s timezone with a read‑only abbreviation; removes the TimezonePicker. Aligns the scope line to chip styling. Populates people from integration.github.listLinkedPeople; repositories are keyed by GitHub numeric ids. Branch and label filters default to Any and clear back to Any. Renames “Version history” to “Prompt history.”

  • automation.get returns ordered triggers (id, kind, config, enabled, nextRunAt) and derives the soonest schedule (rrule, dtstart, timezone, nextRunAt) plus scheduleText (“Event triggered” when none). Allows multiple schedule triggers per automation; resuming recomputes each schedule’s nextRunAt. Legacy syncScheduleTrigger updates the oldest schedule and deletes extras. Adds integration.github.listLinkedPeople. Migration: drop the unique schedule index and add non‑unique automation_triggers_schedule_idx; no backfill.

Summary by CodeRabbit

  • New Features
    • Added a sentence-based trigger editor for automation setup and editing.
    • Added configurable GitHub event triggers with repository, branch, label, actor, author, and comment filters.
    • Added support for multiple schedules per automation.
    • Added linked-person selection for GitHub trigger filters.
    • Added next-run details for scheduled triggers.
  • Bug Fixes
    • Event-triggered automations now display correctly without schedule information.
    • Improved timezone handling, including UTC fallback.
    • Invalid schedules no longer produce incorrect next-run details.