Commit 148f1011 authored by Arkadiusz Hiler's avatar Arkadiusz Hiler

parsemail: Add support for "comment" hint

This makes email with the header "X-Patchwork-Hint: comment" not being
recognized as a patch.

This is useful when replying with diff-like contents, so no new revision
will be created accidentally.
Signed-off-by: Arkadiusz Hiler's avatarArkadiusz Hiler <arkadiusz.hiler@intel.com>
parent 4481117e
......@@ -332,7 +332,7 @@ def is_git_send_email(mail):
'git-send-email' in mail.get('Message-ID', '')
def find_content(project, mail):
def find_content(project, mail, force_comment=False):
patchbuf = None
commentbuf = ''
pullurl = None
......@@ -389,6 +389,9 @@ def find_content(project, mail):
if c is not None:
commentbuf += c.strip() + '\n'
if force_comment:
patchbuf = None
ret = MailContent()
drop_prefixes = [project.linkname, project.get_listemail_tag()]
......@@ -762,7 +765,8 @@ def parse_mail(mail):
(author, save_required) = find_author(mail)
content = find_content(project, mail)
force_comment = (hint == "comment")
content = find_content(project, mail, force_comment)
if not content:
return 0
patch = content.patch
......
......@@ -27,7 +27,8 @@ from patchwork.bin.parsemail import (find_content, find_author, find_project,
parse_mail, split_prefixes, clean_subject,
parse_series_marker)
from patchwork.models import (Project, Person, Patch, Comment, State, EventLog,
Event, get_default_initial_patch_state)
Event, SeriesRevision,
get_default_initial_patch_state)
from patchwork.tests.utils import (read_patch, read_mail, create_email,
defaults, create_user)
......@@ -877,6 +878,68 @@ class ParseInitialTagsTest(PatchTest):
tag__name='Tested-by').count, 1)
class ReplyPatchTest(TestCase):
""" Test that replies to patches are handed correctly """
fixtures = ['default_states', 'default_events']
test_comment = 'Test Comment'
patch_filename = '0001-add-line.patch'
def setUp(self):
self.p = Project(linkname='test-project-1', name='Project 1',
listid='1.example.com', listemail='1@example.com')
self.p.save()
patch = read_patch(self.patch_filename)
patch1 = create_email(self.test_comment + '\n' + patch,
subject="[PATCH 1/2] Meep Meep]")
patch2 = create_email(self.test_comment + '\n' + patch,
subject="[PATCH 2/2] Meep Meep2]",
in_reply_to=patch1['Message-Id'])
self.patch_update = create_email(self.test_comment + '\n' + patch,
subject="[PATCH v2] Meep Meep2",
in_reply_to=patch2['Message-Id'])
self.comment = create_email(self.test_comment,
subject="Re: [PATCH] Meep Meep2",
in_reply_to=patch2['Message-Id'])
for email in [patch1, patch2, self.patch_update, self.comment]:
del email['List-ID']
email['List-ID'] = '<' + self.p.listid + '>'
parse_mail(patch1)
parse_mail(patch2)
def testPatchUpdateShouldCreateNewRevision(self):
revisions_num = SeriesRevision.objects.count()
parse_mail(self.patch_update)
self.assertEqual(revisions_num + 1, SeriesRevision.objects.count())
def testHintedCommentShouldNOTCreateNewRevision(self):
revisions_num = SeriesRevision.objects.count()
self.patch_update['X-Patchwork-Hint'] = 'comment'
parse_mail(self.patch_update)
self.assertEqual(revisions_num, SeriesRevision.objects.count())
def testNormalCommentShouldNOTCreateNewRevision(self):
revisions_num = SeriesRevision.objects.count()
parse_mail(self.comment)
self.assertEqual(revisions_num, SeriesRevision.objects.count())
def tearDown(self):
self.p.delete()
class PrefixTest(TestCase):
def testSplitPrefixes(self):
......
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