Commit ad3af96f authored by Arkadiusz Hiler's avatar Arkadiusz Hiler

parsemail: Support standalone cover letters

When a cover letter is sent as 0/0 it lands in series limbo due to
being in "incomplete" state.

Let's make it visible in the web UI and emit the completion events as
usual, but let's also display big notice what is going on.
Signed-off-by: default avatarArkadiusz Hiler <arkadiusz.hiler@intel.com>
parent de8706a2
......@@ -456,7 +456,12 @@ def find_content(project, mail, force_comment=False):
(ret.series, ret.revision, ret.patch_order, n) = \
find_series_for_mail(project, series_name, msgid, is_patch,
ret.patch_order, n, refs)
ret.revision.n_patches = n or 1
# assume solo patch
if n is None:
n = 1
ret.revision.n_patches = n
date = mail_date(mail)
if not ret.series.submitted or date < ret.series.submitted:
......
......@@ -643,6 +643,20 @@ class SeriesRevision(models.Model):
unique_together = [('series', 'version')]
ordering = ['version']
def save(self):
if self.pk is None:
new = True
else:
new = False
super(SeriesRevision, self).save()
if new and self.patches_count == self.n_patches:
self.completed = datetime.datetime.now()
self.state = RevisionState.INITIAL
super(SeriesRevision, self).save()
series_revision_complete.send(sender=self.__class__, revision=self)
def ordered_patches(self):
return self.patches.order_by('seriesrevisionpatch__order')
......
......@@ -203,6 +203,12 @@ $(document).ready(function() {
</div>
{% endif %}
{% if revision.n_patches == 0 %}
<div class="alert alert-info">
<strong>THIS SERIES IS A JUST COVER LETTER.</strong> Cover letter was sent as 0/0, no patches.
</div>
{% endif %}
{% if revision.is_rerun %}
<div class="alert alert-info">
<strong>THIS SERIES REVISION IS A RERUN.</strong> Please don't overuse the "test again" button.
......
......@@ -28,7 +28,7 @@ from patchwork.bin.parsemail import (find_content, find_author, find_project,
mail_headers, parse_mail, split_prefixes,
clean_subject, parse_series_marker)
from patchwork.models import (Project, Person, Patch, Comment, State, EventLog,
Event, SeriesRevision,
Event, SeriesRevision, Series, RevisionState,
get_default_initial_patch_state)
from patchwork.tests.utils import (read_patch, read_mail, create_email,
defaults, create_user, classproperty)
......@@ -1012,6 +1012,35 @@ class ParseInitialTagsTest(PatchTest):
tag__name='Tested-by').count, 1)
class StandaloneCoverLetter(TestCase):
fixtures = ['default_states', 'default_events']
def setUp(self):
self.p = Project(linkname='test-project-1', name='Project 1',
listid='1.example.com', listemail='1@example.com')
self.p.save()
self.coverletter = create_email("nothing special here",
subject="[PATCH 0/0] Cover Letter]")
del self.coverletter['List-ID']
self.coverletter['List-ID'] = '<' + self.p.listid + '>'
def testParseCover(self):
parse_mail(self.coverletter)
series = Series.objects.get(project=self.p)
revision = series.revisions()[0]
self.assertTrue(revision.is_complete)
self.assertEqual(0, revision.n_patches)
self.assertEqual(0, revision.patches_count)
self.assertEqual(RevisionState.INITIAL, revision.state)
self.assertEqual(revision, series.latest_revision())
event = EventLog.objects.get(series=series)
self.assertEqual('series-new-revision', event.event.name)
class ReplyPatchTest(TestCase):
""" Test that replies to patches are handed correctly """
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment