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