← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~linaro-infrastructure/launchpad/fix-work-item-brackets into lp:launchpad

 

Mattias Backman has proposed merging lp:~linaro-infrastructure/launchpad/fix-work-item-brackets into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #954996 in Launchpad itself: "Explicitly assigned work items cannot contain an ending square bracket"
  https://bugs.launchpad.net/launchpad/+bug/954996

For more details, see:
https://code.launchpad.net/~linaro-infrastructure/launchpad/fix-work-item-brackets/+merge/97584

This branch makes the work items parsing handle assigned work items that have square brackets in the title. 

The problem was fixed by making the parse regexp not greedy.
-- 
https://code.launchpad.net/~linaro-infrastructure/launchpad/fix-work-item-brackets/+merge/97584
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~linaro-infrastructure/launchpad/fix-work-item-brackets into lp:launchpad.
=== modified file 'lib/lp/services/fields/__init__.py'
--- lib/lp/services/fields/__init__.py	2012-03-08 14:18:12 +0000
+++ lib/lp/services/fields/__init__.py	2012-03-15 08:37:21 +0000
@@ -114,7 +114,7 @@
 MILESTONE_RE = re.compile('^work items(.*)\s*:\s*$', re.I)
 # Regexp for work items.
 WORKITEM_RE = re.compile(
-    '^(\[(?P<assignee>.*)\])?\s*(?P<title>.*)\s*:\s*(?P<status>.*)\s*$', re.I)
+    '^(\[(?P<assignee>.*?)\])?\s*(?P<title>.*)\s*:\s*(?P<status>.*)\s*$', re.I)
 
 
 # Field Interfaces

=== modified file 'lib/lp/services/fields/tests/test_fields.py'
--- lib/lp/services/fields/tests/test_fields.py	2012-03-08 14:18:12 +0000
+++ lib/lp/services/fields/tests/test_fields.py	2012-03-15 08:37:21 +0000
@@ -244,6 +244,42 @@
             LaunchpadValidationError, self.field.parseLine,
             '[test-person] :TODO')
 
+    def test_assignee_and_bracket(self):
+        title = "Work item with one ] bracket"
+        work_items_text = ("Work items:\n"
+                           "[person] %s: TODO" % title)
+        parsed = self.field.parse(work_items_text)
+        self.assertEqual(
+            parsed, [{'title': title,
+                      'status': 'TODO',
+                      'assignee': 'person',
+                      'milestone': None,
+                      'sequence': 0}])
+
+    def test_assignee_and_brackets(self):
+        title = "Work item with two [2] brackets"
+        work_items_text = ("Work items:\n"
+                           "[person] %s: TODO" % title)
+        parsed = self.field.parse(work_items_text)
+        self.assertEqual(
+            parsed, [{'title': title,
+                      'status': 'TODO',
+                      'assignee': 'person',
+                      'milestone': None,
+                      'sequence': 0}])
+
+    def test_no_assignee_and_brackets(self):
+        title = "Work item with [] brackets"
+        work_items_text = ("Work items:\n"
+                           "%s: TODO" % title)
+        parsed = self.field.parse(work_items_text)
+        self.assertEqual(
+            parsed, [{'title': title,
+                      'status': 'TODO',
+                      'assignee': None,
+                      'milestone': None,
+                      'sequence': 0}])
+
     def test_multi_line_parsing(self):
         title_1 = 'Work item 1'
         title_2 = 'Work item 2'