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

Proposed by Mattias Backman
Status: Merged
Approved by: Stuart Bishop
Approved revision: no longer in the source branch.
Merged at revision: 14965
Proposed branch: lp:~linaro-infrastructure/launchpad/fix-work-item-brackets
Merge into: lp:launchpad
Diff against target: 59 lines (+37/-1)
2 files modified
lib/lp/services/fields/__init__.py (+1/-1)
lib/lp/services/fields/tests/test_fields.py (+36/-0)
To merge this branch: bzr merge lp:~linaro-infrastructure/launchpad/fix-work-item-brackets
Reviewer Review Type Date Requested Status
Stuart Bishop (community) Approve
Review via email: mp+97584@code.launchpad.net

Commit message

[r=stub] Fix work items parsing.

Description of the change

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.

To post a comment you must log in.
Revision history for this message
Stuart Bishop (stub) wrote :

Fine

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/services/fields/__init__.py'
2--- lib/lp/services/fields/__init__.py 2012-03-08 14:18:12 +0000
3+++ lib/lp/services/fields/__init__.py 2012-03-15 08:37:21 +0000
4@@ -114,7 +114,7 @@
5 MILESTONE_RE = re.compile('^work items(.*)\s*:\s*$', re.I)
6 # Regexp for work items.
7 WORKITEM_RE = re.compile(
8- '^(\[(?P<assignee>.*)\])?\s*(?P<title>.*)\s*:\s*(?P<status>.*)\s*$', re.I)
9+ '^(\[(?P<assignee>.*?)\])?\s*(?P<title>.*)\s*:\s*(?P<status>.*)\s*$', re.I)
10
11
12 # Field Interfaces
13
14=== modified file 'lib/lp/services/fields/tests/test_fields.py'
15--- lib/lp/services/fields/tests/test_fields.py 2012-03-08 14:18:12 +0000
16+++ lib/lp/services/fields/tests/test_fields.py 2012-03-15 08:37:21 +0000
17@@ -244,6 +244,42 @@
18 LaunchpadValidationError, self.field.parseLine,
19 '[test-person] :TODO')
20
21+ def test_assignee_and_bracket(self):
22+ title = "Work item with one ] bracket"
23+ work_items_text = ("Work items:\n"
24+ "[person] %s: TODO" % title)
25+ parsed = self.field.parse(work_items_text)
26+ self.assertEqual(
27+ parsed, [{'title': title,
28+ 'status': 'TODO',
29+ 'assignee': 'person',
30+ 'milestone': None,
31+ 'sequence': 0}])
32+
33+ def test_assignee_and_brackets(self):
34+ title = "Work item with two [2] brackets"
35+ work_items_text = ("Work items:\n"
36+ "[person] %s: TODO" % title)
37+ parsed = self.field.parse(work_items_text)
38+ self.assertEqual(
39+ parsed, [{'title': title,
40+ 'status': 'TODO',
41+ 'assignee': 'person',
42+ 'milestone': None,
43+ 'sequence': 0}])
44+
45+ def test_no_assignee_and_brackets(self):
46+ title = "Work item with [] brackets"
47+ work_items_text = ("Work items:\n"
48+ "%s: TODO" % title)
49+ parsed = self.field.parse(work_items_text)
50+ self.assertEqual(
51+ parsed, [{'title': title,
52+ 'status': 'TODO',
53+ 'assignee': None,
54+ 'milestone': None,
55+ 'sequence': 0}])
56+
57 def test_multi_line_parsing(self):
58 title_1 = 'Work item 1'
59 title_2 = 'Work item 2'