badge.gno
1.34 Kb · 49 lines
1package bouncer
2
3import (
4 "strconv"
5
6 "gno.land/p/g19wmd95cwm3s0w0c5592tgu3zh4zgrtlggvugnj/bouncer/badge/v0"
7)
8
9// Badge returns a Markdown image of pkgpath's live Bouncer badge (grade,
10// score and attestation date), linked to its Passport. A realm shows it by
11// adding one line to its Render:
12//
13// out += bouncer.Badge("gno.land/r/<address>/myrealm")
14//
15// The color follows the verdict, not the grade: a package with a PROVEN
16// High finding is red even at grade B.
17func Badge(pkgpath string) string {
18 if !validPkgPath(pkgpath) {
19 return ""
20 }
21 link := webPath() + ":realm/" + pkgpath
22 a, ok := Latest(pkgpath)
23 if !ok {
24 return badge.Markdown("Bouncer: not scanned", badge.SVG("bouncer", "not scanned", badge.Grey), link)
25 }
26 msg := a.Grade + " " + strconv.Itoa(a.Score) + " · " + date(a.Time)
27 return badge.Markdown("Bouncer: grade "+a.Grade+", score "+strconv.Itoa(a.Score)+", "+verdictWords(a.Verdict),
28 badge.SVG("bouncer", msg, verdictColor(a.Verdict)), link)
29}
30
31func verdictColor(v string) string {
32 switch v {
33 case VerdictNotRecommended:
34 return badge.Red
35 case VerdictReview:
36 return badge.Orange
37 }
38 return badge.Green
39}
40
41func verdictWords(v string) string {
42 switch v {
43 case VerdictNotRecommended:
44 return "not recommended for integration"
45 case VerdictReview:
46 return "review before integration"
47 }
48 return "no known Critical or High issues"
49}