Webhook endpoint at /api/webhooks/gitea receives Gitea status events,
matches them against configurable event triggers with conditions
(event type, repo glob, state, context), renders task templates with
{{variable}} substitution, and creates harness tasks automatically.
Includes circuit breaker: after N consecutive task failures from the
same trigger (default 3), the trigger auto-disables. Re-enable
manually via PATCH /api/event-triggers/:id.
New tables: harness_event_triggers (rules + circuit breaker state),
harness_event_log (audit trail + dedup via X-Gitea-Delivery).
43 lines
1.4 KiB
SQL
43 lines
1.4 KiB
SQL
CREATE TABLE IF NOT EXISTS "harness_event_log" (
|
|
"id" serial PRIMARY KEY NOT NULL,
|
|
"trigger_id" text NOT NULL,
|
|
"delivery_id" text NOT NULL,
|
|
"event_type" text NOT NULL,
|
|
"repo" text NOT NULL,
|
|
"commit_sha" text,
|
|
"branch" text,
|
|
"status" text DEFAULT 'received' NOT NULL,
|
|
"task_id" text,
|
|
"skip_reason" text,
|
|
"error" text,
|
|
"payload" jsonb NOT NULL,
|
|
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
CONSTRAINT "harness_event_log_delivery_id_unique" UNIQUE("delivery_id")
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE IF NOT EXISTS "harness_event_triggers" (
|
|
"id" text PRIMARY KEY NOT NULL,
|
|
"name" text NOT NULL,
|
|
"enabled" boolean DEFAULT true NOT NULL,
|
|
"event_type" text NOT NULL,
|
|
"repo_filter" text,
|
|
"state_filter" text,
|
|
"context_filter" text,
|
|
"task_template" jsonb NOT NULL,
|
|
"consecutive_failures" integer DEFAULT 0 NOT NULL,
|
|
"max_consecutive_failures" integer DEFAULT 3 NOT NULL,
|
|
"disabled_reason" text,
|
|
"webhook_secret" text,
|
|
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
"updated_at" timestamp DEFAULT now() NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE IF NOT EXISTS "harness_orchestrator" (
|
|
"id" text PRIMARY KEY DEFAULT 'singleton' NOT NULL,
|
|
"running" boolean DEFAULT false NOT NULL,
|
|
"current_task_id" text,
|
|
"heartbeat" bigint,
|
|
"updated_at" timestamp DEFAULT now() NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
ALTER TABLE "harness_tasks" ADD COLUMN "cancel_requested" boolean DEFAULT false NOT NULL; |