-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
50 lines (33 loc) · 1.36 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from django.utils import simplejson as json
from nabazlib.Nabaztag import Nabaztag
class Hook(webapp.RequestHandler):
def post(self):
#get the credentials for the nazaztag
u = self.request.get("id")
p = self.request.get("secret")
optionalreponame = self.request.get("repo")
#get the JSON payload. this is stored in the POST variable "payload"
jsonstr = self.request.get("payload")
#parse it
obj = json.loads(jsonstr)
#read out some interesting data
if optionalreponame=='':
reponame = obj['repository']['name']
author = obj['commits'][0]['author']['name']
msg = obj['commits'][0]['message']
numcommits = len(obj['commits'])
#construct the string we want to send to the rabbit
txt = "Git alert! Git alert! %s just pushed %d commits to %s" %(author,numcommits,reponame)
self.response.out.write(txt)
#construct the nabaztag object and send the text
myNabaztag = Nabaztag(u,p)
myNabaztag.say(txt,voice='US-Liberty')
application = webapp.WSGIApplication([
('/', Hook)
], debug=True)
def main():
run_wsgi_app(application)
if __name__ == '__main__':
main()