Created
January 28, 2013 14:07
-
-
Save simon-engledew/4655764 to your computer and use it in GitHub Desktop.
cow-say for git post-receive and campfire
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 | |
import json | |
import requests | |
import json | |
import commands | |
import pipes | |
import sys | |
import glob | |
import os | |
import random | |
singleton = lambda fn: fn() | |
@singleton | |
def config(): | |
with open(os.path.expanduser('~/.campfire'), 'r') as handle: | |
return json.load(handle) | |
cow_formats = [os.path.splitext(os.path.basename(path))[0] for path in glob.glob('/usr/share/cowsay/cows/*.cow')] | |
cow_format = lambda: random.choice(cow_formats) | |
oldrev, newrev, refname = sys.stdin.read().split() | |
for message in (message.strip() for message in commands.getoutput("git log --format='[%an] %s' {0}..{1}".format(oldrev, newrev)).split('\n')): | |
message = json.dumps({ | |
'message': { | |
'body': commands.getoutput('/usr/games/cowsay -f {0} {1}'.format(pipes.quote(cow_format()), pipes.quote(message))), | |
'type': 'PasteMessage' | |
} | |
}) | |
requests.post( | |
'https://{user}.campfirenow.com/room/{room}/speak.json'.format(**config), | |
data=message, | |
headers={'Content-Type': 'application/json'}, | |
auth=(config['token'], 'X'), | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment