From patchwork Sun Oct 14 12:45:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Finucane X-Patchwork-Id: 983718 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42Y1bC5qztz9s8F for ; Sun, 14 Oct 2018 23:48:39 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="BF86LLlS"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42Y1bC3rFgzF35J for ; Sun, 14 Oct 2018 23:48:39 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: lists.ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="BF86LLlS"; dkim-atps=neutral X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=that.guru (client-ip=185.234.75.13; helo=relay013.mxrelay.co; envelope-from=stephen@that.guru; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: lists.ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="BF86LLlS"; dkim-atps=neutral Received: from relay013.mxrelay.co (relay013.mxrelay.co [185.234.75.13]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42Y1YQ52fnzDsRY for ; Sun, 14 Oct 2018 23:47:06 +1100 (AEDT) Received: from filter002.mxroute.com (unknown [185.133.192.179]) by relay013.mxrelay.co (Postfix) with ESMTP id 2EE9142DF8; Sun, 14 Oct 2018 12:46:34 +0000 (UTC) Received: from one.mxroute.com (one.mxroute.com [195.201.59.211]) by filter002.mxroute.com (Postfix) with ESMTPS id F18E83F051; Sun, 14 Oct 2018 12:46:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=that.guru; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=yt42b0iHbDkHNY3QVZWbvpYCp6p0WoXM3iQs4Ehr6PY=; b=BF86LLlSxGjtdWhlkd00GOpjqA +9TM6sFOqb8NC45sm/zBqehPKFn5D2cYfzC5kOP6AyWAtVp89WDRf3rk5iAThJFlLyhOqMcV6BLYT MskwMSJQ2dIhb7ToKRTBj4lIaqQYtYih7Ox4O3/G6x5aXcIKEQxIyvg2aEId/3DLMAbUxhYIQWx7a gpPUR3Mggq5p2mr8JELiPxTIiKj72YQ+HtKNY54bfH7I03wCkCXISN+qfexls4KEfRx7rdia1y1lt 8mnmilcOzFfLdfDidRdL9jHS/o5iQ/wQbKvXhpOizGJh5jtMu+YRhKQ2VveDO5QQytcu8nCenIlNm Ca5tlluw==; From: Stephen Finucane To: patchwork@lists.ozlabs.org Subject: [PATCH v2 04/10] parser: Remove matching label from subject prefixes Date: Sun, 14 Oct 2018 13:45:35 +0100 Message-Id: <20181014124541.13393-5-stephen@that.guru> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181014124541.13393-1-stephen@that.guru> References: <20181014124541.13393-1-stephen@that.guru> X-AuthUser: stephen@that.guru X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mpe@ellerman.id.au, andrew.donnellan@au1.ibm.com MIME-Version: 1.0 Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" Extend the parser to strip the label from the list of prefixes. This means we don't duplicate things twice in the UI. Signed-off-by: Stephen Finucane --- I'm not 100% sure about this which is why I've kept it separate. On one hand, it doesn't make sense to duplicate things like this. On another, not every label is something we'd want to parse from the subject line and it makes prefixes in the UI kind of useless. Perhaps we should add a 'Label.parseable' flag? --- patchwork/parser.py | 9 +++++++-- patchwork/tests/test_parser.py | 19 +++++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/patchwork/parser.py b/patchwork/parser.py index 8c5106c9..9393a062 100644 --- a/patchwork/parser.py +++ b/patchwork/parser.py @@ -498,8 +498,13 @@ def parse_labels(subject_prefixes, project): Args: subject_prefixes: List of subject prefixes to extract tags from """ - return Label.objects.filter(Q(project=project) | Q(project=None), - name__in=subject_prefixes) + labels = Label.objects.filter(Q(project=project) | Q(project=None), + name__in=subject_prefixes) + for label in labels: + if label.name in subject_prefixes: + subject_prefixes.remove(label.name) + + return labels def _find_content(mail): diff --git a/patchwork/tests/test_parser.py b/patchwork/tests/test_parser.py index 9a4066fe..39f40d56 100644 --- a/patchwork/tests/test_parser.py +++ b/patchwork/tests/test_parser.py @@ -905,16 +905,23 @@ class SubjectTest(TestCase): def test_labels(self): label = create_label(name='RFC') - self.assertEqual(list(parse_labels(['RFC'], label.project)), [label]) - self.assertEqual(list(parse_labels(['rfcx'], label.project)), []) + prefixes = ['RFC'] + self.assertEqual(list(parse_labels(prefixes, label.project)), [label]) + self.assertEqual(prefixes, []) - project = create_project() + prefixes = ['rfcx'] + self.assertEqual(list(parse_labels(prefixes, label.project)), []) + self.assertEqual(prefixes, ['rfcx']) - self.assertEqual(list(parse_labels(['RFC'], project)), []) + project = create_project() + prefixes = ['RFC'] + self.assertEqual(list(parse_labels(prefixes, project)), []) + self.assertEqual(prefixes, ['RFC']) label = create_label(name='stuff', project=None) - - self.assertEqual(list(parse_labels(['stuff'], project)), [label]) + prefixes = ['stuff'] + self.assertEqual(list(parse_labels(prefixes, project)), [label]) + self.assertEqual(prefixes, []]) class SubjectMatchTest(TestCase):