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

Proposed by James Westby on 2012-12-18
Status: Merged
Approved by: Jonathan Lange on 2012-12-19
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) 2012-12-18 Approve on 2012-12-19
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.
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
1=== modified file 'tarmac/bin/commands.py'
2--- tarmac/bin/commands.py 2012-12-18 21:25:38 +0000
3+++ tarmac/bin/commands.py 2012-12-18 21:25:38 +0000
4@@ -400,3 +400,50 @@
5 if len(filter(lambda x: x is False, statuses)) > 0:
6 return 2
7 return 0
8+
9+
10+class cmd_check(TarmacCommand):
11+ '''Check whether there are any merge proposals ready to land.'''
12+
13+ takes_args = ['branch_url']
14+ takes_options = [
15+ options.http_debug_option,
16+ options.debug_option]
17+
18+ def _any_merges(self, branch_url):
19+
20+ lp_branch = self.launchpad.branches.getByUrl(url=branch_url)
21+ if lp_branch is None:
22+ self.logger.info('Not a valid branch: {0}'.format(branch_url))
23+ return
24+
25+ proposals = _get_mergable_proposals_for_branch(lp_branch, self.logger)
26+
27+ if not proposals:
28+ self.logger.info(
29+ 'No approved proposals found for %(branch_url)s' % {
30+ 'branch_url': branch_url})
31+ return False
32+ return True
33+
34+ def run(self, branch_url, launchpad=None, **kwargs):
35+ for key, value in kwargs.iteritems():
36+ self.config.set('Tarmac', key, value)
37+
38+ setup(self.logger, debug=self.config.debug,
39+ http_debug=self.config.http_debug)
40+
41+ self.launchpad = launchpad
42+ if self.launchpad is None:
43+ self.logger.debug('Loading launchpad object')
44+ self.launchpad = self.get_launchpad_object()
45+ self.logger.debug('launchpad object loaded')
46+
47+ self.logger.debug('%(branch_url)s specified as branch_url' % {
48+ 'branch_url': branch_url})
49+ if not branch_url.startswith('lp:'):
50+ raise TarmacCommandError('Branch urls must start with lp:')
51+ ret = self._any_merges(branch_url)
52+ if ret:
53+ return 0
54+ return 1

Subscribers

People subscribed via source and target branches