Skip to content

Commit 945b6b2

Browse files
committed
templates: Add emoji_counts macro
This commit adds a public macro called :emoji_counts: which is used to generate overview string for BUILDS or TESTS. This macro simply accepts a variable number of arguments (see https://jinja.palletsprojects.com/en/3.0.x/templates/#macros), each being an emoji count dictionary, and output the overview string for the first one.
1 parent 626f801 commit 945b6b2

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

kcidb/templates/overview.j2

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{# Overview template macros #}
2+
{% import "test.j2" as test_macros %}
3+
4+
{%- macro emoji_counts() -%}
5+
{%- set ns = namespace(
6+
max_emojis={},
7+
pieces=[],
8+
trail=0
9+
) -%}
10+
11+
{# Find maximum emoji counts accross all arguments #}
12+
{%- for emoji in test_macros.WAIVED_STATUS_EMOJIS.values() -%}
13+
{%- set _ = ns.max_emojis.__setitem__(
14+
emoji, varargs | map(attribute=emoji) | max
15+
) -%}
16+
{%- endfor -%}
17+
18+
{# Build a list of "<emoji> <count>" pieces for all emojis #}
19+
{%- for emoji, count in varargs[0].items() -%}
20+
{%- if ns.max_emojis[emoji] > 0 -%}
21+
22+
{# Add an "<emoji> <count>" piece #}
23+
{%- set _ = ns.pieces.extend([
24+
(
25+
"%s %" +
26+
(ns.max_emojis[emoji] | string | length | string) +
27+
"s"
28+
) |
29+
format(
30+
"➖" if count == 0 else emoji,
31+
"" if count == 0 else (count | string)
32+
)
33+
]) -%}
34+
35+
{# Get the number of trailling "➖" character #}
36+
{%- if count -%}
37+
{%- set ns.trail = 0 -%}
38+
{%- else -%}
39+
{%- set ns.trail = ns.trail + 1 -%}
40+
{%- endif -%}
41+
42+
{%- endif -%}
43+
{%- endfor -%}
44+
45+
{# Output the pieces of interest #}
46+
{{- ns.pieces[:(ns.pieces | length) - ns.trail] | join(" ") -}}
47+
48+
{%- endmacro -%}

0 commit comments

Comments
 (0)