mirror of
https://github.com/odoo/runbot.git
synced 2025-03-27 13:25:47 +07:00
[IMP] runbot: handle PR re-targeting
When a PR branch target is changed on Github, the change is not applied in the runbot DB. With this commit, the Github hook payload is taken into account to detect such a change and the branch infos are recomputed accordingly. Also, a button is now available on the branch form in order to manually recompute those changes.
This commit is contained in:
parent
7bd136b9d2
commit
464893d248
@ -32,6 +32,11 @@ class RunbotHook(http.Controller):
|
|||||||
# force update of dependencies to in case a hook is lost
|
# force update of dependencies to in case a hook is lost
|
||||||
if not payload or event == 'push' or (event == 'pull_request' and payload.get('action') in ('synchronize', 'opened', 'reopened')):
|
if not payload or event == 'push' or (event == 'pull_request' and payload.get('action') in ('synchronize', 'opened', 'reopened')):
|
||||||
(repo | repo.dependency_ids).set_hook_time(time.time())
|
(repo | repo.dependency_ids).set_hook_time(time.time())
|
||||||
|
elif event == 'pull_request' and payload and payload.get('action', '') == 'edited' and 'base' in payload.get('changes'):
|
||||||
|
# handle PR that have been re-targeted
|
||||||
|
pr_number = payload.get('pull_request', {}).get('number', '')
|
||||||
|
branch = request.env['runbot.branch'].sudo().search([('repo_id', '=', repo.id), ('name', '=', 'refs/pull/%s' % pr_number)])
|
||||||
|
branch._get_branch_infos(payload.get('pull_request', {}))
|
||||||
else:
|
else:
|
||||||
_logger.debug('Ignoring unsupported hook %s %s', event, payload.get('action', ''))
|
_logger.debug('Ignoring unsupported hook %s %s', event, payload.get('action', ''))
|
||||||
return ""
|
return ""
|
||||||
|
@ -102,12 +102,12 @@ class runbot_branch(models.Model):
|
|||||||
branch.branch_config_id = branch.config_id
|
branch.branch_config_id = branch.config_id
|
||||||
|
|
||||||
@api.depends('name')
|
@api.depends('name')
|
||||||
def _get_branch_infos(self):
|
def _get_branch_infos(self, pull_info=None):
|
||||||
"""compute branch_name, branch_url, pull_head_name and target_branch_name based on name"""
|
"""compute branch_name, branch_url, pull_head_name and target_branch_name based on name"""
|
||||||
for branch in self:
|
for branch in self:
|
||||||
if branch.name:
|
if branch.name:
|
||||||
branch.branch_name = branch.name.split('/')[-1]
|
branch.branch_name = branch.name.split('/')[-1]
|
||||||
pi = branch._get_pull_info()
|
pi = pull_info or branch._get_pull_info()
|
||||||
if pi:
|
if pi:
|
||||||
branch.target_branch_name = pi['base']['ref']
|
branch.target_branch_name = pi['base']['ref']
|
||||||
if not _re_patch.match(pi['head']['label']):
|
if not _re_patch.match(pi['head']['label']):
|
||||||
@ -116,6 +116,10 @@ class runbot_branch(models.Model):
|
|||||||
else:
|
else:
|
||||||
branch.branch_name = ''
|
branch.branch_name = ''
|
||||||
|
|
||||||
|
def recompute_infos(self):
|
||||||
|
""" public method to recompute infos on demand """
|
||||||
|
self._get_branch_infos()
|
||||||
|
|
||||||
@api.depends('branch_name')
|
@api.depends('branch_name')
|
||||||
def _get_branch_url(self):
|
def _get_branch_url(self):
|
||||||
"""compute the branch url based on branch_name"""
|
"""compute the branch url based on branch_name"""
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<form>
|
<form>
|
||||||
<header>
|
<header>
|
||||||
|
<button name="recompute_infos" string="Recompute Infos" type="object" class="oe_highlight"/>
|
||||||
</header>
|
</header>
|
||||||
<sheet>
|
<sheet>
|
||||||
<div class="oe_button_box" name="button_box">
|
<div class="oe_button_box" name="button_box">
|
||||||
|
Loading…
Reference in New Issue
Block a user