[PATCH v2 02/11] parsemail: Extract prefixes from subject
Stephen Finucane
stephen.finucane at intel.com
Sat Apr 2 01:57:38 AEDT 2016
From: Damien Lespiau <damien.lespiau at intel.com>
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 at intel.com>
Signed-off-by: Stephen Finucane <stephen.finucane at intel.com>
---
patchwork/bin/parsemail.py | 5 +++--
patchwork/tests/test_patchparser.py | 34 +++++++++++++++++++---------------
2 files changed, 22 insertions(+), 17 deletions(-)
diff --git a/patchwork/bin/parsemail.py b/patchwork/bin/parsemail.py
index 3c5ca37..f405f6b 100755
--- a/patchwork/bin/parsemail.py
+++ b/patchwork/bin/parsemail.py
@@ -256,7 +256,8 @@ def find_content(project, mail):
filenames = patch_get_filenames(patchbuf)
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, diff=patchbuf,
content=clean_content(commentbuf), date=mail_date(mail),
headers=mail_headers(mail))
@@ -362,7 +363,7 @@ def clean_subject(subject, drop_prefixes=None):
if prefixes:
subject = '[%s] %s' % (','.join(prefixes), subject)
- return subject
+ return (subject, prefixes)
def clean_content(content):
diff --git a/patchwork/tests/test_patchparser.py b/patchwork/tests/test_patchparser.py
index 760341c..06a2598 100644
--- a/patchwork/tests/test_patchparser.py
+++ b/patchwork/tests/test_patchparser.py
@@ -648,26 +648,30 @@ class PrefixTest(TestCase):
class SubjectTest(TestCase):
def testCleanSubject(self):
- self.assertEqual(clean_subject('meep'), 'meep')
- self.assertEqual(clean_subject('Re: meep'), 'meep')
- self.assertEqual(clean_subject('[PATCH] meep'), 'meep')
- self.assertEqual(clean_subject('[PATCH] meep \n meep'), 'meep meep')
- self.assertEqual(clean_subject('[PATCH RFC] meep'), '[RFC] meep')
- self.assertEqual(clean_subject('[PATCH,RFC] meep'), '[RFC] meep')
- self.assertEqual(clean_subject('[PATCH,1/2] meep'), '[1/2] meep')
+ self.assertEqual(clean_subject('meep'), ('meep', []))
+ self.assertEqual(clean_subject('Re: meep'), ('meep', []))
+ self.assertEqual(clean_subject('[PATCH] meep'), ('meep', []))
+ self.assertEqual(clean_subject("[PATCH] meep \n meep"),
+ ('meep meep', []))
+ self.assertEqual(clean_subject('[PATCH RFC] meep'),
+ ('[RFC] meep', ['RFC']))
+ self.assertEqual(clean_subject('[PATCH,RFC] meep'),
+ ('[RFC] meep', ['RFC']))
+ self.assertEqual(clean_subject('[PATCH,1/2] meep'),
+ ('[1/2] meep', ['1/2']))
self.assertEqual(clean_subject('[PATCH RFC 1/2] meep'),
- '[RFC,1/2] meep')
+ ('[RFC,1/2] meep', ['RFC', '1/2']))
self.assertEqual(clean_subject('[PATCH] [RFC] meep'),
- '[RFC] meep')
+ ('[RFC] meep', ['RFC']))
self.assertEqual(clean_subject('[PATCH] [RFC,1/2] meep'),
- '[RFC,1/2] meep')
+ ('[RFC,1/2] meep', ['RFC', '1/2']))
self.assertEqual(clean_subject('[PATCH] [RFC] [1/2] meep'),
- '[RFC,1/2] meep')
+ ('[RFC,1/2] meep', ['RFC', '1/2']))
self.assertEqual(clean_subject('[PATCH] rewrite [a-z] regexes'),
- 'rewrite [a-z] regexes')
+ ('rewrite [a-z] regexes', []))
self.assertEqual(clean_subject('[PATCH] [RFC] rewrite [a-z] regexes'),
- '[RFC] rewrite [a-z] regexes')
+ ('[RFC] rewrite [a-z] regexes', ['RFC']))
self.assertEqual(clean_subject('[foo] [bar] meep', ['foo']),
- '[bar] meep')
+ ('[bar] meep', ['bar']))
self.assertEqual(clean_subject('[FOO] [bar] meep', ['foo']),
- '[bar] meep')
+ ('[bar] meep', ['bar']))
--
2.0.0
More information about the Patchwork
mailing list