Commit 33f4ed4b authored by Damien Lespiau's avatar Damien Lespiau
Browse files

project: Allow multiple projects to share the same mailing list



I have the case where contributions for several git repositories are
sent to the same mailing-list. We really want to handle them separately
though, some of the repos have different maintainers for instance.

An easy way to solve that is to ask people to add a special tag in
subject prefix of patches. It's can even be sticky to a specific git
checkout with:

  $ git config format.subjectprefix "PATCH evdev"

So people don't have to remember to tag their submissions by hand.

Those tags are stripped out of the patch name because they are redundant
information with the project they are now in.
Signed-off-by: default avatarDamien Lespiau <damien.lespiau@intel.com>
parent 646c2522
......@@ -84,11 +84,33 @@ def find_project(mail):
listid = match.group(1)
try:
project = Project.objects.get(listid = listid)
# order_by will put projects with a blank subject_prefix_tags
# first
projects = Project.objects.filter(listid=listid).\
order_by('subject_prefix_tags')
if not projects:
break
except Project.DoesNotExist:
pass
# fast path for the common case
if len(projects) == 1:
project = projects[0]
break
(_, prefixes) = clean_subject(mail.get('Subject'))
catchall_project = None
if not projects[0].get_subject_prefix_tags():
catchall_project = projects[0]
for p in projects:
if not p.get_subject_prefix_tags():
continue
for prefix in prefixes:
if prefix in p.get_subject_prefix_tags():
project = p
if not project:
project = catchall_project
return project
......@@ -319,7 +341,8 @@ def find_content(project, mail):
ret = MailContent()
(name, prefixes) = clean_subject(mail.get('Subject'), [project.linkname])
drop_prefixes = [project.linkname] + project.get_subject_prefix_tags()
(name, prefixes) = clean_subject(mail.get('Subject'), drop_prefixes)
(x, n) = parse_series_marker(prefixes)
refs = build_references_list(mail)
is_root = refs == []
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('patchwork', '0006_eventlog_parameters'),
]
operations = [
migrations.AddField(
model_name='project',
name='subject_prefix_tags',
field=models.CharField(help_text=b'Comma separated list of tags', max_length=255, blank=True),
),
migrations.AlterField(
model_name='project',
name='listid',
field=models.CharField(max_length=255),
),
]
......@@ -59,7 +59,7 @@ class Person(models.Model):
class Project(models.Model):
linkname = models.CharField(max_length=255, unique=True)
name = models.CharField(max_length=255, unique=True)
listid = models.CharField(max_length=255, unique=True)
listid = models.CharField(max_length=255)
listemail = models.CharField(max_length=200)
web_url = models.CharField(max_length=2000, blank=True)
scm_url = models.CharField(max_length=2000, blank=True)
......@@ -67,6 +67,8 @@ class Project(models.Model):
send_notifications = models.BooleanField(default=False)
use_tags = models.BooleanField(default=True)
git_send_email_only = models.BooleanField(default=False)
subject_prefix_tags = models.CharField(max_length=255, blank=True,
help_text='Comma separated list of tags')
def __unicode__(self):
return self.name
......@@ -82,6 +84,11 @@ class Project(models.Model):
return []
return list(Tag.objects.all())
def get_subject_prefix_tags(self):
tags = [t.strip() for t in self.subject_prefix_tags.split(',')]
tags = [tag for tag in tags if tag]
return tags
class Meta:
ordering = ['linkname']
......
......@@ -371,6 +371,82 @@ class ListIdHeaderTest(TestCase):
def tearDown(self):
self.project.delete()
class MultipleProjectsPerMailingListTest(TestCase):
"""Do we handle hosting multiple projects on the same mailing-list?"""
fixtures = ['default_states', 'default_events']
def setUp(self):
self.project1 = Project(linkname='test-project-1', name='Project 1',
listid='list.example.com', listemail='1@example.com')
self.project1.save()
self.project2 = Project(linkname='test-project-2', name='Project 2',
listid='list.example.com', listemail='2@example.com')
self.project2.save()
def testTagList(self):
self.project1.subject_prefix_tags = ''
self.assertEquals(self.project1.get_subject_prefix_tags(), [])
self.project1.subject_prefix_tags = ' '
self.assertEquals(self.project1.get_subject_prefix_tags(), [])
self.project1.subject_prefix_tags = 'i-g-t'
self.assertEquals(self.project1.get_subject_prefix_tags(), ['i-g-t'])
self.project1.subject_prefix_tags = 'a,b'
self.assertEquals(self.project1.get_subject_prefix_tags(), ['a', 'b'])
self.project1.subject_prefix_tags = 'a, ,b,'
self.assertEquals(self.project1.get_subject_prefix_tags(), ['a', 'b'])
def testSingleTag(self):
self.project2.subject_prefix_tags = 'i-g-t'
self.project2.save()
email = create_email(defaults.patch, project=self.project1,
subject='[PATCH] Subject')
self.assertEquals(find_project(email), self.project1)
email = create_email(defaults.patch, project=self.project1,
subject='[PATCH i-g-t] Subject')
self.assertEquals(find_project(email), self.project2)
def testSingleTagInverted(self):
"""To test the order_by()"""
self.project1.subject_prefix_tags = 'i-g-t'
self.project1.save()
self.project2.subject_prefix_tags = ' '
self.project2.save()
email = create_email(defaults.patch, project=self.project1,
subject='[PATCH i-g-t] Subject')
self.assertEquals(find_project(email), self.project1)
email = create_email(defaults.patch, project=self.project1,
subject='[PATCH] Subject')
self.assertEquals(find_project(email), self.project2)
def testMultipleTags(self):
self.project2.subject_prefix_tags = 'i-g-t,intel-gpu-tools'
self.project2.save()
email = create_email(defaults.patch, project=self.project1,
subject='[PATCH] Subject')
self.assertEquals(find_project(email), self.project1)
email = create_email(defaults.patch, project=self.project1,
subject='[PATCH i-g-t] Subject')
self.assertEquals(find_project(email), self.project2)
email = create_email(defaults.patch, project=self.project1,
subject='[PATCH intel-gpu-tools] Subject')
self.assertEquals(find_project(email), self.project2)
def testStripTag(self):
self.project2.subject_prefix_tags = 'i-g-t'
self.project2.save()
email = create_email(defaults.patch, project=self.project1,
subject='[PATCH i-g-t] Subject')
parse_mail(email)
patch = Patch.objects.all()[0]
self.assertEquals(patch.name, 'Subject')
class MBoxPatchTest(PatchTest):
def setUp(self):
self.mail = read_mail(self.mail_file, project = self.project)
......
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