diff --git a/runbot/__manifest__.py b/runbot/__manifest__.py index 7bb4e9ad..65f252fe 100644 --- a/runbot/__manifest__.py +++ b/runbot/__manifest__.py @@ -6,7 +6,7 @@ 'author': "Odoo SA", 'website': "http://runbot.odoo.com", 'category': 'Website', - 'version': '5.2', + 'version': '5.3', 'application': True, 'depends': ['base', 'base_automation', 'website'], 'data': [ diff --git a/runbot/data/runbot_data.xml b/runbot/data/runbot_data.xml index 194549d0..d6fde41c 100644 --- a/runbot/data/runbot_data.xml +++ b/runbot/data/runbot_data.xml @@ -17,17 +17,6 @@ - - master - True - - - - Dummy - True - - - runbot.runbot_upgrade_exception_message Upgrade exception [#{exception.id}]({base_url}/web/#id={exception.id}&view_type=form&model=runbot.upgrade.exception) added\ diff --git a/runbot/migrations/15.0.5.3/post-migration.py b/runbot/migrations/15.0.5.3/post-migration.py new file mode 100644 index 00000000..259b0ea3 --- /dev/null +++ b/runbot/migrations/15.0.5.3/post-migration.py @@ -0,0 +1,28 @@ +from odoo import api, SUPERUSER_ID + + +def migrate(cr, version): + env = api.Environment(cr, SUPERUSER_ID, {}) + projects = env['runbot.project'].search([]) + for project in projects: + if not project.master_bundle_id: + master = env['runbot.bundle'].search([('name', '=', 'master'), ('project_id', '=', project.id)], limit=1) + if not master: + master = env['runbot.bundle'].create({ + 'name': 'master', + 'project_id': project.id, + 'is_base': True, + }) + project.master_bundle_id = master + + if not project.dummy_bundle_id: + dummy = env['runbot.bundle'].search([('name', '=', 'Dummy'), ('project_id', '=', project.id)], limit=1) + if not dummy: + dummy = env['runbot.bundle'].create({ + 'name': 'Dummy', + 'project_id': project.id, + 'no_build': True, + }) + else: + dummy.no_build = True + project.dummy_bundle_id = dummy diff --git a/runbot/migrations/15.0.5.3/pre-migration.py b/runbot/migrations/15.0.5.3/pre-migration.py new file mode 100644 index 00000000..b9f47047 --- /dev/null +++ b/runbot/migrations/15.0.5.3/pre-migration.py @@ -0,0 +1,2 @@ +def migrate(cr, version): + cr.execute("DELETE FROM ir_model_data WHERE module = 'runbot' AND model = 'runbot.bundle' and name in ('bundle_master', 'bundle_dummy')") diff --git a/runbot/models/branch.py b/runbot/models/branch.py index 1b17cb34..daa7f64c 100644 --- a/runbot/models/branch.py +++ b/runbot/models/branch.py @@ -145,8 +145,8 @@ class Branch(models.Model): @api.depends('reference_name', 'remote_id.repo_id.project_id') def _compute_bundle_id(self): - dummy = self.env.ref('runbot.bundle_dummy') for branch in self: + dummy = branch.remote_id.repo_id.project_id.dummy_bundle_id if branch.bundle_id == dummy: continue name = branch.reference_name diff --git a/runbot/models/codeowner.py b/runbot/models/codeowner.py index e0bd8b1f..e22b3c1a 100644 --- a/runbot/models/codeowner.py +++ b/runbot/models/codeowner.py @@ -37,7 +37,7 @@ class Codeowner(models.Model): def _validate_version_domain(self): for rec in self: try: - self._match_version(self.env.ref('runbot.bundle_master').version_id) + self._match_version(self.env['runbot.version'].search([], limit=1)[0]) except Exception as e: raise ValidationError("Unable to validate version_domain: %s" % e) diff --git a/runbot/models/project.py b/runbot/models/project.py index 9c2a6696..b4836ca2 100644 --- a/runbot/models/project.py +++ b/runbot/models/project.py @@ -1,4 +1,4 @@ -from odoo import models, fields +from odoo import models, fields, api class Project(models.Model): @@ -15,6 +15,32 @@ class Project(models.Model): sequence = fields.Integer('Sequence') organisation = fields.Char('organisation', default=lambda self: self.env['ir.config_parameter'].sudo().get_param('runbot.runbot_organisation')) 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') + + @api.model_create_multi + def create(self, create_values): + projects = super().create(create_values) + base_bundle_values = [] + dummy_bundle_values = [] + for project in projects: + base_bundle_values.append({ + 'project_id': project.id, + 'name': 'master', + 'is_base': True, + }) + dummy_bundle_values.append({ + 'project_id': project.id, + 'name': 'Dummy', + 'no_build': True, + }) + master_bundles = self.env['runbot.bundle'].create(base_bundle_values) + dummy_bundles = self.env['runbot.bundle'].create(dummy_bundle_values) + for project, bundle in zip(projects, master_bundles): + project.master_bundle_id = bundle + for project, bundle in zip(projects, dummy_bundles): + project.dummy_bundle_id = bundle + return projects class Category(models.Model): diff --git a/runbot/tests/test_branch.py b/runbot/tests/test_branch.py index 1f7e18ac..994e48f0 100644 --- a/runbot/tests/test_branch.py +++ b/runbot/tests/test_branch.py @@ -146,7 +146,7 @@ class TestBranchForbidden(RunbotCase): """Test that a branch matching the repo forbidden regex, goes to dummy bundle""" def test_forbidden(self): - dummy_bundle = self.env.ref('runbot.bundle_dummy') + dummy_bundle = self.remote_server_dev.repo_id.project_id.dummy_bundle_id self.remote_server_dev.repo_id.forbidden_regex = '^bad_name.+' with mute_logger("odoo.addons.runbot.models.branch"): branch = self.Branch.create({ @@ -199,7 +199,7 @@ class TestBranchIsBase(RunbotCaseMinimalSetup): @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.""" - dummy_bundle = self.env.ref('runbot.bundle_dummy') + dummy_bundle = self.repo_addons.project_id.dummy_bundle_id # master branch on dev remote initial_addons_dev_commit = self.Commit.create({ diff --git a/runbot_populate/models/runbot.py b/runbot_populate/models/runbot.py index 9274d066..7dce099c 100644 --- a/runbot_populate/models/runbot.py +++ b/runbot_populate/models/runbot.py @@ -14,15 +14,19 @@ class Runbot(models.AbstractModel): @patch('odoo.addons.runbot.models.repo.Repo._git') def _create_demo_data(self, mock_git, mock_github): mock_github.return_value = False + project = self.env.ref('runbot.main_project') bundles = self.env['runbot.bundle'].browse( self.env['ir.model.data'].search([ ('module', '=', 'runbot_populate'), ('model', '=', 'runbot.bundle') ]).mapped('res_id') - ) - bundles |= self.env.ref('runbot.bundle_master') + ).filtered(lambda bundle: bundle.project_id == project) + bundles |= project.master_bundle_id bundles = bundles.sorted('is_base', reverse=True) - assert bundles|self.env.ref('runbot.bundle_dummy') == bundles.search([]) + existing_bundle = bundles.search([('project_id', '=', project.id)]) + expected_bundle = bundles | project.dummy_bundle_id + + assert expected_bundle == existing_bundle if bundles.branch_ids: # only populate data if no branch are found