Permalink
Browse files

initial attempt at a github change receiver

  • Loading branch information...
1 parent efb794a commit 31c8eb279ea0871ce6886653ea411249ecf2bb58 Titus Brown committed Feb 24, 2010
View
1 examples/change-receiver/github-notify.json
@@ -0,0 +1 @@
+{"commits":[{"modified":["IDEAS"],"url":"http://github.com/ctb/pony-build/commit/e95f152f6d4e50da340d361a41789e0f0b904d56","message":"test","author":{"email":"t@titus-browns-macbook-2.local","name":"Titus Brown"},"timestamp":"2009-12-04T17:03:04-08:00","removed":[],"id":"e95f152f6d4e50da340d361a41789e0f0b904d56","added":[]}],"repository":{"forks":4,"description": "CI for Python","url":"http://github.com/ctb/pony-build","fork":false,"watchers":31,"private":false,"homepage":"","owner":{"email":"titus@idyll.org","name":"ctb"},"name":"pony-build","open_issues":1},"ref":"refs/heads/test","before":"cd759759417253f630123e89684e9fd29a4d9225","after":"e95f152f6d4e50da340d361a41789e0f0b904d56"}
View
49 examples/change-receiver/github-receiver.cgi
@@ -0,0 +1,49 @@
+#! /u/t/dev/venv/bin/python
+"""
+A simple webhook receiver for github notification events.
+"""
+import sys
+
+import pprint
+
+import quixote
+from quixote.directory import Directory
+from quixote.server.cgi_server import run
+from quixote.publish import Publisher
+
+import json
+from cgi import parse_qs
+
+def process_notify_data(payload):
+ pprint.pprint(payload)
+
+ print 'branch info is:', payload['ref']
+ print 'repository name:', payload['repository']['name']
+ print 'repository url:', payload['repository']['url']
+
+ return
+
+class GithubSubscriber(Directory):
+ _q_exports = [ '' ]
+
+ def _q_index(self):
+ request = quixote.get_request()
+ form = request.form
+
+ if 'payload' in form:
+ payload = form['payload']
+ payload = json.loads(payload)
+
+ process_notify_data(payload)
+
+ response = request.response
+ response.set_status(204)
+ else:
+ return "ok, but got nothing?"
+
+def create_publisher():
+ # sets global Quixote publisher
+ return Publisher(GithubSubscriber(), display_exceptions='plain')
+
+if __name__ == '__main__':
+ run(create_publisher)
View
14 examples/change-receiver/test-post-github-notify.py
@@ -0,0 +1,14 @@
+#! /usr/bin/env python
+import sys
+import httplib
+from urlparse import urlparse
+import urllib
+
+url = sys.argv[1]
+
+package = open('github-notify.json').read()
+d = dict(payload=package)
+
+print urllib.urlencode(d)
+
+print urllib.urlopen(url, urllib.urlencode(d)).read()

0 comments on commit 31c8eb2

Please sign in to comment.