-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[REF] runbot: Get repo data from json request of github webhook
- Loading branch information
Showing
1 changed file
with
21 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
import logging | ||
import operator | ||
import os | ||
import pprint | ||
import re | ||
import resource | ||
import shutil | ||
|
@@ -1243,11 +1244,27 @@ 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_owner = repo_data['owner'].get('name') or repo_data['owner'].get('login') | ||
repo_name = repo_data['name'] | ||
repo_domain = [ | ||
'|', ('name', '=', '[email protected]:%s/%s.git' % (repo_owner, repo_name)), | ||
('name', '=', 'https://github.com/%s/%s.git' % (repo_owner, repo_name)), | ||
] | ||
repo = request.registry['runbot.repo'].search( | ||
request.cr, SUPERUSER_ID, repo_domain, limit=1) | ||
repo_id = repo[0] if len(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) | ||
|