Monorepo for Tangled tangled.org

appview/repo: add webhook management endpoints #1069

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/3menyebs7uu22
+7 -20
Interdiff #1 #2
appview/repo/router.go

This file has not been changed.

appview/repo/settings.go

This file has not been changed.

+7 -20
appview/repo/webhooks.go
··· 1 1 package repo 2 2 3 3 import ( 4 - "crypto/rand" 5 - "encoding/hex" 6 4 "net/http" 7 5 "strconv" 8 6 "strings" ··· 57 55 return 58 56 } 59 57 60 - // Validate URL 61 58 if !strings.HasPrefix(url, "http://") && !strings.HasPrefix(url, "https://") { 62 59 rp.pages.Notice(w, "webhooks-error", "Webhook URL must start with http:// or https://") 63 60 return 64 61 } 65 62 66 63 secret := strings.TrimSpace(r.FormValue("secret")) 67 - if secret == "" { 68 - // Generate a random secret if not provided 69 - secretBytes := make([]byte, 32) 70 - if _, err := rand.Read(secretBytes); err != nil { 71 - l.Error("failed to generate secret", "err", err) 72 - rp.pages.Notice(w, "webhooks-error", "Failed to generate secret") 73 - return 74 - } 75 - secret = hex.EncodeToString(secretBytes) 76 - } 64 + // if secret is empty, we don't sign 77 65 78 66 active := r.FormValue("active") == "on" 79 67 80 - // Parse events - only push events are supported for now 81 68 events := []string{} 82 69 if r.FormValue("event_push") == "on" { 83 - events = append(events, "push") 70 + events = append(events, string(models.WebhookEventPush)) 84 71 } 85 72 86 73 if len(events) == 0 { ··· 116 103 return 117 104 } 118 105 119 - rp.pages.HxLocation(w, "/"+f.Did+"/"+f.Name+"/settings?tab=hooks") 106 + rp.pages.HxRefresh(w) 120 107 } 121 108 122 109 // UpdateWebhook updates an existing webhook ··· 171 158 // Parse events - only push events are supported for now 172 159 events := []string{} 173 160 if r.FormValue("event_push") == "on" { 174 - events = append(events, "push") 161 + events = append(events, string(models.WebhookEventPush)) 175 162 } 176 163 177 164 if len(events) > 0 { ··· 198 185 return 199 186 } 200 187 201 - rp.pages.Notice(w, "webhooks-success", "Webhook updated successfully") 188 + rp.pages.HxRefresh(w) 202 189 } 203 190 204 191 // DeleteWebhook deletes a webhook ··· 254 241 return 255 242 } 256 243 257 - rp.pages.HxLocation(w, "/"+f.Did+"/"+f.Name+"/settings?tab=hooks") 244 + rp.pages.HxRefresh(w) 258 245 } 259 246 260 247 // ToggleWebhook toggles the active state of a webhook ··· 313 300 return 314 301 } 315 302 316 - rp.pages.HxLocation(w, "/"+f.Did+"/"+f.Name+"/settings?tab=hooks") 303 + rp.pages.HxRefresh(w) 317 304 }

History

6 rounds 1 comment
sign up or login to add to the discussion
1 commit
expand
appview/repo: add webhook management endpoints
2/3 failed, 1/3 success
expand
expand 0 comments
pull request successfully merged
1 commit
expand
appview/repo: add webhook management endpoints
2/3 failed, 1/3 success
expand
expand 0 comments
1 commit
expand
appview/repo: add webhook management endpoints
2/3 failed, 1/3 success
expand
expand 0 comments
1 commit
expand
appview/repo: add webhook management endpoints
2/3 failed, 1/3 success
expand
expand 0 comments
1 commit
expand
appview/repo: add webhook management endpoints
2/3 failed, 1/3 success
expand
expand 1 comment
  • here, we can just trigger a hx-refresh
  • similarly for update hooks here, (there does not seem to be a webhooks-success element!)
  • here, similar, hx-refresh should suffice
  • likewise for toggle

changeset lgtm otherwise!

1 commit
expand
appview/repo: add webhook management endpoints
2/3 failed, 1/3 success
expand
expand 0 comments