2018-08-22 05:04:11 +00:00
|
|
|
#!/usr/bin/env python2
|
2018-08-22 14:24:30 +00:00
|
|
|
import os
|
2018-10-02 04:39:42 +00:00
|
|
|
import sys
|
2018-08-22 05:04:11 +00:00
|
|
|
from argparse import ArgumentParser
|
2018-10-02 04:39:42 +00:00
|
|
|
|
2018-08-22 14:24:30 +00:00
|
|
|
from launchpadlib.credentials import UnencryptedFileCredentialStore
|
2018-08-22 05:04:11 +00:00
|
|
|
from launchpadlib.launchpad import Launchpad
|
|
|
|
|
2018-10-02 04:39:42 +00:00
|
|
|
|
2018-08-22 14:24:30 +00:00
|
|
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
|
2018-08-22 05:04:11 +00:00
|
|
|
|
|
|
|
def parse_args():
|
|
|
|
"""
|
|
|
|
Parse the command line arguments
|
|
|
|
"""
|
|
|
|
parser = ArgumentParser()
|
|
|
|
parser.add_argument('-p', '--merge-proposal', required=True,
|
|
|
|
help='The main part of the URL to the merge proposal, without the hostname.')
|
|
|
|
parser.add_argument('-m', '--message', required=True,
|
|
|
|
help='The comment to add to the merge proposal')
|
2018-08-22 23:06:26 +00:00
|
|
|
parser.add_argument('-s', '--subject', default=None, help='The subject for the comment')
|
2018-08-22 05:04:11 +00:00
|
|
|
return parser.parse_args()
|
|
|
|
|
|
|
|
|
|
|
|
def get_merge_proposal(merge_proposal_url):
|
|
|
|
"""
|
|
|
|
Get the merge proposal for the ``merge_proposal_url``
|
|
|
|
"""
|
2018-08-22 14:24:30 +00:00
|
|
|
lp = Launchpad.login_with('OpenLP CI', 'production', version='devel',
|
|
|
|
credential_store=UnencryptedFileCredentialStore(os.path.join(HERE, 'launchpadcreds.txt')))
|
2018-08-22 05:04:11 +00:00
|
|
|
openlp_project = lp.projects['openlp']
|
|
|
|
merge_proposals = openlp_project.getMergeProposals()
|
|
|
|
for merge_proposal in merge_proposals:
|
2018-08-22 05:10:51 +00:00
|
|
|
if str(merge_proposal).endswith(merge_proposal_url):
|
2018-08-22 05:04:11 +00:00
|
|
|
return merge_proposal
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
2018-08-22 23:06:26 +00:00
|
|
|
def create_comment(merge_proposal, comment, subject):
|
2018-08-22 05:04:11 +00:00
|
|
|
"""
|
|
|
|
Create a comment on the merge proposal
|
|
|
|
"""
|
2018-08-22 23:06:26 +00:00
|
|
|
if not subject:
|
|
|
|
subject = 'Jenkins test update'
|
2018-08-27 17:48:47 +00:00
|
|
|
merge_proposal.createComment(subject=subject, content=comment)
|
2018-08-22 05:04:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
"""
|
|
|
|
Run the thing
|
|
|
|
"""
|
|
|
|
args = parse_args()
|
|
|
|
merge_proposal = get_merge_proposal(args.merge_proposal)
|
|
|
|
if not merge_proposal:
|
|
|
|
print('No merge proposal with that URL found')
|
|
|
|
sys.exit(1)
|
|
|
|
else:
|
2018-08-22 23:06:26 +00:00
|
|
|
create_comment(merge_proposal, args.message, args.subject)
|
2018-08-22 05:10:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|