From 9a5e01a3b421221066c6eb12ac88f3975ac25506 Mon Sep 17 00:00:00 2001
From: JP <77391175+joao-paulo-parity@users.noreply.github.com>
Date: Thu, 16 Feb 2023 07:13:33 -0300
Subject: [PATCH] Update release-related templates for the new changelogerator
 output format (#6702)

* update templates to upcoming context.json format

* fix merging error

* more fixes

* fix templates

* fix

* print "changelogerator --version"

* print changelogerator version as debug

* remove excluded debug info

* WIP

* Switch to changelogerator v0.10.1

* Update bundle deps

* fix

---------

Co-authored-by: Wilfried Kopp <wilfried@parity.io>
---
 polkadot/scripts/ci/changelog/Gemfile            |  2 +-
 polkadot/scripts/ci/changelog/Gemfile.lock       |  4 ++--
 polkadot/scripts/ci/changelog/bin/changelog      |  3 +++
 .../ci/changelog/templates/change.md.tera        | 16 ++++++++--------
 .../ci/changelog/templates/changes_api.md.tera   |  6 ++----
 .../changelog/templates/changes_client.md.tera   |  6 ++----
 .../ci/changelog/templates/changes_misc.md.tera  |  8 ++++----
 .../changelog/templates/changes_runtime.md.tera  |  6 ++----
 .../scripts/ci/changelog/templates/debug.md.tera |  2 +-
 .../ci/changelog/templates/high_priority.md.tera |  4 ++--
 .../changelog/templates/host_functions.md.tera   |  4 ++--
 .../ci/changelog/templates/migrations-db.md.tera |  8 ++++----
 .../templates/migrations-runtime.md.tera         |  8 ++++----
 13 files changed, 37 insertions(+), 40 deletions(-)

diff --git a/polkadot/scripts/ci/changelog/Gemfile b/polkadot/scripts/ci/changelog/Gemfile
index 948e9ddaafc..46b058e3c50 100644
--- a/polkadot/scripts/ci/changelog/Gemfile
+++ b/polkadot/scripts/ci/changelog/Gemfile
@@ -16,7 +16,7 @@ gem 'optparse', '~> 0.1.1'
 
 gem 'logger', '~> 1.4'
 
-gem 'changelogerator', '0.9.1'
+gem 'changelogerator', '0.10.1'
 
 gem 'test-unit', group: :dev
 
diff --git a/polkadot/scripts/ci/changelog/Gemfile.lock b/polkadot/scripts/ci/changelog/Gemfile.lock
index 8bad7ea9d8b..422aa3a8844 100644
--- a/polkadot/scripts/ci/changelog/Gemfile.lock
+++ b/polkadot/scripts/ci/changelog/Gemfile.lock
@@ -4,7 +4,7 @@ GEM
     addressable (2.8.0)
       public_suffix (>= 2.0.2, < 5.0)
     ast (2.4.2)
-    changelogerator (0.9.1)
+    changelogerator (0.10.1)
       git_diff_parser (~> 3)
       octokit (~> 4)
     faraday (1.8.0)
@@ -70,7 +70,7 @@ PLATFORMS
   x86_64-darwin-22
 
 DEPENDENCIES
-  changelogerator (= 0.9.1)
+  changelogerator (= 0.10.1)
   git_diff_parser (~> 3)
   logger (~> 1.4)
   octokit (~> 4)
diff --git a/polkadot/scripts/ci/changelog/bin/changelog b/polkadot/scripts/ci/changelog/bin/changelog
index 6627502b25b..e642a448904 100755
--- a/polkadot/scripts/ci/changelog/bin/changelog
+++ b/polkadot/scripts/ci/changelog/bin/changelog
@@ -19,6 +19,9 @@ logger = Logger.new($stdout)
 logger.level = Logger::DEBUG
 logger.debug('Starting')
 
+changelogerator_version = `changelogerator --version`
+logger.debug(changelogerator_version)
+
 owner = 'paritytech'
 repo = 'polkadot'
 
diff --git a/polkadot/scripts/ci/changelog/templates/change.md.tera b/polkadot/scripts/ci/changelog/templates/change.md.tera
index 0cb23226cc4..cfde3be6e85 100644
--- a/polkadot/scripts/ci/changelog/templates/change.md.tera
+++ b/polkadot/scripts/ci/changelog/templates/change.md.tera
@@ -1,11 +1,11 @@
 {# This macro shows ONE change #}
 {%- macro change(c, cml="[C]", dot="[P]", sub="[S]") -%}
 
-{%- if c.meta.C and c.meta.C.value >= 7 -%}
+{%- if c.meta.C and c.meta.C.agg.max >= 7 -%}
 {%- set prio = " ‼️ HIGH" -%}
-{%- elif c.meta.C and c.meta.C.value >= 3 -%}
+{%- elif c.meta.C and c.meta.C.agg.max >= 3 -%}
 {%- set prio = " ❗️ Medium" -%}
-{%- elif c.meta.C and c.meta.C.value < 3 -%}
+{%- elif c.meta.C and c.meta.C.agg.max < 3 -%}
 {%- set prio = " Low" -%}
 {%- else -%}
 {%- set prio = "" -%}
@@ -13,13 +13,13 @@
 
 {%- set audit = "" -%}
 
-{%- if c.meta.D and c.meta.D.value == 1 -%}
+{%- if c.meta.D and c.meta.D.D1 -%}
 {%- set audit = "✅ audited " -%}
-{%- elif c.meta.D and c.meta.D.value == 2 -%}
+{%- elif c.meta.D and c.meta.D.D2 -%}
 {%- set audit = "✅ trivial " -%}
-{%- elif c.meta.D and c.meta.D.value == 3 -%}
+{%- elif c.meta.D and c.meta.D.D3 -%}
 {%- set audit = "✅ trivial " -%}
-{%- elif c.meta.D and c.meta.D.value == 5 -%}
+{%- elif c.meta.D and c.meta.D.D5 -%}
 {%- set audit = "⏳ pending non-critical audit " -%}
 {%- else -%}
 {%- set audit = "" -%}
@@ -33,7 +33,7 @@
 {%- set repo = "   " -%}
 {%- endif -%}
 
-{%- if c.meta.T and c.meta.T.value == 6 -%}
+{%- if c.meta.T and c.meta.T.T6 -%}
 {%- set xcm = " [✉️ XCM]" -%}
 {%- else -%}
 {%- set xcm = "" -%}
diff --git a/polkadot/scripts/ci/changelog/templates/changes_api.md.tera b/polkadot/scripts/ci/changelog/templates/changes_api.md.tera
index 0096065e43e..29e08b8cd38 100644
--- a/polkadot/scripts/ci/changelog/templates/changes_api.md.tera
+++ b/polkadot/scripts/ci/changelog/templates/changes_api.md.tera
@@ -5,14 +5,12 @@
 {%- for pr in changes | sort(attribute="merged_at") %}
 
 {%- if pr.meta.B %}
-    {%- if pr.meta.B.value == 0 %}
+    {%- if pr.meta.B.B0 %}
     {#- We skip silent ones -#}
     {%- else -%}
 
-        {%- if pr.meta.T and pr.meta.T.value == 2 and not pr.title is containing("ompanion") %}
+        {%- if pr.meta.T and pr.meta.T.T2 and not pr.title is containing("ompanion") %}
 - {{ m_c::change(c=pr) }}
-{%- else %}
-<!-- EXCLUDED PR#{{pr.number}} - {{pr.html_url}} -->
         {%- endif -%}
     {% endif -%}
     {% endif -%}
diff --git a/polkadot/scripts/ci/changelog/templates/changes_client.md.tera b/polkadot/scripts/ci/changelog/templates/changes_client.md.tera
index 20e7fe8fe7c..6d31961c365 100644
--- a/polkadot/scripts/ci/changelog/templates/changes_client.md.tera
+++ b/polkadot/scripts/ci/changelog/templates/changes_client.md.tera
@@ -5,14 +5,12 @@
 {%- for pr in changes | sort(attribute="merged_at") %}
 
 {%- if pr.meta.B %}
-    {%- if pr.meta.B.value == 0 %}
+    {%- if pr.meta.B.B0 %}
     {#- We skip silent ones -#}
     {%- else -%}
 
-        {%- if pr.meta.T and pr.meta.T.value == 0 and not pr.title is containing("ompanion") %}
+        {%- if pr.meta.T and pr.meta.T.T0 and not pr.title is containing("ompanion") %}
 - {{ m_c::change(c=pr) }}
-{%- else %}
-<!-- EXCLUDED PR#{{pr.number}} - {{pr.html_url}} -->
         {%- endif -%}
     {% endif -%}
     {% endif -%}
diff --git a/polkadot/scripts/ci/changelog/templates/changes_misc.md.tera b/polkadot/scripts/ci/changelog/templates/changes_misc.md.tera
index af38104f2db..725b03081eb 100644
--- a/polkadot/scripts/ci/changelog/templates/changes_misc.md.tera
+++ b/polkadot/scripts/ci/changelog/templates/changes_misc.md.tera
@@ -4,10 +4,10 @@
 {#- First pass to count #}
 {%- for pr in changes -%}
     {%- if pr.meta.B %}
-        {%- if pr.meta.B.value == 0 -%}
+        {%- if pr.meta.B.B0 -%}
         {#- We skip silent ones -#}
         {%- else -%}
-            {%- if pr.meta.T and pr.meta.T.value > 2   %}
+            {%- if pr.meta.T and pr.meta.T.agg.max > 2   %}
 {%- set_global misc_count = misc_count + 1 -%}
             {%- endif -%}
         {% endif -%}
@@ -26,10 +26,10 @@ There are other misc. changes. You can expand the list below to view them all.
 {#- The changes are sorted by merge date #}
 {%- for pr in changes | sort(attribute="merged_at") %}
     {%- if pr.meta.B and not pr.title is containing("ompanion") %}
-        {%- if pr.meta.B.value == 0 %}
+        {%- if pr.meta.B.B0 %}
         {#- We skip silent ones -#}
         {%- else -%}
-            {%- if pr.meta.T and pr.meta.T.value > 2   %}
+            {%- if pr.meta.T and pr.meta.T.agg.max > 2 %}
 - {{ m_c::change(c=pr) }}
             {%- endif -%}
         {% endif -%}
diff --git a/polkadot/scripts/ci/changelog/templates/changes_runtime.md.tera b/polkadot/scripts/ci/changelog/templates/changes_runtime.md.tera
index ccc44ef7852..bd126c0628c 100644
--- a/polkadot/scripts/ci/changelog/templates/changes_runtime.md.tera
+++ b/polkadot/scripts/ci/changelog/templates/changes_runtime.md.tera
@@ -6,14 +6,12 @@
 {% for pr in changes | sort(attribute="merged_at") -%}
 
 {%- if pr.meta.B -%}
-{%- if pr.meta.B.value == 0 -%}
+{%- if pr.meta.B.B0 -%}
 {#- We skip silent ones -#}
 {%- else -%}
 
-{%- if pr.meta.T and pr.meta.T.value == 1 and not pr.title is containing("ompanion") %}
+{%- if pr.meta.T and pr.meta.T.T1 and not pr.title is containing("ompanion") %}
 - {{ m_c::change(c=pr) }}
-{%- else %}
-<!-- EXCLUDED PR#{{pr.number}} - {{pr.html_url}} -->
 {%- endif -%}
 {%- endif -%}
 
diff --git a/polkadot/scripts/ci/changelog/templates/debug.md.tera b/polkadot/scripts/ci/changelog/templates/debug.md.tera
index 41f3702d7c0..8c829b09ffe 100644
--- a/polkadot/scripts/ci/changelog/templates/debug.md.tera
+++ b/polkadot/scripts/ci/changelog/templates/debug.md.tera
@@ -1,4 +1,4 @@
-{%- set to_ignore = changes | filter(attribute="meta.B.value", value=0) %}
+{%- set to_ignore = changes | filter(attribute="meta.B.B0") %}
 
 <!--
 changes:
diff --git a/polkadot/scripts/ci/changelog/templates/high_priority.md.tera b/polkadot/scripts/ci/changelog/templates/high_priority.md.tera
index aabc9f01f62..39938da44d1 100644
--- a/polkadot/scripts/ci/changelog/templates/high_priority.md.tera
+++ b/polkadot/scripts/ci/changelog/templates/high_priority.md.tera
@@ -23,9 +23,9 @@
 The changes motivating this priority level are:
 {% for pr in changes | sort(attribute="merged_at") -%}
     {%- if pr.meta.C -%}
-        {%- if pr.meta.C.value == p %}
+        {%- if pr.meta.C.agg.max >= p %}
 - {{ m_c::change(c=pr) }}
-{%- if pr.meta.T and pr.meta.T.value == 1 %} (RUNTIME)
+{%- if pr.meta.T and pr.meta.T.T1 %} (RUNTIME)
 {% endif %}
         {%- endif -%}
     {%- endif -%}
diff --git a/polkadot/scripts/ci/changelog/templates/host_functions.md.tera b/polkadot/scripts/ci/changelog/templates/host_functions.md.tera
index f47be913b2f..6d9d09a43da 100644
--- a/polkadot/scripts/ci/changelog/templates/host_functions.md.tera
+++ b/polkadot/scripts/ci/changelog/templates/host_functions.md.tera
@@ -3,10 +3,10 @@
 
 {% for pr in changes | sort(attribute="merged_at") -%}
 
-{%- if pr.meta.B and pr.meta.B.value == 0 -%}
+{%- if pr.meta.B and pr.meta.B.B0 -%}
 {#- We skip silent ones -#}
 {%- else -%}
-    {%- if pr.meta.E and pr.meta.E.value == 4 -%}
+    {%- if pr.meta.E and pr.meta.E.E4 -%}
         {%- set_global host_fn_count = host_fn_count + 1 -%}
             - {{ m_c::change(c=pr) }}
         {% endif -%}
diff --git a/polkadot/scripts/ci/changelog/templates/migrations-db.md.tera b/polkadot/scripts/ci/changelog/templates/migrations-db.md.tera
index 917073b2f26..f70914aa8ef 100644
--- a/polkadot/scripts/ci/changelog/templates/migrations-db.md.tera
+++ b/polkadot/scripts/ci/changelog/templates/migrations-db.md.tera
@@ -1,9 +1,9 @@
 {% import "change.md.tera" as m_c %}
 {%- set_global db_migration_count = 0 -%}
 {%- for pr in changes -%}
-    {%- if pr.meta.B and pr.meta.B.value == 0 %}
+    {%- if pr.meta.B and pr.meta.B.B0 %}
         {#- We skip silent ones -#}
-    {%- elif pr.meta.E and pr.meta.E.value == 2 -%}
+    {%- elif pr.meta.E and pr.meta.E.E2 -%}
         {%- set_global db_migration_count = db_migration_count + 1 -%}
     {%- endif -%}
 {%- endfor %}
@@ -22,9 +22,9 @@ Some migrations may break compatibility, making a backup of your database is hig
 {%- endif %}
 {% for pr in changes | sort(attribute="merged_at") -%}
 
-{%- if pr.meta.B and pr.meta.B.value == 0 %}
+{%- if pr.meta.B and pr.meta.B.B0 %}
 {#- We skip silent ones -#}
-{%- elif pr.meta.E and pr.meta.E.value == 2 -%}
+{%- elif pr.meta.E and pr.meta.E.E2 -%}
 - {{ m_c::change(c=pr) }}
 {% endif -%}
 {% endfor -%}
diff --git a/polkadot/scripts/ci/changelog/templates/migrations-runtime.md.tera b/polkadot/scripts/ci/changelog/templates/migrations-runtime.md.tera
index fda22d30b6e..1cd67f6cc56 100644
--- a/polkadot/scripts/ci/changelog/templates/migrations-runtime.md.tera
+++ b/polkadot/scripts/ci/changelog/templates/migrations-runtime.md.tera
@@ -1,9 +1,9 @@
 {%- import "change.md.tera" as m_c %}
 {%- set_global runtime_migration_count = 0 -%}
 {%- for pr in changes -%}
-    {%- if pr.meta.B and pr.meta.B.value == 0 %}
+    {%- if pr.meta.B and pr.meta.B.B0 %}
         {#- We skip silent ones -#}
-    {%- elif pr.meta.E and pr.meta.E.value == 1 -%}
+    {%- elif pr.meta.E and pr.meta.E.E1 -%}
         {%- set_global runtime_migration_count = runtime_migration_count + 1 -%}
     {%- endif -%}
 {%- endfor %}
@@ -21,9 +21,9 @@ Runtime migrations are operations running once during a runtime upgrade.
 {%- endif %}
 {% for pr in changes | sort(attribute="merged_at") -%}
 
-{%- if pr.meta.B and pr.meta.B.value == 0 %}
+{%- if pr.meta.B and pr.meta.B.B0 %}
 {#- We skip silent ones -#}
-{%- elif pr.meta.E and pr.meta.E.value == 1 -%}
+{%- elif pr.meta.E and pr.meta.E.E1 -%}
 - {{ m_c::change(c=pr) }}
 {% endif -%}
 {% endfor -%}
-- 
GitLab