~evhan/chicken-sourcehut

ref: 37dc620efa73034094296bf2631624ec85469542 chicken-sourcehut/sourcehut.git.scm -rw-r--r-- 2.1 KiB
37dc620eEvan Hanson Fix long option parsing 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; REST API bindings for git.sr.ht
;;;
;;; Copyright (c) 2020, Evan Hanson
;;;
;;; See LICENSE for details.
;;;

(declare (module (sourcehut git))
         (import (except (scheme) log))
         (export artifact log refs))

(import (chicken format)
        (chicken keyword)
        (chicken type)
        (sourcehut)
        (srfi 1))

(define-inline (make-crud path #!optional (body '()))
  `((#:service "git" #:path ,path) . ,body))

(define-inline (make-form-crud path form)
  `((#:service "git" #:path ,path #:form (,form))))

;;
;; https://man.sr.ht/git.sr.ht/api.md#get-apireposnamerefs
;; https://man.sr.ht/git.sr.ht/api.md#get-apiusernamereposnamerefs
;;
(: refs (string #!optional string -> (list-of pair)))
(define (refs username-or-repo #!optional repo)
  (make-crud
   (if (not repo)
       (format "/api/repos/~A/refs" username-or-repo)
       (format "/api/~A/repos/~A/refs" username-or-repo repo))))

;;
;; https://man.sr.ht/git.sr.ht/api.md#get-apireposnamelog
;; https://man.sr.ht/git.sr.ht/api.md#get-apiusernamereposnamelog
;;
(: log (string #!optional string -> (list-of pair)))
(define (log username-or-repo #!optional repo)
  (make-crud
   (if (not repo)
       (format "/api/repos/~A/log" username-or-repo)
       (format "/api/~A/repos/~A/log" username-or-repo repo))))

;;
;; https://man.sr.ht/git.sr.ht/api.md#post-apireposnameartifactsref
;; https://man.sr.ht/git.sr.ht/api.md#post-apiusernamereposnameartifactsref
;;
(: artifact (string string #!optional string #!rest any -> (list-of pair)))
(define (artifact username-or-repo repo-or-ref #!optional ref #!rest args)
  (cond ((string? ref)
         (make-form-crud
          (format "/api/~A/repos/~A/artifacts/~A" username-or-repo repo-or-ref ref)
          (cons 'file args)))
        ((get-keyword #:file (cons ref args))
         (make-form-crud
          (format "/api/repos/~A/artifacts/~A" username-or-repo repo-or-ref)
          (cons* 'file ref args)))
        (else
         (signal-condition
          '(sourcehut)
          '(arity)
          '(exn location paste message "artifact #:file must be given")))))