From 7e49b4cd2b632c2665897b251f2113de82a2f99c Mon Sep 17 00:00:00 2001 From: Xavier-Do Date: Mon, 24 Feb 2020 14:45:23 +0100 Subject: [PATCH] [IMP] runbot: add a public route for monitoring --- runbot/controllers/frontend.py | 33 ++++++++++++++++++++++++++++++++ runbot/templates/dashboard.xml | 35 ++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/runbot/controllers/frontend.py b/runbot/controllers/frontend.py index 358e5f62..c27d5a2d 100644 --- a/runbot/controllers/frontend.py +++ b/runbot/controllers/frontend.py @@ -13,6 +13,7 @@ from odoo.http import Controller, request, route from ..common import uniq_list, flatten, fqdn from odoo.osv import expression +from odoo.exceptions import UserError class Runbot(Controller): @@ -329,6 +330,38 @@ class Runbot(Controller): } return request.render(view_id if view_id else config.monitoring_view_id.id or "runbot.monitoring", qctx) + @route(['/runbot/config/', + '/runbot/config/'], type='http', auth="public", website=True) + def config(self, config_id=None, config_name=None, refresh=None, **kwargs): + + if config_id: + monitored_config_id = config_id + else: + config = request.env['runbot.build.config'].search([('name', '=', config_name)], limit=1) + if config: + monitored_config_id = config.id + else: + raise UserError('Config name not found') + + readable_repos = request.env['runbot.repo'].search([]) + request.env.cr.execute("""SELECT DISTINCT ON (branch_id) branch_id, id FROM runbot_build + WHERE config_id = %s + AND global_state in ('running', 'done') + AND branch_id in (SELECT id FROM runbot_branch where sticky='t' and repo_id in %s) + AND local_state != 'duplicate' + AND hidden = false + ORDER BY branch_id ASC, id DESC""", [int(monitored_config_id), tuple(readable_repos.ids)]) + last_monitored = request.env['runbot.build'].browse([r[1] for r in request.env.cr.fetchall()]) + + config = request.env['runbot.build.config'].browse(monitored_config_id) + qctx = { + 'config': config, + 'refresh': refresh, + 'last_monitored': last_monitored, # nightly + 'kwargs': kwargs + } + return request.render(config.monitoring_view_id.id or "runbot.config_monitoring", qctx) + @route(['/runbot/branch/', '/runbot/branch//page/'], website=True, auth='public', type='http') def branch_builds(self, branch_id=None, search='', page=1, limit=50, refresh='', **kwargs): """ list builds of a runbot branch """ diff --git a/runbot/templates/dashboard.xml b/runbot/templates/dashboard.xml index 07394522..2ef1dbc9 100644 --- a/runbot/templates/dashboard.xml +++ b/runbot/templates/dashboard.xml @@ -120,6 +120,41 @@ + +