I've seen quite a few false positive, ie. mail with diffs in them (because people use diffs to illustrate an idea) were treated as patches.
One goal I have is to lower patchwork maintenance (ie limit the number of fixes we need to do by hand). That's a small improvement towards that direction. Signed-off-by: Damien Lespiau <[email protected]> --- patchwork/bin/parsemail.py | 5 ++- .../migrations/0004_project_git_send_email_only.py | 19 +++++++++++ patchwork/models.py | 1 + patchwork/tests/test_patchparser.py | 38 ++++++++++++++++++++++ 4 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 patchwork/migrations/0004_project_git_send_email_only.py diff --git a/patchwork/bin/parsemail.py b/patchwork/bin/parsemail.py index bba55c0..ba0b148 100755 --- a/patchwork/bin/parsemail.py +++ b/patchwork/bin/parsemail.py @@ -321,8 +321,11 @@ def find_content(project, mail): is_root = refs == [] is_cover_letter = is_root and x == 0 is_patch = patchbuf is not None + is_git_send_email = mail.get('X-Mailer', '').startswith('git-send-email ') - if pullurl or is_patch: + drop_patch = project.git_send_email_only and not is_git_send_email + + if pullurl or (is_patch and not drop_patch): ret.patch_order = x or 1 ret.patch = Patch(name = name, pull_url = pullurl, content = patchbuf, date = mail_date(mail), headers = mail_headers(mail)) diff --git a/patchwork/migrations/0004_project_git_send_email_only.py b/patchwork/migrations/0004_project_git_send_email_only.py new file mode 100644 index 0000000..5dc928a --- /dev/null +++ b/patchwork/migrations/0004_project_git_send_email_only.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('patchwork', '0003_series'), + ] + + operations = [ + migrations.AddField( + model_name='project', + name='git_send_email_only', + field=models.BooleanField(default=False), + ), + ] diff --git a/patchwork/models.py b/patchwork/models.py index aea0fd0..5df08f9 100644 --- a/patchwork/models.py +++ b/patchwork/models.py @@ -65,6 +65,7 @@ class Project(models.Model): webscm_url = models.CharField(max_length=2000, blank=True) send_notifications = models.BooleanField(default=False) use_tags = models.BooleanField(default=True) + git_send_email_only = models.BooleanField(default=False) def __unicode__(self): return self.name diff --git a/patchwork/tests/test_patchparser.py b/patchwork/tests/test_patchparser.py index 8905396..61fdd5a 100644 --- a/patchwork/tests/test_patchparser.py +++ b/patchwork/tests/test_patchparser.py @@ -595,6 +595,44 @@ class InitialPatchStateTest(MailFromPatchTest): parse_mail(email) self._assertState(self.default_state) +class GitSendEmailTest(MailFromPatchTest): + def _assertNPatches(self, n): + self.assertEquals(Patch.objects.count(), n) + + def testSettingOffGitSendEmail(self): + """git_send_email_only is false (default value) and email has been sent + with git send-email""" + email = self.get_email() + email['X-Mailer'] = 'git-send-email 1.8.3.1' + parse_mail(email) + self._assertNPatches(1) + + def testSettingOffNoGitSendEmail(self): + """git_send_email_only is false (default value) and email has not been + sent with git send-email""" + email = self.get_email() + parse_mail(email) + self._assertNPatches(1) + + def testSettingOnGitSendEmail(self): + """git_send_email_only is true and email has been sent with + git send-email""" + self.p1.git_send_email_only = True + self.p1.save() + email = self.get_email() + email['X-Mailer'] = 'git-send-email 1.8.3.1' + parse_mail(email) + self._assertNPatches(1) + + def testSettingOnNoGitSendEmail(self): + """git_send_email_only is true and email has been not sent with + git send-email""" + self.p1.git_send_email_only = True + self.p1.save() + email = self.get_email() + parse_mail(email) + self._assertNPatches(0) + class ParseInitialTagsTest(PatchTest): patch_filename = '0001-add-line.patch' test_comment = ('test comment\n\n' + -- 2.1.0 _______________________________________________ Patchwork mailing list [email protected] https://lists.ozlabs.org/listinfo/patchwork
