@@ -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):
@@ -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):
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 <stephen@that.guru> --- 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(-)