AtlatestRepositoryfjo

fjo / tree / src / woodpeckerclient.sgl

1;;; (woodpecker client) - Woodpecker CI API client utilities.
2;;;
3;;; Provides authentication headers and URL construction for the
4;;; Woodpecker CI API at ci.codeberg.org.
5
6(define-library (woodpecker client)
7 (import (sigil core)
8 (sigil dict)
9 (sigil string)
10 (sigil json)
11 (sigil http client))
13 (export woodpecker-auth-headers
14 woodpecker-api-url
15 woodpecker-get/json)
17 (begin
19 ;;; Build authorization headers for the Woodpecker API.
20 ;;; Woodpecker uses Bearer token auth (unlike Forgejo's "token" prefix).
21 (define (woodpecker-auth-headers token)
22 #{ authorization: (string-append "Bearer " token) })
24 ;;; Build an API URL from a base URL and path segments.
25 ;;;
26 ;;; (woodpecker-api-url "https://ci.codeberg.org" "repos" "123" "pipelines")
27 ;;; => "https://ci.codeberg.org/api/repos/123/pipelines"
28 (define (woodpecker-api-url base-url . parts)
29 (apply build-api-url base-url "api" parts))
31 ;;; Response checker for the Woodpecker API.
32 (define check-response
33 (make-response-checker name: "Woodpecker API"))
35 ;;; Authenticated JSON GET request.
36 (define (woodpecker-get/json token url)
37 (check-response
38 (http-get url headers: (woodpecker-auth-headers token))))
40 ))