Merge lp:~james-w/tarmac/check-command into lp:~ubuntuone-hackers/tarmac/trunk

Proposed by James Westby
Status: Merged
Approved by: Jonathan Lange
Approved revision: 421
Merged at revision: 422
Proposed branch: lp:~james-w/tarmac/check-command
Merge into: lp:~ubuntuone-hackers/tarmac/trunk
Prerequisite: lp:~james-w/tarmac/exit-status
Diff against target: 54 lines (+47/-0)
1 file modified
tarmac/bin/commands.py (+47/-0)
To merge this branch: bzr merge lp:~james-w/tarmac/check-command
Reviewer Review Type Date Requested Status
Jonathan Lange (community) Approve
Review via email: mp+140552@code.launchpad.net

This proposal supersedes a proposal from 2012-12-18.

Description of the change

Hi,

This adds the "check" command that we were using with the jenkins
scripttrigger plugin to only run the job if there were branches to
merge.

Thanks,

James

To post a comment you must log in.
Revision history for this message
Jonathan Lange (jml) wrote :

Good to land.

_any_merges should probably have a docstring, or at least get rid of that blank line after the function declaration.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'tarmac/bin/commands.py'
--- tarmac/bin/commands.py 2012-12-18 21:25:38 +0000
+++ tarmac/bin/commands.py 2012-12-18 21:25:38 +0000
@@ -400,3 +400,50 @@
400 if len(filter(lambda x: x is False, statuses)) > 0:400 if len(filter(lambda x: x is False, statuses)) > 0:
401 return 2401 return 2
402 return 0402 return 0
403
404
405class cmd_check(TarmacCommand):
406 '''Check whether there are any merge proposals ready to land.'''
407
408 takes_args = ['branch_url']
409 takes_options = [
410 options.http_debug_option,
411 options.debug_option]
412
413 def _any_merges(self, branch_url):
414
415 lp_branch = self.launchpad.branches.getByUrl(url=branch_url)
416 if lp_branch is None:
417 self.logger.info('Not a valid branch: {0}'.format(branch_url))
418 return
419
420 proposals = _get_mergable_proposals_for_branch(lp_branch, self.logger)
421
422 if not proposals:
423 self.logger.info(
424 'No approved proposals found for %(branch_url)s' % {
425 'branch_url': branch_url})
426 return False
427 return True
428
429 def run(self, branch_url, launchpad=None, **kwargs):
430 for key, value in kwargs.iteritems():
431 self.config.set('Tarmac', key, value)
432
433 setup(self.logger, debug=self.config.debug,
434 http_debug=self.config.http_debug)
435
436 self.launchpad = launchpad
437 if self.launchpad is None:
438 self.logger.debug('Loading launchpad object')
439 self.launchpad = self.get_launchpad_object()
440 self.logger.debug('launchpad object loaded')
441
442 self.logger.debug('%(branch_url)s specified as branch_url' % {
443 'branch_url': branch_url})
444 if not branch_url.startswith('lp:'):
445 raise TarmacCommandError('Branch urls must start with lp:')
446 ret = self._any_merges(branch_url)
447 if ret:
448 return 0
449 return 1

Subscribers

People subscribed via source and target branches