ci: Represent build status as a symbol.

* guix/ci.scm (define-enumeration-mapping): New macro.
(integer->build-status): New procedure.
(<build>)[status]: Use it.
This commit is contained in:
Ludovic Courtès 2021-07-03 18:02:11 +02:00
parent a2b22cae4f
commit 77dba2281f
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5

View file

@ -75,13 +75,31 @@ (define-json-mapping <build-product> make-build-product
(file-size build-product-file-size) ;integer (file-size build-product-file-size) ;integer
(path build-product-path)) ;string (path build-product-path)) ;string
(define-syntax-rule (define-enumeration-mapping proc
(names integers) ...)
(define (proc value)
(match value
(integers 'names) ...)))
(define-enumeration-mapping integer->build-status
;; Copied from 'build-status' in Cuirass.
(submitted -3)
(scheduled -2)
(started -1)
(succeeded 0)
(failed 1)
(failed-dependency 2)
(failed-other 3)
(canceled 4))
(define-json-mapping <build> make-build build? (define-json-mapping <build> make-build build?
json->build json->build
(id build-id "id") ;integer (id build-id "id") ;integer
(derivation build-derivation) ;string | #f (derivation build-derivation) ;string | #f
(evaluation build-evaluation) ;integer (evaluation build-evaluation) ;integer
(system build-system) ;string (system build-system) ;string
(status build-status "buildstatus" ) ;integer (status build-status "buildstatus" ;symbol
integer->build-status)
(timestamp build-timestamp) ;integer (timestamp build-timestamp) ;integer
(products build-products "buildproducts" ;<build-product>* (products build-products "buildproducts" ;<build-product>*
(lambda (products) (lambda (products)