From 14affdd212585c4ba63a4a52e328c6f7b720e511 Mon Sep 17 00:00:00 2001 From: Xavier-Do Date: Tue, 31 Mar 2026 14:25:46 +0200 Subject: [PATCH] [IMP] runbot: improve light config interface --- runbot/controllers/frontend.py | 10 ++++++---- runbot/models/batch.py | 17 +++++++++++++++++ runbot/static/src/js/runbot.js | 16 ++++++++++++++++ runbot/templates/build.xml | 3 +++ runbot/templates/bundle.xml | 15 +++++++-------- runbot/templates/utils.xml | 1 + 6 files changed, 50 insertions(+), 12 deletions(-) diff --git a/runbot/controllers/frontend.py b/runbot/controllers/frontend.py index 3d6198be5..10145d1a0 100644 --- a/runbot/controllers/frontend.py +++ b/runbot/controllers/frontend.py @@ -181,6 +181,7 @@ def bundle(self, bundle=None, page=1, limit=50, expand_custom=False, **kwargs): ) batchs = request.env['runbot.batch'].search(domain, limit=limit, offset=pager.get('offset', 0), order='id desc') + # compute if we should display the new batch button context = { 'bundle': bundle, 'batchs': batchs, @@ -189,6 +190,7 @@ def bundle(self, bundle=None, page=1, limit=50, expand_custom=False, **kwargs): 'title': 'Bundle %s' % bundle.name, 'page_info_state': bundle.last_batch._get_global_result(), 'expand_custom': expand_custom, + 'needs_update': bundle.last_batch and bundle.last_batch.needs_update(), } return request.render('runbot.bundle', context) @@ -198,7 +200,7 @@ def bundle(self, bundle=None, page=1, limit=50, expand_custom=False, **kwargs): '/runbot/bundle//force/', ], type='http', auth="user", methods=['GET', 'POST'], csrf=False) def force_bundle(self, bundle, auto_rebase=False, use_base_commits=False, **_post): - if not request.env.user.has_group('runbot.group_runbot_advanced_user') and ':' not in bundle.name: + if not request.env.user.has_group('runbot.group_runbot_advanced_user') and ':' not in bundle.name and not bundle.last_batch.needs_update(): message = "Only users with a specific group can do that. Please contact runbot administrators" raise Forbidden(message) _logger.info('user %s forcing bundle %s', request.env.user.name, bundle.name) # user must be able to read bundle @@ -686,9 +688,9 @@ def configure_bundle_triggers(self, bundle_id, action, expand_custom=False, **kw bundle.sudo()._configure_custom_trigger_start_mode('light') else: raise NotFound() - expand_kwrags = '?expand_custom=1' if expand_custom else '' - - return werkzeug.utils.redirect(f'/runbot/bundle/{bundle_id}{expand_kwrags}') + if expand_custom: + return werkzeug.utils.redirect(f'/runbot/bundle/{bundle_id}?expand_custom=1') + return werkzeug.utils.redirect(f'/runbot/bundle/{bundle_id}') @route(['/runbot/trigger_custom//set_mode/'], type='http', auth='user', sitemap=False) def configure_custom_trigger(self, trigger_custom_id, mode, **kwargs): diff --git a/runbot/models/batch.py b/runbot/models/batch.py index db4999751..331f44b51 100644 --- a/runbot/models/batch.py +++ b/runbot/models/batch.py @@ -532,6 +532,23 @@ def _log(self, message, *args, level='INFO'): 'level': level, }) + def needs_update(self): + bundle = self.bundle_id + custom_trigger_per_trigger = {ct.trigger_id: ct for ct in bundle.trigger_custom_ids} + for slot in self.slot_ids: + trigger = slot.trigger_id + custom_trigger = custom_trigger_per_trigger.get(trigger) + if not custom_trigger: + continue + expected_config = trigger.config_id + if custom_trigger.config_id: + expected_config = custom_trigger.config_id + elif trigger.light_config_id and custom_trigger.start_mode == 'light': + expected_config = trigger.light_config_id + if slot.params_id.config_id != expected_config: + return True + return False + class BatchLog(models.Model): _name = 'runbot.batch.log' _description = 'Batch log' diff --git a/runbot/static/src/js/runbot.js b/runbot/static/src/js/runbot.js index 58a902976..76b2a129b 100644 --- a/runbot/static/src/js/runbot.js +++ b/runbot/static/src/js/runbot.js @@ -38,3 +38,19 @@ function copyToClipboard(text) { } navigator.clipboard.writeText(text); } + +document.addEventListener('DOMContentLoaded', function() { + const collapseElement = document.getElementById('customTriggers'); + if (collapseElement) { + collapseElement.addEventListener('show.bs.collapse', function () { + const url = new URL(window.location); + url.searchParams.set('expand_custom', '1'); + window.history.replaceState({}, '', url); + }); + collapseElement.addEventListener('hide.bs.collapse', function () { + const url = new URL(window.location); + url.searchParams.delete('expand_custom'); + window.history.replaceState({}, '', url); + }); + } +}); diff --git a/runbot/templates/build.xml b/runbot/templates/build.xml index b751ae50b..0e50b7ce4 100644 --- a/runbot/templates/build.xml +++ b/runbot/templates/build.xml @@ -114,6 +114,9 @@ + + Mode: Light Configure
+
Version: diff --git a/runbot/templates/bundle.xml b/runbot/templates/bundle.xml index a67bfe16c..af1036a40 100644 --- a/runbot/templates/bundle.xml +++ b/runbot/templates/bundle.xml @@ -71,34 +71,33 @@ - - + - Disable all + Disable all - Light + Light - Default + Default - Force all + Force all - - + + Apply
diff --git a/runbot/templates/utils.xml b/runbot/templates/utils.xml index 1687e18e7..bf89535f2 100644 --- a/runbot/templates/utils.xml +++ b/runbot/templates/utils.xml @@ -273,6 +273,7 @@ + Light