kitgit

tirbofish/kitgit · commit

a0dfd688a14714472114234724f685bd104b115d

feat: add repository webhooks with delivery status

Verified

Thribhu K <4tkbytes@pm.me> · 2026-07-28 15:12

view full diff

diff --git a/migrations/014_webhooks.sql b/migrations/014_webhooks.sql
new file mode 100644
index 0000000..880aed9
--- /dev/null
+++ b/migrations/014_webhooks.sql
@@ -0,0 +1,27 @@
+-- Repository webhooks + delivery log
+
+CREATE TABLE webhooks (
+    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
+    repo_id UUID NOT NULL REFERENCES repositories(id) ON DELETE CASCADE,
+    url TEXT NOT NULL,
+    secret TEXT NOT NULL DEFAULT '',
+    events TEXT[] NOT NULL DEFAULT '{}',
+    active BOOLEAN NOT NULL DEFAULT TRUE,
+    created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
+    CONSTRAINT webhooks_url_http CHECK (url ~* '^https?://')
+);
+CREATE INDEX webhooks_repo_id_idx ON webhooks(repo_id);
+
+CREATE TABLE webhook_deliveries (
+    id BIGSERIAL PRIMARY KEY,
+    webhook_id UUID NOT NULL REFERENCES webhooks(id) ON DELETE CASCADE,
+    event TEXT NOT NULL,
+    action TEXT NOT NULL DEFAULT '',
+    success BOOLEAN NOT NULL DEFAULT FALSE,
+    status_code INT,
+    error TEXT,
+    duration_ms INT,
+    created_at TIMESTAMPTZ NOT NULL DEFAULT now()
+);
+CREATE INDEX webhook_deliveries_webhook_id_idx ON webhook_deliveries(webhook_id);
+CREATE INDEX webhook_deliveries_created_at_idx ON webhook_deliveries(created_at DESC);
\ No newline at end of file
diff --git a/src/db/models.rs b/src/db/models.rs
index 874e00c..e790600 100644
--- a/src/db/models.rs
+++ b/src/db/models.rs
@@ -234,6 +234,30 @@ pub struct CommitDay {
     pub count: i32,
 }
 
+#[derive(Debug, Clone, FromRow, Serialize)]
+pub struct Webhook {
+    pub id: Uuid,
+    pub repo_id: Uuid,
+    pub url: String,
+    pub secret: String,
+    pub events: Vec<String>,
+    pub active: bool,

Large diffs are not rendered by default. Showing the first 50 of 979 lines. Show full diff