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
+17 -3
Interdiff #3 #4
appview/db/db.go

This file has not been changed.

+17 -3
appview/db/webhooks.go
··· 50 for rows.Next() { 51 var wh models.Webhook 52 var createdAt, updatedAt, eventsStr string 53 var active int 54 55 err := rows.Scan( 56 &wh.Id, 57 &wh.RepoAt, 58 &wh.Url, 59 - &wh.Secret, 60 &active, 61 &eventsStr, 62 &createdAt, ··· 66 return nil, fmt.Errorf("failed to scan webhook: %w", err) 67 } 68 69 wh.Active = active == 1 70 if eventsStr != "" { 71 wh.Events = strings.Split(eventsStr, ",") ··· 114 active = 1 115 } 116 117 result, err := e.Exec(` 118 insert into webhooks (repo_at, url, secret, active, events) 119 values (?, ?, ?, ?, ?) 120 - `, webhook.RepoAt.String(), webhook.Url, webhook.Secret, active, eventsStr) 121 122 if err != nil { 123 return fmt.Errorf("failed to insert webhook: %w", err) ··· 140 active = 1 141 } 142 143 _, err := e.Exec(` 144 update webhooks 145 set url = ?, secret = ?, active = ?, events = ?, updated_at = strftime('%Y-%m-%dT%H:%M:%SZ', 'now') 146 where id = ? 147 - `, webhook.Url, webhook.Secret, active, eventsStr, webhook.Id) 148 149 if err != nil { 150 return fmt.Errorf("failed to update webhook: %w", err)
··· 50 for rows.Next() { 51 var wh models.Webhook 52 var createdAt, updatedAt, eventsStr string 53 + var secret sql.NullString 54 var active int 55 56 err := rows.Scan( 57 &wh.Id, 58 &wh.RepoAt, 59 &wh.Url, 60 + &secret, 61 &active, 62 &eventsStr, 63 &createdAt, ··· 67 return nil, fmt.Errorf("failed to scan webhook: %w", err) 68 } 69 70 + if secret.Valid { 71 + wh.Secret = secret.String 72 + } 73 wh.Active = active == 1 74 if eventsStr != "" { 75 wh.Events = strings.Split(eventsStr, ",") ··· 118 active = 1 119 } 120 121 + secret := sql.NullString{ 122 + String: webhook.Secret, 123 + Valid: webhook.Secret != "", 124 + } 125 + 126 result, err := e.Exec(` 127 insert into webhooks (repo_at, url, secret, active, events) 128 values (?, ?, ?, ?, ?) 129 + `, webhook.RepoAt.String(), webhook.Url, secret, active, eventsStr) 130 131 if err != nil { 132 return fmt.Errorf("failed to insert webhook: %w", err) ··· 149 active = 1 150 } 151 152 + secret := sql.NullString{ 153 + String: webhook.Secret, 154 + Valid: webhook.Secret != "", 155 + } 156 + 157 _, err := e.Exec(` 158 update webhooks 159 set url = ?, secret = ?, active = ?, events = ?, updated_at = strftime('%Y-%m-%dT%H:%M:%SZ', 'now') 160 where id = ? 161 + `, webhook.Url, secret, active, eventsStr, webhook.Id) 162 163 if err != nil { 164 return fmt.Errorf("failed to update webhook: %w", err)
appview/models/webhook.go

This file has not been changed.

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