mirror of
https://github.com/odoo/runbot.git
synced 2025-03-27 13:25:47 +07:00
[FIX] runbot: branch computation
This commit is contained in:
parent
2fa5a6aee7
commit
ecfdb5693d
@ -30,9 +30,9 @@ class Branch(models.Model):
|
|||||||
pr_body = fields.Char('Pr Body')
|
pr_body = fields.Char('Pr Body')
|
||||||
pr_author = fields.Char('Pr Author')
|
pr_author = fields.Char('Pr Author')
|
||||||
|
|
||||||
pull_head_name = fields.Char(compute='_compute_branch_infos', string='PR HEAD name', readonly=True, store=True)
|
pull_head_name = fields.Char(string='PR HEAD name', readonly=True, store=True)
|
||||||
pull_head_remote_id = fields.Many2one('runbot.remote', 'Pull head repository', compute='_compute_branch_infos', store=True, index=True)
|
pull_head_remote_id = fields.Many2one('runbot.remote', 'Pull head repository', store=True, index=True)
|
||||||
target_branch_name = fields.Char(compute='_compute_branch_infos', string='PR target branch', store=True)
|
target_branch_name = fields.Char( string='PR target branch', store=True)
|
||||||
reviewers = fields.Char('Reviewers')
|
reviewers = fields.Char('Reviewers')
|
||||||
|
|
||||||
reflog_ids = fields.One2many('runbot.ref.log', 'branch_id')
|
reflog_ids = fields.One2many('runbot.ref.log', 'branch_id')
|
||||||
@ -41,7 +41,7 @@ class Branch(models.Model):
|
|||||||
dname = fields.Char('Display name', compute='_compute_dname', search='_search_dname')
|
dname = fields.Char('Display name', compute='_compute_dname', search='_search_dname')
|
||||||
|
|
||||||
alive = fields.Boolean('Alive', default=True)
|
alive = fields.Boolean('Alive', default=True)
|
||||||
draft = fields.Boolean('Draft', compute='_compute_branch_infos', store=True)
|
draft = fields.Boolean('Draft', store=True)
|
||||||
|
|
||||||
@api.depends('name', 'remote_id.short_name')
|
@api.depends('name', 'remote_id.short_name')
|
||||||
def _compute_dname(self):
|
def _compute_dname(self):
|
||||||
@ -64,7 +64,7 @@ class Branch(models.Model):
|
|||||||
- pull_head_name (organisation:branch_name) for external pr
|
- pull_head_name (organisation:branch_name) for external pr
|
||||||
"""
|
"""
|
||||||
for branch in self:
|
for branch in self:
|
||||||
if branch.is_pr:
|
if branch.is_pr and branch.pull_head_name:
|
||||||
_, name = branch.pull_head_name.split(':')
|
_, name = branch.pull_head_name.split(':')
|
||||||
if branch.pull_head_remote_id:
|
if branch.pull_head_remote_id:
|
||||||
reference_name = name
|
reference_name = name
|
||||||
@ -79,8 +79,7 @@ class Branch(models.Model):
|
|||||||
reference_name = f'{forced_version.name}---{reference_name}'
|
reference_name = f'{forced_version.name}---{reference_name}'
|
||||||
branch.reference_name = reference_name
|
branch.reference_name = reference_name
|
||||||
|
|
||||||
@api.depends('name')
|
def _update_branch_infos(self, pull_info=None):
|
||||||
def _compute_branch_infos(self, pull_info=None):
|
|
||||||
"""compute branch_url, pull_head_name and target_branch_name based on name"""
|
"""compute branch_url, pull_head_name and target_branch_name based on name"""
|
||||||
name_to_remote = {}
|
name_to_remote = {}
|
||||||
prs = self.filtered(lambda branch: branch.is_pr)
|
prs = self.filtered(lambda branch: branch.is_pr)
|
||||||
@ -140,18 +139,15 @@ class Branch(models.Model):
|
|||||||
else:
|
else:
|
||||||
branch.branch_url = ''
|
branch.branch_url = ''
|
||||||
|
|
||||||
@api.depends('reference_name', 'remote_id.repo_id.project_id')
|
def _update_bundle_id(self):
|
||||||
def _compute_bundle_id(self):
|
|
||||||
for branch in self:
|
for branch in self:
|
||||||
dummy = branch.remote_id.repo_id.project_id.dummy_bundle_id
|
dummy = branch.remote_id.repo_id.project_id.dummy_bundle_id
|
||||||
if branch.bundle_id == dummy:
|
|
||||||
continue
|
|
||||||
name = branch.reference_name
|
name = branch.reference_name
|
||||||
project = branch.remote_id.repo_id.project_id or self.env.ref('runbot.main_project')
|
project = branch.remote_id.repo_id.project_id or self.env.ref('runbot.main_project')
|
||||||
project.ensure_one()
|
project.ensure_one()
|
||||||
bundle = self.env['runbot.bundle'].search([('name', '=', name), ('project_id', '=', project.id)])
|
bundle = self.env['runbot.bundle'].search([('name', '=', name), ('project_id', '=', project.id)])
|
||||||
need_new_base = not bundle and branch._match_is_base(name)
|
is_base = bundle.is_base if bundle else branch._match_is_base(name)
|
||||||
if (bundle.is_base or need_new_base) and branch.remote_id != branch.remote_id.repo_id.main_remote_id:
|
if is_base and branch.remote_id != branch.remote_id.repo_id.main_remote_id:
|
||||||
_logger.warning('Trying to add a dev branch to base bundle, falling back on dummy bundle')
|
_logger.warning('Trying to add a dev branch to base bundle, falling back on dummy bundle')
|
||||||
bundle = dummy
|
bundle = dummy
|
||||||
elif name and branch.remote_id and branch.remote_id.repo_id._is_branch_forbidden(name):
|
elif name and branch.remote_id and branch.remote_id.repo_id._is_branch_forbidden(name):
|
||||||
@ -165,7 +161,7 @@ class Branch(models.Model):
|
|||||||
'name': name,
|
'name': name,
|
||||||
'project_id': project.id,
|
'project_id': project.id,
|
||||||
}
|
}
|
||||||
if need_new_base:
|
if is_base:
|
||||||
values['is_base'] = True
|
values['is_base'] = True
|
||||||
|
|
||||||
if branch.is_pr and branch.target_branch_name: # most likely external_pr, use target as version
|
if branch.is_pr and branch.target_branch_name: # most likely external_pr, use target as version
|
||||||
@ -183,6 +179,8 @@ class Branch(models.Model):
|
|||||||
@api.model_create_multi
|
@api.model_create_multi
|
||||||
def create(self, value_list):
|
def create(self, value_list):
|
||||||
branches = super().create(value_list)
|
branches = super().create(value_list)
|
||||||
|
branches._update_branch_infos()
|
||||||
|
branches._update_bundle_id()
|
||||||
for branch in branches:
|
for branch in branches:
|
||||||
if branch.head:
|
if branch.head:
|
||||||
self.env['runbot.ref.log'].create({'commit_id': branch.head.id, 'branch_id': branch.id})
|
self.env['runbot.ref.log'].create({'commit_id': branch.head.id, 'branch_id': branch.id})
|
||||||
@ -214,8 +212,9 @@ class Branch(models.Model):
|
|||||||
was_draft = self.draft
|
was_draft = self.draft
|
||||||
was_alive = self.alive
|
was_alive = self.alive
|
||||||
init_target_branch_name = self.target_branch_name
|
init_target_branch_name = self.target_branch_name
|
||||||
self._compute_branch_infos(payload)
|
self._update_branch_infos(payload)
|
||||||
if self.target_branch_name != init_target_branch_name:
|
if self.target_branch_name != init_target_branch_name:
|
||||||
|
#retarget
|
||||||
_logger.info('retargeting %s to %s', self.name, self.target_branch_name)
|
_logger.info('retargeting %s to %s', self.name, self.target_branch_name)
|
||||||
base = self.env['runbot.bundle'].search([
|
base = self.env['runbot.bundle'].search([
|
||||||
('name', '=', self.target_branch_name),
|
('name', '=', self.target_branch_name),
|
||||||
@ -230,6 +229,10 @@ class Branch(models.Model):
|
|||||||
if self.draft:
|
if self.draft:
|
||||||
self.reviewers = '' # reset reviewers on draft
|
self.reviewers = '' # reset reviewers on draft
|
||||||
|
|
||||||
|
if not self.bundle_id:
|
||||||
|
self._update_bundle_id()
|
||||||
|
return
|
||||||
|
|
||||||
if was_alive and not self.alive and self.bundle_id.for_next_freeze:
|
if was_alive and not self.alive and self.bundle_id.for_next_freeze:
|
||||||
if not any(branch.alive and branch.is_pr for branch in self.bundle_id.branch_ids):
|
if not any(branch.alive and branch.is_pr for branch in self.bundle_id.branch_ids):
|
||||||
self.bundle_id.for_next_freeze = False
|
self.bundle_id.for_next_freeze = False
|
||||||
@ -246,10 +249,13 @@ class Branch(models.Model):
|
|||||||
regex = icp.get_param('runbot.runbot_is_base_regex', False)
|
regex = icp.get_param('runbot.runbot_is_base_regex', False)
|
||||||
if regex:
|
if regex:
|
||||||
return re.match(regex, name)
|
return re.match(regex, name)
|
||||||
|
|
||||||
def action_recompute_infos(self):
|
def action_recompute_infos(self):
|
||||||
return self._recompute_infos()
|
return self._recompute_infos()
|
||||||
|
|
||||||
|
def action_update_bundle_id(self):
|
||||||
|
return self._update_bundle_ids()
|
||||||
|
|
||||||
|
|
||||||
class RefLog(models.Model):
|
class RefLog(models.Model):
|
||||||
_name = 'runbot.ref.log'
|
_name = 'runbot.ref.log'
|
||||||
|
@ -149,7 +149,7 @@ class ConfigStep(models.Model):
|
|||||||
|
|
||||||
build._log('', 'Requesting review for pull request [%s](%s): %s' % (pr.dname, pr.branch_url, ', '.join(new_reviewers)), log_type='markdown')
|
build._log('', 'Requesting review for pull request [%s](%s): %s' % (pr.dname, pr.branch_url, ', '.join(new_reviewers)), log_type='markdown')
|
||||||
response = pr.remote_id._github('/repos/:owner/:repo/pulls/%s/requested_reviewers' % pr.name, {"team_reviewers": list(new_reviewers)}, ignore_errors=False)
|
response = pr.remote_id._github('/repos/:owner/:repo/pulls/%s/requested_reviewers' % pr.name, {"team_reviewers": list(new_reviewers)}, ignore_errors=False)
|
||||||
pr._compute_branch_infos(response)
|
pr._update_branch_infos(response)
|
||||||
pr['reviewers'] = ','.join(sorted(reviewers))
|
pr['reviewers'] = ','.join(sorted(reviewers))
|
||||||
else:
|
else:
|
||||||
build._log('', 'All reviewers are already on pull request [%s](%s)' % (pr.dname, pr.branch_url,), log_type='markdown')
|
build._log('', 'All reviewers are already on pull request [%s](%s)' % (pr.dname, pr.branch_url,), log_type='markdown')
|
||||||
|
@ -491,7 +491,7 @@ class Repo(models.Model):
|
|||||||
if not branch.alive:
|
if not branch.alive:
|
||||||
if branch.is_pr:
|
if branch.is_pr:
|
||||||
_logger.info('Recomputing infos of dead pr %s', branch.name)
|
_logger.info('Recomputing infos of dead pr %s', branch.name)
|
||||||
branch._compute_branch_infos()
|
branch._update_branch_infos()
|
||||||
else:
|
else:
|
||||||
branch.alive = True
|
branch.alive = True
|
||||||
|
|
||||||
|
@ -125,15 +125,17 @@ class RunbotCase(TransactionCase):
|
|||||||
'is_pr': False,
|
'is_pr': False,
|
||||||
'remote_id': self.remote_server.id,
|
'remote_id': self.remote_server.id,
|
||||||
})
|
})
|
||||||
self.dev_pr = self.Branch.create({
|
with patch('odoo.addons.runbot.models.branch.Branch._update_branch_infos', return_value=None):
|
||||||
'name': '1234',
|
self.dev_pr = self.Branch.create({
|
||||||
'is_pr': True,
|
'name': '1234',
|
||||||
'remote_id': self.remote_server.id,
|
'is_pr': True,
|
||||||
'target_branch_name': self.dev_bundle.base_id.name,
|
'alive': True,
|
||||||
'pull_head_remote_id': self.remote_server.id,
|
'remote_id': self.remote_server.id,
|
||||||
})
|
'target_branch_name': self.dev_bundle.base_id.name,
|
||||||
self.dev_pr.pull_head_name = f'{self.remote_server.owner}:{self.dev_branch.name}'
|
'pull_head_remote_id': self.remote_server.id,
|
||||||
self.dev_pr.bundle_id = self.dev_bundle.id,
|
'pull_head_name': f'{self.remote_server.owner}:{self.dev_branch.name}',
|
||||||
|
})
|
||||||
|
self.assertEqual(self.dev_pr.bundle_id.id, self.dev_bundle.id)
|
||||||
|
|
||||||
self.dev_batch = self.Batch.create({
|
self.dev_batch = self.Batch.create({
|
||||||
'bundle_id': self.dev_bundle.id,
|
'bundle_id': self.dev_bundle.id,
|
||||||
|
@ -96,9 +96,9 @@ class TestCodeowner(TestBuildConfigStepCommon):
|
|||||||
'remote_id': self.remote_server.id,
|
'remote_id': self.remote_server.id,
|
||||||
'target_branch_name': self.dev_bundle.base_id.name,
|
'target_branch_name': self.dev_bundle.base_id.name,
|
||||||
'pull_head_remote_id': self.remote_server.id,
|
'pull_head_remote_id': self.remote_server.id,
|
||||||
|
'pull_head_name': f'{self.remote_server.owner}:{self.dev_branch.name}',
|
||||||
})
|
})
|
||||||
second_pr.pull_head_name = f'{self.remote_server.owner}:{self.dev_branch.name}'
|
self.assertEqual(second_pr.bundle_id.id, self.dev_bundle.id)
|
||||||
second_pr.bundle_id = self.dev_bundle.id
|
|
||||||
self.config_step._run_codeowner(self.parent_build)
|
self.config_step._run_codeowner(self.parent_build)
|
||||||
self.assertEqual(self.parent_build.log_ids.mapped('message'), [
|
self.assertEqual(self.parent_build.log_ids.mapped('message'), [
|
||||||
"More than one open pr in this bundle for server: ['1234', '1235']"
|
"More than one open pr in this bundle for server: ['1234', '1235']"
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
<form>
|
<form>
|
||||||
<header>
|
<header>
|
||||||
<button name="action_recompute_infos" string="Recompute Infos" type="object" class="oe_highlight"/>
|
<button name="action_recompute_infos" string="Recompute Infos" type="object" class="oe_highlight"/>
|
||||||
|
<button name="action_update_bundle_id" string="Update bundle" type="object" class="oe_highlight"/>
|
||||||
</header>
|
</header>
|
||||||
<sheet>
|
<sheet>
|
||||||
<group name="branch_group">
|
<group name="branch_group">
|
||||||
|
Loading…
Reference in New Issue
Block a user