~mrazik/jenkins-launchpad-plugin/rebuild_link

« back to all changes in this revision

Viewing changes to launchpadTrigger.py

  • Committer: Martin Mrazik
  • Date: 2012-05-30 14:04:13 UTC
  • mto: This revision was merged to the branch mainline in revision 17.
  • Revision ID: martin.mrazik@canonical.com-20120530140413-b21xabvvqx1g9ewm
Simplified the laucnhpadTrigger workflow

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
from launchpad import LaunchpadTrigger
8
8
 
9
9
 
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."""
12
12
 
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)
16
16
 
17
17
 
23
23
    launchpad_trigger.trigger_al_building(mps, job, jenkins_url)
24
24
 
25
25
 
26
 
def build_state(autoland,
27
 
                approved,
28
 
                wip,
29
 
                needs_review):
30
 
    """Build a state dict from given attributes.
31
 
 
32
 
    Note that "Work In Progress" and "Needs Review" states are not
33
 
    relevant when autolanding.
34
 
    """
35
 
 
36
 
    state = []
37
 
    if approved:
38
 
        state.append('Approved')
39
 
    if not autoland:
40
 
        if wip:
41
 
            state.append('Work in progress')
42
 
        if needs_review:
43
 
            state.append('Needs review')
44
 
    return state
45
 
 
46
 
 
47
26
def trigger_jenkins(branch,
48
27
                autoland=False,
49
 
                trigger=False,
50
 
                approved=False,
51
 
                wip=False,
52
 
                needs_review=False,
 
28
                trigger_ci=False,
53
29
                job=None,
54
30
                jenkins_url=None):
55
31
    """Trigger a Jenkins build."""
57
33
    if jenkins_url is None:
58
34
        jenkins_url = JENKINS_URL
59
35
 
60
 
    state = build_state(approved, autoland, wip, needs_review)
61
 
 
62
 
    if trigger:
63
 
        trigger_ci_building(branch, state, job, jenkins_url)
64
 
        return 1
 
36
    if trigger_ci:
 
37
        trigger_ci_building(branch, job, jenkins_url)
65
38
    elif autoland:
66
39
        trigger_al_building(branch, job, jenkins_url)
67
 
        return 1
68
 
    # FIXME: what to return here?
69
 
 
 
40
    return 1
70
41
 
71
42
def main():
72
43
 
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',
84
 
                        action='store_true',
85
 
                        help="select 'Approved' proposals")
86
 
    parser.add_argument('-w', '--wip',
87
 
                        action='store_true',
88
 
                        help="select 'Work In Progress' proposals")
89
 
    parser.add_argument('-n', '--needs-review',
90
 
                        action='store_true',
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())
97
59
 
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']:
102
 
        if not args['job']:
103
 
            parser.error(
104
 
                'you need to define jenkins job if you want to trigger one')
 
60
    if not args['trigger_ci'] and not args['autoland']:
 
61
        parser.error(
 
62
            'You need to specify one of --trigger-ci (-t) or --autoland (-l)')
105
63
 
106
64
    return trigger_jenkins(**args)
107
65