Skip to content

Instantly share code, notes, and snippets.

@petermd
Last active December 15, 2015 04:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petermd/5203384 to your computer and use it in GitHub Desktop.
Save petermd/5203384 to your computer and use it in GitHub Desktop.
#!/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)
@petermd
Copy link
Author

petermd commented May 13, 2014

Updated for pivotal api v5 / https endpoint

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment