Merge lp:~james-w/tarmac/break-up-do-merges into lp:~ubuntuone-hackers/tarmac/trunk
- break-up-do-merges
- Merge into trunk
Proposed by
James Westby
Status: | Merged |
---|---|
Merged at revision: | 420 |
Proposed branch: | lp:~james-w/tarmac/break-up-do-merges |
Merge into: | lp:~ubuntuone-hackers/tarmac/trunk |
Prerequisite: | lp:~james-w/tarmac/commit-message |
Diff against target: |
453 lines (+206/-191) 1 file modified
tarmac/bin/commands.py (+206/-191) |
To merge this branch: | bzr merge lp:~james-w/tarmac/break-up-do-merges |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jonathan Lange (community) | Needs Fixing | ||
Review via email: mp+140554@code.launchpad.net |
This proposal supersedes a proposal from 2012-12-18.
Commit message
Description of the change
Hi,
This branch breaks up the _do_merges method a little, as it was huge.
I tried to keep changes to a minimum while moving the code around, but it
used "continue" for flow control, so I had to change it a little to
use return values.
Thanks,
James
To post a comment you must log in.
Revision history for this message
Jonathan Lange (jml) wrote : | # |
Revision history for this message
Jonathan Lange (jml) : | # |
review:
Needs Fixing
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'tarmac/bin/commands.py' | |||
2 | --- tarmac/bin/commands.py 2012-09-05 18:08:50 +0000 | |||
3 | +++ tarmac/bin/commands.py 2012-12-18 21:25:42 +0000 | |||
4 | @@ -134,6 +134,194 @@ | |||
5 | 134 | help_commands(self.outf) | 134 | help_commands(self.outf) |
6 | 135 | 135 | ||
7 | 136 | 136 | ||
8 | 137 | def _get_mergable_proposals_for_branch(lp_branch, logger, imply_commit_message=False): | ||
9 | 138 | """Return a list of the mergable proposals for the given branch.""" | ||
10 | 139 | proposals = [] | ||
11 | 140 | for entry in lp_branch.landing_candidates: | ||
12 | 141 | logger.debug("Considering merge proposal: {0}".format(entry.web_link)) | ||
13 | 142 | |||
14 | 143 | if entry.queue_status != u'Approved': | ||
15 | 144 | logger.debug( | ||
16 | 145 | " Skipping proposal: status is {0}, not " | ||
17 | 146 | "'Approved'".format(entry.queue_status)) | ||
18 | 147 | continue | ||
19 | 148 | |||
20 | 149 | if (not imply_commit_message and not entry.commit_message): | ||
21 | 150 | logger.debug( | ||
22 | 151 | " Skipping proposal: proposal has no commit message") | ||
23 | 152 | continue | ||
24 | 153 | |||
25 | 154 | proposals.append(entry) | ||
26 | 155 | return proposals | ||
27 | 156 | |||
28 | 157 | |||
29 | 158 | def _get_reviews(proposal): | ||
30 | 159 | """Get the set of reviews from the proposal.""" | ||
31 | 160 | reviews = [] | ||
32 | 161 | for vote in proposal.votes: | ||
33 | 162 | if not vote.comment: | ||
34 | 163 | continue | ||
35 | 164 | else: | ||
36 | 165 | reviews.append('%s;%s' % (vote.reviewer.display_name, | ||
37 | 166 | vote.comment.vote)) | ||
38 | 167 | |||
39 | 168 | if len(reviews) == 0: | ||
40 | 169 | return None | ||
41 | 170 | |||
42 | 171 | return reviews | ||
43 | 172 | |||
44 | 173 | |||
45 | 174 | def setup(logger, debug=False, http_debug=False): | ||
46 | 175 | if debug: | ||
47 | 176 | set_up_debug_logging() | ||
48 | 177 | logger.debug('Debug logging enabled') | ||
49 | 178 | if http_debug: | ||
50 | 179 | httplib2.debuglevel = 1 | ||
51 | 180 | logger.debug('HTTP debugging enabled.') | ||
52 | 181 | logger.debug('Loading plugins') | ||
53 | 182 | load_plugins() | ||
54 | 183 | logger.debug('Plugins loaded') | ||
55 | 184 | |||
56 | 185 | |||
57 | 186 | def merge_proposals(target, proposals, logger, config, command): | ||
58 | 187 | logger.debug('Firing tarmac_pre_merge hook') | ||
59 | 188 | tarmac_hooks.fire('tarmac_pre_merge', | ||
60 | 189 | command, target) | ||
61 | 190 | |||
62 | 191 | statuses = [] | ||
63 | 192 | try: | ||
64 | 193 | for proposal in proposals: | ||
65 | 194 | status = merge_proposal(target, proposal, logger, | ||
66 | 195 | config, command) | ||
67 | 196 | statuses.append(status) | ||
68 | 197 | # This except is here because we need the else and can't have it | ||
69 | 198 | # without an except as well. | ||
70 | 199 | except: | ||
71 | 200 | raise | ||
72 | 201 | else: | ||
73 | 202 | logger.debug('Firing tarmac_post_merge hook') | ||
74 | 203 | tarmac_hooks.fire('tarmac_post_merge', | ||
75 | 204 | command, target) | ||
76 | 205 | finally: | ||
77 | 206 | target.cleanup() | ||
78 | 207 | return statuses | ||
79 | 208 | |||
80 | 209 | |||
81 | 210 | def merge_proposal(target, proposal, logger, config, command): | ||
82 | 211 | target.cleanup() | ||
83 | 212 | logger.debug( | ||
84 | 213 | u'Preparing to merge %(source_branch)s' % { | ||
85 | 214 | 'source_branch': proposal.source_branch.web_link}) | ||
86 | 215 | try: | ||
87 | 216 | prerequisite = proposal.prerequisite_branch | ||
88 | 217 | if prerequisite: | ||
89 | 218 | merges = [x for x in prerequisite.landing_targets | ||
90 | 219 | if x.target_branch == target.lp_branch and | ||
91 | 220 | x.queue_status != u'Superseded'] | ||
92 | 221 | if len(merges) == 0: | ||
93 | 222 | raise TarmacMergeError( | ||
94 | 223 | u'No proposals of prerequisite branch.', | ||
95 | 224 | u'No proposals found for merge of %s ' | ||
96 | 225 | u'into %s.' % ( | ||
97 | 226 | prerequisite.web_link, | ||
98 | 227 | target.lp_branch.web_link)) | ||
99 | 228 | elif len(merges) > 1: | ||
100 | 229 | raise TarmacMergeError( | ||
101 | 230 | u'Too many proposals of prerequisite.', | ||
102 | 231 | u'More than one proposal found for merge ' | ||
103 | 232 | u'of %s into %s, which is not Superseded.' % ( | ||
104 | 233 | prerequisite.web_link, | ||
105 | 234 | target.lp_branch.web_link)) | ||
106 | 235 | elif len(merges) == 1: | ||
107 | 236 | if merges[0].queue_status != u'Merged': | ||
108 | 237 | raise TarmacMergeError( | ||
109 | 238 | u'Prerequisite not yet merged.', | ||
110 | 239 | u'The prerequisite %s has not yet been ' | ||
111 | 240 | u'merged into %s.' % ( | ||
112 | 241 | prerequisite.web_link, | ||
113 | 242 | target.lp_branch.web_link)) | ||
114 | 243 | |||
115 | 244 | if not proposal.reviewed_revid: | ||
116 | 245 | raise TarmacMergeError( | ||
117 | 246 | u'No approved revision specified.') | ||
118 | 247 | |||
119 | 248 | |||
120 | 249 | source = Branch.create( | ||
121 | 250 | proposal.source_branch, config, target=target) | ||
122 | 251 | |||
123 | 252 | source_bzr_branch = source.get_bzr_branch() | ||
124 | 253 | approved = source_bzr_branch.revision_id_to_revno( | ||
125 | 254 | str(proposal.reviewed_revid)) | ||
126 | 255 | tip = source_bzr_branch.revno() | ||
127 | 256 | |||
128 | 257 | if tip > approved: | ||
129 | 258 | message = u'Unapproved changes made after approval' | ||
130 | 259 | lp_comment = ( | ||
131 | 260 | u'There are additional revisions which have not ' | ||
132 | 261 | u'been approved in review. Please seek review and ' | ||
133 | 262 | u'approval of these new revisions.') | ||
134 | 263 | raise UnapprovedChanges(message, lp_comment) | ||
135 | 264 | |||
136 | 265 | logger.debug( | ||
137 | 266 | 'Merging %(source)s at revision %(revision)s' % { | ||
138 | 267 | 'source': proposal.source_branch.web_link, | ||
139 | 268 | 'revision': proposal.reviewed_revid}) | ||
140 | 269 | |||
141 | 270 | target.merge(source, str(proposal.reviewed_revid)) | ||
142 | 271 | |||
143 | 272 | logger.debug('Firing tarmac_pre_commit hook') | ||
144 | 273 | tarmac_hooks.fire('tarmac_pre_commit', | ||
145 | 274 | command, target, source, proposal) | ||
146 | 275 | |||
147 | 276 | except TarmacMergeError, failure: | ||
148 | 277 | logger.warn( | ||
149 | 278 | u'Merging %(source)s into %(target)s failed: %(msg)s' % | ||
150 | 279 | {'source': proposal.source_branch.web_link, | ||
151 | 280 | 'target': proposal.target_branch.web_link, | ||
152 | 281 | 'msg': str(failure)}) | ||
153 | 282 | |||
154 | 283 | subject = u'Re: [Merge] %(source)s into %(target)s' % { | ||
155 | 284 | "source": proposal.source_branch.display_name, | ||
156 | 285 | "target": proposal.target_branch.display_name} | ||
157 | 286 | |||
158 | 287 | if failure.comment: | ||
159 | 288 | comment = failure.comment | ||
160 | 289 | else: | ||
161 | 290 | comment = str(failure) | ||
162 | 291 | |||
163 | 292 | proposal.createComment(subject=subject, content=comment) | ||
164 | 293 | try: | ||
165 | 294 | proposal.setStatus( | ||
166 | 295 | status=config.rejected_branch_status) | ||
167 | 296 | except AttributeError: | ||
168 | 297 | proposal.setStatus(status=u'Needs review') | ||
169 | 298 | proposal.lp_save() | ||
170 | 299 | return False | ||
171 | 300 | |||
172 | 301 | except PointlessMerge: | ||
173 | 302 | logger.warn( | ||
174 | 303 | 'Merging %(source)s into %(target)s would be ' | ||
175 | 304 | 'pointless.' % { | ||
176 | 305 | 'source': proposal.source_branch.web_link, | ||
177 | 306 | 'target': proposal.target_branch.web_link}) | ||
178 | 307 | return False | ||
179 | 308 | |||
180 | 309 | merge_url = get_review_url(proposal) | ||
181 | 310 | revprops = {'merge_url': merge_url} | ||
182 | 311 | |||
183 | 312 | commit_message = proposal.commit_message | ||
184 | 313 | if commit_message is None and config.imply_commit_message: | ||
185 | 314 | commit_message = proposal.description | ||
186 | 315 | |||
187 | 316 | target.commit(commit_message, | ||
188 | 317 | reviews=_get_reviews(proposal)) | ||
189 | 318 | |||
190 | 319 | logger.debug('Firing tarmac_post_commit hook') | ||
191 | 320 | tarmac_hooks.fire('tarmac_post_commit', | ||
192 | 321 | command, target, source, proposal) | ||
193 | 322 | return True | ||
194 | 323 | |||
195 | 324 | |||
196 | 137 | class cmd_merge(TarmacCommand): | 325 | class cmd_merge(TarmacCommand): |
197 | 138 | '''Automatically merge approved merge proposal branches.''' | 326 | '''Automatically merge approved merge proposal branches.''' |
198 | 139 | 327 | ||
199 | @@ -143,7 +331,8 @@ | |||
200 | 143 | options.http_debug_option, | 331 | options.http_debug_option, |
201 | 144 | options.debug_option, | 332 | options.debug_option, |
202 | 145 | options.imply_commit_message_option, | 333 | options.imply_commit_message_option, |
204 | 146 | options.one_option] | 334 | options.one_option, |
205 | 335 | ] | ||
206 | 147 | 336 | ||
207 | 148 | def _do_merges(self, branch_url): | 337 | def _do_merges(self, branch_url): |
208 | 149 | 338 | ||
209 | @@ -152,204 +341,29 @@ | |||
210 | 152 | self.logger.info('Not a valid branch: {0}'.format(branch_url)) | 341 | self.logger.info('Not a valid branch: {0}'.format(branch_url)) |
211 | 153 | return | 342 | return |
212 | 154 | 343 | ||
214 | 155 | proposals = self._get_mergable_proposals_for_branch(lp_branch) | 344 | proposals = _get_mergable_proposals_for_branch(lp_branch, self.logger, |
215 | 345 | imply_commit_message=self.config.imply_commit_message) | ||
216 | 156 | 346 | ||
217 | 157 | if not proposals: | 347 | if not proposals: |
218 | 158 | self.logger.info( | 348 | self.logger.info( |
219 | 159 | 'No approved proposals found for %(branch_url)s' % { | 349 | 'No approved proposals found for %(branch_url)s' % { |
220 | 160 | 'branch_url': branch_url}) | 350 | 'branch_url': branch_url}) |
222 | 161 | return | 351 | return [] |
223 | 352 | |||
224 | 353 | if self.config.one: | ||
225 | 354 | proposals = proposals[0] | ||
226 | 162 | 355 | ||
227 | 163 | target = Branch.create(lp_branch, self.config, create_tree=True) | 356 | target = Branch.create(lp_branch, self.config, create_tree=True) |
403 | 164 | 357 | statuses = merge_proposals(target, proposals, self.logger, self.config, self) | |
404 | 165 | self.logger.debug('Firing tarmac_pre_merge hook') | 358 | return statuses |
405 | 166 | tarmac_hooks.fire('tarmac_pre_merge', | 359 | |
231 | 167 | self, target) | ||
232 | 168 | |||
233 | 169 | try: | ||
234 | 170 | for proposal in proposals: | ||
235 | 171 | target.cleanup() | ||
236 | 172 | self.logger.debug( | ||
237 | 173 | u'Preparing to merge %(source_branch)s' % { | ||
238 | 174 | 'source_branch': proposal.source_branch.web_link}) | ||
239 | 175 | try: | ||
240 | 176 | prerequisite = proposal.prerequisite_branch | ||
241 | 177 | if prerequisite: | ||
242 | 178 | merges = [x for x in prerequisite.landing_targets | ||
243 | 179 | if x.target_branch == target.lp_branch and | ||
244 | 180 | x.queue_status != u'Superseded'] | ||
245 | 181 | if len(merges) == 0: | ||
246 | 182 | raise TarmacMergeError( | ||
247 | 183 | u'No proposals of prerequisite branch.', | ||
248 | 184 | u'No proposals found for merge of %s ' | ||
249 | 185 | u'into %s.' % ( | ||
250 | 186 | prerequisite.web_link, | ||
251 | 187 | target.lp_branch.web_link)) | ||
252 | 188 | elif len(merges) > 1: | ||
253 | 189 | raise TarmacMergeError( | ||
254 | 190 | u'Too many proposals of prerequisite.', | ||
255 | 191 | u'More than one proposal found for merge ' | ||
256 | 192 | u'of %s into %s, which is not Superseded.' % ( | ||
257 | 193 | prerequisite.web_link, | ||
258 | 194 | target.lp_branch.web_link)) | ||
259 | 195 | elif len(merges) == 1: | ||
260 | 196 | if merges[0].queue_status != u'Merged': | ||
261 | 197 | raise TarmacMergeError( | ||
262 | 198 | u'Prerequisite not yet merged.', | ||
263 | 199 | u'The prerequisite %s has not yet been ' | ||
264 | 200 | u'merged into %s.' % ( | ||
265 | 201 | prerequisite.web_link, | ||
266 | 202 | target.lp_branch.web_link)) | ||
267 | 203 | |||
268 | 204 | if not proposal.reviewed_revid: | ||
269 | 205 | raise TarmacMergeError( | ||
270 | 206 | u'No approved revision specified.') | ||
271 | 207 | |||
272 | 208 | |||
273 | 209 | source = Branch.create( | ||
274 | 210 | proposal.source_branch, self.config, target=target) | ||
275 | 211 | |||
276 | 212 | source_bzr_branch = source.get_bzr_branch() | ||
277 | 213 | approved = source_bzr_branch.revision_id_to_revno( | ||
278 | 214 | str(proposal.reviewed_revid)) | ||
279 | 215 | tip = source_bzr_branch.revno() | ||
280 | 216 | |||
281 | 217 | if tip > approved: | ||
282 | 218 | message = u'Unapproved changes made after approval' | ||
283 | 219 | lp_comment = ( | ||
284 | 220 | u'There are additional revisions which have not ' | ||
285 | 221 | u'been approved in review. Please seek review and ' | ||
286 | 222 | u'approval of these new revisions.') | ||
287 | 223 | raise UnapprovedChanges(message, lp_comment) | ||
288 | 224 | |||
289 | 225 | self.logger.debug( | ||
290 | 226 | 'Merging %(source)s at revision %(revision)s' % { | ||
291 | 227 | 'source': proposal.source_branch.web_link, | ||
292 | 228 | 'revision': proposal.reviewed_revid}) | ||
293 | 229 | |||
294 | 230 | target.merge(source, str(proposal.reviewed_revid)) | ||
295 | 231 | |||
296 | 232 | self.logger.debug('Firing tarmac_pre_commit hook') | ||
297 | 233 | tarmac_hooks.fire('tarmac_pre_commit', | ||
298 | 234 | self, target, source, proposal) | ||
299 | 235 | |||
300 | 236 | except TarmacMergeError, failure: | ||
301 | 237 | self.logger.warn( | ||
302 | 238 | u'Merging %(source)s into %(target)s failed: %(msg)s' % | ||
303 | 239 | {'source': proposal.source_branch.web_link, | ||
304 | 240 | 'target': proposal.target_branch.web_link, | ||
305 | 241 | 'msg': str(failure)}) | ||
306 | 242 | |||
307 | 243 | subject = u'Re: [Merge] %(source)s into %(target)s' % { | ||
308 | 244 | "source": proposal.source_branch.display_name, | ||
309 | 245 | "target": proposal.target_branch.display_name} | ||
310 | 246 | |||
311 | 247 | if failure.comment: | ||
312 | 248 | comment = failure.comment | ||
313 | 249 | else: | ||
314 | 250 | comment = str(failure) | ||
315 | 251 | |||
316 | 252 | proposal.createComment(subject=subject, content=comment) | ||
317 | 253 | try: | ||
318 | 254 | proposal.setStatus( | ||
319 | 255 | status=self.config.rejected_branch_status) | ||
320 | 256 | except AttributeError: | ||
321 | 257 | proposal.setStatus(status=u'Needs review') | ||
322 | 258 | proposal.lp_save() | ||
323 | 259 | |||
324 | 260 | # If we've been asked to only merge one branch, then exit. | ||
325 | 261 | if self.config.one: | ||
326 | 262 | return True | ||
327 | 263 | |||
328 | 264 | continue | ||
329 | 265 | except PointlessMerge: | ||
330 | 266 | self.logger.warn( | ||
331 | 267 | 'Merging %(source)s into %(target)s would be ' | ||
332 | 268 | 'pointless.' % { | ||
333 | 269 | 'source': proposal.source_branch.web_link, | ||
334 | 270 | 'target': proposal.target_branch.web_link}) | ||
335 | 271 | continue | ||
336 | 272 | |||
337 | 273 | merge_url = get_review_url(proposal) | ||
338 | 274 | revprops = {'merge_url': merge_url} | ||
339 | 275 | |||
340 | 276 | commit_message = proposal.commit_message | ||
341 | 277 | if commit_message is None and self.config.imply_commit_message: | ||
342 | 278 | commit_message = proposal.description | ||
343 | 279 | |||
344 | 280 | target.commit(commit_message, | ||
345 | 281 | revprops=revprops, | ||
346 | 282 | authors=source.authors, | ||
347 | 283 | reviews=self._get_reviews(proposal)) | ||
348 | 284 | |||
349 | 285 | self.logger.debug('Firing tarmac_post_commit hook') | ||
350 | 286 | tarmac_hooks.fire('tarmac_post_commit', | ||
351 | 287 | self, target, source, proposal) | ||
352 | 288 | |||
353 | 289 | # If we've been asked to only merge one branch, then exit. | ||
354 | 290 | if self.config.one: | ||
355 | 291 | return True | ||
356 | 292 | |||
357 | 293 | # This except is here because we need the else and can't have it | ||
358 | 294 | # without an except as well. | ||
359 | 295 | except: | ||
360 | 296 | raise | ||
361 | 297 | else: | ||
362 | 298 | self.logger.debug('Firing tarmac_post_merge hook') | ||
363 | 299 | tarmac_hooks.fire('tarmac_post_merge', | ||
364 | 300 | self, target) | ||
365 | 301 | finally: | ||
366 | 302 | target.cleanup() | ||
367 | 303 | |||
368 | 304 | def _get_mergable_proposals_for_branch(self, lp_branch): | ||
369 | 305 | """Return a list of the mergable proposals for the given branch.""" | ||
370 | 306 | proposals = [] | ||
371 | 307 | for entry in lp_branch.landing_candidates: | ||
372 | 308 | self.logger.debug("Considering merge proposal: {0}".format(entry.web_link)) | ||
373 | 309 | |||
374 | 310 | if entry.queue_status != u'Approved': | ||
375 | 311 | self.logger.debug( | ||
376 | 312 | " Skipping proposal: status is {0}, not " | ||
377 | 313 | "'Approved'".format(entry.queue_status)) | ||
378 | 314 | continue | ||
379 | 315 | |||
380 | 316 | if (not self.config.imply_commit_message and | ||
381 | 317 | not entry.commit_message): | ||
382 | 318 | self.logger.debug( | ||
383 | 319 | " Skipping proposal: proposal has no commit message") | ||
384 | 320 | continue | ||
385 | 321 | |||
386 | 322 | proposals.append(entry) | ||
387 | 323 | return proposals | ||
388 | 324 | |||
389 | 325 | def _get_reviews(self, proposal): | ||
390 | 326 | """Get the set of reviews from the proposal.""" | ||
391 | 327 | reviews = [] | ||
392 | 328 | for vote in proposal.votes: | ||
393 | 329 | if not vote.comment: | ||
394 | 330 | continue | ||
395 | 331 | else: | ||
396 | 332 | reviews.append('%s;%s' % (vote.reviewer.display_name, | ||
397 | 333 | vote.comment.vote)) | ||
398 | 334 | |||
399 | 335 | if len(reviews) == 0: | ||
400 | 336 | return None | ||
401 | 337 | |||
402 | 338 | return reviews | ||
406 | 339 | 360 | ||
407 | 340 | def run(self, branch_url=None, launchpad=None, **kwargs): | 361 | def run(self, branch_url=None, launchpad=None, **kwargs): |
408 | 341 | for key, value in kwargs.iteritems(): | 362 | for key, value in kwargs.iteritems(): |
409 | 342 | self.config.set('Tarmac', key, value) | 363 | self.config.set('Tarmac', key, value) |
410 | 343 | 364 | ||
420 | 344 | if self.config.debug: | 365 | setup(self.logger, debug=self.config.debug, |
421 | 345 | set_up_debug_logging() | 366 | http_debug=self.config.http_debug) |
413 | 346 | self.logger.debug('Debug logging enabled') | ||
414 | 347 | if self.config.http_debug: | ||
415 | 348 | httplib2.debuglevel = 1 | ||
416 | 349 | self.logger.debug('HTTP debugging enabled.') | ||
417 | 350 | self.logger.debug('Loading plugins') | ||
418 | 351 | load_plugins() | ||
419 | 352 | self.logger.debug('Plugins loaded') | ||
422 | 353 | 367 | ||
423 | 354 | self.launchpad = launchpad | 368 | self.launchpad = launchpad |
424 | 355 | if self.launchpad is None: | 369 | if self.launchpad is None: |
425 | @@ -357,23 +371,24 @@ | |||
426 | 357 | self.launchpad = self.get_launchpad_object() | 371 | self.launchpad = self.get_launchpad_object() |
427 | 358 | self.logger.debug('launchpad object loaded') | 372 | self.logger.debug('launchpad object loaded') |
428 | 359 | 373 | ||
429 | 374 | statuses = [] | ||
430 | 375 | |||
431 | 360 | if branch_url: | 376 | if branch_url: |
432 | 361 | self.logger.debug('%(branch_url)s specified as branch_url' % { | 377 | self.logger.debug('%(branch_url)s specified as branch_url' % { |
433 | 362 | 'branch_url': branch_url}) | 378 | 'branch_url': branch_url}) |
434 | 363 | if not branch_url.startswith('lp:'): | 379 | if not branch_url.startswith('lp:'): |
435 | 364 | raise TarmacCommandError('Branch urls must start with lp:') | 380 | raise TarmacCommandError('Branch urls must start with lp:') |
438 | 365 | self._do_merges(branch_url) | 381 | statuses.extend(self._do_merges(branch_url)) |
437 | 366 | |||
439 | 367 | else: | 382 | else: |
440 | 368 | for branch in self.config.branches: | 383 | for branch in self.config.branches: |
441 | 369 | self.logger.debug( | 384 | self.logger.debug( |
442 | 370 | 'Merging approved branches against %(branch)s' % { | 385 | 'Merging approved branches against %(branch)s' % { |
443 | 371 | 'branch': branch}) | 386 | 'branch': branch}) |
444 | 372 | try: | 387 | try: |
446 | 373 | merged = self._do_merges(branch) | 388 | statuses.extend(self._do_merges(branch)) |
447 | 374 | 389 | ||
448 | 375 | # If we've been asked to only merge one branch, then exit. | 390 | # If we've been asked to only merge one branch, then exit. |
450 | 376 | if merged and self.config.one: | 391 | if statuses and self.config.one: |
451 | 377 | break | 392 | break |
452 | 378 | except LockContention: | 393 | except LockContention: |
453 | 379 | continue | 394 | continue |
On 18 December 2012 21:26, James Westby <email address hidden> wrote: /code.launchpad .net/~james- w/tarmac/ break-up- do-merges/ +merge/ 140554
> James Westby has proposed merging lp:~james-w/tarmac/break-up-do-merges into lp:~ubuntuone-hackers/tarmac/trunk with lp:~james-w/tarmac/commit-message as a prerequisite.
>
> Requested reviews:
> Ubuntu One hackers (ubuntuone-hackers)
>
> For more details, see:
> https:/
>
> Hi,
>
> This branch breaks up the _do_merges method a little, as it was huge.
>
It was!
See inline.
> I tried to keep changes to a minimum while moving the code around, but it
> used "continue" for flow control, so I had to change it a little to
> use return values.
>
... bin/commands. py' bin/commands. py 2012-09-05 18:08:50 +0000 bin/commands. py 2012-12-18 21:25:42 +0000 self.outf) proposals_ for_branch( lp_branch, logger, imply_commit_ message= False): landing_ candidates: debug(" Considering merge proposal: {0}".format( entry.web_ link)) ".format( entry.queue_ status) ) message and not entry.commit_ message) : append( entry)
> === modified file 'tarmac/
> --- tarmac/
> +++ tarmac/
> @@ -134,6 +134,194 @@
> help_commands(
>
>
> +def _get_mergable_
> + """Return a list of the mergable proposals for the given branch."""
> + proposals = []
> + for entry in lp_branch.
> + logger.
> +
> + if entry.queue_status != u'Approved':
> + logger.debug(
> + " Skipping proposal: status is {0}, not "
> + "'Approved'
> + continue
> +
> + if (not imply_commit_
> + logger.debug(
> + " Skipping proposal: proposal has no commit message")
> + continue
> +
> + proposals.
> + return proposals
> +
This seems a natural candidate for an iterator. Still, no big deal.
> +def _get_reviews( proposal) : append( '%s;%s' % (vote.reviewer. display_ name,
> + """Get the set of reviews from the proposal."""
> + reviews = []
> + for vote in proposal.votes:
> + if not vote.comment:
> + continue
> + else:
> + reviews.
> + vote.comment.vote))
> +
> + if len(reviews) == 0:
> + return None
> +
> + return reviews
> +
Again, a potential iterator, and again, I don't care enough for this branch.
Implementation could probably be more functional, but even this is a
huge step forwards.
> +
> +def setup(logger, debug=False, http_debug=False):
"setup" is a noun, "set up" a verb phrase. This should be spelled
"set_up". Also, it should probably say what it's going to set up.
> +def merge_proposals (target, proposals, logger, config, command): debug(' Firing tarmac_pre_merge hook') hooks.fire( 'tarmac_ pre_merge' , target, proposal, logger, append( status)
> + logger.
> + tarmac_
> + command, target)
> +
> + statuses = []
> + try:
> + for proposal in proposals:
> + status = merge_proposal(
> + config, command)
> + statuses.
> + # This except is here because we need the else and can't have it
> + # without an except as well.
Wat.
try:
thing()
except:
raise
else:
another_thing()
...