mirror of
https://github.com/odoo/runbot.git
synced 2025-03-15 15:35:46 +07:00
[FIX] better base bundle computation
This commit is contained in:
parent
36fdec11d5
commit
6061d786a8
@ -306,7 +306,6 @@ class Batch(models.Model):
|
||||
for commit_link in self.commit_link_ids:
|
||||
commit_link.commit_id = commit_link.commit_id._rebase_on(commit_link.base_commit_id)
|
||||
commit_link_by_repos = {commit_link.commit_id.repo_id.id: commit_link for commit_link in self.commit_link_ids}
|
||||
bundle_repos = bundle.branch_ids.mapped('remote_id.repo_id')
|
||||
version_id = self.bundle_id.version_id.id
|
||||
project_id = self.bundle_id.project_id.id
|
||||
trigger_customs = {}
|
||||
@ -341,11 +340,10 @@ class Batch(models.Model):
|
||||
|
||||
build = self.env['runbot.build']
|
||||
link_type = 'created'
|
||||
force_trigger = trigger_custom and trigger_custom.start_mode == 'force'
|
||||
skip_trigger = (trigger_custom and trigger_custom.start_mode == 'disabled') or trigger.manual
|
||||
should_start = ((trigger.repo_ids & bundle_repos) or bundle.build_all or bundle.sticky)
|
||||
if force_trigger or (should_start and not skip_trigger): # only auto link build if bundle has a branch for this trigger
|
||||
|
||||
if trigger.should_build(bundle, trigger_custom):
|
||||
link_type, build = self._create_build(params)
|
||||
|
||||
self.env['runbot.batch.slot'].create({
|
||||
'batch_id': self.id,
|
||||
'trigger_id': trigger.id,
|
||||
|
@ -87,7 +87,7 @@ class Bundle(models.Model):
|
||||
for bundle in self:
|
||||
bundle.to_upgrade = bundle.is_base
|
||||
|
||||
@api.depends('name', 'is_base', 'defined_base_id', 'base_id.is_base', 'project_id')
|
||||
@api.depends('name', 'is_base', 'defined_base_id', 'base_id.is_base', 'project_id', 'branch_ids.target_branch_name', 'branch_ids.alive', 'branch_ids.is_pr')
|
||||
def _compute_base_id(self):
|
||||
for bundle in self:
|
||||
if bundle.is_base:
|
||||
@ -98,17 +98,19 @@ class Bundle(models.Model):
|
||||
continue
|
||||
project_id = bundle.project_id.id
|
||||
master_base = False
|
||||
fallback = False
|
||||
for bid, bname in self._get_base_ids(project_id):
|
||||
if bundle.name.startswith('%s-' % bname):
|
||||
bundle.base_id = self.browse(bid)
|
||||
fallback_id = False
|
||||
pr = bundle.branch_ids.sorted('id desc').filtered(lambda branch: branch.alive and branch.is_pr)
|
||||
|
||||
for base_id, base_name in self._get_base_ids(project_id):
|
||||
if (pr and base_name == pr.target_branch_name) or bundle.name.startswith(f'{base_name}-'):
|
||||
bundle.base_id = self.browse(base_id)
|
||||
break
|
||||
elif bname == 'master':
|
||||
master_base = self.browse(bid)
|
||||
elif not fallback or fallback.id < bid:
|
||||
fallback = self.browse(bid)
|
||||
elif base_name == 'master':
|
||||
master_base = self.browse(base_id)
|
||||
elif not fallback_id or fallback_id < base_id:
|
||||
fallback_id = base_id
|
||||
else:
|
||||
bundle.base_id = master_base or fallback
|
||||
bundle.base_id = bundle.base_id or master_base or self.browse(fallback_id)
|
||||
|
||||
@tools.ormcache('project_id')
|
||||
def _get_base_ids(self, project_id):
|
||||
@ -241,11 +243,13 @@ class Bundle(models.Model):
|
||||
warnings.append(('warning', 'No base defined on this bundle'))
|
||||
else:
|
||||
for branch in self.branch_ids:
|
||||
if not branch.alive:
|
||||
continue
|
||||
if branch.is_pr and branch.target_branch_name != self.base_id.name:
|
||||
if branch.target_branch_name.startswith(self.base_id.name):
|
||||
warnings.append(('info', 'PR %s targeting a non base branch: %s' % (branch.dname, branch.target_branch_name)))
|
||||
else:
|
||||
warnings.append(('warning' if branch.alive else 'info', 'PR %s targeting wrong version: %s (expecting %s)' % (branch.dname, branch.target_branch_name, self.base_id.name)))
|
||||
warnings.append(('warning', 'PR %s targeting wrong version: %s (expecting %s)' % (branch.dname, branch.target_branch_name, self.base_id.name)))
|
||||
elif not branch.is_pr and not branch.name.startswith(self.base_id.name) and not self.defined_base_id:
|
||||
warnings.append(('warning', 'Branch %s not starting with version name (%s)' % (branch.dname, self.base_id.name)))
|
||||
return warnings
|
||||
|
@ -37,6 +37,7 @@ class Trigger(models.Model):
|
||||
project_id = fields.Many2one('runbot.project', string="Project id", required=True)
|
||||
repo_ids = fields.Many2many('runbot.repo', relation='runbot_trigger_triggers', string="Triggers", domain="[('project_id', '=', project_id)]")
|
||||
dependency_ids = fields.Many2many('runbot.repo', relation='runbot_trigger_dependencies', string="Dependencies")
|
||||
pr_only = fields.Boolean("Only start trigger if bundle has PR alive")
|
||||
config_id = fields.Many2one('runbot.build.config', string="Config", required=True)
|
||||
batch_dependent = fields.Boolean('Batch Dependent', help="Force adding batch in build parameters to make it unique and give access to bundle")
|
||||
|
||||
@ -90,6 +91,27 @@ class Trigger(models.Model):
|
||||
return safe_eval(self.version_domain)
|
||||
return []
|
||||
|
||||
def should_build(self, bundle, trigger_custom):
|
||||
if trigger_custom and trigger_custom.start_mode == 'force':
|
||||
return True
|
||||
|
||||
if self.manual:
|
||||
return False
|
||||
|
||||
if (trigger_custom and trigger_custom.start_mode == 'disabled'):
|
||||
return False
|
||||
|
||||
if bundle.build_all or bundle.sticky:
|
||||
return True
|
||||
|
||||
if self.repo_ids & bundle.branch_ids.remote_id.repo_id:
|
||||
if not self.pr_only:
|
||||
return True
|
||||
if any(branch.alive and branch.is_pr for branch in bundle.branch_ids):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
class Remote(models.Model):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user