diff --git a/runbot/controllers/frontend.py b/runbot/controllers/frontend.py index 34dcb03f6..139b9cd61 100644 --- a/runbot/controllers/frontend.py +++ b/runbot/controllers/frontend.py @@ -249,6 +249,13 @@ def slot_create_build(self, slot=None, **kwargs): build = slot.sudo()._create_missing_build() return werkzeug.utils.redirect('/runbot/build/%s' % build.id) + @o_route(['/runbot/batch/fill_missing_slots/'], auth='user', type='http') + def batch_fill_missing_slots(self, batch=None, **kwargs): + if not request.env.user.has_group('runbot.group_runbot_admin'): + raise NotFound + batch._add_missing_slots() + return werkzeug.utils.redirect(f'/runbot/batch/{batch.id}') + @route([ '/runbot/commit/', '/runbot/commit/' diff --git a/runbot/models/batch.py b/runbot/models/batch.py index 1469d9e08..8e96f597f 100644 --- a/runbot/models/batch.py +++ b/runbot/models/batch.py @@ -499,6 +499,36 @@ def _log(self, message, *args, level='INFO'): 'level': level, }) + def _add_missing_slots(self): + missing_trigger_ids = self.env['runbot.trigger'].search([ + ('project_id', '=', self.bundle_id.project_id.id), + ('category_id', '=', self.category_id.id), + ('id', 'not in', self.slot_ids.trigger_id.ids) + ]).filtered( + lambda t: not t.version_domain or + self.bundle_id.version_id.filtered_domain(t._get_version_domain()) + ) + bundle = self.bundle_id + dockerfile_id = bundle.dockerfile_id or bundle.base_id.dockerfile_id or bundle.project_id.dockerfile_id or bundle.version_id.dockerfile_id + for trigger in missing_trigger_ids: + params_value = { + 'version_id': self.bundle_id.version_id.id, + 'project_id': self.bundle_id.project_id.id, + 'create_batch_id': self.id, + 'config_id': trigger.config_id.id, + 'trigger_id': trigger.id, + 'config_data': dict(trigger.config_data or {}), + 'modules': bundle.modules, + 'dockerfile_id': dockerfile_id.id, + 'commit_link_ids': [(6, 0, self.commit_link_ids.ids)], + } + params = self.env['runbot.build.params'].create(params_value) + self.env['runbot.batch.slot'].create({ + 'batch_id': self.id, + 'trigger_id': trigger.id, + 'params_id': params.id, + 'link_type': 'created', + }) class BatchLog(models.Model): _name = 'runbot.batch.log' diff --git a/runbot/models/repo.py b/runbot/models/repo.py index 0cafbe0be..583c50b90 100644 --- a/runbot/models/repo.py +++ b/runbot/models/repo.py @@ -193,6 +193,13 @@ def action_test_modules_filters(self): output += markupsafe.Markup(f'''

{commit.repo_id.name}

Failed to get modules for {commit.repo_id.name}:{commit.name} {e}''') self.message_post(body=output) + def action_fill_batches_missing_slots(self): + sticky_bundles = self.env['runbot.bundle'].search([('project_id', '=', self.project_id.id), ('sticky', '=', True)]) + for bundle in sticky_bundles: + last_batch_in_category = bundle.with_context(category_id=self.category_id.id).last_done_batch + if last_batch_in_category: + last_batch_in_category._add_missing_slots() + class Remote(models.Model): """ diff --git a/runbot/templates/batch.xml b/runbot/templates/batch.xml index c01aeea7a..6631bf17e 100644 --- a/runbot/templates/batch.xml +++ b/runbot/templates/batch.xml @@ -150,7 +150,7 @@
- +
BuildsBuilds diff --git a/runbot/views/repo_views.xml b/runbot/views/repo_views.xml index 1280c9a7d..301d9db54 100644 --- a/runbot/views/repo_views.xml +++ b/runbot/views/repo_views.xml @@ -8,6 +8,9 @@
+
+ +