pullreq_to_mantisbt.py

changeset 4
7c02e457e6ab
child 5
9d63b4f82112
equal deleted inserted replaced
3:b328fdc09692 4:7c02e457e6ab
1 #!/usr/bin/env python
2
3 import json
4 import urllib
5 import urllib2
6 import sys
7 import re
8 from suds.xsd.doctor import Import
9 from suds.xsd.doctor import ImportDoctor
10 from suds.client import Client
11
12 bturl=sys.argv[1]
13 btuser=sys.argv[2]
14 btpass=sys.argv[3]
15 ticket=sys.argv[4]
16 bitbucketjson=sys.argv[5]
17 titlefile=sys.argv[6]
18
19 with open (bitbucketjson, 'r') as fp:
20 jsondata = json.loads (fp.read())
21
22 with open (titlefile, 'r') as fp:
23 title = fp.read()
24
25 regex = re.compile (r'^https://api\.bitbucket\.org/2\.0/repositories/([^/]+)/([^/]+)/pullrequests/([0-9]+)$')
26 match = regex.match (jsondata["links"]["self"]["href"])
27
28 if not match:
29 print "Bad JSON input (couldn't regex the pull request URL)"
30 quit()
31
32 suds_import = Import ('http://schemas.xmlsoap.org/soap/encoding/', \
33 'http://schemas.xmlsoap.org/soap/encoding/')
34 suds_client = Client ('https://%s/api/soap/mantisconnect.php?wsdl' % bturl, \
35 plugins=[ImportDoctor (suds_import)])
36
37 data = suds_client.service.mc_issue_get (btuser, btpass, ticket)
38 data["status"]["id"] = 60
39 suds_client.service.mc_issue_update (btuser, btpass, ticket, data)
40 note = {}
41 note["text"] = "https://bitbucket.org/%s/%s/pull-request/%s" % (match.group(1), match.group(2), match.group(3))
42 noteid = suds_client.service.mc_issue_note_add (btuser, btpass, ticket, note)
43 print "Pullrequest notice posted to mantisbt: https://%s/view.php?id=%s#c%s" % (bturl, ticket, noteid)
44

mercurial