Last active
December 15, 2015 04:39
-
-
Save petermd/5203384 to your computer and use it in GitHub Desktop.
post-commit hook for svn to notify pivotaltracker (see https://www.pivotaltracker.com/help/api?version=v5#Tracker_Updates_in_SCM_Post_Commit_Hooks)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# | |
# post-commit hook for svn to notify pivotaltracker | |
# | |
# Posts commit to pivotal to enable auto-tracking of commits. Adds viewvc link if url provided. Place in SVN/hooks/post-commit as follows | |
# | |
# pivotal_notify.py -v "http://SVNSERVER/BIN/viewvc.cgi" "$REPOS" "$REV" "$PIVOTAL_API_TOKEN" | |
# | |
from xml.sax.saxutils import escape | |
import os,sys,getopt | |
import urllib2 | |
def usage(reason): | |
if (reason): | |
print "ERR: "+reason | |
print "pivotal-notify.py [-v VIEWVC] REPO REV TOKEN" | |
sys.exit(2) | |
def svnlook(cmd,repo,rev): | |
return os.popen("/usr/bin/svnlook "+cmd+" "+repo+" -r "+REV).read(); | |
def pivotal_notify(path,token,data): | |
httpReq=urllib2.Request(url="https://www.pivotaltracker.com"+path, | |
data=data, | |
headers={'Content-Type' : 'application/xml', | |
'X-TrackerToken' : token}) | |
return urllib2.urlopen(httpReq).read() | |
# Config | |
# SVN Commit Hook | |
try: | |
opts,args=getopt.getopt(sys.argv[1:],"v:") | |
except getopt.GetoptError,err: | |
usage(err) | |
if len(args)!=3: | |
usage("incorrect number of arguments") | |
VIEWVC=None | |
for o,a in opts: | |
if o=="-v": | |
VIEWVC=a | |
else: | |
usage("unsupported argument") | |
REPO=args[0] | |
REV=args[1] | |
PIVOTAL_TOKEN=args[2] | |
author=svnlook("author",REPO,REV).strip() | |
commitMsg=svnlook("log",REPO,REV).strip() | |
# Message | |
url="" | |
if (VIEWVC): | |
url='<url>'+escape(VIEWVC+"?view=rev&revision="+REV)+'</url>' | |
request='<source_commit><message>'+escape(commitMsg)+'</message><author>'+escape(author)+'</author><commit_id>'+REV+'</commit_id>'+url+'</source_commit>' | |
response=pivotal_notify("/services/v5/source_commits",PIVOTAL_TOKEN,request) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated for pivotal api v5 / https endpoint