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={} |
|
38 data["status"]={} |
|
39 data["status"]["id"] = 60 |
|
40 suds_client.service.mc_issue_update (btuser, btpass, ticket, data) |
|
41 note = {} |
|
42 note["text"] = "https://bitbucket.org/%s/%s/pull-request/%s" % (match.group(1), match.group(2), match.group(3)) |
|
43 noteid = suds_client.service.mc_issue_note_add (btuser, btpass, ticket, note) |
|
44 print "Pull request notice posted to mantisbt: https://%s/view.php?id=%s#c%s" % (bturl, ticket, noteid) |
|