summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoreltrac <hi@eltr.ac>2026-10-30 11:46:40 +0800
committereltrac <hi@eltr.ac>2026-10-30 11:46:40 +0800
commita5f0d0dc9e73ba46a4ff974a256de770d70ac788 (patch)
tree814f8d59a3dd1c76716fe181ad07f8e8ec4cb03f /src
parentdd4c7ca7850f166af4997912a3ded5639bd14a56 (diff)
test, webhook: tidy up webhook; add tests
- (send-webhook) does not need to validate URLs; (trigger) already does that; replace validation logic with :pre conditional - (make-request) does not need to fallback to empty string when event-key is nil. it should never be nil.
Diffstat (limited to 'src')
-rw-r--r--src/weepinbell/webhook.clj19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/weepinbell/webhook.clj b/src/weepinbell/webhook.clj
index c93b74a..e777e92 100644
--- a/src/weepinbell/webhook.clj
+++ b/src/weepinbell/webhook.clj
@@ -13,15 +13,14 @@
;; utilities
(defn- send-webhook [url opts]
- (if (valid-http-url? url)
- (client/post url opts
- (fn async-callback [{:keys [status _ _ error]}]
- (cond
- error (timbre/error "error ocurred sending webhook to" url ":" error)
- (>= status 500) (timbre/error "something's wrong with webhook server of" url)
- (>= status 400) (timbre/error "webhook url is invalid:" url)
- :else (timbre/info "request sent to" url))))
- (timbre/warn "webhook url not valid, skipped" url)))
+ {:pre [(valid-http-url? url) (map? opts)]}
+ (client/post url opts
+ (fn async-callback [{:keys [status _ _ error]}]
+ (cond
+ error (timbre/error "error ocurred sending webhook to" url ":" error)
+ (>= status 500) (timbre/error "something's wrong with webhook server of" url)
+ (>= status 400) (timbre/error "webhook url is invalid:" url)
+ :else (timbre/info "request sent to" url)))))
(defn make-request [event-key data request-fn]
(cond
@@ -41,7 +40,7 @@
source (:source webmention)
target (:target webmention)]
(-> url
- (string/replace "{event}" (or (name event-key) ""))
+ (string/replace "{event}" (name event-key))
(string/replace "{target}" (or target ""))
(string/replace "{source}" (or source ""))
(string/replace "{target-encoded}" (if target (url-encode target) ""))