From 417907a8663b0d57879c9dbdeac24ad9fd64db67 Mon Sep 17 00:00:00 2001
From: Jan Pokorný <jpokorny@redhat.com>
Date: May 11 2016 13:49:47 +0000
Subject: [PATCH 1/7] releases: simplify commit message splitting, drop extraneous spaces


Signed-off-by: Jan Pokorný <jpokorny@redhat.com>

---

diff --git a/pagure/templates/releases.html b/pagure/templates/releases.html
index 77c41a7..576f5e7 100644
--- a/pagure/templates/releases.html
+++ b/pagure/templates/releases.html
@@ -42,9 +42,10 @@
         {% if tag['objecttype'] == "tag" %}
           {% if tag['object'].message %}
             <strong>{{tag['tagname']}}</strong>
-            {{ tag['object'].message.split('\n')[0] }}
-            {% set detailtext = tag['object'].message.partition('\n')[2] %}
-            {% if detailtext != "" %}
+            {% set msg_head_tail = tag['object'].message.split('\n', 1) %}
+            {{ msg_head_tail[0] }}
+            {% set detailtext = msg_head_tail.pop().strip() %}
+            {% if msg_head_tail and detailtext %}
             <div style="white-space:pre-wrap">
               {{ detailtext }}
             </div>

From 1dd7c2bc8f80f2614bf2ea2c1ff21a828af75618 Mon Sep 17 00:00:00 2001
From: Jan Pokorný <jpokorny@redhat.com>
Date: May 11 2016 13:49:47 +0000
Subject: [PATCH 2/7] releases: strip GPG signature from tag message if present


Signed-off-by: Jan Pokorný <jpokorny@redhat.com>

---

diff --git a/pagure/templates/releases.html b/pagure/templates/releases.html
index 576f5e7..2c68876 100644
--- a/pagure/templates/releases.html
+++ b/pagure/templates/releases.html
@@ -45,10 +45,13 @@
             {% set msg_head_tail = tag['object'].message.split('\n', 1) %}
             {{ msg_head_tail[0] }}
             {% set detailtext = msg_head_tail.pop().strip() %}
-            {% if msg_head_tail and detailtext %}
-            <div style="white-space:pre-wrap">
-              {{ detailtext }}
-            </div>
+            {% if msg_head_tail and detailtext.endswith('\n-----END PGP SIGNATURE-----') %}
+              {% set detailtext = detailtext.rsplit('\n-----BEGIN PGP SIGNATURE-----\n', 1)[0] %}
+              {% if detailtext %}
+              <div style="white-space:pre-wrap">
+                {{ detailtext }}
+              </div>
+              {% endif %}
             {% endif %}
           {% endif %}
         {% else %}

From 51db2f66d0235cf8afa715ab0815422735331220 Mon Sep 17 00:00:00 2001
From: Pierre-Yves Chibon <pingou@pingoured.fr>
Date: May 11 2016 14:08:30 +0000
Subject: [PATCH 3/7] Style fixes


---

diff --git a/pagure/templates/releases.html b/pagure/templates/releases.html
index 2c68876..b9d5fdb 100644
--- a/pagure/templates/releases.html
+++ b/pagure/templates/releases.html
@@ -24,8 +24,8 @@
 <p>
   If the developers have upload one or more tarball(s), you will be able to
   find them in the <a href="{{ config['APP_URL'] + config['UPLOAD_FOLDER'] + repo.fullname }}">
-    release folder
-  </a>.
+    release folder.
+  </a>
 </p>
 {% endif %}
 
@@ -37,7 +37,9 @@
                     username=username, repo=repo.name,
                     identifier=tag['object'].oid) }}">
         <div class="pull-xs-right">{{tag['date'] | humanize}}
-          <span id="tagid" class="label label-default">{{ tag['object'].oid | short }}</span>
+          <span id="tagid" class="label label-default">
+            {{ tag['object'].oid | short }}
+          </span>
         </div>
         {% if tag['objecttype'] == "tag" %}
           {% if tag['object'].message %}

From 223185210d89b3f0f376fe3036b9f93ee3df1fb1 Mon Sep 17 00:00:00 2001
From: Pierre-Yves Chibon <pingou@pingoured.fr>
Date: May 11 2016 14:08:57 +0000
Subject: [PATCH 4/7] Drop the ``.strip()`` which seems to have the opposite effect of what we want


---

diff --git a/pagure/templates/releases.html b/pagure/templates/releases.html
index b9d5fdb..f8a93a4 100644
--- a/pagure/templates/releases.html
+++ b/pagure/templates/releases.html
@@ -46,9 +46,11 @@
             <strong>{{tag['tagname']}}</strong>
             {% set msg_head_tail = tag['object'].message.split('\n', 1) %}
             {{ msg_head_tail[0] }}
-            {% set detailtext = msg_head_tail.pop().strip() %}
-            {% if msg_head_tail and detailtext.endswith('\n-----END PGP SIGNATURE-----') %}
-              {% set detailtext = detailtext.rsplit('\n-----BEGIN PGP SIGNATURE-----\n', 1)[0] %}
+            {% set detailtext = msg_head_tail.pop() %}
+            {% if msg_head_tail and detailtext.endswith(
+                '\n-----END PGP SIGNATURE-----') %}
+              {% set detailtext = detailtext.rsplit(
+                '\n-----BEGIN PGP SIGNATURE-----\n', 1)[0] %}
               {% if detailtext %}
               <div style="white-space:pre-wrap">
                 {{ detailtext }}

From e832e20845f3bdeb2629291a046d31655d5bec9a Mon Sep 17 00:00:00 2001
From: Pierre-Yves Chibon <pingou@pingoured.fr>
Date: May 11 2016 14:11:44 +0000
Subject: [PATCH 5/7] Use string.partition() to simplify the code


---

diff --git a/pagure/templates/releases.html b/pagure/templates/releases.html
index f8a93a4..98da74d 100644
--- a/pagure/templates/releases.html
+++ b/pagure/templates/releases.html
@@ -44,13 +44,13 @@
         {% if tag['objecttype'] == "tag" %}
           {% if tag['object'].message %}
             <strong>{{tag['tagname']}}</strong>
-            {% set msg_head_tail = tag['object'].message.split('\n', 1) %}
-            {{ msg_head_tail[0] }}
-            {% set detailtext = msg_head_tail.pop() %}
+            {% set msg_head_tail, _, detailtext = tag[
+                    'object'].message.partition('\n') %}
+            {{ msg_head_tail }}
             {% if msg_head_tail and detailtext.endswith(
                 '\n-----END PGP SIGNATURE-----') %}
               {% set detailtext = detailtext.rsplit(
-                '\n-----BEGIN PGP SIGNATURE-----\n', 1)[0] %}
+                '\n-----BEGIN PGP SIGNATURE-----', 1)[0] %}
               {% if detailtext %}
               <div style="white-space:pre-wrap">
                 {{ detailtext }}

From 0f5e8fdde75dadd508b77827d28158f5762fed0a Mon Sep 17 00:00:00 2001
From: Pierre-Yves Chibon <pingou@pingoured.fr>
Date: May 11 2016 14:42:21 +0000
Subject: [PATCH 6/7] Move the logic around splitting the message head/body inside the python code


---

diff --git a/pagure/lib/git.py b/pagure/lib/git.py
index b354a35..789317a 100644
--- a/pagure/lib/git.py
+++ b/pagure/lib/git.py
@@ -1261,11 +1261,18 @@ def get_git_tags_objects(project):
                 objecttype = "commit"
 
             tags[commit_time] = {
-                "object":repo_obj[repo_obj.lookup_reference(tag).target],
-                "tagname":tag.replace("refs/tags/",""),
-                "date":commit_time,
-                "objecttype": objecttype
-                }
+                "object": repo_obj[repo_obj.lookup_reference(tag).target],
+                "tagname": tag.replace("refs/tags/",""),
+                "date": commit_time,
+                "objecttype": objecttype,
+                "head_msg": None,
+                "body_msg": None,
+            }
+            if objecttype == 'tag':
+                head_msg, _, body_msg = tags[commit_time][
+                    "object"].message.partition('\n')
+                tags[commit_time]["head_msg"] = head_msg
+                tags[commit_time]["body_msg"] = body_msg
     sorted_tags = []
 
     for tag in sorted(tags, reverse=True):
diff --git a/pagure/templates/releases.html b/pagure/templates/releases.html
index 98da74d..2828925 100644
--- a/pagure/templates/releases.html
+++ b/pagure/templates/releases.html
@@ -44,12 +44,10 @@
         {% if tag['objecttype'] == "tag" %}
           {% if tag['object'].message %}
             <strong>{{tag['tagname']}}</strong>
-            {% set msg_head_tail, _, detailtext = tag[
-                    'object'].message.partition('\n') %}
-            {{ msg_head_tail }}
-            {% if msg_head_tail and detailtext.endswith(
+            {{ tag['head_msg'] }}
+            {% if tag['head_msg'] and tag['body_msg'].endswith(
                 '\n-----END PGP SIGNATURE-----') %}
-              {% set detailtext = detailtext.rsplit(
+              {% set detailtext = tag['body_msg'].rsplit(
                 '\n-----BEGIN PGP SIGNATURE-----', 1)[0] %}
               {% if detailtext %}
               <div style="white-space:pre-wrap">

From cc2fc7f308e5accdae67a550bc5a00b4a494c33c Mon Sep 17 00:00:00 2001
From: Pierre-Yves Chibon <pingou@pingoured.fr>
Date: May 11 2016 15:05:23 +0000
Subject: [PATCH 7/7] Strip the GPG signature in python directly, simplifies the template even more


---

diff --git a/pagure/lib/git.py b/pagure/lib/git.py
index 789317a..d8050ad 100644
--- a/pagure/lib/git.py
+++ b/pagure/lib/git.py
@@ -1271,6 +1271,9 @@ def get_git_tags_objects(project):
             if objecttype == 'tag':
                 head_msg, _, body_msg = tags[commit_time][
                     "object"].message.partition('\n')
+                if body_msg.strip().endswith('\n-----END PGP SIGNATURE-----'):
+                    body_msg = body_msg.rsplit(
+                        '-----BEGIN PGP SIGNATURE-----', 1)[0].strip()
                 tags[commit_time]["head_msg"] = head_msg
                 tags[commit_time]["body_msg"] = body_msg
     sorted_tags = []
diff --git a/pagure/templates/releases.html b/pagure/templates/releases.html
index 2828925..8c61d06 100644
--- a/pagure/templates/releases.html
+++ b/pagure/templates/releases.html
@@ -45,15 +45,10 @@
           {% if tag['object'].message %}
             <strong>{{tag['tagname']}}</strong>
             {{ tag['head_msg'] }}
-            {% if tag['head_msg'] and tag['body_msg'].endswith(
-                '\n-----END PGP SIGNATURE-----') %}
-              {% set detailtext = tag['body_msg'].rsplit(
-                '\n-----BEGIN PGP SIGNATURE-----', 1)[0] %}
-              {% if detailtext %}
-              <div style="white-space:pre-wrap">
-                {{ detailtext }}
-              </div>
-              {% endif %}
+            {% if tag['body_msg'] %}
+            <div style="white-space:pre-wrap">
+              {{ tag['body_msg'] }}
+            </div>
             {% endif %}
           {% endif %}
         {% else %}

