mirror of
https://github.com/odoo/runbot.git
synced 2025-03-15 15:35:46 +07:00
[REF] runbot: get rid of defined_base_id hack
Also removes some compute of stored fields with hacky behaviour
This commit is contained in:
parent
9372405396
commit
d37720b479
Binary file not shown.
@ -23,16 +23,18 @@ class Branch(models.Model):
|
||||
head_name = fields.Char('Head name', related='head.name', store=True)
|
||||
|
||||
reference_name = fields.Char(compute='_compute_reference_name', string='Bundle name', store=True)
|
||||
bundle_id = fields.Many2one('runbot.bundle', 'Bundle', compute='_compute_bundle_id', store=True, ondelete='cascade', index=True)
|
||||
bundle_id = fields.Many2one('runbot.bundle', 'Bundle', index=True)
|
||||
|
||||
is_pr = fields.Boolean('IS a pr', required=True)
|
||||
is_pr = fields.Boolean("Is a pr", required=True)
|
||||
alive = fields.Boolean('Alive', default=True)
|
||||
draft = fields.Boolean('Draft', store=True)
|
||||
pr_title = fields.Char('Pr Title')
|
||||
pr_body = fields.Char('Pr Body')
|
||||
pr_author = fields.Char('Pr Author')
|
||||
|
||||
pull_head_name = fields.Char(compute='_compute_branch_infos', string='PR HEAD name', readonly=1, store=True)
|
||||
pull_head_remote_id = fields.Many2one('runbot.remote', 'Pull head repository', compute='_compute_branch_infos', store=True, index=True)
|
||||
target_branch_name = fields.Char(compute='_compute_branch_infos', string='PR target branch', store=True)
|
||||
pull_head_name = fields.Char("PR head name", readonly=1)
|
||||
pull_head_remote_id = fields.Many2one('runbot.remote', "Pull head repository", index=True)
|
||||
target_branch_name = fields.Char("PR target branch")
|
||||
|
||||
reviewers = fields.Char('Reviewers')
|
||||
|
||||
reflog_ids = fields.One2many('runbot.ref.log', 'branch_id')
|
||||
@ -40,9 +42,6 @@ class Branch(models.Model):
|
||||
branch_url = fields.Char(compute='_compute_branch_url', string='Branch url', readonly=1)
|
||||
dname = fields.Char('Display name', compute='_compute_dname', search='_search_dname')
|
||||
|
||||
alive = fields.Boolean('Alive', default=True)
|
||||
draft = fields.Boolean('Draft', compute='_compute_branch_infos', store=True)
|
||||
|
||||
@api.depends('name', 'remote_id.short_name')
|
||||
def _compute_dname(self):
|
||||
for branch in self:
|
||||
@ -80,7 +79,7 @@ class Branch(models.Model):
|
||||
branch.reference_name = reference_name
|
||||
|
||||
@api.depends('name')
|
||||
def _compute_branch_infos(self, pull_info=None):
|
||||
def _setup_branch_infos(self, pull_info=None):
|
||||
"""compute branch_url, pull_head_name and target_branch_name based on name"""
|
||||
name_to_remote = {}
|
||||
prs = self.filtered(lambda branch: branch.is_pr)
|
||||
@ -143,8 +142,7 @@ class Branch(models.Model):
|
||||
else:
|
||||
branch.branch_url = ''
|
||||
|
||||
@api.depends('reference_name', 'remote_id.repo_id.project_id')
|
||||
def _compute_bundle_id(self):
|
||||
def _setup_bundle_id(self):
|
||||
dummy = self.env.ref('runbot.bundle_dummy')
|
||||
for branch in self:
|
||||
if branch.bundle_id == dummy:
|
||||
@ -153,39 +151,32 @@ class Branch(models.Model):
|
||||
project = branch.remote_id.repo_id.project_id or self.env.ref('runbot.main_project')
|
||||
project.ensure_one()
|
||||
bundle = self.env['runbot.bundle'].search([('name', '=', name), ('project_id', '=', project.id)])
|
||||
need_new_base = not bundle and 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:
|
||||
match_is_base = bool(not bundle and branch.match_is_base(name))
|
||||
if (bundle.is_base or match_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')
|
||||
bundle = dummy
|
||||
elif name and branch.remote_id and branch.remote_id.repo_id._is_branch_forbidden(name):
|
||||
# this is not used anymore on runbot.oodoo.com
|
||||
_logger.warning('Trying to add a forbidden branch, falling back on dummy bundle')
|
||||
bundle = dummy
|
||||
elif bundle.is_base and branch.is_pr:
|
||||
_logger.warning('Trying to add pr to base bundle, falling back on dummy bundle')
|
||||
bundle = dummy
|
||||
elif not bundle:
|
||||
elif not bundle and name:
|
||||
values = {
|
||||
'name': name,
|
||||
'name': branch.reference_name,
|
||||
'project_id': project.id,
|
||||
'is_base': match_is_base,
|
||||
}
|
||||
if need_new_base:
|
||||
values['is_base'] = True
|
||||
bundle = self.env['runbot.bundle'].create(values) # this prevent creating a branch in UI
|
||||
|
||||
if branch.is_pr and branch.target_branch_name: # most likely external_pr, use target as version
|
||||
base = self.env['runbot.bundle'].search([
|
||||
('name', '=', branch.target_branch_name),
|
||||
('is_base', '=', True),
|
||||
('project_id', '=', project.id)
|
||||
])
|
||||
if base:
|
||||
values['defined_base_id'] = base.id
|
||||
if name:
|
||||
bundle = self.env['runbot.bundle'].create(values) # this prevent creating a branch in UI
|
||||
branch.bundle_id = bundle
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, value_list):
|
||||
branches = super().create(value_list)
|
||||
branches._setup_branch_infos()
|
||||
branches._setup_bundle_id()
|
||||
for branch in branches:
|
||||
if branch.head:
|
||||
self.env['runbot.ref.log'].create({'commit_id': branch.head.id, 'branch_id': branch.id})
|
||||
@ -217,24 +208,18 @@ class Branch(models.Model):
|
||||
""" public method to recompute infos on demand """
|
||||
was_draft = self.draft
|
||||
was_alive = self.alive
|
||||
init_target_branch_name = self.target_branch_name
|
||||
self._compute_branch_infos(payload)
|
||||
if self.target_branch_name != init_target_branch_name:
|
||||
_logger.info('retargeting %s to %s', self.name, self.target_branch_name)
|
||||
base = self.env['runbot.bundle'].search([
|
||||
('name', '=', self.target_branch_name),
|
||||
('is_base', '=', True),
|
||||
('project_id', '=', self.remote_id.repo_id.project_id.id)
|
||||
])
|
||||
if base and self.bundle_id.defined_base_id != base:
|
||||
_logger.info('Changing base of bundle %s to %s(%s)', self.bundle_id, base.name, base.id)
|
||||
self.bundle_id.defined_base_id = base.id
|
||||
self.bundle_id._force()
|
||||
init_base = self.bundle_id.base_id
|
||||
|
||||
self._setup_branch_infos(payload)
|
||||
|
||||
if self.draft:
|
||||
self.reviewers = '' # reset reviewers on draft
|
||||
|
||||
if (not self.draft and was_draft) or (self.alive and not was_alive) or (self.target_branch_name != init_target_branch_name and self.alive):
|
||||
if (
|
||||
self.bundle_id.base_id != init_base or
|
||||
(not self.draft and was_draft) or
|
||||
(self.alive and not was_alive)
|
||||
):
|
||||
self.bundle_id._force()
|
||||
|
||||
@api.model
|
||||
|
@ -184,6 +184,7 @@ class BuildResult(models.Model):
|
||||
docker_start = fields.Datetime('Docker start')
|
||||
job_time = fields.Integer(compute='_compute_job_time', string='Job time')
|
||||
build_time = fields.Integer(compute='_compute_build_time', string='Build time')
|
||||
total_time = fields.Integer(compute='_compute_total_time', string='Total computation time')
|
||||
|
||||
gc_date = fields.Datetime('Local cleanup date', compute='_compute_gc_date')
|
||||
gc_delay = fields.Integer('Cleanup Delay', help='Used to compute gc_date')
|
||||
@ -374,8 +375,8 @@ class BuildResult(models.Model):
|
||||
def update_build_end(self):
|
||||
for build in self:
|
||||
build.build_end = now()
|
||||
if build.parent_id and build.parent_id.local_state in ('running', 'done'):
|
||||
build.parent_id.update_build_end()
|
||||
#if build.parent_id and build.parent_id.local_state in ('running', 'done'):
|
||||
# build.parent_id.update_build_end()
|
||||
|
||||
@api.depends('params_id.version_id.name')
|
||||
def _compute_dest(self):
|
||||
@ -414,13 +415,18 @@ class BuildResult(models.Model):
|
||||
@api.depends('build_start', 'build_end', 'global_state')
|
||||
def _compute_build_time(self):
|
||||
for build in self:
|
||||
if build.build_end and build.global_state != 'waiting':
|
||||
if build.build_end:
|
||||
build.build_time = int(dt2time(build.build_end) - dt2time(build.build_start))
|
||||
elif build.build_start:
|
||||
build.build_time = int(time.time() - dt2time(build.build_start))
|
||||
else:
|
||||
build.build_time = 0
|
||||
|
||||
@api.depends('build_time', 'children_ids.total_time')
|
||||
def _compute_total_time(self):
|
||||
for build in self:
|
||||
build.total_time = build.build_time + sum(build.children_ids.mapped('total_time'))
|
||||
|
||||
@api.depends('job_start')
|
||||
def _compute_build_age(self):
|
||||
"""Return the time between job start and now"""
|
||||
@ -812,7 +818,7 @@ class BuildResult(models.Model):
|
||||
if build_export_path in exports:
|
||||
self._log('_checkout', 'Multiple repo have same export path in build, some source may be missing for %s' % build_export_path, level='ERROR')
|
||||
self._kill(result='ko')
|
||||
exports[build_export_path] = commit.export(self)
|
||||
exports[build_export_path] = commit._export(self)
|
||||
|
||||
checkout_time = time.time() - start
|
||||
if checkout_time > 60:
|
||||
@ -1135,6 +1141,9 @@ class BuildResult(models.Model):
|
||||
def get_formated_build_time(self):
|
||||
return s2human(self.build_time)
|
||||
|
||||
def get_formated_total_time(self):
|
||||
return s2human(self.total_time)
|
||||
|
||||
def get_formated_build_age(self):
|
||||
return s2human(self.build_age)
|
||||
|
||||
|
@ -330,7 +330,7 @@ class ConfigStep(models.Model):
|
||||
return run()
|
||||
return eval_ctx.get('docker_params')
|
||||
except ValueError as e:
|
||||
save_eval_value_error_re = r'<class \'odoo.addons.runbot.models.repo.RunbotException\'>: "(.*)" while evaluating\n.*'
|
||||
save_eval_value_error_re = r'(.*)" while evaluating\n.*'
|
||||
message = e.args[0]
|
||||
groups = re.match(save_eval_value_error_re, message)
|
||||
if groups:
|
||||
|
@ -95,7 +95,7 @@ class Bundle(models.Model):
|
||||
project_id = bundle.project_id.id
|
||||
master_base = False
|
||||
fallback_id = False
|
||||
pr = bundle.branch_ids.sorted('id desc').filtered(lambda branch: branch.alive and branch.is_pr)
|
||||
pr = bundle.branch_ids.sorted('id', reverse=True).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}-'):
|
||||
|
@ -52,7 +52,7 @@ class Commit(models.Model):
|
||||
module = os.path.basename(os.path.dirname(manifest_path))
|
||||
yield (addons_path, module, manifest_file_name)
|
||||
|
||||
def export(self, build):
|
||||
def _export(self, build):
|
||||
"""Export a git repo into a sources"""
|
||||
# TODO add automated tests
|
||||
self.ensure_one()
|
||||
|
@ -466,7 +466,7 @@ class Repo(models.Model):
|
||||
if not branch.alive:
|
||||
if branch.is_pr:
|
||||
_logger.info('Recomputing infos of dead pr %s', branch.name)
|
||||
branch._compute_branch_infos()
|
||||
branch._setup_branch_infos()
|
||||
else:
|
||||
branch.alive = True
|
||||
|
||||
|
@ -158,8 +158,10 @@
|
||||
<t t-esc="build.host"/>
|
||||
<br/>
|
||||
</t>
|
||||
<b>Total time:</b>
|
||||
<b>Completion time:</b>
|
||||
<t t-esc="build.get_formated_build_time()"/>
|
||||
<b>Total time:</b>
|
||||
<t t-esc="build.get_formated_total_time()"/>
|
||||
<br/>
|
||||
<t t-if="build.stat_ids">
|
||||
<b>Stats:</b>
|
||||
@ -379,6 +381,12 @@
|
||||
<td>
|
||||
<span t-esc="build.get_formated_build_time()"/>
|
||||
</td>
|
||||
<td>
|
||||
<span t-esc="build.get_formated_total_time()"/>
|
||||
</td>
|
||||
<td>
|
||||
<span t-esc="build.host"/>
|
||||
</td>
|
||||
<td>
|
||||
<t t-call="runbot.build_button">
|
||||
<t t-set="bu" t-value="build"/>
|
||||
|
Loading…
Reference in New Issue
Block a user