Skip to content

Commit d6145d2

Browse files
authored
Merge pull request #105 from grafana/104-improve-compliance-badge-support
Improve compliance badge support
2 parents 3083799 + 4c4f0cb commit d6145d2

File tree

6 files changed

+58
-3
lines changed

6 files changed

+58
-3
lines changed

cmd/api.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,18 @@ func writeAPIGroupGlobal(registry k6registry.Registry, target string) error {
6565
return writeJSON(filepath.Join(target, "catalog.json"), k6registry.RegistryToCatalog(registry))
6666
}
6767

68+
const gradesvg = `<svg xmlns="http://www.w3.org/2000/svg" width="17" height="20"><clipPath id="B"><rect width="17" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#B)"><path fill="%s" d="M0 0h17v20H0z"/><path fill="url(#A)" d="M0 0h17v20H0z"/></g><g text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text x="85" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="70">%s</text><text x="85" y="140" transform="scale(.1)" fill="#fff" textLength="70">%s</text></g></svg>` //nolint:lll
69+
6870
func writeAPIGroupModule(registry k6registry.Registry, target string) error {
6971
base := filepath.Join(target, "module")
7072

7173
for _, ext := range registry {
7274
dir := filepath.Join(base, ext.Module)
7375

7476
if ext.Compliance != nil {
75-
b, err := badge.RenderBytes("k6 registry", string(ext.Compliance.Grade), badgecolor(ext.Compliance.Grade))
77+
sgrade := string(ext.Compliance.Grade)
78+
79+
b, err := badge.RenderBytes("k6 registry", sgrade, badgecolor(ext.Compliance.Grade))
7680
if err != nil {
7781
return err
7882
}
@@ -81,6 +85,13 @@ func writeAPIGroupModule(registry k6registry.Registry, target string) error {
8185
if err != nil {
8286
return err
8387
}
88+
89+
grade := fmt.Sprintf(gradesvg, badgecolor(ext.Compliance.Grade), sgrade, sgrade)
90+
91+
err = writeData(filepath.Join(dir, "grade.svg"), []byte(grade))
92+
if err != nil {
93+
return err
94+
}
8495
}
8596

8697
if err := writeJSON(filepath.Join(dir, "extension.json"), ext); err != nil {

cmd/lint.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ func checkCompliance(ctx context.Context, module string, cloneURL string, tstamp
157157
return nil, err
158158
}
159159

160-
compliance.Checks = nil
160+
for idx := range compliance.Checks {
161+
compliance.Checks[idx].Details = ""
162+
}
161163

162164
err = saveCompliance(ctx, module, compliance)
163165
if err != nil {

cmd/load.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,19 @@ func loadOne(ctx context.Context, ext *k6registry.Extension, lint bool) error {
105105
return err
106106
}
107107

108-
ext.Compliance = &k6registry.Compliance{Grade: k6registry.Grade(compliance.Grade), Level: compliance.Level}
108+
var issues []string
109+
110+
for _, check := range compliance.Checks {
111+
if !check.Passed {
112+
issues = append(issues, string(check.ID))
113+
}
114+
}
115+
116+
ext.Compliance = &k6registry.Compliance{
117+
Grade: k6registry.Grade(compliance.Grade),
118+
Level: compliance.Level,
119+
Issues: issues,
120+
}
109121
}
110122

111123
return nil

docs/registry.schema.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,23 @@
186186
"C",
187187
"A"
188188
]
189+
},
190+
"issues": {
191+
"type": "array",
192+
"description": "A list of compliance check IDs that failed.\n\nThe `issues`` property is primarily used for debugging. It contains the (implementation-dependent) identifiers of those compliance checks that failed.\n",
193+
"items": {
194+
"type": "string"
195+
},
196+
"examples": [
197+
[
198+
"build",
199+
"smoke"
200+
],
201+
[
202+
"readme",
203+
"versions"
204+
]
205+
]
189206
}
190207
},
191208
"additionalProperties": false

registry_gen.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

releases/v0.1.34.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
k6registry `v0.1.34` is here 🎉!
2+
3+
This is an internal maintenance release.
4+
- Add go tooling to docker image (k6lint build checker requires it)
5+
- Keep a list of failed k6lint checkers (for debugging purposes)
6+
- Generate a grade badge that only contains the grade letter

0 commit comments

Comments
 (0)