mirror of
https://github.com/odoo/runbot.git
synced 2025-03-16 07:55:45 +07:00
[REF] runbot: hook - Find the right repo from payload
This change allow use a global webhook from github based on the organization without use a configuration for each repository. closes: #5
This commit is contained in:
parent
4a558741e0
commit
fa6a0944f4
@ -1,6 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import datetime
|
||||
import json
|
||||
|
||||
from odoo import http, tools
|
||||
from odoo.http import request
|
||||
@ -8,9 +9,21 @@ from odoo.http import request
|
||||
|
||||
class RunbotHook(http.Controller):
|
||||
|
||||
@http.route(['/runbot/hook/<int:repo_id>'], type='http', auth="public", website=True, csrf=False)
|
||||
@http.route(['/runbot/hook/<int:repo_id>', '/runbot/hook/org'], type='http', auth="public", website=True, csrf=False)
|
||||
def hook(self, repo_id=None, **post):
|
||||
# TODO if repo_id == None parse the json['repository']['ssh_url'] and find the right repo
|
||||
if repo_id is None:
|
||||
event = request.httprequest.headers.get("X-Github-Event")
|
||||
repo_data = json.loads(request.params['payload']).get('repository')
|
||||
if repo_data and event in ['push', 'pull_request']:
|
||||
repo_domain = [
|
||||
'|', '|', ('name', '=', repo_data['ssh_url']),
|
||||
('name', '=', repo_data['clone_url']),
|
||||
('name', '=', repo_data['clone_url'].rstrip('.git')),
|
||||
]
|
||||
repo = request.env['runbot.repo'].sudo().search(
|
||||
repo_domain, limit=1)
|
||||
repo_id = repo.id
|
||||
|
||||
repo = request.env['runbot.repo'].sudo().browse([repo_id])
|
||||
repo.hook_time = datetime.datetime.now().strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT)
|
||||
return ""
|
||||
|
Loading…
Reference in New Issue
Block a user