1
1
from argparse import ArgumentParser
3
from jlp import launchpadutils, get_launchpad, logger
4
from jlp import launchpadutils, get_launchpad, logger, get_config_option, get_jinja_environment
6
7
from shutil import rmtree
19
20
help="URL of the merge proposal to update")
20
21
parser.add_argument('-i', '--skip-message', action='store_true',
21
22
help="Skip checking if a commit message is set")
23
parser.add_argument('-t', '--template-dir',
24
help='Optional directory of alternate jinja2 templates.',
22
26
args = vars(parser.parse_args())
24
28
# launchpadlib is not thread/process safe so we are creating launchpadlib
42
46
# this is the status from tests
43
47
overal_status = args['status']
44
# by default reason is empty as it is usually just a failed build
47
49
#override the status to FAILED and set reason if no commit message is set
48
50
match = re.match('^(.*)/job/([^/]*)/.*$', args['build_url'])
51
template = 'ci_test.j2'
49
52
if args['skip_message']:
50
53
logger.debug('Skipping check for empty commit message')
54
57
if not launchpadutils.is_commit_message_set(mp,
55
58
jenkins_job, jenkins_url):
56
59
overal_status = 'FAILED'
57
reason = "No commit message was specified in the merge " + \
58
"proposal. Click on the following link and set the " + \
59
"commit message (if you want a jenkins rebuild you " +\
60
"need to trigger it yourself):\n" + \
61
args['merge_proposal'] + "/+edit-commit-message\n"
60
template = 'no_commit.j2'
62
61
logger.debug('Commit message not set. Failing CI.')
64
63
logger.debug('Unable to get job name from build_url.' +
65
64
'Skipping check for empty commit message')
67
if overal_status == 'PASSED':
68
launchpadutils.approve_mp(mp, args['revision'], args['build_url'])
69
else: # status == False corresponds to NOT 'PASSED'
70
launchpadutils.disapprove_mp(mp,
66
template_args = launchpadutils.get_template_args(
70
args['merge_proposal']
72
env = get_jinja_environment(args['template_dir'])
73
real_template = env.get_template(template)
74
msg = real_template.render(args=template_args)
75
if overal_status != 'PASSED':
76
launchpadutils.report_to_launchpad(
80
vote=launchpadutils.LaunchpadVote.NEEDS_FIXING
83
launchpadutils.report_to_launchpad(
87
vote=launchpadutils.LaunchpadVote.APPROVE