Skip to content

Commit de258a8

Browse files
authored
enable better differentiation of badge color (#803)
resolves #801 Signed-off-by: Matthias Büchse <[email protected]>
1 parent d41d1c4 commit de258a8

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

compliance-monitor/monitor.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -281,18 +281,16 @@ def evaluate(self, scope_results):
281281
by_validity[self.versions[vname].validity].append(vname)
282282
# go through worsening validity values until a passing version is found
283283
relevant = []
284+
best_passed = None
284285
for validity in ('effective', 'warn', 'deprecated'):
285286
vnames = by_validity[validity]
286287
relevant.extend(vnames)
287288
if any(version_results[vname]['result'] == 1 for vname in vnames):
289+
best_passed = validity
288290
break
289291
# always include draft (but only at the end)
290292
relevant.extend(by_validity['draft'])
291293
passed = [vname for vname in relevant if version_results[vname]['result'] == 1]
292-
if passed:
293-
summary = 1 if self.versions[passed[0]].validity in ('effective', 'warn') else -1
294-
else:
295-
summary = 0
296294
return {
297295
'name': self.name,
298296
'versions': version_results,
@@ -302,7 +300,7 @@ def evaluate(self, scope_results):
302300
vname + ASTERISK_LOOKUP[self.versions[vname].validity]
303301
for vname in passed
304302
]),
305-
'summary': summary,
303+
'best_passed': best_passed,
306304
}
307305

308306
def update_lookup(self, target_dict):
@@ -727,8 +725,13 @@ def pick_filter(results, subject, scope):
727725
def summary_filter(scope_results):
728726
"""Jinja filter to construct summary from `scope_results`"""
729727
passed_str = scope_results.get('passed_str', '') or '–'
730-
summary = scope_results.get('summary', 0)
731-
color = {1: '✅'}.get(summary, '🛑') # instead of 🟢🔴 (hard to distinguish for color-blind folks)
728+
best_passed = scope_results.get('best_passed')
729+
# avoid simple 🟢🔴 (hard to distinguish for color-blind folks)
730+
color = {
731+
'effective': '✅',
732+
'warn': '✅', # forgo differentiation here in favor of simplicity (will be apparent in version list)
733+
'deprecated': '🟧',
734+
}.get(best_passed, '🛑')
732735
return f'{color} {passed_str}'
733736

734737

0 commit comments

Comments
 (0)