Skip to content

Commit c68b9ba

Browse files
d-fenceXavier-Do
authored andcommitted
[IMP] runbot: add a commit link details page
A new frontend page and route is added to show details of commit_links. The datails includes the diff with the base commit for the commit links specified in the url. Also, the commit links can be filtered by version and repository. Version ids and repository ids have to be given in URL params as comma separated ids. The build error frequency graph is also improved. Each cell is now clickable and links to the batches of the day. On that `batch by date` page, a link is added to the commit details page, filtered by the versions and repositories where the build error was seen. The original diff page was a custom page made by @Xavier-Do Further improvements have to be made: - add a form on the batches by date page to customize the details filters - improve the UI of the diff page
1 parent 94a262f commit c68b9ba

File tree

5 files changed

+138
-10
lines changed

5 files changed

+138
-10
lines changed

runbot/__manifest__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
'templates/nginx.xml',
3838
'templates/build_error.xml',
3939
'templates/batches_by_date.xml',
40+
'templates/commit_link_details.xml',
4041

4142
'views/branch_views.xml',
4243
'views/build_error_link_views.xml',

runbot/controllers/frontend.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import functools
33
import logging
44
from collections import OrderedDict
5+
from subprocess import CalledProcessError
56
from urllib.parse import urlsplit
67

78
import werkzeug
@@ -11,11 +12,12 @@
1112
from werkzeug.exceptions import Forbidden, NotFound
1213

1314
from odoo import fields
14-
from odoo.addons.website.controllers.main import QueryURL
1515
from odoo.http import Controller, Response, request
1616
from odoo.http import route as o_route
1717
from odoo.osv import expression
1818

19+
from odoo.addons.website.controllers.main import QueryURL
20+
1921
_logger = logging.getLogger(__name__)
2022

2123

@@ -752,11 +754,49 @@ def batches_by_date(self, project_id=None, category_id=None, batches_date=None,
752754
for batch in batches:
753755
builds_by_batch_id[batch.id] = build_error.build_ids.filtered_domain([('id', 'child_of', batch.slot_ids.build_id.ids)])
754756

757+
build_error = build_error if build_error else self.env['runbot.build.error']
758+
diff_versions_filter = build_error.version_ids
759+
diff_repos_filter = build_error.trigger_ids.dependency_ids
760+
commit_link_details_url = f'/runbot/commit_link/details/{",".join(map(str, batches.commit_link_ids.ids))}'
761+
755762
return request.render("runbot.batches_by_date", {
756763
'batches_date': batches_date,
757764
'batches': batches,
758765
'next_date_url': next_date_url,
759766
'previous_date_url': previous_date_url,
767+
'commit_link_details_url': commit_link_details_url,
760768
'builds_by_batch_id': builds_by_batch_id,
761769
'category': request.env['runbot.category'].browse(category_id),
770+
'diff_versions_filter': diff_versions_filter,
771+
'diff_repos_filter': diff_repos_filter,
772+
})
773+
774+
@route([
775+
"/runbot/commit_link/details/<string:commit_link_ids>",
776+
], type="http", auth="user", website=True, sitemap=False)
777+
def commit_links_diffs(self, commit_link_ids=None, versions_filter_ids=None, repos_filter_ids=None, **kwargs):
778+
commit_links = request.env['runbot.commit.link'].browse([int(id) for id in commit_link_ids.split(',')])
779+
if versions_filter_ids:
780+
vids = [int(v) for v in versions_filter_ids.split(',')]
781+
commit_links = commit_links.filtered_domain([('branch_id.bundle_id.version_id.id', 'in', vids)])
782+
if repos_filter_ids:
783+
rids = [int(r) for r in repos_filter_ids.split(',')]
784+
commit_links = commit_links.filtered_domain([('branch_id.repo_id.id', 'in', rids)])
785+
diff_by_commit_link_ids = {}
786+
popot_filter = ":!*.po :!*.pot"
787+
git_show_filter = ["--", "."] + popot_filter.split()
788+
selected_commit_links = request.env['runbot.commit.link']
789+
for commit_link in commit_links:
790+
if commit_link.merge_base_commit_id:
791+
git_show_argument = f"{commit_link.merge_base_commit_id.name}..{commit_link.commit_id.name}"
792+
try:
793+
diff = commit_link.commit_id.repo_id.sudo()._git(['show', git_show_argument] + git_show_filter, errors='ignore').removeprefix('commit ')
794+
except CalledProcessError as e:
795+
diff = f'Error with command git command:\n{e.cmd}\n{e.stdout}'
796+
diff_by_commit_link_ids[commit_link.id] = diff
797+
selected_commit_links |= commit_link
798+
799+
return request.render("runbot.commit_link_details", {
800+
'commit_links': selected_commit_links,
801+
'diff_by_commit_link_ids': diff_by_commit_link_ids,
762802
})

runbot/models/build_error.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,30 @@ def draw_svg(daily_version_freq, y_labels=None, max_value: int = 10, error_id: i
3737
x_keys = sorted(daily_version_freq.keys())
3838
height = 40
3939
for idx, (x_key) in enumerate(x_keys):
40-
batch_date = x_key.strftime('%Y-%m-%d')
40+
batch_date = x_key.strftime("%Y-%m-%d")
4141
for idy, (y_key, y_label) in enumerate(y_labels.items()):
4242
value = daily_version_freq[x_key].get(y_key, 0)
4343
if not value:
44-
continue
45-
if value > max_value:
46-
value = max_value
47-
cell_opacity = ((max_value * 0.3 + value) / (max_value * 0.3 + max_value))
48-
cell_color = get_color(value, cell_opacity)
44+
cell_color = "white"
45+
cell_opacity = 0
46+
else:
47+
value = min(value, max_value)
48+
cell_opacity = ((max_value * 0.3 + value) / (max_value * 0.3 + max_value))
49+
cell_color = get_color(value, cell_opacity)
50+
href = f'/runbot/batches/{project_id}/{category_id}/{batch_date}/{error_id or ""}'
4951
pos_y = idy * 10 + 0.5
5052
pos_x = idx * 10 + 0.5
5153
rects.append(
52-
f''''
53-
<a href="/runbot/batches/{project_id}/{category_id}/{batch_date}/{error_id if error_id else ""}">
54+
f'''
55+
<a href="{href}">
5456
<title>{batch_date} {y_label} ({value})</title>
5557
<rect fill="{cell_color}" width="9" height="9" x="{pos_x}" y="{pos_y}"/>
56-
</a>'''
58+
</a>''',
5759
)
5860
rects = ''.join(rects)
5961
return f'<div style="height: {height}px"><svg xmlns="https://www.w3.org/2000/svg" viewbox="0 0 {len(x_keys) * 10} {len(y_labels) * 10}" style="border: 1px solid black; height: 100%; width: 100%;" preserveAspectRatio="none" shape-rendering="cripsEdges">{rects}</svg></div>'
6062

63+
6164
class BuildErrorLink(models.Model):
6265
_name = 'runbot.build.error.link'
6366
_description = 'Build Build Error Extended Relation'

runbot/templates/batches_by_date.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,26 @@
1010
<div class="btn-group" role="group">
1111
<a t-att-href="previous_date_url" class="btn btn-sm text-start" title="Previous date"><i class="fa fa-chevron-left"/></a>
1212
<a t-att-href="next_date_url" class="btn btn-sm text-start" title="Next date"><i class="fa fa-chevron-right"/></a>
13+
<t t-set="repo_url_separator" t-value="'?'"/>
14+
<t t-if="diff_versions_filter">
15+
<t t-set="commit_link_details_url" t-value="commit_link_details_url + '?versions_filter_ids=' + ','.join(map(str, diff_versions_filter.ids))"/>
16+
<t t-set="repo_url_separator" t-value="'&amp;'"/>
17+
</t>
18+
<t t-if="diff_repos_filter">
19+
<t t-set="commit_link_details_url" t-value="commit_link_details_url + repo_url_separator + 'repos_filter_ids=' + ','.join(map(str, diff_repos_filter.ids))"/>
20+
</t>
21+
<a t-att-href="commit_link_details_url" class="btn btn-sm text-start" title="Compare all batches with their bases" groups="runbot.group_runbot_advanced_user">
22+
<i class="fa fa-arrows-v"/>
23+
</a>
1324
</div>
1425
</h5>
1526
<t t-foreach="batches" t-as="batch">
1627
<div class="col-md-1">
1728
<t t-esc="batch.bundle_id.name" />
29+
<t t-set="batch_diff_url" t-value="'/runbot/commit_link/details/' + ','.join(map(str, batch.commit_link_ids.ids))"/>
30+
<a t-att-href="batch_diff_url" class="btn btn-sm text-start" title="Compare batch with its base" groups="runbot.group_runbot_advanced_user">
31+
<i class="fa fa-arrows-v"/>
32+
</a>
1833
</div>
1934
<div class="col-md-11">
2035
<div class="batch_row" >
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<odoo>
3+
<data>
4+
<template id="runbot.commit_link_details">
5+
<t t-call="runbot.layout" groups="base.group_user">
6+
<t t-foreach="commit_links" t-as="commit_link">
7+
<t t-set="commit" t-value="commit_link.commit_id"/>
8+
<t t-set="collapse" t-value="'collapse' + str(commit_link.id)"/>
9+
<t t-set="href" t-value="'#' + collapse"/>
10+
<div class="container sticky-top bg-white" style="margin-left: 50%;">
11+
<p>
12+
<span type="button" data-bs-toggle="collapse" t-att-data-bs-target="href" role="button" aria-expanded="true" t-att-aria-controls="collapse"><i class="fa fa-toggle-up"/></span>
13+
<a t-attf-href="/runbot/commit/#{commit.id}">
14+
<span class="label" t-esc="commit.dname"/>
15+
<span t-esc="'+%s' % commit_link.diff_add" class="text-success"/>
16+
<span t-esc="'-%s' % commit_link.diff_remove" class="text-danger"/>
17+
<span class="text-info">
18+
(
19+
<span t-esc="commit_link.file_changed"/>
20+
<i class="fa fa-file"/>
21+
)
22+
<span io="behind">(
23+
<span t-esc="'%s ahead' % commit_link.base_ahead" class="text-success"/>
24+
,
25+
<span t-esc="'%s behind' % commit_link.base_behind" class="text-danger"/>
26+
)</span>
27+
</span>
28+
</a>
29+
<br/>
30+
Branch: <span t-esc="commit_link.branch_id.name"/><br/>
31+
Version: <span t-esc="commit_link.branch_id.bundle_id.version_id.name"/><br/>
32+
Base head:<span t-esc="commit_link.base_commit_id.name"/><br/>
33+
Merge base:<span t-esc="commit_link.merge_base_commit_id.name"/><br/>
34+
</p>
35+
</div>
36+
<div t-att-id="collapse" class="collapsed show" style="background-color:#223;color:CCC;padding:10px;">
37+
<t t-set="diff_command" t-value="str(commit_link.merge_base_commit_id.name) +'..'+commit.name"/>
38+
<i> &gt; git -C <t t-esc="commit.repo_id.name"/> show <t t-esc="diff_command"/> </i>
39+
<t t-set="diff" t-value="diff_by_commit_link_ids.get(int(commit_link.id),'')"/>
40+
<t t-set="commits" t-value="diff.split('\ncommit ')"/>
41+
<div>
42+
<t t-foreach="commits" t-as="commit_desc">
43+
<t t-set="commit_name" t-value="commit_desc.split('\n', 1)[0]"/>
44+
<t t-set="commit_desc" t-value="'commit ' + commit_desc"/>
45+
<!--t t-set="pr" t-value="commit_desc.split(commit.repo_id.main_remote_id.short_name+'#')[1].split('\n')[0] if commit.repo_id.main_remote_id.short_name+'#' in commit_desc else None"/-->
46+
<t t-set="url" t-value="'https://github.com/%s/commit/%s' % (commit.repo_id.main_remote_id.short_name, commit_name)"/>
47+
<a t-att-href="url" t-att-title="commit_name" target="_blank">
48+
<div style="border-bottom:25px solid #ccc;">
49+
<t t-foreach="commit_desc.split('\n')" t-as="line">
50+
<t t-set="color" t-value="'#DDD'"/>
51+
<t t-set="color" t-value="'#faa'" t-if="line.startswith('-')"/>
52+
<t t-set="color" t-value="'#afa'" t-if="line.startswith('+')"/>
53+
<t t-if="line_first">
54+
<div t-esc="line" class="sticky-top bg-dark" t-attf-style="margin-right: 50%; font-family:SFMono-Regular, Menlo, Monaco, Consolas,monospace;white-space-collapse: preserve;color:{{color}}"/>
55+
</t>
56+
<t t-else="">
57+
<div t-esc="line" t-attf-style="font-family:SFMono-Regular, Menlo, Monaco, Consolas,monospace;white-space-collapse: preserve;color:{{color}}"/>
58+
</t>
59+
</t>
60+
</div>
61+
</a>
62+
</t>
63+
</div>
64+
</div>
65+
</t>
66+
</t>
67+
</template>
68+
</data>
69+
</odoo>

0 commit comments

Comments
 (0)