Merge lp:~dpb/lp2kanban/moar-functions into lp:lp2kanban

Proposed by David Britton
Status: Merged
Merged at revision: 140
Proposed branch: lp:~dpb/lp2kanban/moar-functions
Merge into: lp:lp2kanban
Diff against target: 306 lines (+64/-36)
2 files modified
src/lp2kanban/bugs2cards.py (+37/-15)
src/lp2kanban/tests/test_bugs2cards.py (+27/-21)
To merge this branch: bzr merge lp:~dpb/lp2kanban/moar-functions
Reviewer Review Type Date Requested Status
🤖 Landscape Builder test results Needs Fixing
Chad Smith Approve
Review via email: mp+304015@code.launchpad.net

Commit message

Split apart large sync_cards into functions for some code separation.

Description of the change

Split apart large sync_cards into functions for some code separation. Follow-on branches will continue this.

All tests should still pass (with minimal changes).

To post a comment you must log in.
Revision history for this message
Chad Smith (chad.smith) wrote :

loooks good from this side. thanks for the cleanups.

review: Approve
Revision history for this message
🤖 Landscape Builder (landscape-builder) wrote :

The attempt to merge lp:~davidpbritton/lp2kanban/moar-functions into lp:lp2kanban failed. Below is the output from the failed tests.

mkdir download-cache
python bootstrap.py -v 1.7.1 -f eggs -c buildout.cfg

Traceback (most recent call last):
  File "bootstrap.py", line 80, in <module>
    exec(urlopen('https://bootstrap.pypa.io/ez_setup.py').read(), ez)
  File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen
    return _opener.open(url, data, timeout)
  File "/usr/lib/python2.7/urllib2.py", line 404, in open
    response = self._open(req, data)
  File "/usr/lib/python2.7/urllib2.py", line 422, in _open
    '_open', req)
  File "/usr/lib/python2.7/urllib2.py", line 382, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 1222, in https_open
    return self.do_open(httplib.HTTPSConnection, req)
  File "/usr/lib/python2.7/urllib2.py", line 1184, in do_open
    raise URLError(err)
urllib2.URLError: <urlopen error [Errno 110] Connection timed out>
make: *** [bin/buildout] Error 1

Revision history for this message
🤖 Landscape Builder (landscape-builder) wrote :

No approved revision specified.

Revision history for this message
🤖 Landscape Builder (landscape-builder) :
review: Abstain (executing tests)
Revision history for this message
🤖 Landscape Builder (landscape-builder) wrote :

Command: make check
Result: Fail
Revno: 144
Branch: lp:~davidpbritton/lp2kanban/moar-functions
Jenkins: https://ci.lscape.net/job/latch-test/8155/

review: Needs Fixing (test results)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/lp2kanban/bugs2cards.py'
2--- src/lp2kanban/bugs2cards.py 2016-05-02 20:32:26 +0000
3+++ src/lp2kanban/bugs2cards.py 2016-08-26 17:12:09 +0000
4@@ -558,8 +558,9 @@
5 return None
6
7
8-def create_new_cards(board, launchpad_project, bug_tag, cardtype_name=None,
9- cardlane_path=None, feature_lanes=None):
10+def create_cards_in_project(
11+ board, launchpad_project, bug_tag, cardtype_name=None,
12+ cardlane_path=None, feature_lanes=None):
13 """Create cards for bugs tagged in Launchpad.
14
15 If a bug is tagged with the given tag, a new card will be created in
16@@ -641,11 +642,10 @@
17 return None
18
19
20-def sync_board(board, bconf, lp=None, lp_users=None):
21- if not lp:
22- lp = get_lp(bconf)
23- if not lp_users:
24- lp_users = LaunchpadUsersForBoard()
25+def get_lp_data(board, bconf):
26+ """Given a board and config, return lp, lp projects and lp users."""
27+ lp = get_lp(bconf)
28+ lp_users = LaunchpadUsersForBoard()
29 all_projects = []
30 project_group = bconf.get('project_group')
31 if project_group:
32@@ -661,14 +661,22 @@
33 if project:
34 all_projects.append(project)
35 lp_users.set_up_users(lp, board, bconf)
36+ return lp, all_projects, lp_users
37+
38+
39+def create_cards(board, bconf, lp_users, lp_projects):
40+ """Create new cards on all projects."""
41 new_bug_tag = bconf.get("bug_to_card_tag")
42 if new_bug_tag is not None:
43- for project in all_projects:
44- create_new_cards(
45- board, project, new_bug_tag, bconf.get("bug_to_card_type"),
46+ for lp_project in lp_projects:
47+ create_cards_in_project(
48+ board, lp_project, new_bug_tag, bconf.get("bug_to_card_type"),
49 bconf.get("bug_to_card_lane"), lp_users.feature_lanes)
50- print " Syncing cards:"
51- # Process linked branch cards
52+
53+
54+def sync_cards_linked_branches(board, bconf, lp, lp_users):
55+ """Sync any cards that have linked external branches."""
56+ print " Syncing branch cards:"
57 for card in board.getCardsWithExternalLinks(only_branches=True):
58 if card.external_card_id:
59 # Cards with external_id are processed by getCardsWithExternalIds
60@@ -705,6 +713,9 @@
61 else:
62 print " * %s (in %s)" % (card.title, card_path)
63
64+
65+def sync_cards_external_ids(board, bconf, lp, lp_users, lp_projects):
66+ """Sync any cards that have linked external ids (bugs in launchpad)."""
67 for card in board.getCardsWithExternalIds():
68 if should_sync_card(card, bconf):
69 lp_bug = get_lp_bug(card, lp)
70@@ -712,10 +723,10 @@
71 continue
72 ignore_external_projects = (
73 bconf.get("autosync") == "active-projects")
74- if ignore_external_projects and not is_bug_in_projects(lp_bug, all_projects):
75+ if ignore_external_projects and not is_bug_in_projects(lp_bug, lp_projects):
76 continue # Skip bugs in external projects
77 synced, card_status, assignees, mp_url, mp_type = get_bug_status(
78- lp_bug, all_projects, lp_users.lp_to_kanban.keys())
79+ lp_bug, lp_projects, lp_users.lp_to_kanban.keys())
80
81 card_path = card.lane.path
82 if isinstance(card.lane.board, LeankitTaskBoard):
83@@ -752,6 +763,8 @@
84 print " * %s: %s -- Not synced" % (
85 lp_bug.id, card.title)
86
87+def move_cards_to_taskboards(board, bconf, lp, lp_users):
88+ """Move branch cards to feature cards if they are landed."""
89 if "${group}" in bconf["landing_lanes"]:
90 # Replace the optional template ${group} with configured board groups.
91 # This creates a list of landing_lanes, one per group on the board.
92@@ -768,6 +781,9 @@
93 move_cards_to_feature_taskboard(
94 feature_card, lp_bug, valid_taskboard_lanes)
95
96+
97+def convert_cards_to_work_items(board, bconf, lp, lp_users, lp_projects):
98+ """Create work items out of cards if desired."""
99 if bconf.get("convert_cards_to_work_items", False) == "on":
100 # Sync cards to blueprint work items, if so configured.
101 print " Checking for cards to sync with work items..."
102@@ -874,7 +890,13 @@
103 if board is None:
104 print "Could not retrieve board. Skipping."
105 continue
106- sync_board(board, boards_config[board_name])
107+ bconf = boards_config[board_name]
108+ lp, lp_projects, lp_users = get_lp_data(board, bconf)
109+ create_cards(board, bconf, lp_users, lp_projects)
110+ sync_cards_linked_branches(board, bconf, lp, lp_users)
111+ sync_cards_external_ids(board, bconf, lp, lp_users, lp_projects)
112+ move_cards_to_taskboards(board, bconf, lp, lp_users)
113+ convert_cards_to_work_items(board, bconf, lp, lp_users)
114 save_board(board)
115 except (KeyError, AssertionError) as e:
116 print "Exception caught. Skipping board."
117
118=== modified file 'src/lp2kanban/tests/test_bugs2cards.py'
119--- src/lp2kanban/tests/test_bugs2cards.py 2016-05-04 14:58:20 +0000
120+++ src/lp2kanban/tests/test_bugs2cards.py 2016-08-26 17:12:09 +0000
121@@ -15,7 +15,7 @@
122
123 from lp2kanban.bugs2cards import (
124 CardStatus,
125- create_new_cards,
126+ create_cards_in_project,
127 find_card_target_lane_next,
128 get_branch_info,
129 is_bug_in_projects,
130@@ -31,7 +31,8 @@
131 parse_groups_config,
132 should_sync_card,
133 should_move_card,
134- sync_board
135+ sync_cards_external_ids,
136+ move_cards_to_taskboards
137 )
138 from lp2kanban.kanban import (
139 RESOURCE_TYPE_LINK_SERIES,
140@@ -980,7 +981,7 @@
141 board = FauxBoard()
142 bug_lane = board.addLane('bugs')
143 project = FauxLaunchpadProject(bug_tasks=[])
144- create_new_cards(board, project, 'kanban')
145+ create_cards_in_project(board, project, 'kanban')
146 self.assertEqual([], board.cards)
147
148 def test_new_bugs_card_added(self):
149@@ -993,7 +994,7 @@
150 bug_id=42, title='Test bug',
151 description='Test bug description.',
152 tags=['kanban'])])
153- create_new_cards(board, project, 'kanban')
154+ create_cards_in_project(board, project, 'kanban')
155 [card] = board.cards
156 self.assertEqual('Test bug', card.title)
157 self.assertEqual('Test bug description.', card.description)
158@@ -1011,7 +1012,7 @@
159 bug_id=42, title='Test bug',
160 description='Test bug description.',
161 tags=['kanban'])])
162- create_new_cards(board, project, 'kanban')
163+ create_cards_in_project(board, project, 'kanban')
164 [bug_task] = project.bug_tasks
165 self.assertEqual([], bug_task.bug.tags)
166 self.assertTrue(bug_task.bug.saved)
167@@ -1026,7 +1027,7 @@
168 tags=['kanban'])])
169 old_save = FauxCard.save
170 FauxCard.save = lambda x: None
171- create_new_cards(board, project, 'kanban')
172+ create_cards_in_project(board, project, 'kanban')
173 [bug_task] = project.bug_tasks
174 self.assertEqual(['kanban'], bug_task.bug.tags)
175 self.assertFalse(bug_task.bug.saved)
176@@ -1034,7 +1035,7 @@
177
178 def test_new_bugs_tagged_only(self):
179 # Cards are created only for bugs having the bug tag that is
180- # passed in to create_new_cards().
181+ # passed in to create_cards_in_project().
182 board = FauxBoard()
183 bug_lane = board.addLane('bugs')
184 project = FauxLaunchpadProject(
185@@ -1047,7 +1048,7 @@
186 FauxBugTask(
187 bug_id=42, title='Tagged with no tags',
188 tags=[])])
189- create_new_cards(board, project, 'kanban')
190+ create_cards_in_project(board, project, 'kanban')
191 [card] = board.cards
192 self.assertEqual('Tagged with right tag', card.title)
193 self.assertEqual('42', card.external_card_id)
194@@ -1064,7 +1065,7 @@
195 tags=['kanban'])])
196 feature_type = FauxCardType(id=2, name='Feature', is_default=False)
197 board.cardtypes[feature_type.id] = feature_type
198- create_new_cards(board, project, 'kanban', cardtype_name='Feature')
199+ create_cards_in_project(board, project, 'kanban', cardtype_name='Feature')
200 [card] = board.cards
201 self.assertEqual(feature_type.id, card.type_id)
202 self.assertTrue(card.saved)
203@@ -1082,7 +1083,7 @@
204 tags=['kanban'])])
205 feature_type = FauxCardType(id=2, name='Feature', is_default=False)
206 board.cardtypes[feature_type.id] = feature_type
207- create_new_cards(
208+ create_cards_in_project(
209 board, project, 'kanban', cardtype_name='Feature',
210 cardlane_path='incoming')
211 [card] = board.cards
212@@ -1098,7 +1099,7 @@
213 bug_id=42, title='Test bug',
214 description='x' * 20000,
215 tags=['kanban'])])
216- create_new_cards(board, project, 'kanban')
217+ create_cards_in_project(board, project, 'kanban')
218 [card] = board.cards
219 self.assertEqual('Test bug', card.title)
220 self.assertEqual(19500, len(card.description))
221@@ -1628,7 +1629,7 @@
222 self.deploy_lane = FauxLane(board=self.board, path='deploy')
223 self.lp_users = FauxLaunchpadUsersForBoard()
224
225- def test_sync_board_moves_landing_cards_to_taskboard_in_landing_lane(self):
226+ def test_sync_cards_moves_landing_cards_to_taskboard_in_landing_lane(self):
227 """
228 Feature-linked cards in landing lanes will move to taskboard when the
229 feature card is in landing_lanes.
230@@ -1641,11 +1642,12 @@
231 landed_card.type = self.branch_type
232 landed_card.lane = self.landing_lane
233 self.board.cards.extend([coding_card, landed_card])
234- sync_board(self.board, self.bconf, lp=FauxLP(), lp_users=self.lp_users)
235+ move_cards_to_taskboards(
236+ self.board, self.bconf, lp=FauxLP(), lp_users=self.lp_users)
237 self.assertIsNone(coding_card.moved_to)
238 self.assertEqual(self.feature_card, landed_card.moved_to)
239
240- def test_sync_board_moves_landing_cards_to_taskboard_in_deploy_lane(self):
241+ def test_sync_cards_moves_landing_cards_to_taskboard_in_deploy_lane(self):
242 """
243 Feature-linked cards in landing lanes will move to taskboard when the
244 feature card is in deploy_lanes.
245@@ -1658,11 +1660,12 @@
246 landed_card.type = self.branch_type
247 landed_card.lane = self.landing_lane
248 self.board.cards.extend([coding_card, landed_card])
249- sync_board(self.board, self.bconf, lp=FauxLP(), lp_users=self.lp_users)
250+ move_cards_to_taskboards(
251+ self.board, self.bconf, lp=FauxLP(), lp_users=self.lp_users)
252 self.assertIsNone(coding_card.moved_to)
253 self.assertEqual(self.feature_card, landed_card.moved_to)
254
255- def test_sync_board_moves_no_cards_to_taskboard_not_landed_or_deploy(self):
256+ def test_sync_cards_moves_no_cards_to_taskboard_not_landed_or_deploy(self):
257 """
258 Feature-linked cards in landing lanes will not move to taskboard when
259 the feature card is not in the landing_lanes or deploy_lanes.
260@@ -1672,10 +1675,11 @@
261 landed_card.type = self.branch_type
262 landed_card.lane = self.landing_lane
263 self.board.cards.extend([landed_card])
264- sync_board(self.board, self.bconf, lp=FauxLP(), lp_users=self.lp_users)
265+ move_cards_to_taskboards(
266+ self.board, self.bconf, lp=FauxLP(), lp_users=self.lp_users)
267 self.assertIsNone(landed_card.moved_to)
268
269- def test_sync_board_moves_landing_cards_to_taskboard_with_groups(self):
270+ def test_sync_cards_moves_landing_cards_to_taskboard_with_groups(self):
271 """
272 When landing_lanes contains ${groups} template, feature-linkd cards in
273 all configured landing lanes will be moved to the feature taskboard.
274@@ -1699,12 +1703,13 @@
275 landed_card2.type = self.branch_type
276 landed_card2.lane = landing_lane2
277 self.board.cards.extend([coding_card, landed_card1, landed_card2])
278- sync_board(self.board, self.bconf, lp=FauxLP(), lp_users=lp_users)
279+ move_cards_to_taskboards(
280+ self.board, self.bconf, lp=FauxLP(), lp_users=lp_users)
281 self.assertIsNone(coding_card.moved_to)
282 self.assertEqual(self.feature_card, landed_card1.moved_to)
283 self.assertEqual(self.feature_card, landed_card2.moved_to)
284
285- def test_sync_board_skips_bugs_of_external_projects_when_active_projects_set(self):
286+ def test_sync_cards_skips_bugs_of_external_projects_when_active_projects_set(self):
287 """Bugs of external projects are skipped when autosync set to active-projects."""
288 # Configure bugs2cards to sync only active-projects myproject1 and myproject2
289 self.bconf.update({"autosync": "active-projects",
290@@ -1716,6 +1721,7 @@
291 project2 = FauxTarget(resource_type_link="project2", project="myproject2")
292 otherproject = FauxTarget(resource_type_link="project", project="otherproject")
293 lp_users = FauxLaunchpadUsersForBoard(lp_to_kanban={"person1": "Person One"})
294+ lp_projects = [project1, project2]
295 bug_task1 = FauxBugTask(
296 bug_id=123, target=project1, title='Test bug in myproject',
297 description='Test bug description.')
298@@ -1739,7 +1745,7 @@
299 # Include project1 and project2 in our active 'projects' fake LP data
300 lp = FauxLP({"projects": {"myproject": project1, "myproject2": project2},
301 "bugs": {123: bug_task1.bug, "456": bug_task2.bug}})
302- sync_board(board, self.bconf, lp=lp, lp_users=lp_users)
303+ sync_cards_external_ids(board, self.bconf, lp, lp_users, lp_projects)
304 coding_lane = FauxLane(board=board, path='coding')
305 self.assertEqual(new_lane, bug_card1.moved_to)
306 self.assertIsNone(bug_card2.moved_to)

Subscribers

People subscribed via source and target branches

to all changes: