Skip to content

Instantly share code, notes, and snippets.

@zimmerst
Created May 31, 2017 00:40
Show Gist options
  • Save zimmerst/928967a480d6e1b0b794eec06874a360 to your computer and use it in GitHub Desktop.
Save zimmerst/928967a480d6e1b0b794eec06874a360 to your computer and use it in GitHub Desktop.
notification script to keep track of svn changes
#!/RAID/USERS/zimmer/sw/python2.7/bin/python2.7
from slackweb import Slack
from tempfile import NamedTemporaryFile
from subprocess import Popen
from sys import exit as sys_exit
from time import ctime-hook.py
def svnlook(arg,repo,multiline=True):nw slack-commit-hook.py
command="svnlook {arg} {repo}".format(arg=arg,repo=repo)
tmp_err = NamedTemporaryFile(dir="/tmp", delete=True)
tmp_out = NamedTemporaryFile(dir="/tmp", delete=True)
p = Popen(command.split(), stdout=tmp_out, stderr=tmp_err, shell=False)
rc = p.wait() emacs -nw slack-commit-hook.py
if rc:nc scripts]$ ./post-commit
tmp_err.seek(0)fg
fout = open(__file__.replace(".py",".err","a"))
fout.write("{date}: error for svnlook {arg} {rep}\n".format(date=ctime(),arg=arg,rep=repo))
fout.write("".join(tmp_err.readlines()))
fout.close()
tmp_err.close()
sys_exit(1)
else:
tmp_out.seek(0)
f = tmp_out.read()
tmp_out.close()
if multiline:
return f.strip()
else:
return f
url="https://hooks.slack.com/services/YOURTOKEN"
channel="#svn"
icon_emoji=":robot_face:"
username="svn-notify-bot"
repo="/name/of/svn/repo/on/server"
#lookup = ['author','date','log','changed']
msg = ""
my_map = {"author":"author","date":"commit time","log":"commit message","youngest":"revision"}
rev=""
for key in ['author','date','log','youngest']:
val = svnlook(key,repo,multiline=True)
if key == "youngest":
rev = val
val = "<{url}|{val}>".format(val=val,url="http://dpnc.unige.ch/trac/dampe/changeset/{val}/DmpSoftware/branches".format(val=rev))
msg+="*{key}*: {val}\n".format(key=my_map[key],val=val)
changelog = svnlook("changed",repo)
msg+="*changed files*:\n```{ch}```".format(ch=changelog)
slack = Slack(url=url)
slack.notify(text=msg,channel=channel,icon_emoji=icon_emoji,username=username,mrkdwn=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment