[PATCH 09/10] parsemail: Implement series linking
Stephen Finucane
stephen.finucane at intel.com
Mon Jun 13 20:41:41 AEST 2016
Signed-off-by: Stephen Finucane <stephen.finucane at intel.com>
---
patchwork/bin/parsemail.py | 54 ++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 54 insertions(+), 0 deletions(-)
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
--
1.7.4.1
More information about the Patchwork
mailing list