Skip to content

Commit ac53729

Browse files
committed
pull_request: improve warnings and blockers UI (bug 2024930) r=sheehan,shtrom
- add icons beside warnings/blockers to make them more prominent - and check mark when there are no warnings/blockers - add spinners when loading warnings/blockers - other small html tweaks Pull request: #1070
1 parent 94f1939 commit ac53729

3 files changed

Lines changed: 38 additions & 31 deletions

File tree

src/lando/api/views.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from django.core.handlers.wsgi import WSGIRequest
99
from django.http import HttpRequest, JsonResponse
1010
from django.utils.decorators import method_decorator
11+
from django.utils.html import escape
1112
from django.views import View
1213
from django.views.decorators.csrf import csrf_exempt
1314

@@ -61,7 +62,10 @@ def _wrapper(self: View, request: WSGIRequest, *args, **kwargs) -> Callable:
6162

6263

6364
def generate_warnings_and_blockers(
64-
target_repo: Repo, pull_request: PullRequest, request: HttpRequest
65+
target_repo: Repo,
66+
pull_request: PullRequest,
67+
request: HttpRequest,
68+
do_escape: bool = True,
6569
) -> dict[str, list[str]]:
6670
"""Run checks on a pull request and return blockers and warnings."""
6771
# PullRequestPatchHelper.diff doesn't include binary changes.
@@ -79,6 +83,12 @@ def generate_warnings_and_blockers(
7983
blockers += pr_checks.run(pr_blockers, pull_request)
8084
pr_warnings = [chk.name() for chk in ALL_PULL_REQUEST_WARNINGS]
8185
warnings = pr_checks.run(pr_warnings, pull_request)
86+
87+
if do_escape:
88+
# Sanitize blockers and warnings as they may be rendered in a page.
89+
warnings = [escape(warning) for warning in warnings]
90+
blockers = [escape(blocker) for blocker in blockers]
91+
8292
return {"warnings": warnings, "blockers": blockers}
8393

8494

src/lando/static_src/legacy/js/components/Stack.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,22 +152,23 @@ $.fn.stack = function() {
152152

153153
var has_blockers = blockers.length !== 0;
154154
var has_warnings = warnings.length !== 0;
155+
var success_placeholder = `<li><span class="fa-li has-text-success"><i class="fa fa-check"></i></span>None found.</li>`;
155156

156157
if (!has_blockers) {
157-
$("#blockers").html("None found.");
158+
$("#blockers").html(success_placeholder);
158159
} else {
159160
$("#blockers").html("");
160161
for (var blocker of blockers) {
161-
$("#blockers").append(`<li>${blocker}</li>`);
162+
$("#blockers").append(`<li><span class="fa-li has-text-danger"><i class="fa fa-ban"></i></span>${blocker}</li>`);
162163
}
163164
}
164165

165166
if (!has_warnings) {
166-
$("#warnings").html("None found.");
167+
$("#warnings").html(success_placeholder);
167168
} else {
168169
$("#warnings").html("");
169170
for (var warning of warnings) {
170-
$("#warnings").append(`<li>${warning}</li>`);
171+
$("#warnings").append(`<li><span class="fa-li has-text-warning"><i class="fa fa-warning"></i></span>${warning}</li>`);
171172
}
172173
}
173174

src/lando/ui/jinja2/stack/pull_request.html

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,52 +15,48 @@ <h1>
1515
data-csrf-token="{{ csrf_token }}">Loading</button>
1616
</p>
1717
</p>
18-
<p class="acknowledge-warnings-section">
19-
<label class="checkbox">
20-
<input type="checkbox" id="acknowledge-warnings" autocomplete="off" />
21-
Acknowledge all warnings below to continue.
22-
</label>
23-
</p>
2418
<div class="StackPage-stack">
19+
<p class="acknowledge-warnings-section">
20+
<label class="checkbox">
21+
<input type="checkbox" id="acknowledge-warnings" autocomplete="off" />
22+
Acknowledge all warnings below to continue.
23+
</label>
24+
</p>
2525
<table>
2626
<tr>
2727
<th>Warnings</th>
2828
<td>
29-
<ul id="warnings">
29+
<ul id="warnings" class="fa-ul">
3030
<li>
31-
Checking...
32-
</li />
31+
<span class="fa-li"><i class="fa fa-spinner fa-pulse"></i></span>Checking...
32+
</li>
3333
</ul>
3434
</td>
3535
</tr>
3636
<tr>
3737
<th>Blockers</th>
3838
<td>
39-
<ul id="blockers">
39+
<ul id="blockers" class="fa-ul">
4040
<li>
41-
Checking...
42-
</li />
41+
<span class="fa-li"><i class="fa fa-spinner fa-pulse"></i></span>Checking...
42+
</li>
4343
</ul>
4444
</td>
4545
</tr>
4646
{% if is_try_compatible %}
4747
<tr>
4848
<th>Last try job</th>
4949
<td>
50-
<ul>
51-
<li>
52-
<button class="button is-link is-small is-info post-try-job"
53-
data-pull-number="{{ pull_request.number }}"
54-
data-repo-name="{{ target_repo.name }}"
55-
data-csrf-token="{{ csrf_token }}">Request a try push</button>
56-
{% if last_try_job %}
57-
{{ last_try_job }}
58-
{{ treeherder_link(last_try_job.landed_treeherder_revision, last_try_job.target_repo, "Treeherder") | safe }}
59-
{% else %}
60-
No try jobs found.
61-
{% endif %}
62-
</li />
63-
</ul>
50+
<button class="button is-link is-small is-info post-try-job"
51+
data-pull-number="{{ pull_request.number }}"
52+
data-repo-name="{{ target_repo.name }}"
53+
data-csrf-token="{{ csrf_token }}">Request a try push</button>
54+
{% if last_try_job %}
55+
{{ last_try_job }}
56+
{{ treeherder_link(last_try_job.landed_treeherder_revision, last_try_job.target_repo, "Treeherder") | safe }}
57+
{% else %}
58+
No try jobs found.
59+
{% endif %}
6460
</td>
6561
</tr>
6662
{% endif %}

0 commit comments

Comments
 (0)