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
10 changes: 6 additions & 4 deletions runbot/controllers/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand All @@ -198,7 +200,7 @@ def bundle(self, bundle=None, page=1, limit=50, expand_custom=False, **kwargs):
'/runbot/bundle/<model("runbot.bundle"):bundle>/force/<int:auto_rebase>',
], 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
Expand Down Expand Up @@ -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/<int:trigger_custom_id>/set_mode/<string:mode>'], type='http', auth='user', sitemap=False)
def configure_custom_trigger(self, trigger_custom_id, mode, **kwargs):
Expand Down
17 changes: 17 additions & 0 deletions runbot/models/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
16 changes: 16 additions & 0 deletions runbot/static/src/js/runbot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
});
3 changes: 3 additions & 0 deletions runbot/templates/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@
</t>
</div>
</t>
<t t-if="build.params_id.config_id==build.trigger_id.light_config_id">
<b>Mode:</b> <span class="badge btn btn-info">Light</span> <a t-if="unique_batch" t-attf-href="/runbot/bundle/{{unique_batch.bundle_id.id}}">Configure</a><br/>
</t>
<t t-if='more'>
<b>Version:</b>
<t t-out="build.params_id.version_id.name"/>
Expand Down
15 changes: 7 additions & 8 deletions runbot/templates/bundle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,34 +71,33 @@
<td>
<t t-set="current_mode" t-value="'custom'"/>
<t t-set="modified_repos" t-value="bundle.branch_ids.remote_id.repo_id"/>

<t t-if="not bundle.trigger_custom_ids"> <t t-set="current_mode" t-value="'auto'"/></t>
<t t-if="not bundle.trigger_custom_ids"> <t t-set="current_mode" t-value="'none'"/></t>
<t t-elif="all(trigger_custom.start_mode == 'disabled' for trigger_custom in bundle.trigger_custom_ids)"> <t t-set="current_mode" t-value="'disabled'"/></t>
<t t-elif="all(trigger_custom.start_mode == 'force' for trigger_custom in bundle.trigger_custom_ids)"> <t t-set="current_mode" t-value="'force'"/></t>
<t t-elif="all(trigger_custom.start_mode == 'auto' for trigger_custom in bundle.trigger_custom_ids)"> <t t-set="current_mode" t-value="'auto'"/></t>
<t t-elif="all(trigger_custom.start_mode in ('light', 'auto') for trigger_custom in bundle.trigger_custom_ids)"> <t t-set="current_mode" t-value="'light'"/></t>
<t t-if="current_mode=='disabled'">
<a role="button" t-attf-class="btn btn-primary btn-ssm" data-bs-toggle="collapse" href="#customTriggers">Disable all</a>
<button role="button" t-attf-class="btn btn-primary btn-ssm" data-bs-toggle="collapse" data-bs-target="#customTriggers">Disable all</button>
</t><t t-else="">
<a role="button" t-attf-class="btn btn-default btn-ssm" t-attf-href="/runbot/bundle/{{bundle.id}}/triggers/disable_all"> Disable all</a>
</t>
<t t-if="current_mode=='light'">
<a role="button" t-attf-class="btn btn-primary btn-ssm" data-bs-toggle="collapse" href="#customTriggers">Light</a>
<button role="button" t-attf-class="btn btn-primary btn-ssm" data-bs-toggle="collapse" data-bs-target="#customTriggers">Light</button>
</t><t t-else="">
<a role="button" t-attf-class="btn btn-default btn-ssm" t-attf-href="/runbot/bundle/{{bundle.id}}/triggers/light_all">Light</a>
</t>
<t t-if="current_mode=='auto'">
<a role="button" t-attf-class="btn btn-primary btn-ssm" data-bs-toggle="collapse" href="#customTriggers">Default</a>
<button role="button" t-attf-class="btn btn-primary btn-ssm" data-bs-toggle="collapse" data-bs-target="#customTriggers">Default</button>
</t><t t-else="">
<a role="button" t-attf-class="btn btn-default btn-ssm" t-attf-href="/runbot/bundle/{{bundle.id}}/triggers/auto_all">Default</a>
</t>
<t t-if="current_mode=='force'">
<a role="button" t-attf-class="btn btn-primary btn-ssm" data-bs-toggle="collapse" href="#customTriggers">Force all</a>
<button role="button" t-attf-class="btn btn-primary btn-ssm" data-bs-toggle="collapse" data-bs-target="#customTriggers">Force all</button>
</t><t t-else="">
<a role="button" t-attf-class="btn btn-default btn-ssm" t-attf-href="/runbot/bundle/{{bundle.id}}/triggers/force_all">Force all</a>
</t>
<a role="button" t-attf-class="btn btn-{{'primary' if current_mode=='custom' else 'default'}} btn-ssm" data-bs-toggle="collapse" href="#customTriggers" aria-expanded="false" aria-controls="customTriggers"> Custom <i class="fa fa-caret-down ms-1"/></a>

<button role="button" t-attf-class="btn btn-{{'primary' if current_mode=='custom' else 'default'}} btn-ssm" data-bs-toggle="collapse" data-bs-target="#customTriggers" aria-expanded="false" aria-controls="customTriggers"> Custom <i class="fa fa-caret-down ms-1"/></button>
<a t-if="needs_update" role="button" class="btn btn-default btn-ssm" t-attf-href="/runbot/bundle/{{bundle.id}}/force"><i class="fa fa-play"/> Apply</a>
<div t-attf-class="collapse {{'show' if expand_custom else ''}}" id="customTriggers">
<div class="card card-body mt-2">
<t t-foreach="bundle.trigger_custom_ids" t-as="trigger_custom">
Expand Down
1 change: 1 addition & 0 deletions runbot/templates/utils.xml
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@
<span t-attf-class="btn btn-{{color}} disabled" t-att-title="slot.link_type">
<i t-attf-class="fa fa-{{slot._fa_link_type()}}"/>
</span>
<a t-if="slot.params_id.config_id == slot.trigger_id.light_config_id" class="badge btn btn-info" t-attf-href="/runbot/bundle/{{slot.batch_id.bundle_id.id}}">Light</a>
<a t-if="bu" t-attf-href="/runbot/batch/{{slot.batch_id.id}}/build/#{bu.id}" t-attf-class="btn btn-default slot_name">
<span t-out="slot.trigger_id.name"/>
</a>
Expand Down