pullreq_to_mantisbt.py

Sun, 08 Jun 2014 19:24:37 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Sun, 08 Jun 2014 19:24:37 +0300
changeset 4
7c02e457e6ab
child 5
9d63b4f82112
permissions
-rw-r--r--

- added automatic tracker updating but commented it out since it also bumps timestamps on every note on said ticket...

#!/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)

mercurial