diff -r b328fdc09692 -r 7c02e457e6ab pullreq_to_mantisbt.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pullreq_to_mantisbt.py Sun Jun 08 19:24:37 2014 +0300 @@ -0,0 +1,44 @@ +#!/usr/bin/env python + +import json +import urllib +import urllib2 +import sys +import re +from suds.xsd.doctor import Import +from suds.xsd.doctor import ImportDoctor +from suds.client import Client + +bturl=sys.argv[1] +btuser=sys.argv[2] +btpass=sys.argv[3] +ticket=sys.argv[4] +bitbucketjson=sys.argv[5] +titlefile=sys.argv[6] + +with open (bitbucketjson, 'r') as fp: + jsondata = json.loads (fp.read()) + +with open (titlefile, 'r') as fp: + title = fp.read() + +regex = re.compile (r'^https://api\.bitbucket\.org/2\.0/repositories/([^/]+)/([^/]+)/pullrequests/([0-9]+)$') +match = regex.match (jsondata["links"]["self"]["href"]) + +if not match: + print "Bad JSON input (couldn't regex the pull request URL)" + quit() + +suds_import = Import ('http://schemas.xmlsoap.org/soap/encoding/', \ + 'http://schemas.xmlsoap.org/soap/encoding/') +suds_client = Client ('https://%s/api/soap/mantisconnect.php?wsdl' % bturl, \ + plugins=[ImportDoctor (suds_import)]) + +data = suds_client.service.mc_issue_get (btuser, btpass, ticket) +data["status"]["id"] = 60 +suds_client.service.mc_issue_update (btuser, btpass, ticket, data) +note = {} +note["text"] = "https://bitbucket.org/%s/%s/pull-request/%s" % (match.group(1), match.group(2), match.group(3)) +noteid = suds_client.service.mc_issue_note_add (btuser, btpass, ticket, note) +print "Pullrequest notice posted to mantisbt: https://%s/view.php?id=%s#c%s" % (bturl, ticket, noteid) +