Sun, 08 Jun 2014 19:24:37 +0300
- added automatic tracker updating but commented it out since it also bumps timestamps on every note on said ticket...
.hgignore | file | annotate | diff | comparison | revisions | |
pull-request.sh | file | annotate | diff | comparison | revisions | |
pullreq_to_mantisbt.py | file | annotate | diff | comparison | revisions |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Sun Jun 08 19:24:37 2014 +0300 @@ -0,0 +1,1 @@ +settings.cfg
--- a/pull-request.sh Sun Jun 08 17:17:22 2014 +0300 +++ b/pull-request.sh Sun Jun 08 19:24:37 2014 +0300 @@ -8,8 +8,8 @@ fi # Get path to this script -pushd `dirname $0` >/dev/null - selfpath=`pwd` +pushd $(dirname $0) >/dev/null + selfpath=$(dirname $(readlink $0)) popd >/dev/null # What's the upstream? @@ -78,6 +78,10 @@ head=$(echo $heads |cut -d ' ' -f $head_index) title=$(hg log -r ${head} -r tip --template '{desc}') source_repo=$(hg paths default |rev |cut -d '/' -f 1,2 |rev) +bturl=$(grep bturl $selfpath/settings.cfg |cut -d ' ' -f 2) +btuser=$(grep btuser $selfpath/settings.cfg |cut -d ' ' -f 2) +btpass=$(grep btpass $selfpath/settings.cfg |cut -d ' ' -f 2) +ticket=$(hg log -r $head --template '{bookmarks}' |cut -f 2 -d '|') while [ "$(echo $title |wc -c)" -gt "255" ] do @@ -104,7 +108,21 @@ response=$(tempfile) # Post the pull request. -curl -X POST -H "Content-Type: application/json" -u "${username}:${password}" \ - "https://api.bitbucket.org/2.0/repositories/${upstream}/pullrequests" -d "$json" -o "$response" >/dev/stdout 2>&1 +curl \ + -X POST \ + -H "Content-Type: application/json" \ + -u "${username}:${password}" \ + -d "$json" \ + -o "$response" \ + "https://api.bitbucket.org/2.0/repositories/${upstream}/pullrequests" \ + >/dev/stdout 2>&1 echo "response JSON: $response" + +# if [ -n "$bturl" -a -n "$btuser" -a -n "$btpass" -a -n "$ticket" ] +# then +# titlefile=$(tempfile) +# echo -n $title >$titlefile +# python $selfpath/pullreq_to_mantisbt.py "$bturl" "$btuser" "$btpass" "$ticket" "$response" "$titlefile" +# rm $titlefile +# fi \ No newline at end of file
--- /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) +