Skip to content

Commit

Permalink
Merge pull request #1354 from lukebakken/github-buildbot-tweaks
Browse files Browse the repository at this point in the history
Enhance github_buildbot.py
  • Loading branch information
Mikhail Sobolev committed Nov 14, 2014
2 parents 185f3c3 + cb6f52e commit debc302
Showing 1 changed file with 31 additions and 9 deletions.
40 changes: 31 additions & 9 deletions master/contrib/github_buildbot.py
Expand Up @@ -55,15 +55,9 @@ def render_POST(self, request):
request
the http request object
"""
event_type = request.getHeader("X-GitHub-Event")

# Reject non-push events
if event_type != "push":
logging.info(
"Rejecting request. Expected a push even got %r instead.",
event_type)
request.setResponseCode(BAD_REQUEST)
return json.dumps({"error": "Bad Request."})
# All responses are application/json
request.setHeader("Content-Type", "application/json")

content = request.content.read()

Expand Down Expand Up @@ -103,8 +97,36 @@ def render_POST(self, request):
request.setResponseCode(BAD_REQUEST)
return json.dumps({"error": "Bad Request."})

event_type = request.getHeader("X-GitHub-Event")
logging.debug("X-GitHub-Event: %r", event_type)

if event_type == "ping":
request.setResponseCode(OK)
return json.dumps({"result": "pong"})

# Reject non-push, non-ping events
if event_type != "push":
logging.info(
"Rejecting request. Expected a push event but received %r instead.",
event_type)
request.setResponseCode(BAD_REQUEST)
return json.dumps({"error": "Bad Request."})

try:
payload = json.loads(content)

content_type = request.getHeader("Content-Type")

if content_type == "application/json":
payload = json.loads(content)
elif content_type == "application/x-www-form-urlencoded":
payload = json.loads(request.args["payload"][0])
else:
logging.info(
"Rejecting request. Unknown 'Content-Type', received %r",
content_type)
request.setResponseCode(BAD_REQUEST)
return json.dumps({"error": "Bad Request."})

logging.debug("Payload: %r", payload)
user = payload['pusher']['name']
repo = payload['repository']['name']
Expand Down

0 comments on commit debc302

Please sign in to comment.