[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: Fix badge display.
From: |
Mathieu Othacehe |
Subject: |
branch master updated: Fix badge display. |
Date: |
Fri, 28 May 2021 08:17:45 -0400 |
This is an automated email from the git hooks/post-receive script.
mothacehe pushed a commit to branch master
in repository guix-cuirass.
The following commit(s) were added to refs/heads/master by this push:
new e6bfa48 Fix badge display.
e6bfa48 is described below
commit e6bfa48061b39594e548386f406754c3d1207076
Author: Mathieu Othacehe <othacehe@gnu.org>
AuthorDate: Fri May 28 14:11:42 2021 +0200
Fix badge display.
* src/static/images/badge-running.svg: Remove it.
* Makefile.am (dist_images_DATA): Ditto.
* src/cuirass/database.scm (db-get-latest-evaluation,
db-get-evaluation-absolute-summary): New procedures.
* src/cuirass/http.scm (url-handler): Fix badge display.
* src/cuirass/templates.scm (badge-svg): Adapt it.
* tests/database.scm ("db-get-evaluation-absolute-summary",
"db-get-latest-evaluation"): New tests.
* doc/cuirass.texi (Badges): Adapt it.
---
Makefile.am | 1 -
doc/cuirass.texi | 6 +-
src/cuirass/database.scm | 24 ++++-
src/cuirass/http.scm | 6 +-
src/cuirass/templates.scm | 41 +++------
src/static/images/badge-running.svg | 179 ------------------------------------
tests/database.scm | 14 +++
7 files changed, 55 insertions(+), 216 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index c0de526..2b7e053 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -115,7 +115,6 @@ dist_fonts_DATA = \
dist_images_DATA = \
src/static/images/badge-error.svg \
src/static/images/badge-per.svg \
- src/static/images/badge-running.svg \
src/static/images/guix.png \
src/static/images/icon.png
dist_js_DATA = \
diff --git a/doc/cuirass.texi b/doc/cuirass.texi
index 1a252dc..1e3c2d3 100644
--- a/doc/cuirass.texi
+++ b/doc/cuirass.texi
@@ -306,10 +306,8 @@ your favorite forge.
@item @url{http://cuirass-url/jobset/spec/badge}
Generates a badge for the @code{spec} specification. The badge
represents the percentage of successful jobs for the latest evaluation
-of the @code{spec} specification. If the latest evaluation is still
-being processed, a @code{running} badge is generated. If no
-evaluation could be found for the @code{spec} specification, an
-@code{error} badge is generated.
+of the @code{spec} specification. If no evaluation could be found for
+the @code{spec} specification, an @code{error} badge is generated.
@end itemize
diff --git a/src/cuirass/database.scm b/src/cuirass/database.scm
index ee866a7..0f752cb 100644
--- a/src/cuirass/database.scm
+++ b/src/cuirass/database.scm
@@ -97,8 +97,10 @@
db-get-next-eval
db-get-evaluations-id-min
db-get-evaluations-id-max
+ db-get-latest-evaluation
db-get-latest-evaluations
db-get-evaluation-summary
+ db-get-evaluation-absolute-summary
db-get-evaluations-absolute-summary
db-get-builds-query-min
db-get-builds-query-max
@@ -1491,6 +1493,16 @@ SELECT MAX(id) FROM Evaluations
WHERE specification=" spec))
((max) (and max (string->number max))))))
+(define (db-get-latest-evaluation spec)
+ "Return the latest successful evaluation for the given specification SPEC."
+ (with-db-worker-thread db
+ (match (expect-one-row
+ (exec-query/bind db "
+SELECT max(id) FROM Evaluations
+WHERE status = 0 AND specification = " spec
+" GROUP BY Evaluations.specification;"))
+ ((eval) (and eval (string->number eval))))))
+
(define (db-get-latest-evaluations)
"Return the latest successful evaluation for each specification."
(with-db-worker-thread db
@@ -1537,12 +1549,20 @@ ORDER BY Evaluations.id ASC;"))
(#:scheduled . ,(or (string->number scheduled) 0))))
(else #f))))
+(define (db-get-evaluation-absolute-summary evaluation)
+ (expect-one-row
+ (db-get-evaluations-absolute-summary (list evaluation))))
+
(define (db-get-evaluations-absolute-summary evaluations)
(define eval-ids
(format #f "{~a}"
(string-join
- (map number->string
- (map (cut assq-ref <> #:id) evaluations))
+ (map (lambda (eval)
+ (number->string
+ (if (number? eval)
+ eval
+ (assq-ref eval #:id))))
+ evaluations)
",")))
(define (number n)
diff --git a/src/cuirass/http.scm b/src/cuirass/http.scm
index 10c60bd..dd70ad8 100644
--- a/src/cuirass/http.scm
+++ b/src/cuirass/http.scm
@@ -1076,10 +1076,8 @@ passed, only display JOBS targeting this SYSTEM."
(('GET "jobset" spec "badge")
(let* ((params (request-parameters request))
- (summary
- (match (db-get-evaluations-build-summary spec 1 #f #f)
- ((summary) summary)
- (else #f))))
+ (summary (db-get-evaluation-absolute-summary
+ (db-get-latest-evaluation spec))))
(respond-svg
(badge-svg badge-string summary))))
diff --git a/src/cuirass/templates.scm b/src/cuirass/templates.scm
index fb83fda..ac5b678 100644
--- a/src/cuirass/templates.scm
+++ b/src/cuirass/templates.scm
@@ -1931,29 +1931,18 @@ text-dark d-flex position-absolute w-100"))
"Return the badge SVG for the specification with the given SUMMARY. The
BADGE-STRING procedure takes a badge name as input an returns the badge
content as a string."
- (define complete?
- (eq? (assq-ref summary #:status) 0))
-
- (cond
- ((not summary)
- (badge-string "badge-error.svg"))
- (complete?
- (let* ((succeeded
- (assq-ref summary #:succeeded))
- (failed
- (assq-ref summary #:failed))
- (scheduled
- (assq-ref summary #:scheduled))
- (percentage
- (nearest-exact-integer
- (* 100
- (/ succeeded
- (+ succeeded failed scheduled)))))
- (percentage-str
- (string-append
- (number->string percentage) "%")))
- (string-replace-substring
- (badge-string "badge-per.svg")
- "X%" percentage-str)))
- (else
- (badge-string "badge-running.svg"))))
+ (if summary
+ (let* ((succeeded
+ (assq-ref summary #:succeeded))
+ (total
+ (assq-ref summary #:total))
+ (percentage
+ (nearest-exact-integer
+ (* 100 (/ succeeded total))))
+ (percentage-str
+ (string-append
+ (number->string percentage) "%")))
+ (string-replace-substring
+ (badge-string "badge-per.svg")
+ "X%" percentage-str))
+ (badge-string "badge-error.svg")))
diff --git a/src/static/images/badge-running.svg
b/src/static/images/badge-running.svg
deleted file mode 100644
index 0a4b096..0000000
--- a/src/static/images/badge-running.svg
+++ /dev/null
@@ -1,179 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<svg
- xmlns:dc="http://purl.org/dc/elements/1.1/"
- xmlns:cc="http://creativecommons.org/ns#"
- xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
- xmlns:svg="http://www.w3.org/2000/svg"
- xmlns="http://www.w3.org/2000/svg"
- xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
- xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
- width="99.998856"
- height="26.153"
- id="svg2"
- version="1.1"
- inkscape:version="1.0.2 (e86c870879, 2021-01-15)"
- sodipodi:docname="badge_running.svg">
- <title
- id="title3831">Cuirass icon</title>
- <defs
- id="defs4">
- <rect
- x="9094.3613"
- y="2431.5554"
- width="363.25549"
- height="110.18591"
- id="rect226" />
- </defs>
- <sodipodi:namedview
- id="base"
- pagecolor="#ffffff"
- bordercolor="#666666"
- borderopacity="1.0"
- inkscape:pageopacity="0"
- inkscape:pageshadow="2"
- inkscape:zoom="8"
- inkscape:cx="71.646296"
- inkscape:cy="11.632563"
- inkscape:document-units="px"
- inkscape:current-layer="g328"
- showgrid="false"
- inkscape:window-width="2560"
- inkscape:window-height="1376"
- inkscape:window-x="0"
- inkscape:window-y="27"
- inkscape:window-maximized="1"
- inkscape:showpageshadow="false"
- borderlayer="true"
- inkscape:document-rotation="0"
- inkscape:snap-global="true"
- showguides="true"
- inkscape:guide-bbox="true"
- inkscape:snap-bbox="true"
- fit-margin-top="0"
- fit-margin-left="0"
- fit-margin-right="0"
- fit-margin-bottom="0"
- showborder="false">
- <inkscape:grid
- type="axonomgrid"
- id="grid3004"
- units="mm"
- empspacing="5"
- visible="true"
- enabled="true"
- snapvisiblegridlinesonly="true"
- spacingy="3.7mm"
- originx="-8829.3366"
- originy="-1180.3996" />
- </sodipodi:namedview>
- <metadata
- id="metadata7">
- <rdf:RDF>
- <cc:Work
- rdf:about="">
- <dc:format>image/svg+xml</dc:format>
- <dc:type
- rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
- <dc:title>Cuirass icon</dc:title>
- <dc:date>2021-01-09</dc:date>
- <dc:creator>
- <cc:Agent>
- <dc:title>Luis Felipe López Acevedo</dc:title>
- </cc:Agent>
- </dc:creator>
- <dc:rights>
- <cc:Agent>
- <dc:title />
- </cc:Agent>
- </dc:rights>
- <cc:license
- rdf:resource="http://creativecommons.org/licenses/by-sa/4.0/" />
- </cc:Work>
- <cc:License
- rdf:about="http://creativecommons.org/licenses/by-sa/4.0/">
- <cc:permits
- rdf:resource="http://creativecommons.org/ns#Reproduction" />
- <cc:permits
- rdf:resource="http://creativecommons.org/ns#Distribution" />
- <cc:requires
- rdf:resource="http://creativecommons.org/ns#Notice" />
- <cc:requires
- rdf:resource="http://creativecommons.org/ns#Attribution" />
- <cc:permits
- rdf:resource="http://creativecommons.org/ns#DerivativeWorks" />
- <cc:requires
- rdf:resource="http://creativecommons.org/ns#ShareAlike" />
- </cc:License>
- </rdf:RDF>
- </metadata>
- <g
- inkscape:groupmode="layer"
- id="layer2"
- inkscape:label="ref"
- sodipodi:insensitive="true"
- transform="translate(-8814.2185,-1148.2736)" />
- <g
- inkscape:label="layer"
- inkscape:groupmode="layer"
- id="layer1"
- transform="translate(-8814.2185,-2000.6358)">
- <text
- xml:space="preserve"
- id="text224"
-
style="font-style:normal;font-weight:normal;font-size:96px;line-height:0;font-family:sans-serif;white-space:pre;shape-inside:url(#rect226);fill:#000000;fill-opacity:1;stroke:none;"><tspan
- style="visibility:hidden"
- x="9094.3613"
- y="2631.4797"><tspan
- dx="0 61.078125 61.078125"
-
style="font-size:96px;line-height:1.35;fill:#ff6600">40%</tspan></tspan></text>
- <path
- style="fill:#fd7e14;fill-opacity:1;stroke-width:0.707107"
- d=""
- id="path244"
- transform="translate(9421.1025,2673.3733)" />
- <path
- style="fill:#fd7e14;fill-opacity:1;stroke-width:0.707107"
- d=""
- id="path246"
- transform="translate(9421.1025,2673.3733)" />
- <g
- id="g328"
- transform="matrix(0.13076492,0,0,0.13076492,7664.8791,1688.7373)">
- <rect
- style="fill:#191919;fill-opacity:1;stroke:none;stroke-width:0.284347"
- id="rect4281"
- width="200"
- height="200.00011"
- x="8789.3555"
- y="2385.1848" />
- <g
- id="g1247"
- transform="matrix(0.75,0,0,0.75,1729.7789,386.40491)">
- <path
- id="path4303"
-
style="fill:#fd7e14;fill-opacity:1;stroke:none;stroke-width:1.40209;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
- d="m 9551.1873,2698.3734 v 38.6156 h 15.2577 v -3.0224 l
6.7796,-6.7797 h 20.339 20.339 l 6.7797,6.7797 v 20.0692 a 27.118644,27.118644
0 0 1 0,0.2698 v 20.3389 l -6.7797,6.7797 h -20.339 -20.339 l -6.7796,-6.7797 v
-3.7572 h -15.2577 v 54.2372 h 15.2577 v -3.0223 l 6.7796,-6.7797 h 20.339
20.339 l 6.7797,6.7797 v 20.0692 a 27.118644,27.118644 0 0 1 0,0.2698 v 20.3389
l -6.7797,6.7797 h -20.339 -20.339 l -6.7796,-6.7797 v -3.7573 h -15.2577 v
39.3506 h 82.2034 l 12.7119,-12.71 [...]
- <path
- id="path4305"
- style="fill:#ffffff;fill-opacity:1;stroke-width:1.86014"
- d="m 9458.8145,2698.3733 -12.7119,12.7119 v 174.5763 l
12.7119,12.7119 h 82.2034 v -39.3506 -8.9545 h 35.5966 v 5.9322 l 3.3898,3.3898
h 27.1186 l 3.3899,-3.3898 v -27.1187 l -3.3899,-3.3898 h -27.1186 l
-3.3898,3.3898 v 5.9322 h -35.5966 v -9.6895 -54.2372 -8.9546 h 35.5966 v
5.9322 l 3.3898,3.3898 h 27.1186 l 3.3899,-3.3898 v -27.1187 l -3.3899,-3.3898
h -27.1186 l -3.3898,3.3898 v 5.9322 h -35.5966 v -9.6894 -38.6157 z m
13.5593,16.9492 h 51.6949 v 166.1017 h -51.6949 l -9. [...]
- </g>
- <path
- style="fill:#191919;fill-opacity:1;stroke-width:0.844933"
- d="m 8989.3555,2485.1848 v -100 h 282.3611 282.3612 v 100 100 h
-282.3612 -282.3611 z"
- id="path222" />
- <text
- xml:space="preserve"
-
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:98.8576px;line-height:1.25;font-family:Ubuntu;-inkscape-font-specification:Ubuntu;fill:#fd7e14;fill-opacity:1;stroke:none;stroke-width:0.726558"
- x="9455.4414"
- y="2420.0381"
- id="text260"
- transform="scale(0.96288659,1.0385439)"><tspan
- sodipodi:role="line"
- id="tspan258"
- x="9455.4414"
- y="2420.0381"
-
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:Ubuntu;-inkscape-font-specification:Ubuntu;stroke-width:0.726558">running</tspan></text>
- </g>
- </g>
-</svg>
diff --git a/tests/database.scm b/tests/database.scm
index 21a6fa8..2662417 100644
--- a/tests/database.scm
+++ b/tests/database.scm
@@ -329,6 +329,16 @@ timestamp, checkouttime, evaltime) VALUES ('guix', 0, 0,
0, 0);")
(assq-ref summary #:scheduled)))
summaries)))
+ (test-equal "db-get-evaluation-absolute-summary"
+ '(0 1 0)
+ (let ((summary
+ (db-get-evaluation-absolute-summary
+ (db-get-latest-evaluation "guix"))))
+ (list
+ (assq-ref summary #:succeeded)
+ (assq-ref summary #:failed)
+ (assq-ref summary #:scheduled))))
+
(test-equal "db-get-evaluations-absolute-summary"
'((0 1 0) (0 1 0))
(let* ((evaluations
@@ -358,6 +368,10 @@ timestamp, checkouttime, evaltime) VALUES ('guix', 0, 0,
0, 0);")
#f
(db-get-evaluations-id-max "foo"))
+ (test-equal "db-get-latest-evaluation"
+ 4
+ (db-get-latest-evaluation "guix"))
+
(test-equal "db-get-latest-evaluations"
4
(match (db-get-latest-evaluations)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: Fix badge display.,
Mathieu Othacehe <=