Monorepo for Tangled tangled.org

appview:{db,models}: webhook tables and crud ops #1066

merged opened by anirudh.fi targeting master from icy/qlyxxp
Labels

None yet.

assignee

None yet.

Participants 2
AT URI
at://did:plc:hwevmowznbiukdf6uk5dwrrq/sh.tangled.repo.pull/3menyebs7l722
+44 -2
Interdiff #1 #2
-1
appview/db/db.go
··· 608 608 create index if not exists idx_references_to_at on reference_links(to_at); 609 609 create index if not exists idx_webhooks_repo_at on webhooks(repo_at); 610 610 create index if not exists idx_webhook_deliveries_webhook_id on webhook_deliveries(webhook_id); 611 - create index if not exists idx_webhook_deliveries_created_at on webhook_deliveries(created_at desc); 612 611 `) 613 612 if err != nil { 614 613 return nil, err
appview/db/webhooks.go

This file has not been changed.

+44 -1
appview/models/webhook.go
··· 1 1 package models 2 2 3 3 import ( 4 + "slices" 4 5 "time" 5 6 6 7 "github.com/bluesky-social/indigo/atproto/syntax" 7 8 ) 8 9 10 + type WebhookEvent string 11 + 12 + const ( 13 + WebhookEventPush WebhookEvent = "push" 14 + ) 15 + 9 16 type Webhook struct { 10 17 Id int64 11 18 RepoAt syntax.ATURI 12 19 Url string 13 20 Secret string 14 21 Active bool 15 - Events []string // e.g., ["push", "pull_request", "issues"] 22 + Events []string // comma-separated event types 16 23 CreatedAt time.Time 17 24 UpdatedAt time.Time 18 25 } 19 26 27 + // HasEvent checks if the webhook is subscribed to a specific event 28 + func (w *Webhook) HasEvent(event WebhookEvent) bool { 29 + return slices.Contains(w.Events, string(event)) 30 + } 31 + 20 32 type WebhookDelivery struct { 21 33 Id int64 22 34 WebhookId int64 ··· 29 41 Success bool 30 42 CreatedAt time.Time 31 43 } 44 + 45 + // WebhookPayload represents the webhook payload structure 46 + type WebhookPayload struct { 47 + Ref string `json:"ref"` 48 + Before string `json:"before"` 49 + After string `json:"after"` 50 + Repository WebhookRepository `json:"repository"` 51 + Pusher WebhookUser `json:"pusher"` 52 + } 53 + 54 + // WebhookRepository represents repository information in webhook payload 55 + type WebhookRepository struct { 56 + Name string `json:"name"` 57 + FullName string `json:"full_name"` 58 + Description string `json:"description"` 59 + Fork bool `json:"fork"` 60 + HtmlUrl string `json:"html_url"` 61 + CloneUrl string `json:"clone_url"` 62 + SshUrl string `json:"ssh_url"` 63 + Website string `json:"website,omitempty"` 64 + StarsCount int `json:"stars_count,omitempty"` 65 + OpenIssues int `json:"open_issues_count,omitempty"` 66 + CreatedAt string `json:"created_at"` 67 + UpdatedAt string `json:"updated_at"` 68 + Owner WebhookUser `json:"owner"` 69 + } 70 + 71 + // WebhookUser represents user information in webhook payload 72 + type WebhookUser struct { 73 + Did string `json:"did"` 74 + }

History

6 rounds 5 comments
sign up or login to add to the discussion
1 commit
expand
appview/{db,models}: webhook tables and crud ops
3/3 success
expand
expand 0 comments
pull request successfully merged
1 commit
expand
appview/{db,models}: webhook tables and crud ops
3/3 success
expand
expand 0 comments
1 commit
expand
appview/{db,models}: webhook tables and crud ops
3/3 success
expand
expand 3 comments

the db code needs to be updated accordingly to handle null strings, by reading into a sql.Null[string] and checking for s.Valid.

Oh, right...

1 commit
expand
appview/{db,models}: webhook tables and crud ops
3/3 success
expand
expand 1 comment
  • here: we should make the secret nullable in the db, since we no longer sign if secret is not supplied
1 commit
expand
appview:{db,models}: webhook tables and crud ops
3/3 success
expand
expand 1 comment
  • we dont need this index
  • would be nice to make [this] more strongly typed, we could have an enum for this, like type WebhookEvent string with more concrete variants
1 commit
expand
appview:{db,models}: webhook tables and crud ops
3/3 success
expand
expand 0 comments