|
| 1 | +from wsgiref.simple_server import make_server |
| 2 | +from pyramid.config import Configurator |
| 3 | +from pyramid.view import view_config, view_defaults |
| 4 | + |
| 5 | + |
| 6 | +@view_defaults( |
| 7 | + route_name="github_payload", renderer="json", request_method="POST" |
| 8 | +) |
| 9 | +class PayloadView(object): |
| 10 | + """ |
| 11 | + View receiving of Github payload. By default, this view it's fired only if |
| 12 | + the request is json and method POST. |
| 13 | + """ |
| 14 | + |
| 15 | + def __init__(self, request): |
| 16 | + self.request = request |
| 17 | + # Payload from Github, it's a dict |
| 18 | + self.payload = self.request.json |
| 19 | + |
| 20 | + @view_config(header="X-Github-Event:push") |
| 21 | + def payload_push(self): |
| 22 | + """This method is a continuation of PayloadView process, triggered if |
| 23 | + header HTTP-X-Github-Event type is Push""" |
| 24 | + # {u'name': u'marioidival', u'email': u'[email protected]'} |
| 25 | + print self.payload['pusher'] |
| 26 | + |
| 27 | + # do busy work... |
| 28 | + return "nothing to push payload" # or simple {} |
| 29 | + |
| 30 | + @view_config(header="X-Github-Event:pull_request") |
| 31 | + def payload_pull_request(self): |
| 32 | + """This method is a continuation of PayloadView process, triggered if |
| 33 | + header HTTP-X-Github-Event type is Pull Request""" |
| 34 | + # {u'name': u'marioidival', u'email': u'[email protected]'} |
| 35 | + print self.payload['pusher'] |
| 36 | + |
| 37 | + # do busy work... |
| 38 | + return "nothing to pull request payload" # or simple {} |
| 39 | + |
| 40 | + |
| 41 | +if __name__ == "__main__": |
| 42 | + config = Configurator() |
| 43 | + |
| 44 | + config.add_route("github_payload", "/github_payload/") |
| 45 | + config.scan() |
| 46 | + |
| 47 | + app = config.make_wsgi_app() |
| 48 | + server = make_server("0.0.0.0", 8888, app) |
| 49 | + server.serve_forever() |
0 commit comments