diff mbox

Add support for stripping a subject prefix that's different from linkname

Message ID 1290769056-25560-1-git-send-email-sascha-pgp@silbe.org
State Changes Requested
Headers show

Commit Message

Sascha Silbe Nov. 26, 2010, 10:57 a.m. UTC
Strip off Project.subjectprefix from the subject of incoming patches.
Will fall back to Project.linkname if subjectprefix is unset or empty.

At Sugar Labs, we have a mailing list called sugar-devel (using its name
as subject prefix) where patches for several repositories get sent to,
including sugar and sugar-toolkit. In order to distinguish between the
repositories, patch submitters include the repository name as a subject
prefix (e.g. "[PATCH v2 sugar]"). Since the link name for the project
is set to just "sugar", Patchwork would leave the list prefix
([sugar-devel]) as part of the patch name, but remove the repository
name (... sugar]). By allowing to override the subject prefix, we can
get Patchwork to strip the list name and leave the repository name
alone.

Signed-off-by: Sascha Silbe <sascha-pgp@silbe.org>
---
 apps/patchwork/bin/parsemail.py                 |    3 ++-
 apps/patchwork/models.py                        |    1 +
 lib/sql/migration/007-project-subjectprefix.sql |    3 +++
 3 files changed, 6 insertions(+), 1 deletions(-)

Comments

Jeremy Kerr Dec. 10, 2010, 4:04 a.m. UTC | #1
Hi Sascha,

> Strip off Project.subjectprefix from the subject of incoming patches.
> Will fall back to Project.linkname if subjectprefix is unset or empty.

Looks good. Do you think a regex would be more adaptable, or would that be 
overkill?

Could you include a change to the testsuite too? Since I'm not using the 
feature myself, I probably won't notice if I accidentally break it :)

Cheers,


Jeremy
Sascha Silbe Feb. 11, 2011, 1:21 p.m. UTC | #2
Excerpts from Jeremy Kerr's message of Fri Dec 10 05:04:16 +0100 2010:

> > Strip off Project.subjectprefix from the subject of incoming patches.
> > Will fall back to Project.linkname if subjectprefix is unset or empty.
> 
> Looks good. Do you think a regex would be more adaptable, or would that be 
> overkill?

I've thought about this a bit some time ago. A regular expression
subject rewriting rule might indeed be useful in some cases.

However, I currently need to focus on other projects, so I don't know
when I'll have time to work on this (including the test cases).

Sascha
diff mbox

Patch

diff --git a/apps/patchwork/bin/parsemail.py b/apps/patchwork/bin/parsemail.py
index 68bd94c..2e70e9a 100755
--- a/apps/patchwork/bin/parsemail.py
+++ b/apps/patchwork/bin/parsemail.py
@@ -171,7 +171,8 @@  def find_content(project, mail):
 
     if patchbuf:
         mail_headers(mail)
-	name = clean_subject(mail.get('Subject'), [project.linkname])
+        prefixes = [project.subjectprefix or project.linkname]
+        name = clean_subject(mail.get('Subject'), prefixes)
         patch = Patch(name = name, content = patchbuf,
                     date = mail_date(mail), headers = mail_headers(mail))
 
diff --git a/apps/patchwork/models.py b/apps/patchwork/models.py
index 7653e6c..7e96a7c 100644
--- a/apps/patchwork/models.py
+++ b/apps/patchwork/models.py
@@ -64,6 +64,7 @@  class Project(models.Model):
     name = models.CharField(max_length=255, unique=True)
     listid = models.CharField(max_length=255, unique=True)
     listemail = models.CharField(max_length=200)
+    subjectprefix = models.CharField(max_length=255, null=True, blank=True)
 
     def __str__(self):
         return self.name
diff --git a/lib/sql/migration/007-project-subjectprefix.sql b/lib/sql/migration/007-project-subjectprefix.sql
new file mode 100644
index 0000000..c02102f
--- /dev/null
+++ b/lib/sql/migration/007-project-subjectprefix.sql
@@ -0,0 +1,3 @@ 
+BEGIN;
+ALTER TABLE patchwork_project ADD COLUMN subjectprefix varchar(255) NULL;
+COMMIT;