diff mbox

[01/14] parsemail: Return the list of prefixes when cleaning up the subject

Message ID 1445378383-16977-2-git-send-email-damien.lespiau@intel.com
State Rejected
Headers show

Commit Message

Damien Lespiau Oct. 20, 2015, 9:59 p.m. UTC
The patch is a preparation step towards understanding series. It will be
handy to parse those prefixes, looking for 'x/n' to retrieve the order
of a patch in a series.

Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
Acked-by: Stephen Finucane <stephen.finucane@intel.com>
---
 patchwork/bin/parsemail.py          |  6 +++---
 patchwork/tests/test_patchparser.py | 34 +++++++++++++++++++---------------
 2 files changed, 22 insertions(+), 18 deletions(-)
diff mbox

Patch

diff --git a/patchwork/bin/parsemail.py b/patchwork/bin/parsemail.py
index c15564e..ae588f0 100755
--- a/patchwork/bin/parsemail.py
+++ b/patchwork/bin/parsemail.py
@@ -213,7 +213,8 @@  def find_content(project, mail):
     comment = None
 
     if pullurl or patchbuf:
-        name = clean_subject(mail.get('Subject'), [project.linkname])
+        (name, prefixes) = clean_subject(mail.get('Subject'),
+                                         [project.linkname])
         patch = Patch(name = name, pull_url = pullurl, content = patchbuf,
                     date = mail_date(mail), headers = mail_headers(mail))
 
@@ -287,7 +288,6 @@  def clean_subject(subject, drop_prefixes = None):
     in the subject. If drop_prefixes is provided, remove those too,
     comparing case-insensitively."""
 
-
     subject = clean_header(subject)
 
     if drop_prefixes is None:
@@ -320,7 +320,7 @@  def clean_subject(subject, drop_prefixes = None):
     if prefixes:
         subject = '[%s] %s' % (','.join(prefixes), subject)
 
-    return subject
+    return (subject, prefixes)
 
 sig_re = re.compile('^(-- |_+)\n.*', re.S | re.M)
 def clean_content(str):
diff --git a/patchwork/tests/test_patchparser.py b/patchwork/tests/test_patchparser.py
index a49bf9b..eb83220 100644
--- a/patchwork/tests/test_patchparser.py
+++ b/patchwork/tests/test_patchparser.py
@@ -594,26 +594,30 @@  class PrefixTest(TestCase):
 class SubjectTest(TestCase):
 
     def testCleanSubject(self):
-        self.assertEquals(clean_subject('meep'), 'meep')
-        self.assertEquals(clean_subject('Re: meep'), 'meep')
-        self.assertEquals(clean_subject('[PATCH] meep'), 'meep')
-        self.assertEquals(clean_subject('[PATCH] meep \n meep'), 'meep meep')
-        self.assertEquals(clean_subject('[PATCH RFC] meep'), '[RFC] meep')
-        self.assertEquals(clean_subject('[PATCH,RFC] meep'), '[RFC] meep')
-        self.assertEquals(clean_subject('[PATCH,1/2] meep'), '[1/2] meep')
+        self.assertEquals(clean_subject('meep'), ('meep', []))
+        self.assertEquals(clean_subject('Re: meep'), ('meep', []))
+        self.assertEquals(clean_subject('[PATCH] meep'), ('meep', []))
+        self.assertEquals(clean_subject("[PATCH] meep \n meep"),
+                                        ('meep meep', []))
+        self.assertEquals(clean_subject('[PATCH RFC] meep'),
+                                        ('[RFC] meep', ['RFC']))
+        self.assertEquals(clean_subject('[PATCH,RFC] meep'),
+                                        ('[RFC] meep', ['RFC']))
+        self.assertEquals(clean_subject('[PATCH,1/2] meep'),
+                                        ('[1/2] meep', ['1/2']))
         self.assertEquals(clean_subject('[PATCH RFC 1/2] meep'),
-                                            '[RFC,1/2] meep')
+                                        ('[RFC,1/2] meep', ['RFC', '1/2']))
         self.assertEquals(clean_subject('[PATCH] [RFC] meep'),
-                                            '[RFC] meep')
+                                        ('[RFC] meep', ['RFC']))
         self.assertEquals(clean_subject('[PATCH] [RFC,1/2] meep'),
-                                            '[RFC,1/2] meep')
+                                        ('[RFC,1/2] meep', ['RFC', '1/2']))
         self.assertEquals(clean_subject('[PATCH] [RFC] [1/2] meep'),
-                                            '[RFC,1/2] meep')
+                                        ('[RFC,1/2] meep', ['RFC', '1/2']))
         self.assertEquals(clean_subject('[PATCH] rewrite [a-z] regexes'),
-                                            'rewrite [a-z] regexes')
+                                        ('rewrite [a-z] regexes', []))
         self.assertEquals(clean_subject('[PATCH] [RFC] rewrite [a-z] regexes'),
-                                            '[RFC] rewrite [a-z] regexes')
+                                        ('[RFC] rewrite [a-z] regexes', ['RFC']))
         self.assertEquals(clean_subject('[foo] [bar] meep', ['foo']),
-                                            '[bar] meep')
+                                        ('[bar] meep', ['bar']))
         self.assertEquals(clean_subject('[FOO] [bar] meep', ['foo']),
-                                            '[bar] meep')
+                                        ('[bar] meep', ['bar']))