|
10 | 10 | import operator |
11 | 11 | import os |
12 | 12 | import psycopg2 |
| 13 | +import pprint |
13 | 14 | import re |
14 | 15 | import resource |
15 | 16 | import shutil |
@@ -1208,7 +1209,7 @@ def repo(self, repo=None, search='', limit='100', refresh='', **post): |
1208 | 1209 | repo_ids = repo_obj.search(cr, uid, []) |
1209 | 1210 | repos = repo_obj.browse(cr, uid, repo_ids) |
1210 | 1211 | if not repo and repos: |
1211 | | - repo = repos[0] |
| 1212 | + repo = repos[0] |
1212 | 1213 |
|
1213 | 1214 | context = { |
1214 | 1215 | 'repos': repos, |
@@ -1301,11 +1302,25 @@ def branch_info(branch): |
1301 | 1302 |
|
1302 | 1303 | return request.render("runbot.repo", context) |
1303 | 1304 |
|
1304 | | - @http.route(['/runbot/hook/<int:repo_id>'], type='http', auth="public", website=True) |
| 1305 | + @http.route(['/runbot/hook/<int:repo_id>', '/runbot/hook/org'], type='json', auth="public", website=True) |
1305 | 1306 | def hook(self, repo_id=None, **post): |
1306 | | - # TODO if repo_id == None parse the json['repository']['ssh_url'] and find the right repo |
1307 | | - repo = request.registry['runbot.repo'].browse(request.cr, SUPERUSER_ID, [repo_id]) |
1308 | | - repo.hook_time = datetime.datetime.now().strftime(openerp.tools.DEFAULT_SERVER_DATETIME_FORMAT) |
| 1307 | + if repo_id is None: |
| 1308 | + repo_data = request.jsonrequest.get('repository') |
| 1309 | + event = request.httprequest.headers.get("X-Github-Event") |
| 1310 | + if repo_data and event in ['push', 'pull_request']: |
| 1311 | + repo_domain = [ |
| 1312 | + '|', ('name', '=', repo_data['ssh_url']), |
| 1313 | + ('name', '=', repo_data['clone_url']), |
| 1314 | + ] |
| 1315 | + repo = request.registry['runbot.repo'].search( |
| 1316 | + request.cr, SUPERUSER_ID, repo_domain, limit=1) |
| 1317 | + repo_id = repo[0] if repo else None |
| 1318 | + |
| 1319 | + if repo_id: |
| 1320 | + repo = request.registry['runbot.repo'].browse(request.cr, SUPERUSER_ID, [repo_id]) |
| 1321 | + repo.hook_time = datetime.datetime.now().strftime(openerp.tools.DEFAULT_SERVER_DATETIME_FORMAT) |
| 1322 | + else: |
| 1323 | + _logger.debug('Repo not found from request data: %s', pprint.pformat(request.jsonrequest)[:450]) |
1309 | 1324 | return "" |
1310 | 1325 |
|
1311 | 1326 | @http.route(['/runbot/dashboard'], type='http', auth="public", website=True) |
|
0 commit comments