Commit fbf8b55e authored by Damien Lespiau's avatar Damien Lespiau
Browse files

project: Provide a setting to only consider git send-email patches



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: default avatarDamien Lespiau <damien.lespiau@intel.com>
parent fdb38127
......@@ -322,8 +322,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))
......
# -*- 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),
),
]
......@@ -61,6 +61,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
......
......@@ -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' +
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment