diff --git a/kcidb/templates/build.j2 b/kcidb/templates/build.j2 index 64e082d6..2de5608b 100644 --- a/kcidb/templates/build.j2 +++ b/kcidb/templates/build.j2 @@ -1,4 +1,5 @@ {# Build template macros #} +{% import "test.j2" as test_macros %} {% macro summary(build) %} {{- [build.architecture, build.config_name, @@ -6,19 +7,18 @@ reject("none") | join(" ") | default(build.id, true) -}} {% endmacro %} -{% macro container_emoji_counts(output_dictionary, container) %} - {% set invalid = container.builds | selectattr("valid", "false") | list | length %} - {% set valid = container.builds | selectattr("valid", "true") | list | length %} - {% set unknown = container.builds | selectattr("valid", "none") | list | length %} - {% if invalid %} - {% set _ = output_dictionary.__setitem__("❌", invalid | string) %} - {% endif %} - {% if valid %} - {% set _ = output_dictionary.__setitem__("✅", valid | string) %} - {% endif %} - {% if unknown %} - {% set _ = output_dictionary.__setitem__("❓", unknown | string) %} - {% endif %} +{% macro container_emoji_counts(emoji_counts, container) %} + {% for emoji in test_macros.WAIVED_STATUS_EMOJIS.values() %} + {% set _ = emoji_counts.__setitem__( + emoji, + container.builds | + selectattr( + "valid", + "==", + {"❌": false, "✅": true, "❓": none}.get(emoji, {}) + ) | list | length + ) %} + {% endfor %} {% endmacro %} {% macro container_summary(container, max_list_len) %} diff --git a/kcidb/templates/checkout_description.txt.j2 b/kcidb/templates/checkout_description.txt.j2 index cb800d3e..39242c26 100644 --- a/kcidb/templates/checkout_description.txt.j2 +++ b/kcidb/templates/checkout_description.txt.j2 @@ -22,12 +22,12 @@ OVERVIEW Checkout: {{ misc_macros.valid_badge(checkout.valid) }} {% if checkout.builds %} - Builds: {{ overview_macros.emoji_overview(build_emoji_counts, - test_emoji_counts) }} + Builds: {{ overview_macros.emoji_counts(build_emoji_counts, + test_emoji_counts) }} {% endif %} {% if checkout.tests %} - Tests: {{ overview_macros.emoji_overview(test_emoji_counts, - build_emoji_counts) }} + Tests: {{ overview_macros.emoji_counts(test_emoji_counts, + build_emoji_counts) }} {% endif %} CHECKOUT diff --git a/kcidb/templates/overview.j2 b/kcidb/templates/overview.j2 index c9850a75..1ed2c006 100644 --- a/kcidb/templates/overview.j2 +++ b/kcidb/templates/overview.j2 @@ -1,60 +1,45 @@ {# Overview template macros #} - -{% macro partial_emoji_overview(ns) %} - - # get the overview string for "❌", "✅", "❓". - {%- for emoji in ["❌", "✅", "❓"] -%} - {%- if emoji in varargs[0] %} - {%- if emoji in varargs[1] %} - # if "emoji" exists in each of the emoji count dictionaries, - # generate a formatting string from the length of the longest - # count between them. - - {% set _ = ns.elements.extend([emoji, varargs[0][emoji]]) -%} - {% if varargs[0][emoji] | length > varargs[1][emoji] | length %} - {% set index = 0 %} - {% else %} - {% set index = 1 %} - {% endif %} - {% set ns.format_string = ns.format_string + "%s " + "%" + - varargs[index][emoji] | length | string + "s " %} - {% else %} - # if "emoji" exists in the first but not latter of the - # emoji count dictionaries, generate formatting string - # from the length of first count. - - {% set _ = ns.elements.extend([emoji, varargs[0][emoji]]) -%} - {% set ns.format_string = ns.format_string + "%s " + "%" + - varargs[0][emoji] | length | string + "s " %} - {% endif %} - - {% else %} - {%- if emoji in varargs[1] %} - # if "emoji" exist in the latter but not first of the - # emoji count dictionaries, insert "➖" instead. - - {% set _ = ns.elements.extend(["➖", ""]) %} - {% set ns.format_string = ns.format_string + "%s " + "%" + - varargs[1][emoji] | length | string + "s " %} - {% endif %} - - {% endif -%} +{% import "test.j2" as test_macros %} + +{%- macro emoji_counts() -%} + {%- set ns = namespace( + max_emojis={}, + pieces=[], + first=test_macros.WAIVED_STATUS_EMOJIS | length, + last=-1 + ) -%} + + {# Find maximum emoji counts accross all arguments #} + {%- for emoji in test_macros.WAIVED_STATUS_EMOJIS.values() -%} + {%- set _ = ns.max_emojis.__setitem__( + emoji, varargs | map(attribute=emoji) | max + ) -%} {%- endfor -%} -{% endmacro %} - -{% macro emoji_overview() -%} - {% set ns = namespace(elements=[], format_string='') %} - {%- set _ = partial_emoji_overview(ns, varargs[0], varargs[1]) -%} - {# generate formatting string for other emoji(s) in TESTS. #} - {% for emoji in varargs[0] -%} - {% if emoji not in ["❌", "✅", '❓'] %} - {% set _ = ns.elements.extend([emoji, varargs[0][emoji]]) %} - {% set ns.format_string = ns.format_string + "%" + - emoji | length | string + "s %" + - varargs[0][emoji] | length | string + "s " %} - {% endif %} + {# Build a list of " " pieces for all emojis #} + {%- for emoji, count in varargs[0].items() -%} + {%- if ns.max_emojis[emoji] > 0 -%} + {# Remember the first non-zero emoji across all arguments #} + {%- set ns.first = [ ns.first, loop.index0 ] | min -%} + {# Add an " " piece #} + {%- set _ = ns.pieces.extend([ + ( + "%s %" + + (ns.max_emojis[emoji] | string | length | string) + + "s" + ) | + format( + "➖" if count == 0 else emoji, + "" if count == 0 else (count | string) + ) + ]) -%} + {# Remember the last non-zero emoji in this argument #} + {%- if count > 0 -%} + {%- set ns.last = loop.index0 -%} + {%- endif -%} + {%- endif -%} {%- endfor -%} - {{- ns.format_string | format(*ns.elements) -}} + {# Output the pieces of interest #} + {{- ns.pieces[ns.first:ns.last + 1] | join(" ") -}} {%- endmacro -%} diff --git a/kcidb/templates/revision_description.txt.j2 b/kcidb/templates/revision_description.txt.j2 index ad58ef08..4ecab2b8 100644 --- a/kcidb/templates/revision_description.txt.j2 +++ b/kcidb/templates/revision_description.txt.j2 @@ -24,12 +24,12 @@ OVERVIEW Patches: {{ misc_macros.valid_badge(revision.checkouts_valid) }} {% endif %} {% if revision.builds %} - Builds: {{ overview_macros.emoji_overview(build_emoji_counts, - test_emoji_counts) }} + Builds: {{ overview_macros.emoji_counts(build_emoji_counts, + test_emoji_counts) }} {% endif %} {% if revision.tests %} - Tests: {{ overview_macros.emoji_overview(test_emoji_counts, - build_emoji_counts) }} + Tests: {{ overview_macros.emoji_counts(test_emoji_counts, + build_emoji_counts) }} {% endif %} REVISION diff --git a/kcidb/templates/test.j2 b/kcidb/templates/test.j2 index 6930838d..75e653d1 100644 --- a/kcidb/templates/test.j2 +++ b/kcidb/templates/test.j2 @@ -57,16 +57,12 @@ reject("none") | join(" ") | default(test.id, true) -}} {% endmacro %} -{% macro container_emoji_counts(output_dictionary, container) %} - {% for waived, status_nodes in container.tests_root.waived_status_nodes.items() %} - {% for status, nodes in status_nodes.items() %} - {% if nodes %} - {% set _ = output_dictionary.__setitem__( - waived_status_emoji(waived, status), - nodes | length | string - ) %} - {% endif %} - {% endfor %} +{% macro container_emoji_counts(emoji_counts, container) %} + {% for (waived, status), emoji in WAIVED_STATUS_EMOJIS.items() %} + {% set _ = emoji_counts.__setitem__( + emoji, + container.tests_root.waived_status_nodes[waived][status] | length + ) %} {% endfor -%} {% endmacro %}