Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REF] runbot: Get repo data from json request of github webhook #81

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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