X-Git-Url: http://andersk.mit.edu/gitweb/zcommit.git/blobdiff_plain/c3d0ddbaedda638e063f075c3ddb1efe6b9d89d7..HEAD:/zcommit.py
diff --git a/zcommit.py b/zcommit.py
index e56aedb..ed11afb 100755
--- a/zcommit.py
+++ b/zcommit.py
@@ -8,8 +8,9 @@ import os
import subprocess
import sys
import traceback
+import dateutil.parser
-HERE = os.path.dirname(__file__)
+HERE = os.path.abspath(os.path.dirname(__file__))
ZWRITE = os.path.join(HERE, 'bin', 'zsend')
LOG_FILENAME = 'logs/zcommit.log'
@@ -35,13 +36,44 @@ msg: %(msg)s""" % {'sender' : sender,
'msg' : msg})
cmd = [ZWRITE, '-S', sender, '-c', klass, '-i', instance,
'-s', zsig, '-d', '-m', msg]
- subprocess.check_call(cmd)
+ subprocess.check_call([p.encode('utf-8') for p in cmd])
class Application(object):
@cherrypy.expose
def index(self):
logger.debug('Hello world app reached')
- return 'Hello world!'
+ return """
+
Welcome to zcommit.
+
+ zcommit allows you to send zephyr notifications by sending an HTTP
+POST request to a URL. Currently zcommit supports POST-backs from
+github. If you would like it to support another form of POST-back,
+please let us know (zcommit@mit.edu).
+
+ URL structure
+
+The URL you post to is structured as follows:
+http://zcommit.mit.edu/$type/$key1/$value1/$key2/$value2/....
+So for example, the URL
+http://zcommit.mit.edu/github/class/zcommit/instance/commit
+is parsed as having type github, class zcommit, and
+instance commit. Using this information, zcommit figures out
+how to form a useful message which is then sends as a zephyr.
+
+ Types
+
+ Github
+
+Set your POST-back URL to
+http://zcommit.mit.edu/github/class/$classname, followed by
+any of the following optional key/value parameters:
+
+
+- /instance/$instance
+- /zsig/$zsig (sets the prefix of the zsig; the postfix is always the branch name)
+- /sender/$sender
+
+"""
class Github(object):
@cherrypy.expose
@@ -60,7 +92,7 @@ class Application(object):
raise cherrypy.HTTPError(400, 'Invalid submission URL')
logger.debug('Passed validation')
for i in xrange(0, len(args), 2):
- opts[args[i]] = args[i + 1]
+ opts[args[i]] = unicode(args[i + 1], 'utf-8', 'replace')
logger.debug('Set opts')
if 'class' not in opts:
raise cherrypy.HTTPError(400, 'Must specify a zephyr class name')
@@ -74,26 +106,30 @@ class Application(object):
zsig = '%s: %s' % (opts['zsig'], zsig)
sender = opts.get('sender', 'daemon.zcommit')
logger.debug('Set zsig')
- for c in reversed(payload['commits']):
+ for c in payload['commits']:
inst = opts.get('instance', c['id'][:8])
actions = []
if c.get('added'):
- actions.append('Added: %s\n' % '\n '.join(c['added']))
+ actions.extend(' A %s\n' % f for f in c['added'])
if c.get('removed'):
- actions.append('Removed: %s\n' % '\n '.join(c['removed']))
+ actions.extend(' D %s\n' % f for f in c['removed'])
if c.get('modified'):
- actions.append('Modified: %s\n' % '\n '.join(c['modified']))
+ actions.extend(' M %s\n' % f for f in c['modified'])
if not actions:
- actions.append('Something weird happened... could not figure out what action to take')
+ actions.append('Did not add/remove/modify any nonempty files.')
info = {'name' : c['author']['name'],
'email' : c['author']['email'],
'message' : c['message'],
- 'timestamp' : c['timestamp'],
- 'actions' : '--\n'.join(actions)}
+ 'timestamp' : dateutil.parser.parse(c['timestamp']).strftime('%F %T %z'),
+ 'actions' : ''.join(actions),
+ 'url' : c['url']}
- msg = """%(name)s <%(email)s> (%(timestamp)s)
-> %(message)s
---
+ msg = """%(url)s
+Author: %(name)s <%(email)s>
+Date: %(timestamp)s
+
+%(message)s
+---
%(actions)s""" % info
zephyr(sender, opts['class'], inst, zsig, msg)
msg = 'Thanks for posting!'