Commitd54bf895Recorded29 Mar 2026Repositorysigil-forgejo

Use shared API client helpers from (sigil http client)

Message

Replace local forgejo-api-url, check-response, and forgejo-json-headers with build-api-url and make-response-checker from the shared library.

Changed
 src/forgejo/client.sgl | 21 +++++----------------
 1 file changed, 5 insertions(+), 16 deletions(-)
Diff
src/forgejo/client.sglmodified
@@ -29,28 +29,17 @@
29
;;; (forgejo-api-url "https://codeberg.org" "repos" "sigil" "kiln")
30
;;; => "https://codeberg.org/api/v1/repos/sigil/kiln"
31
(define (forgejo-api-url base-url . parts)
32
(apply string-append base-url "/api/v1"
33
(map (lambda (p) (string-append "/" p)) parts)))
+32
(apply build-api-url base-url "api" "v1" parts))
+33
+34
;;; Response checker for the Forgejo API.
+35
(define check-response
+36
(make-response-checker name: "Forgejo API"))
37
38
;; JSON headers for requests with a body.
39
(define (forgejo-json-headers token)
40
(dict-merge (forgejo-auth-headers token)
41
#{ content-type: "application/json" }))
42
40
;; Check an HTTP response and return parsed JSON, or raise an error
41
;; with the status code and response body.
42
(define (check-response response)
43
(if (not (http-response? response))
44
(error "Forgejo API request failed: no response"))
45
(let ((status (http-response-status response))
46
(body (http-response-body response)))
47
(if (>= status 400)
48
(error (string-append "Forgejo API error " (number->string status)
49
": " (or body "")))
50
(if (and body (not (string=? body "")))
51
(json-decode body)
52
#t))))
53
43
;;; Authenticated JSON GET request.
44
(define (forgejo-get/json token url)
45
(check-response