mirror of
https://github.com/odoo/runbot.git
synced 2025-03-15 23:45:44 +07:00
[IMP] runbot: add bundle_ids to ErrorLog SQL view
This commit is contained in:
parent
0e2f75c5d6
commit
6c3f14ed61
@ -4,6 +4,7 @@ import logging
|
||||
|
||||
from ..common import pseudo_markdown
|
||||
from odoo import models, fields, tools
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
@ -95,7 +96,6 @@ class RunbotErrorLog(models.Model):
|
||||
path = fields.Char(string='Path', readonly=True)
|
||||
line = fields.Char(string='Line', readonly=True)
|
||||
build_id = fields.Many2one('runbot.build', string='Build', readonly=True)
|
||||
#bu_name = fields.Char(String='Build name', readonly=True) as aggregate
|
||||
dest = fields.Char(String='Build dest', readonly=True)
|
||||
local_state = fields.Char(string='Local state', readonly=True)
|
||||
local_result = fields.Char(string='Local result', readonly=True)
|
||||
@ -104,9 +104,9 @@ class RunbotErrorLog(models.Model):
|
||||
bu_create_date = fields.Datetime(string='Build create date', readonly=True)
|
||||
host = fields.Char(string='Host', readonly=True)
|
||||
parent_id = fields.Many2one('runbot.build', string='Parent build', readonly=True)
|
||||
#bundle_id = fields.Many2one('runbot.bundle', string='Bundle', readonly=True)
|
||||
#bundle_name = fields.Char(string='Bundle name', readonly=True)
|
||||
#bundle_sticky = fields.Boolean(string='Sticky', readonly=True)
|
||||
top_parent_id = fields.Many2one('runbot.build', string="Top parent", readonly=True)
|
||||
bundle_ids = fields.Many2many('runbot.bundle', compute='_compute_bundle_id', search='_search_bundle', string='Bundle', readonly=True)
|
||||
sticky = fields.Boolean(string='Bundle Sticky', compute='_compute_bundle_id', search='_search_sticky', readonly=True)
|
||||
build_url = fields.Char(compute='_compute_build_url', readonly=True)
|
||||
|
||||
def _compute_repo_short_name(self):
|
||||
@ -125,11 +125,62 @@ class RunbotErrorLog(models.Model):
|
||||
"target": "new",
|
||||
}
|
||||
|
||||
def _compute_bundle_id(self):
|
||||
slots = self.env['runbot.batch.slot'].search([('build_id', 'in', self.mapped('top_parent_id').ids)])
|
||||
for l in self:
|
||||
l.bundle_ids = slots.filtered(lambda rec: rec.build_id.id == l.top_parent_id.id).batch_id.bundle_id
|
||||
l.sticky = any(l.bundle_ids.filtered('sticky'))
|
||||
|
||||
def _search_bundle(self, operator, value):
|
||||
query = """
|
||||
SELECT id
|
||||
FROM runbot_build as build
|
||||
WHERE EXISTS(
|
||||
SELECT * FROM runbot_batch_slot as slot
|
||||
JOIN
|
||||
runbot_batch batch ON batch.id = slot.batch_id
|
||||
JOIN
|
||||
runbot_bundle bundle ON bundle.id = batch.bundle_id
|
||||
%s
|
||||
"""
|
||||
if operator in ('ilike', '=', 'in'):
|
||||
value = '%%%s%%' % value if operator == 'ilike' else value
|
||||
col_name = 'id' if operator == 'in' else 'name'
|
||||
where_condition = "WHERE slot.build_id = build.id AND bundle.%s %s any(%%s));" if operator == 'in' else "WHERE slot.build_id = build.id AND bundle.%s %s %%s);"
|
||||
operator = '=' if operator == 'in' else operator
|
||||
where_condition = where_condition % (col_name, operator)
|
||||
query = query % where_condition
|
||||
self.env.cr.execute(query, (value,))
|
||||
build_ids = [t[0] for t in self.env.cr.fetchall()]
|
||||
return [('top_parent_id', 'in', build_ids)]
|
||||
|
||||
raise UserError('Operator `%s` not implemented for bundle search' % operator)
|
||||
|
||||
def search_count(self, args):
|
||||
return 4242 # hack to speed up the view
|
||||
|
||||
def _search_sticky(self, operator, value):
|
||||
if operator == '=':
|
||||
self.env.cr.execute("""
|
||||
SELECT id
|
||||
FROM runbot_build as build
|
||||
WHERE EXISTS(
|
||||
SELECT * FROM runbot_batch_slot as slot
|
||||
JOIN
|
||||
runbot_batch batch ON batch.id = slot.batch_id
|
||||
JOIN
|
||||
runbot_bundle bundle ON bundle.id = batch.bundle_id
|
||||
WHERE
|
||||
bundle.sticky = %s AND slot.build_id = build.id);
|
||||
""", (value,))
|
||||
build_ids = [t[0] for t in self.env.cr.fetchall()]
|
||||
return [('top_parent_id', 'in', build_ids)]
|
||||
return []
|
||||
|
||||
def _parse_logs(self):
|
||||
BuildError = self.env['runbot.build.error']
|
||||
BuildError._parse_logs(self)
|
||||
|
||||
|
||||
def init(self):
|
||||
""" Create an SQL view for ir.logging """
|
||||
tools.drop_view_if_exists(self._cr, 'runbot_error_log')
|
||||
@ -152,7 +203,8 @@ class RunbotErrorLog(models.Model):
|
||||
bu.global_result AS global_result,
|
||||
bu.create_date AS bu_create_date,
|
||||
bu.host AS host,
|
||||
bu.parent_id AS parent_id
|
||||
bu.parent_id AS parent_id,
|
||||
split_part(bu.parent_path, '/',1)::int AS top_parent_id
|
||||
FROM
|
||||
ir_logging AS l
|
||||
JOIN
|
||||
|
@ -14,6 +14,7 @@
|
||||
<div class="oe_title">
|
||||
<h1><field name="build_id"/></h1>
|
||||
<field name="build_url" widget="url"/>
|
||||
&nbsp;<field name="log_create_date"/>
|
||||
</div>
|
||||
<group>
|
||||
<group>
|
||||
@ -44,6 +45,7 @@
|
||||
<tree string="Build Errors">
|
||||
<button name="action_goto_build" type="object" icon="fa-external-link "/>
|
||||
<field name="build_id"/>
|
||||
<field name="bundle_ids" widget="many2many_tags"/>
|
||||
<field name="log_create_date"/>
|
||||
<field name="name"/>
|
||||
<field name="func"/>
|
||||
@ -65,6 +67,13 @@
|
||||
<field name="build_id"/>
|
||||
<filter string="Failed builds" name="failed_builds" domain="[('global_state', '=', 'done'), ('global_result', '=', 'ko')]"/>
|
||||
<separator/>
|
||||
<filter string="Master bundle" name="master_bundle" domain="[('bundle_ids.name', '=', 'master')]"/>
|
||||
<filter string="Sticky bundles" name="sticky_bundles" domain="[('sticky', '=', True)]"/>
|
||||
<separator/>
|
||||
<!-- <filter name="filter_log_create_date" date="log_create_date" string="Log Date" default_period="last_7_days"/> -->
|
||||
<filter string="Last 7 Days" name="log_date" domain="[
|
||||
('log_create_date', '>=', (datetime.datetime.combine(context_today() + relativedelta(days=-7), datetime.time(0,0,0)).to_utc()).strftime('%Y-%m-%d %H:%M:%S')),
|
||||
('log_create_date', '<', (datetime.datetime.combine(context_today(), datetime.time(0,0,0)).to_utc()).strftime('%Y-%m-%d %H:%M:%S'))]"/>
|
||||
</search>
|
||||
</field>
|
||||
</record>
|
||||
@ -73,7 +82,8 @@
|
||||
<field name="name">Error Logs</field>
|
||||
<field name="res_model">runbot.error.log</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
<field name="context">{'search_default_sticky_branches': True, 'search_default_failed_builds': True}</field>
|
||||
<!-- <field name="context">{'search_default_sticky_bundles': True, 'search_default_failed_builds': True, 'time_ranges': {'field': 'log_create_date', 'range': 'last_7_days'},}</field> -->
|
||||
<field name="context">{'search_default_sticky_bundles': True, 'search_default_failed_builds': True, 'search_default_log_date': True}</field>
|
||||
</record>
|
||||
|
||||
<menuitem
|
||||
|
Loading…
Reference in New Issue
Block a user