[yocto] [patchwork][PATCH] parsemail: Set patch state from email metadata

Jose Lamego jose.a.lamego at linux.intel.com
Tue Jan 24 10:21:52 PST 2017


Patch state can only be set/changed at patchwork web interface,
resulting in a poor user experience for project maintainers.

This change allows project maintainers to change a patch status
directly from an email message sent as a reply to the related mailing list
thread by including a the string "[Patchwork-Status: <new status>]"

[YOCTO #10624]

Signed-off-by: Jose Lamego <jose.a.lamego at linux.intel.com>
---
 patchwork/bin/parsemail.py | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/patchwork/bin/parsemail.py b/patchwork/bin/parsemail.py
index 1ce0cdf..eb92243 100755
--- a/patchwork/bin/parsemail.py
+++ b/patchwork/bin/parsemail.py
@@ -820,6 +820,37 @@ def parse_mail(mail):
         comment.save()
         LOGGER.debug('Comment saved')
 
+        # if comment's author has project-maintainer permissions,
+        # parse comment content and process the status-change command
+        # if it is found
+        if project in (author.user).profile.maintainer_projects.all():
+            cmd = None
+            comment_re = re.compile('^\[Patchwork-Status:\s*(Under Review|\
+Rejected|RFC|Not Applicable|Changes Requested|Awaiting Upstream|Superseded|\
+Deferred)\]$', re.M | re.I)
+            # if multiple valid status-change commands are found, use last one
+            for match in comment_re.finditer(comment.content):
+                cmd = re.sub(r'(\[Patchwork-Status:\s*)(.*)(\])', r'\2',
+                             "{}".format(match.group(0)))
+            if cmd is not None:
+                new_state = State.objects.get(name=cmd.title())
+                mod_patch = Patch.objects.get(pk=comment.patch.pk)
+                if new_state and mod_patch.state != new_state:
+                    mod_patch.state = new_state
+                    mod_patch.save()
+                    cmd_message = 'This is a system generated Comment: Patch \
+%s status was updated to "%s" due to request in comment.' % (
+                                  comment.patch.pk, cmd)
+                    cmd_msgid = "%s: System generated by comment %s" % (
+                                datetime.datetime.now().strftime("\
+%d%b%Y.%H:%M:%S.%f"), comment.pk)
+                    new_comment = Comment(pk=None, patch=comment.patch,
+                                          content=cmd_message,
+                                          date=datetime.datetime.now(),
+                                          submitter=comment.submitter,
+                                          msgid=cmd_msgid)
+                    new_comment.save()
+
     series_revision_complete.disconnect(on_revision_complete)
 
     return 0
-- 
1.9.1




More information about the yocto mailing list