[PATCH v2 3/4] tagging: use tag infrastructure to create tags in mboxes

vkabatov at redhat.com vkabatov at redhat.com
Tue Sep 18 03:05:11 AEST 2018


From: Veronika Kabatova <vkabatov at redhat.com>

Signed-off-by: Veronika Kabatova <vkabatov at redhat.com>
---
 patchwork/models.py                           | 12 ------------
 patchwork/tests/test_mboxviews.py             | 19 ++++++++++++++++---
 patchwork/views/utils.py                      |  9 ++++++---
 .../tagging-rework-9907e9dc3f835566.yaml      |  3 +++
 4 files changed, 25 insertions(+), 18 deletions(-)

diff --git a/patchwork/models.py b/patchwork/models.py
index 5caf7641..a7c75e63 100644
--- a/patchwork/models.py
+++ b/patchwork/models.py
@@ -284,18 +284,6 @@ class EmailMixin(models.Model):
     submitter = models.ForeignKey(Person, on_delete=models.CASCADE)
     content = models.TextField(null=True, blank=True)
 
-    response_re = re.compile(
-        r'^(Tested|Reviewed|Acked|Signed-off|Nacked|Reported)-by:.*$',
-        re.M | re.I)
-
-    @property
-    def patch_responses(self):
-        if not self.content:
-            return ''
-
-        return ''.join([match.group(0) + '\n' for match in
-                        self.response_re.finditer(self.content)])
-
     def _extract_tags(self, tags):
         found_tags = {}
         if not self.content:
diff --git a/patchwork/tests/test_mboxviews.py b/patchwork/tests/test_mboxviews.py
index 9d941bf8..f7be7b0e 100644
--- a/patchwork/tests/test_mboxviews.py
+++ b/patchwork/tests/test_mboxviews.py
@@ -36,9 +36,10 @@ from patchwork.tests.utils import create_user
 
 
 class MboxPatchResponseTest(TestCase):
-
     """Test that the mbox view appends the Acked-by from a patch comment."""
 
+    fixtures = ['default_tags']
+
     def setUp(self):
         self.project = create_project()
         self.person = create_person()
@@ -53,7 +54,9 @@ class MboxPatchResponseTest(TestCase):
             submitter=self.person,
             content='comment 2 text\nAcked-by: 2\n')
         response = self.client.get(reverse('patch-mbox', args=[patch.id]))
-        self.assertContains(response, 'Acked-by: 1\nAcked-by: 2\n')
+        # Can't guarantee the order in which the tags are returned
+        self.assertContains(response, 'Acked-by: 1\n')
+        self.assertContains(response, 'Acked-by: 2\n')
 
     def test_patch_utf8_nbsp(self):
         patch = create_patch(
@@ -73,6 +76,8 @@ class MboxPatchSplitResponseTest(TestCase):
     """Test that the mbox view appends the Acked-by from a patch comment,
        and places it before an '---' update line."""
 
+    fixtures = ['default_tags']
+
     def setUp(self):
         project = create_project()
         self.person = create_person()
@@ -88,7 +93,15 @@ class MboxPatchSplitResponseTest(TestCase):
 
     def test_patch_response(self):
         response = self.client.get(reverse('patch-mbox', args=[self.patch.id]))
-        self.assertContains(response, 'Acked-by: 1\nAcked-by: 2\n')
+        # Can't guarantee the order in which the tags are returned
+        self.assertContains(response, 'Acked-by: 1\n')
+        self.assertContains(response, 'Acked-by: 2\n')
+        # We need to check for 3 Acked-by strings, one comes from the body of
+        # the patch and the other two are the tags themselves.
+        self.assertRegex(
+            response.content.decode(),
+            '(?s).*Acked-by: 1\n.*Acked-by.*Acked-by.*---\nupdate.*'
+        )
 
 
 class MboxHeaderTest(TestCase):
diff --git a/patchwork/views/utils.py b/patchwork/views/utils.py
index 4644c621..0586265b 100644
--- a/patchwork/views/utils.py
+++ b/patchwork/views/utils.py
@@ -27,11 +27,13 @@ import email.utils
 import re
 
 from django.conf import settings
+from django.db.models import Q
 from django.http import Http404
 from django.utils import six
 
 from patchwork.models import Comment
 from patchwork.models import Patch
+from patchwork.models import SubmissionTag
 
 if settings.ENABLE_REST_API:
     from rest_framework.authtoken.models import Token
@@ -74,9 +76,10 @@ def _submission_to_mbox(submission):
     else:
         postscript = ''
 
-    # TODO(stephenfin): Make this use the tags infrastructure
-    for comment in Comment.objects.filter(submission=submission):
-        body += comment.patch_responses
+    for (tagname, value) in SubmissionTag.objects.filter(
+            Q(submission=submission) | Q(series=submission.series)
+    ).values_list('tag__name', 'value').distinct():
+        body += '%s: %s\n' % (tagname, value)
 
     if postscript:
         body += '---\n' + postscript + '\n'
diff --git a/releasenotes/notes/tagging-rework-9907e9dc3f835566.yaml b/releasenotes/notes/tagging-rework-9907e9dc3f835566.yaml
index fdfd39f0..7fd64184 100644
--- a/releasenotes/notes/tagging-rework-9907e9dc3f835566.yaml
+++ b/releasenotes/notes/tagging-rework-9907e9dc3f835566.yaml
@@ -24,3 +24,6 @@ upgrade:
     the actual tag data will be created by the command, to make the migration  
     itself faster. Please note that this will take a lot of time and based on  
     the size of the data in question, might be useful to run in batches.  
+other:
+  - |
+    The tagging feature is now used to populate tags in mbox files.
-- 
2.17.1



More information about the Patchwork mailing list