7
7
from launchpad import LaunchpadTrigger
10
def trigger_ci_building(branch, state, job, jenkins_url):
10
def trigger_ci_building(branch,job, jenkins_url):
11
11
"""Trigger a CI build."""
13
13
launchpad_trigger = LaunchpadTrigger()
14
mps = launchpad_trigger.get_merge_proposals(branch, state)
14
mps = launchpad_trigger.get_merge_proposals(branch, ['Needs review'])
15
15
launchpad_trigger.trigger_ci_building(mps, job, jenkins_url)
23
23
launchpad_trigger.trigger_al_building(mps, job, jenkins_url)
26
def build_state(autoland,
30
"""Build a state dict from given attributes.
32
Note that "Work In Progress" and "Needs Review" states are not
33
relevant when autolanding.
38
state.append('Approved')
41
state.append('Work in progress')
43
state.append('Needs review')
47
26
def trigger_jenkins(branch,
55
31
"""Trigger a Jenkins build."""
57
33
if jenkins_url is None:
58
34
jenkins_url = JENKINS_URL
60
state = build_state(approved, autoland, wip, needs_review)
63
trigger_ci_building(branch, state, job, jenkins_url)
37
trigger_ci_building(branch, job, jenkins_url)
66
39
trigger_al_building(branch, job, jenkins_url)
68
# FIXME: what to return here?
74
45
description="Trigger a Jenkins job resulting from a merge proposal.")
75
46
parser.add_argument('-b', '--branch', required=True,
76
47
help="the proposed Launchpad branch to merge")
77
parser.add_argument('-t', '--trigger',
48
parser.add_argument('-t', '--trigger-ci',
78
49
action='store_true',
79
50
help="trigger a 'CI' build")
80
51
parser.add_argument('-l', '--autoland',
81
52
action='store_true',
82
53
help="trigger an autolanding build")
83
parser.add_argument('-a', '--approved',
85
help="select 'Approved' proposals")
86
parser.add_argument('-w', '--wip',
88
help="select 'Work In Progress' proposals")
89
parser.add_argument('-n', '--needs-review',
91
help="select 'Needs Review' proposals")
92
parser.add_argument('-j', '--job',
54
parser.add_argument('-j', '--job', required=True,
93
55
help="name of the Jenkins job to trigger")
94
parser.add_argument('-e', '--jenkins-url',
56
parser.add_argument('-e', '--jenkins-url',
95
57
help="URL of the Jenkins job to trigger")
96
58
args = vars(parser.parse_args())
98
if (args['trigger'] and not args['approved'] and not args['wip']
99
and not args['needs_review']):
100
parser.error('you must specify one of -a, -w or -n')
101
if args['trigger'] or args['autoland']:
104
'you need to define jenkins job if you want to trigger one')
60
if not args['trigger_ci'] and not args['autoland']:
62
'You need to specify one of --trigger-ci (-t) or --autoland (-l)')
106
64
return trigger_jenkins(**args)