]> andersk Git - zcommit.git/commitdiff
Initial checkin
authorGreg Brockman <gdb@mit.edu>
Tue, 23 Mar 2010 07:25:38 +0000 (03:25 -0400)
committerGreg Brockman <gdb@mit.edu>
Tue, 23 Mar 2010 07:25:38 +0000 (03:25 -0400)
zcommit.py [new file with mode: 0755]

diff --git a/zcommit.py b/zcommit.py
new file mode 100755 (executable)
index 0000000..59f1678
--- /dev/null
@@ -0,0 +1,70 @@
+#!/usr/bin/python
+
+import cherrypy
+from flup.server.fcgi import WSGIServer
+import subprocess
+import sys
+
+def zephyr(klass, instance, zsig, msg):
+    # TODO: spoof the sender
+    cmd = ['zwrite', '-c', klass, '-i', instance,
+           '-s', zsig, '-d', '-m', msg]
+    subprocess.check_call(cmd)
+
+class Application(object):
+    @cherrypy.expose
+    def index(self):
+        return 'Hello world!'
+
+    @cherrypy.expose
+    def default(self, *args, **kwargs):
+        return 'hello'
+
+    class Github(object):
+        @cherrypy.expose
+        def default(self, *args, **query):
+            opts = {}
+            if len(args) % 2:
+                raise cherrypy.HTTPError(400, 'Invalid submission URL')
+            for i in xrange(0, len(args), 2):
+                opts[args[i]] = args[i + 1]
+
+            if 'class' not in opts:
+                raise cherrypy.HTTPError(400, 'Must specify a zephyr class name')
+
+            if cherrypy.request.method == 'POST':
+                payload = json.loads(query['payload'])
+
+                zsig = payload['ref']
+                if 'zsig' in opts:
+                    zsig = '%s: %s' % (opts['zsig'], zsig)
+                else:
+                    zsig = 'zcommit bot'
+
+                for c in reversed(payload['commits']):
+                    inst = opts.get('instance', c['id'][:8])
+                    c['added_as_str'] = '\n'.join(c['added'])
+                    msg = """%(name)s <%(email)s>
+%(message)s
+%(timestamp)s
+--
+%(added)s""" % c
+                    zephyr(opts['class'], inst, zsig, msg)
+            else:
+                msg = ('If you had sent a POST request to this URL, would have sent'
+                       ' a zepyhr to -c %s' % opts['class'])
+            return msg
+
+    github = Github()
+
+def main():
+    app = cherrypy.tree.mount(Application(), '/zcommit')
+    cherrypy.server.unsubscribe()
+    cherrypy.engine.start()
+    try:
+        WSGIServer(app, environ={'SCRIPT_NAME' : '/zcommit'}).run()
+    finally:
+        cherrypy.engine.stop()
+
+if __name__ == '__main__':
+    sys.exit(main())
This page took 0.060354 seconds and 5 git commands to generate.