Merge lp:~bac/lp2kanban/pick-newest-mp into lp:~launchpad/lp2kanban/trunk

Proposed by Brad Crittenden
Status: Merged
Merged at revision: 64
Proposed branch: lp:~bac/lp2kanban/pick-newest-mp
Merge into: lp:~launchpad/lp2kanban/trunk
Diff against target: 146 lines (+53/-18)
3 files modified
setup.py (+1/-0)
src/lp2kanban/bugs2cards.py (+18/-17)
src/lp2kanban/tests/test_bugs2cards.py (+34/-1)
To merge this branch: bzr merge lp:~bac/lp2kanban/pick-newest-mp
Reviewer Review Type Date Requested Status
Benji York (community) code Approve
Review via email: mp+143925@code.launchpad.net

Description of the change

If there are multiple active merge proposals, choose the most recent to link.

In testing I found a bug where a single mp_info was being reused, so the latest added to the list was always the winner.

To post a comment you must log in.
Revision history for this message
Benji York (benji) wrote :

The branch looks great.

I suggest ignoring the two-lines-beween-module-globals rule for
"constants" -- just as we do for imports.

review: Approve (code)
lp:~bac/lp2kanban/pick-newest-mp updated
65. By Brad Crittenden

lint

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'setup.py'
2--- setup.py 2011-07-18 14:25:26 +0000
3+++ setup.py 2013-01-18 19:14:20 +0000
4@@ -15,6 +15,7 @@
5 'argparse',
6 'launchpadlib',
7 'lazr.uri',
8+ 'testtools',
9 'setuptools',
10 ],
11 )
12
13=== modified file 'src/lp2kanban/bugs2cards.py'
14--- src/lp2kanban/bugs2cards.py 2013-01-16 23:10:55 +0000
15+++ src/lp2kanban/bugs2cards.py 2013-01-18 19:14:20 +0000
16@@ -93,6 +93,22 @@
17 self.kanban_to_lp[board.users[user]] = lp_user
18
19
20+ORDERED_STATUSES = {'Rejected': 0,
21+ 'Work in progress': 0,
22+ 'Needs review': 1,
23+ 'Approved': 2,
24+ 'Merged': 2,
25+ }
26+REVIEW_STATUS = 'In Review'
27+TRANSFORM_STATUS = {'Rejected': 'In Progress',
28+ 'Work in progress': 'In Progress',
29+ 'Needs review': REVIEW_STATUS,
30+ 'Approved': 'Approved',
31+ 'Merged': 'Merged',
32+ }
33+FINAL_STATUSES = ('Approved', 'Merged')
34+
35+
36 def get_branch_info(branches):
37 """Returns a bug's status based on the given branches.
38
39@@ -107,26 +123,11 @@
40 # refuse to guess.
41 return info
42
43- ORDERED_STATUSES = {'Rejected': 0,
44- 'Work in progress': 0,
45- 'Needs review': 1,
46- 'Approved': 2,
47- 'Merged': 2,
48- }
49- REVIEW_STATUS = 'In Review'
50- TRANSFORM_STATUS = {'Rejected': 'In Progress',
51- 'Work in progress': 'In Progress',
52- 'Needs review': REVIEW_STATUS,
53- 'Approved': 'Approved',
54- 'Merged': 'Merged',
55- }
56- FINAL_STATUSES = ('Approved', 'Merged')
57-
58 def _get_mp_info():
59 mps = []
60 for bug_branch in branches:
61- mp_info = Record(rank=None, status=None, mp=None)
62 for mp in bug_branch.branch.landing_targets:
63+ mp_info = Record(rank=None, status=None, mp=None)
64 status = mp.queue_status
65 mp_info.rank = ORDERED_STATUSES.get(status, 1)
66 mp_info.status = TRANSFORM_STATUS.get(status, REVIEW_STATUS)
67@@ -138,7 +139,7 @@
68 mps.append(mp_info)
69 if len(mps) == 0:
70 return None
71- mps.sort(key=lambda x:x.rank, reverse=True)
72+ mps.sort(key=lambda x:(x.rank, x.mp.date_created), reverse=True)
73 return mps[0]
74
75 def _get_mp_link(mp):
76
77=== modified file 'src/lp2kanban/tests/test_bugs2cards.py'
78--- src/lp2kanban/tests/test_bugs2cards.py 2013-01-17 14:29:57 +0000
79+++ src/lp2kanban/tests/test_bugs2cards.py 2013-01-18 19:14:20 +0000
80@@ -6,6 +6,7 @@
81 )
82 from StringIO import StringIO
83 from textwrap import dedent
84+import datetime
85 import unittest
86
87 from lp2kanban.bugs2cards import (
88@@ -24,6 +25,7 @@
89 FauxCard,
90 )
91
92+
93 class ConfigReadingTest(unittest.TestCase):
94
95 def test_parse_config_no_globals(self):
96@@ -101,11 +103,12 @@
97
98
99 class FauxMP:
100- def __init__(self, queue_status, target_name, link=None, description=None):
101+ def __init__(self, queue_status, target_name, link=None, description=None, date_created=None):
102 self.queue_status = queue_status
103 self.target_branch = Record(name=target_name)
104 self.web_link = link
105 self.description = description or ''
106+ self.date_created = date_created
107
108
109 class BranchInfoTests(unittest.TestCase):
110@@ -185,6 +188,36 @@
111 ])]
112 result = get_branch_info(branches)
113 self.assertEqual(result['status'], 'Approved')
114+ self.assertEqual(result['target'], 'approved-branch')
115+
116+ def test_first_highest_ranked_returned(self):
117+ # If there are multiple merge proposals of the same highest rank, the
118+ # newest one wins.
119+ branches = [FauxBugBranch(
120+ [FauxMP('In Review', 'devel'),
121+ FauxMP('Approved', 'first'),
122+ FauxMP('Approved', 'second'),
123+ FauxMP('Rejected', 'bad-branch'),
124+ ])]
125+ result = get_branch_info(branches)
126+ self.assertEqual(result['status'], 'Approved')
127+ self.assertEqual(result['target'], 'first')
128+
129+ def test_newest_highest_ranked_returned(self):
130+ # If there are multiple merge proposals of the same highest rank, but
131+ # not in final states, the newest one wins.
132+ now = datetime.datetime.now()
133+ yesterday = now - datetime.timedelta(days=1)
134+ lastweek = now - datetime.timedelta(days=7)
135+ branches = [FauxBugBranch(
136+ [FauxMP('Needs review', 'lastweek', date_created=lastweek),
137+ FauxMP('Needs review', 'now', date_created=now),
138+ FauxMP('Needs review', 'yesterday', date_created=yesterday),
139+ FauxMP('Rejected', 'bad-branch'),
140+ ])]
141+ result = get_branch_info(branches)
142+ self.assertEqual(result['status'], 'In Review')
143+ self.assertEqual(result['target'], 'now')
144
145 def test_first_seen_final_state_returned(self):
146 # If there are multiple MPs in a final state, the first one seen wins.

Subscribers

People subscribed via source and target branches