Signed-off-by: Anirudh Oppiliappan anirudh@tangled.org
appview/db/db.go
appview/db/db.go
This file has not been changed.
+17
-3
appview/db/webhooks.go
+17
-3
appview/db/webhooks.go
···
50
50
for rows.Next() {
51
51
var wh models.Webhook
52
52
var createdAt, updatedAt, eventsStr string
53
+
var secret sql.NullString
53
54
var active int
54
55
55
56
err := rows.Scan(
56
57
&wh.Id,
57
58
&wh.RepoAt,
58
59
&wh.Url,
59
-
&wh.Secret,
60
+
&secret,
60
61
&active,
61
62
&eventsStr,
62
63
&createdAt,
···
66
67
return nil, fmt.Errorf("failed to scan webhook: %w", err)
67
68
}
68
69
70
+
if secret.Valid {
71
+
wh.Secret = secret.String
72
+
}
69
73
wh.Active = active == 1
70
74
if eventsStr != "" {
71
75
wh.Events = strings.Split(eventsStr, ",")
···
114
118
active = 1
115
119
}
116
120
121
+
secret := sql.NullString{
122
+
String: webhook.Secret,
123
+
Valid: webhook.Secret != "",
124
+
}
125
+
117
126
result, err := e.Exec(`
118
127
insert into webhooks (repo_at, url, secret, active, events)
119
128
values (?, ?, ?, ?, ?)
120
-
`, webhook.RepoAt.String(), webhook.Url, webhook.Secret, active, eventsStr)
129
+
`, webhook.RepoAt.String(), webhook.Url, secret, active, eventsStr)
121
130
122
131
if err != nil {
123
132
return fmt.Errorf("failed to insert webhook: %w", err)
···
140
149
active = 1
141
150
}
142
151
152
+
secret := sql.NullString{
153
+
String: webhook.Secret,
154
+
Valid: webhook.Secret != "",
155
+
}
156
+
143
157
_, err := e.Exec(`
144
158
update webhooks
145
159
set url = ?, secret = ?, active = ?, events = ?, updated_at = strftime('%Y-%m-%dT%H:%M:%SZ', 'now')
146
160
where id = ?
147
-
`, webhook.Url, webhook.Secret, active, eventsStr, webhook.Id)
161
+
`, webhook.Url, secret, active, eventsStr, webhook.Id)
148
162
149
163
if err != nil {
150
164
return fmt.Errorf("failed to update webhook: %w", err)
appview/models/webhook.go
appview/models/webhook.go
This file has not been changed.
History
6 rounds
5 comments
anirudh.fi
submitted
#5
1 commit
expand
collapse
appview/{db,models}: webhook tables and crud ops
Signed-off-by: Anirudh Oppiliappan <anirudh@tangled.org>
3/3 success
expand
collapse
expand 0 comments
pull request successfully merged
anirudh.fi
submitted
#4
1 commit
expand
collapse
appview/{db,models}: webhook tables and crud ops
Signed-off-by: Anirudh Oppiliappan <anirudh@tangled.org>
3/3 success
expand
collapse
expand 0 comments
anirudh.fi
submitted
#3
1 commit
expand
collapse
appview/{db,models}: webhook tables and crud ops
Signed-off-by: Anirudh Oppiliappan <anirudh@tangled.org>
3/3 success
expand
collapse
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...
anirudh.fi
submitted
#2
1 commit
expand
collapse
appview/{db,models}: webhook tables and crud ops
Signed-off-by: Anirudh Oppiliappan <anirudh@tangled.org>
3/3 success
expand
collapse
anirudh.fi
submitted
#1
1 commit
expand
collapse
appview:{db,models}: webhook tables and crud ops
Signed-off-by: Anirudh Oppiliappan <anirudh@tangled.org>
3/3 success
expand
collapse
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 stringwith more concrete variants
anirudh.fi
submitted
#0
1 commit
expand
collapse
appview:{db,models}: webhook tables and crud ops
Signed-off-by: Anirudh Oppiliappan <anirudh@tangled.org>
@oppi.li, done.