diff mbox

[09/10] parsemail: Implement series linking

Message ID 1465814502-14108-10-git-send-email-stephen.finucane@intel.com
State Superseded
Headers show

Commit Message

Stephen Finucane June 13, 2016, 10:41 a.m. UTC
Signed-off-by: Stephen Finucane <stephen.finucane@intel.com>
---
 patchwork/bin/parsemail.py |   54 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 54 insertions(+), 0 deletions(-)

Comments

Andy Doan June 23, 2016, 6:27 p.m. UTC | #1
On 06/13/2016 05:41 AM, Stephen Finucane wrote:
> Signed-off-by: Stephen Finucane <stephen.finucane@intel.com>

Reviewed-by: Andy Doan <andy.doan@linaro.org>
Stephen Finucane June 23, 2016, 10:03 p.m. UTC | #2
On 23 Jun 13:27, Andy Doan wrote:
> On 06/13/2016 05:41 AM, Stephen Finucane wrote:
> >Signed-off-by: Stephen Finucane <stephen.finucane@intel.com>
> 
> Reviewed-by: Andy Doan <andy.doan@linaro.org>

I've actually found this yields a little too many false positives:
turns out that patches with the same name are more common than you'd
think. I'm going to drop this from this series and work on it for a
different series. Would appreciate input here when we come around to
it.

Stephen
diff mbox

Patch

diff --git a/patchwork/bin/parsemail.py b/patchwork/bin/parsemail.py
index ddcd9e7..f48b7ef 100755
--- a/patchwork/bin/parsemail.py
+++ b/patchwork/bin/parsemail.py
@@ -50,6 +50,7 @@  from patchwork.models import get_default_initial_patch_state
 from patchwork.models import Patch
 from patchwork.models import Person
 from patchwork.models import Project
+from patchwork.models import Series
 from patchwork.models import SeriesRevision
 from patchwork.models import SeriesReference
 from patchwork.models import State
@@ -151,6 +152,55 @@  def find_series(mail):
     return series
 
 
+def link_series(obj):
+    """Find related series and link with provided series.
+
+    Attempts to find one or more related series for the given series.
+    If successful, all series will be linked together via a series
+    group; if one of the related series is already assigned to a series
+    group then said group will be used, else a new series group will be
+    created.
+
+    NOTE(stephenfin) At the moment this comparison takes place by
+    comparing the subjects of patches and/or cover letters in the new
+    series with those of existing series. This handles most cases as
+    (a) a series revision in which _all_ patch subjects have changed
+    can be effectively seen as a new, unrelated series and (b) a user
+    who sends a new revision of a _single_ patch from a series with a
+    changed subject is making life hard for reviewers (where the
+    context?) and can be ignored. The only case this doesn't handle is
+    a single patch being resent with a typo fix in the subject line. A
+    string comparison with threshold could be useful if this proves to
+    be problematic.
+
+    Args:
+        obj: A series-associated CoverLetter or Patch to use for
+            finding related series
+
+    Returns:
+        None
+    """
+    if not obj.series:
+        return
+
+    model = type(obj)
+    related_objs = model.objects.filter(name=obj.name).exclude(id=obj.id)
+    if related_objs:
+        # all related cover letters/patches _should_ share the same
+        # series, so take the first one
+        related_series = related_objs[0].series
+        if related_series.group:
+            group = related_series.group
+        else:
+            group = Series()
+            group.save()
+            related_series.group = group
+            related_series.save()
+
+        obj.series.group = group
+        obj.series.save()
+
+
 def find_author(mail):
 
     from_header = clean_header(mail.get('From'))
@@ -599,6 +649,8 @@  def parse_mail(mail, list_id=None):
         patch.save()
         LOGGER.debug('Patch saved')
 
+        link_series(patch)
+
         return patch
     elif x == 0:  # (potential) cover letters
         # if refs are empty, it's implicitly a cover letter. If not,
@@ -645,6 +697,8 @@  def parse_mail(mail, list_id=None):
             cover_letter.save()
             LOGGER.debug('Cover letter saved')
 
+            link_series(cover_letter)
+
             return cover_letter
 
     # comments