Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions runbot/controllers/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/<model("runbot.batch"):batch>'], 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/<model("runbot.commit"):commit>',
'/runbot/commit/<string(minlength=6, maxlength=40):commit_hash>'
Expand Down
30 changes: 30 additions & 0 deletions runbot/models/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
7 changes: 7 additions & 0 deletions runbot/models/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,13 @@ def action_test_modules_filters(self):
output += markupsafe.Markup(f'''<h4>{commit.repo_id.name}</h4> 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):
"""
Expand Down
2 changes: 1 addition & 1 deletion runbot/templates/batch.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
<div class="col-lg-6">
<table class="table table-stripped">
<tr>
<td>Builds</td>
<td>Builds <a t-attf-href="/runbot/batch/fill_missing_slots/{{batch.id}}" groups="runbot.group_runbot_admin" class="btn btn-sm" title="Fill missing Slots"><i class="fa fa-plus-square"></i></a></td>
<td>
<t t-foreach="batch.slot_ids.filtered(lambda s: not s.trigger_id.manual)" t-as="slot">
<t t-call="runbot.slot_button"/>
Expand Down
3 changes: 3 additions & 0 deletions runbot/views/repo_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
<header>
</header>
<sheet>
<div name="button_box">
<button type="object" icon="fa-plus-square" groups="runbot.group_runbot_admin" name="action_fill_batches_missing_slots" help="Fill trigger slots on latest batches in the same category. Only in sticky bundles.">Fill slots</button>
</div>
<widget name="web_ribbon" title="Archived" bg_color="bg-danger" invisible="active"/>
<field name="active" invisible="1"/>
<group name="Base config">
Expand Down