Skip to content

Commit 3a7a355

Browse files
committed
[IMP] runbot: add a button to create missing trigger slots
1 parent bb62bc8 commit 3a7a355

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

runbot/controllers/frontend.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,13 @@ def slot_create_build(self, slot=None, **kwargs):
249249
build = slot.sudo()._create_missing_build()
250250
return werkzeug.utils.redirect('/runbot/build/%s' % build.id)
251251

252+
@o_route(['/runbot/batch/fill_missing_slots/<model("runbot.batch"):batch>'], auth='user', type='http')
253+
def batch_fill_missing_slots(self, batch=None, **kwargs):
254+
if not request.env.user.has_group('runbot.group_runbot_admin'):
255+
raise NotFound
256+
batch._add_missing_slots()
257+
return werkzeug.utils.redirect(f'/runbot/batch/{batch.id}')
258+
252259
@route([
253260
'/runbot/commit/<model("runbot.commit"):commit>',
254261
'/runbot/commit/<string(minlength=6, maxlength=40):commit_hash>'

runbot/models/batch.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,36 @@ def _log(self, message, *args, level='INFO'):
499499
'level': level,
500500
})
501501

502+
def _add_missing_slots(self):
503+
missing_trigger_ids = self.env['runbot.trigger'].search([
504+
('project_id', '=', self.bundle_id.project_id.id),
505+
('category_id', '=', self.category_id.id),
506+
('id', 'not in', self.slot_ids.trigger_id.ids)
507+
]).filtered(
508+
lambda t: not t.version_domain or
509+
self.bundle_id.version_id.filtered_domain(t._get_version_domain())
510+
)
511+
bundle = self.bundle_id
512+
dockerfile_id = bundle.dockerfile_id or bundle.base_id.dockerfile_id or bundle.project_id.dockerfile_id or bundle.version_id.dockerfile_id
513+
for trigger in missing_trigger_ids:
514+
params_value = {
515+
'version_id': self.bundle_id.version_id.id,
516+
'project_id': self.bundle_id.project_id.id,
517+
'create_batch_id': self.id,
518+
'config_id': trigger.config_id.id,
519+
'trigger_id': trigger.id,
520+
'config_data': dict(trigger.config_data or {}),
521+
'modules': bundle.modules,
522+
'dockerfile_id': dockerfile_id.id,
523+
'commit_link_ids': [(6, 0, self.commit_link_ids.ids)],
524+
}
525+
params = self.env['runbot.build.params'].create(params_value)
526+
self.env['runbot.batch.slot'].create({
527+
'batch_id': self.id,
528+
'trigger_id': trigger.id,
529+
'params_id': params.id,
530+
'link_type': 'created',
531+
})
502532

503533
class BatchLog(models.Model):
504534
_name = 'runbot.batch.log'

runbot/templates/batch.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@
150150
<div class="col-lg-6">
151151
<table class="table table-stripped">
152152
<tr>
153-
<td>Builds</td>
153+
<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>
154154
<td>
155155
<t t-foreach="batch.slot_ids.filtered(lambda s: not s.trigger_id.manual)" t-as="slot">
156156
<t t-call="runbot.slot_button"/>

0 commit comments

Comments
 (0)