Skip to content

Commit

Permalink
[REF] runbot: Get repo data from json request of github webhook
Browse files Browse the repository at this point in the history
  • Loading branch information
moylop260 committed Feb 15, 2016
1 parent a368702 commit ca81015
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions runbot/runbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import operator
import os
import psycopg2
import pprint
import re
import resource
import shutil
Expand Down Expand Up @@ -1301,11 +1302,25 @@ def branch_info(branch):

return request.render("runbot.repo", context)

@http.route(['/runbot/hook/<int:repo_id>'], type='http', auth="public", website=True)
@http.route(['/runbot/hook/<int:repo_id>', '/runbot/hook/org'], type='json', auth="public", website=True)
def hook(self, repo_id=None, **post):
# TODO if repo_id == None parse the json['repository']['ssh_url'] and find the right repo
repo = request.registry['runbot.repo'].browse(request.cr, SUPERUSER_ID, [repo_id])
repo.hook_time = datetime.datetime.now().strftime(openerp.tools.DEFAULT_SERVER_DATETIME_FORMAT)
if repo_id is None:
repo_data = request.jsonrequest.get('repository')
event = request.httprequest.headers.get("X-Github-Event")
if repo_data and event in ['push', 'pull_request']:
repo_domain = [
'|', ('name', '=', repo_data['ssh_url']),
('name', '=', repo_data['clone_url']),
]
repo = request.registry['runbot.repo'].search(
request.cr, SUPERUSER_ID, repo_domain, limit=1)
repo_id = repo[0] if repo else None

if repo_id:
repo = request.registry['runbot.repo'].browse(request.cr, SUPERUSER_ID, [repo_id])
repo.hook_time = datetime.datetime.now().strftime(openerp.tools.DEFAULT_SERVER_DATETIME_FORMAT)
else:
_logger.debug('Repo not found from request data: %s', pprint.pformat(request.jsonrequest)[:450])
return ""

@http.route(['/runbot/dashboard'], type='http', auth="public", website=True)
Expand Down

0 comments on commit ca81015

Please sign in to comment.