Patchwork Recognize mail headers for delegate and state

login
register
mail settings
Submitter Dirk Wallenstein
Date Jan. 26, 2011, 12:57 p.m.
Message ID <1296046625-25263-1-git-send-email-halsmit@t-online.de>
Download mbox | patch
Permalink /patch/80503/
State Superseded
Headers show

Comments

Dirk Wallenstein - Jan. 26, 2011, 12:57 p.m.
Introduce two new Patchwork mail headers that determine the initial
state and delegate of a patch.  They take a state name as displayed in
Patchwork and the email address of the wanted delegate.  An example:

X-Patchwork-State: Changes Requested
X-Patchwork-Delegate: maintainer@project.tld

Signed-off-by: Dirk Wallenstein <halsmit@t-online.de>
---

 apps/patchwork/bin/parsemail.py |   24 +++++++++++++++++++++++-
 1 files changed, 23 insertions(+), 1 deletions(-)
Wolfgang Denk - Jan. 26, 2011, 1:25 p.m.
Dear Dirk,

In message <1296046625-25263-1-git-send-email-halsmit@t-online.de> you wrote:
> Introduce two new Patchwork mail headers that determine the initial
> state and delegate of a patch.  They take a state name as displayed in
> Patchwork and the email address of the wanted delegate.  An example:
> 
> X-Patchwork-State: Changes Requested
> X-Patchwork-Delegate: maintainer@project.tld
> 
> Signed-off-by: Dirk Wallenstein <halsmit@t-online.de>

Cool! Thanks a lot!


Jeremy, any chance to test this in real life? If you need a guinea
pig I'm willing to sacrifice the U-Boot setup :-)

Best regards,

Wolfgang Denk

Patch

diff --git a/apps/patchwork/bin/parsemail.py b/apps/patchwork/bin/parsemail.py
index 1b73169..dbd4c3c 100755
--- a/apps/patchwork/bin/parsemail.py
+++ b/apps/patchwork/bin/parsemail.py
@@ -34,8 +34,10 @@  except ImportError:
     from email.Utils import parsedate_tz, mktime_tz
 
 from patchwork.parser import parse_patch
-from patchwork.models import Patch, Project, Person, Comment
+from patchwork.models import Patch, Project, Person, Comment, State
+from django.contrib.auth.models import User
 
+default_patch_state = 'New'
 list_id_headers = ['List-ID', 'X-Mailing-List', 'X-list']
 
 whitespace_re = re.compile('\s+')
@@ -346,6 +348,24 @@  def clean_content(str):
     str = sig_re.sub('', str)
     return str.strip()
 
+def get_state(state_name):
+    """ Return the state with the given name or the default State """
+    if state_name:
+        try:
+            return State.objects.get(name__iexact=state_name.strip())
+        except State.DoesNotExist:
+            pass
+    return State.objects.get(name=default_patch_state)
+
+def get_delegate(delegate_email):
+    """ Return the delegate with the given email or None """
+    if delegate_email:
+        try:
+            return User.objects.get(email__iexact=delegate_email.strip())
+        except User.DoesNotExist:
+            pass
+    return None
+
 def parse_mail(mail):
 
     # some basic sanity checks
@@ -381,6 +401,8 @@  def parse_mail(mail):
         patch.submitter = author
         patch.msgid = msgid
         patch.project = project
+        patch.state = get_state(mail.get('X-Patchwork-State'))
+        patch.delegate = get_delegate(mail.get('X-Patchwork-Delegate'))
         try:
             patch.save()
         except Exception, ex: