diff --git a/runbot/models/batch.py b/runbot/models/batch.py index eabe8c7c..91bb88fd 100644 --- a/runbot/models/batch.py +++ b/runbot/models/batch.py @@ -115,6 +115,9 @@ class Batch(models.Model): 'build_type': 'normal' if self.category_id == self.env.ref('runbot.default_category') else 'scheduled', 'no_auto_run': self.bundle_id.no_auto_run, }) + if self.bundle_id.host_id: + build.host = self.bundle_id.host_id.name + build._github_status(post_commit=False) return link_type, build diff --git a/runbot/models/bundle.py b/runbot/models/bundle.py index 9b4830a2..a8b160a1 100644 --- a/runbot/models/bundle.py +++ b/runbot/models/bundle.py @@ -45,6 +45,25 @@ class Bundle(models.Model): trigger_custom_ids = fields.One2many('runbot.bundle.trigger.custom', 'bundle_id') auto_rebase = fields.Boolean('Auto rebase', default=False) + host_id = fields.Many2one('runbot.host', compute="_compute_host_id", store=True) + + @api.depends('name') + def _compute_host_id(self): + assigned_only = None + runbots = {} + for bundle in self: + elems = bundle.name.split('-') + for elem in elems: + if elem.startswith('runbot'): + if elem.replace('runbot', '') == '_x': + if assigned_only is None: + assigned_only = self.env['runbot.host'].search([('assigned_only', '=', True)], limit=1) + bundle.host_id = assigned_only or False + elif elem.replace('runbot', '').isdigit(): + if elem not in runbots: + runbots[elem] = self.env['runbot.host'].search([('name', 'like', '%s%%' % elem)], limit=1) + bundle.host_id = runbots[elem] or False + @api.depends('sticky') def _compute_make_stats(self): for bundle in self: diff --git a/runbot/tests/test_branch.py b/runbot/tests/test_branch.py index ca8eeef8..2ce2855e 100644 --- a/runbot/tests/test_branch.py +++ b/runbot/tests/test_branch.py @@ -169,6 +169,29 @@ class TestBranchIsBase(RunbotCaseMinimalSetup): self.assertTrue(branch.bundle_id.is_base, "A branch matching the is_base_regex parameter should create is_base bundle") self.assertTrue(branch.bundle_id.sticky, "A branch matching the is_base_regex parameter should create sticky bundle") + def test_host(self): + r10 = self.env['runbot.host'].create({'name': 'runbot10.odoo.com'}) + r12 = self.env['runbot.host'].create({'name': 'runbot12.odoo.com', 'assigned_only': True}) + + branch = self.Branch.create({ + 'remote_id': self.remote_server.id, + 'name': 'saas-13.4-runbotinexist-test', + 'is_pr': False, + }) + self.assertFalse(branch.bundle_id.host_id) + branch = self.Branch.create({ + 'remote_id': self.remote_server.id, + 'name': 'saas-13.4-runbot10-test', + 'is_pr': False, + }) + self.assertEqual(branch.bundle_id.host_id, r10) + branch = self.Branch.create({ + 'remote_id': self.remote_server.id, + 'name': 'saas-13.4-runbot_x-test', + 'is_pr': False, + }) + self.assertEqual(branch.bundle_id.host_id, r12) + @mute_logger("odoo.addons.runbot.models.branch") def test_is_base_regex_on_dev_remote(self): """Test that a branch matching the is_base regex on a secondary remote goes to the dummy bundles."""