diff --git a/runbot/models/batch.py b/runbot/models/batch.py index 0d064ab6..5e965570 100644 --- a/runbot/models/batch.py +++ b/runbot/models/batch.py @@ -181,11 +181,13 @@ class Batch(models.Model): dependency_repos = triggers.mapped('dependency_ids') all_repos = triggers.mapped('repo_ids') | dependency_repos missing_repos = all_repos - pushed_repo + foreign_projects = dependency_repos.mapped('project_id') - project ###################################### # Find missing commits ###################################### def _fill_missing(branch_commits, match_type): + used_branches = [] if branch_commits: for branch, commit in branch_commits.items(): # branch first in case pr is closed. nonlocal missing_repos @@ -203,6 +205,8 @@ class Batch(models.Model): values['merge_base_commit_id'] = commit.id self.write({'commit_link_ids': [(0, 0, values)]}) missing_repos -= commit.repo_id + used_branches.append(branch) + return used_branches # CHECK branch heads consistency branch_per_repo = {} @@ -249,6 +253,14 @@ class Batch(models.Model): if batches: self.base_reference_batch_id = batches[0] + if missing_repos and bundle.always_use_foreign and foreign_projects: + self._log('Starting by filling foreign repo') + foreign_bundles = bundle.search([('name', '=', bundle.name), ('project_id', 'in', foreign_projects.ids)]) + used_branches = _fill_missing({branch: branch.head for branch in foreign_bundles.mapped('branch_ids').sorted('is_pr', reverse=True)}, 'head') + if used_branches: + commits = ', '.join([f'[{branch.repo_id.name}]({branch.bundle_id.name})' for branch in used_branches]) + self._log(f'Found {len(used_branches)} commits in foreigh repo: {commits}') + batch = self.base_reference_batch_id if batch: if missing_repos: @@ -279,14 +291,9 @@ class Batch(models.Model): # 4. FIND missing commit in foreign project if missing_repos: - foreign_projects = dependency_repos.mapped('project_id') - project if foreign_projects: - self._log('Not all commit found. Fallback on foreign base branches heads.') - foreign_bundles = bundle.search([('name', '=', bundle.name), ('project_id', 'in', foreign_projects.ids)]) - _fill_missing({branch: branch.head for branch in foreign_bundles.mapped('branch_ids').sorted('is_pr', reverse=True)}, 'head') - if missing_repos: - foreign_bundles = bundle.search([('name', '=', bundle.base_id.name), ('project_id', 'in', foreign_projects.ids)]) - _fill_missing({branch: branch.head for branch in foreign_bundles.mapped('branch_ids')}, 'base_head') + base_foreign_bundles = bundle.search([('name', '=', bundle.base_id.name), ('project_id', 'in', foreign_projects.ids)]) + _fill_missing({branch: branch.head for branch in base_foreign_bundles.mapped('branch_ids')}, 'base_head') # CHECK missing commit if missing_repos: diff --git a/runbot/models/bundle.py b/runbot/models/bundle.py index 266d2eb2..e6681062 100644 --- a/runbot/models/bundle.py +++ b/runbot/models/bundle.py @@ -7,8 +7,6 @@ from collections import defaultdict from odoo import models, fields, api, tools from ..common import dt2time, s2human_long -_logger = logging.getLogger(__name__) - class Bundle(models.Model): _name = 'runbot.bundle' @@ -23,6 +21,7 @@ class Bundle(models.Model): no_build = fields.Boolean('No build') no_auto_run = fields.Boolean('No run') build_all = fields.Boolean('Force all triggers') + always_use_foreign = fields.Boolean('Use foreigh bundle', help='By default, check for the same bundle name in another project to fill missing commits.', default=lambda self: self.project_id.always_use_foreign) modules = fields.Char("Modules to install", help="Comma-separated list of modules to install and test.") batch_ids = fields.One2many('runbot.batch', 'bundle_id') diff --git a/runbot/models/project.py b/runbot/models/project.py index 6e203648..79acf60a 100644 --- a/runbot/models/project.py +++ b/runbot/models/project.py @@ -17,6 +17,8 @@ class Project(models.Model): token = fields.Char("Github token", groups="runbot.group_runbot_admin") master_bundle_id = fields.Many2one('runbot.bundle', string='Master bundle') dummy_bundle_id = fields.Many2one('runbot.bundle', string='Dummy bundle') + always_use_foreign = fields.Boolean('Use foreigh bundle', help='By default, check for the same bundle name in another project to fill missing commits.', default=False) + @api.model_create_multi def create(self, vals_list): diff --git a/runbot/views/bundle_views.xml b/runbot/views/bundle_views.xml index 34a095f8..42fff982 100644 --- a/runbot/views/bundle_views.xml +++ b/runbot/views/bundle_views.xml @@ -8,6 +8,7 @@ + @@ -58,6 +59,7 @@ +