Skip to content

Commit 823e023

Browse files
committed
ui: show link back to lando PR view from jobs and error breakdowns (bug 2002161)
* ui: show link back to lando PR view from jobs * ui: show correct link back to lando PR view from error breakdowns (bug 2002161) * jinja: add pull_request_link jinja function (bug 2002161) Pull request: #769
1 parent 82cb5d6 commit 823e023

File tree

6 files changed

+45
-30
lines changed

6 files changed

+45
-30
lines changed

src/lando/jinja.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import logging
22
import re
33
import urllib.parse
4-
from typing import Optional
54

65
from compressor.contrib.jinja2ext import CompressorExtension
76
from django.conf import settings
@@ -13,6 +12,7 @@
1312
from markupsafe import Markup
1413

1514
from lando.main.models import JobStatus, LandingJob, Repo, UpliftJob
15+
from lando.main.models.revision import Revision
1616
from lando.main.scm import SCM_TYPE_GIT
1717
from lando.treestatus.models import (
1818
ReasonCategory,
@@ -255,13 +255,13 @@ def linkify_bug_numbers(text: str) -> str:
255255
return re.sub(search, replace, str(text), flags=re.IGNORECASE)
256256

257257

258-
def linkify_revision_urls(text: str) -> str:
258+
def linkify_phabricator_revision_urls(text: str) -> str:
259259
search = r"(?=\b)(" + re.escape(settings.PHABRICATOR_URL) + r"/D\d+)(?=\b)"
260260
replace = r'<a href="\g<1>">\g<1></a>'
261261
return re.sub(search, replace, str(text), flags=re.IGNORECASE)
262262

263263

264-
def linkify_revision_ids(text: str) -> str:
264+
def linkify_phabricator_revision_ids(text: str) -> str:
265265
"""Linkify revision IDs to proper Phabricator URLs."""
266266
search = r"\b(D\d+)\b"
267267
replace = (
@@ -317,7 +317,11 @@ def bug_url(text: str) -> str:
317317
)
318318

319319

320-
def revision_url(revision_id: int | str, diff_id: Optional[str] = None) -> str:
320+
def pull_request_url(repo: Repo, revision: Revision) -> str:
321+
return f"{repo.normalized_url}/pull/{revision.pull_number}"
322+
323+
324+
def phabricator_revision_url(revision_id: int | str, diff_id: str | None = None) -> str:
321325
if isinstance(revision_id, int):
322326
path = f"D{revision_id}"
323327
elif isinstance(revision_id, str) and not revision_id.startswith("D"):
@@ -438,6 +442,7 @@ def environment(**options): # noqa: ANN201
438442
"config": settings,
439443
"get_messages": messages.get_messages,
440444
"graph_height": graph_height,
445+
"pull_request_url": pull_request_url,
441446
"treeherder_link": treeherder_link,
442447
"new_settings_form": UserSettingsForm,
443448
"static_url": settings.STATIC_URL,
@@ -456,8 +461,8 @@ def environment(**options): # noqa: ANN201
456461
"graph_x_pos": graph_x_pos,
457462
"linkify_bug_numbers": linkify_bug_numbers,
458463
"linkify_faq": linkify_faq,
459-
"linkify_revision_ids": linkify_revision_ids,
460-
"linkify_revision_urls": linkify_revision_urls,
464+
"linkify_phabricator_revision_ids": linkify_phabricator_revision_ids,
465+
"linkify_phabricator_revision_urls": linkify_phabricator_revision_urls,
461466
"linkify_sec_bug_docs": linkify_sec_bug_docs,
462467
"linkify_transplant_details": linkify_transplant_details,
463468
"message_type_to_notification_class": message_type_to_notification_class,
@@ -467,7 +472,7 @@ def environment(**options): # noqa: ANN201
467472
"reviewer_to_action_text": reviewer_to_action_text,
468473
"reviewer_to_status_badge_class": reviewer_to_status_badge_class,
469474
"revision_status_to_badge_class": revision_status_to_badge_class,
470-
"revision_url": revision_url,
475+
"phabricator_revision_url": phabricator_revision_url,
471476
"static": static,
472477
"tostatusbadgeclass": tostatusbadgeclass,
473478
"tostatusbadgename": tostatusbadgename,

src/lando/ui/jinja2/partials/error-breakdown.html

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@
77
{% set tree = job.target_repo.short_name|default("Repo " + job.target_repo.name) %}
88
{% set rejects_paths = job.error_breakdown.rejects_paths %}
99
<p>
10-
While applying <a href="{{ job.error_breakdown.revision_id|revision_url() }}">revision D{{
11-
job.error_breakdown.revision_id }}</a> to <code>{{ tree }}</code>, the following files had
12-
conflicts:
10+
{% if job.is_pull_request_job %}
11+
{% set top_revision = job.revisions[0] %}
12+
While applying <a href="{{ pull_request_url(job.target_repo, top_revision) }}">pull request #{{ top_revision.pull_number }}</a> to
13+
<code>{{ tree }}</code>, the following files had conflicts:
14+
{% else %}
15+
While applying <a href="{{ job.error_breakdown.revision_id|phabricator_revision_url() }}">revision D{{
16+
job.error_breakdown.revision_id }}</a> to <code>{{ tree }}</code>, the following files had
17+
conflicts:
18+
{% endif %}
1319
</p>
1420
<p>
1521
(Hint: try rebasing your changes on the latest commits from <code>{{ tree }}</code> and re-submitting.)

src/lando/ui/jinja2/partials/job.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
<strong>Landing Job:</strong>
1414
<a href="{{ url('jobs-page', args=[job.id]) }}">{{ job.id }}</a>
1515
</p>
16+
{% elif has_revisions and job.is_pull_request_job %}
17+
{% set top_revision = job.revisions[0] %}
18+
<p>
19+
<strong>Pull request:</strong>
20+
<a href="{{ url('pull-request', args=[job.target_repo.name, top_revision.pull_number]) }}">{{ job.target_repo.name }}#{{ top_revision.pull_number }}</a>
21+
</p>
1622
{% elif has_revisions %}
1723
{% set top_revision = job.revisions[0] %}
1824
{% if top_revision.revision_id %}
@@ -27,7 +33,7 @@
2733
<strong>Revisions:</strong>
2834
{% for i in job.serialized_landing_path -%}
2935
{{- "" if loop.first else " ← " -}}
30-
<a href="{{ i['revision_id']|revision_url(diff_id=i['diff_id']) }}">
36+
<a href="{{ i['revision_id']|phabricator_revision_url(diff_id=i['diff_id']) }}">
3137
{{ i['revision_id'] }}
3238
{% if i['diff_id'] %}diff {{ i['diff_id'] }}{% endif %}
3339
</a>

src/lando/ui/jinja2/stack/partials/landing-preview.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ <h3 class="StackPage-landingPreview-sectionLabel">Commits:</h3>
4949
</div>
5050
<div class="StackPage-landingPreview-displayMessagePanel">
5151
<pre class="StackPage-landingPreview-commitMessage">{{
52-
revision['commit_message']|escape_html|linkify_bug_numbers|linkify_revision_urls|safe
52+
revision['commit_message']|escape_html|linkify_bug_numbers|linkify_phabricator_revision_urls|safe
5353
}}</pre>
5454
<div class="StackPage-landingPreview-seeMore"></div>
5555
</div>
@@ -87,8 +87,8 @@ <h3 class="StackPage-landingPreview-sectionLabel">Warnings:</h3>
8787
<li class="StackPage-landingPreview-warning">
8888
<label>
8989
<input type="checkbox" name="warnings[]" value="1" />
90-
{{ dw.message|escape_html|linkify_bug_numbers|linkify_revision_urls|linkify_faq|linkify_sec_bug_docs|safe }}
91-
[{{ w.revision_id | linkify_revision_ids | safe }}]
90+
{{ dw.message|escape_html|linkify_bug_numbers|linkify_phabricator_revision_urls|linkify_faq|linkify_sec_bug_docs|safe }}
91+
[{{ w.revision_id | linkify_phabricator_revision_ids | safe }}]
9292
</label>
9393
</li>
9494
{% endfor %}
@@ -97,12 +97,12 @@ <h3 class="StackPage-landingPreview-sectionLabel">Warnings:</h3>
9797
<li class="StackPage-landingPreview-warning">
9898
<label>
9999
<input type="checkbox" name="warnings[]" value="1" />
100-
{{ warning['display']|escape_html|linkify_bug_numbers|linkify_revision_urls|linkify_faq|linkify_sec_bug_docs|safe }}
100+
{{ warning['display']|escape_html|linkify_bug_numbers|linkify_phabricator_revision_urls|linkify_faq|linkify_sec_bug_docs|safe }}
101101
[
102102
{% for instance in warning['instances'] %}
103103
{{
104104
", " if not loop.first else ""
105-
}}{{ instance['revision_id'] | linkify_revision_ids | safe }}
105+
}}{{ instance['revision_id'] | linkify_phabricator_revision_ids | safe }}
106106
{% endfor %}
107107
]
108108
</label>

src/lando/ui/pull_requests.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ def get(
5353
pull_request = client.build_pull_request(number)
5454
except HTTPError as e:
5555
if e.response.status_code == 404:
56-
raise Http404(
57-
f"Pull request {repo_name}#{number} doesn't exist."
58-
) from e
56+
raise Http404(f"Pull request {repo_name}#{number} doesn't exist") from e
5957
raise e
6058

6159
landing_jobs = get_jobs_for_pull(target_repo, number)

src/lando/ui/tests/test_template_helpers.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
build_manual_uplift_instructions,
99
linkify_bug_numbers,
1010
linkify_faq,
11-
linkify_revision_ids,
12-
linkify_revision_urls,
11+
linkify_phabricator_revision_ids,
12+
linkify_phabricator_revision_urls,
1313
linkify_sec_bug_docs,
1414
linkify_transplant_details,
15+
phabricator_revision_url,
1516
repo_branch_url,
1617
repo_path,
17-
revision_url,
1818
)
1919
from lando.main.models import SCM_TYPE_GIT, SCM_TYPE_HG, JobStatus, LandingJob, Repo
2020
from lando.main.models.revision import Revision
@@ -122,8 +122,8 @@ def test_linkify_bug_numbers(input_text, output_text):
122122
),
123123
],
124124
)
125-
def test_linkify_revision_urls(input_text, output_text):
126-
assert output_text == linkify_revision_urls(input_text)
125+
def test_linkify_phabricator_revision_urls(input_text, output_text):
126+
assert output_text == linkify_phabricator_revision_urls(input_text)
127127

128128

129129
@pytest.mark.parametrize(
@@ -150,8 +150,8 @@ def test_linkify_revision_urls(input_text, output_text):
150150
),
151151
],
152152
)
153-
def test_linkify_revision_ids(input_text, output_text):
154-
assert output_text == linkify_revision_ids(input_text)
153+
def test_linkify_phabricator_revision_ids(input_text, output_text):
154+
assert output_text == linkify_phabricator_revision_ids(input_text)
155155

156156

157157
@pytest.mark.django_db
@@ -280,29 +280,29 @@ def test_repo_branch_url(repo, path):
280280
def test_revision_url__integer():
281281
revision_id = 1234
282282
expected_result = "http://phabricator.test/D1234"
283-
actual_result = revision_url(revision_id)
283+
actual_result = phabricator_revision_url(revision_id)
284284
assert expected_result == actual_result
285285

286286

287287
def test_revision_url__prepended_string():
288288
revision_id = "D1234"
289289
expected_result = "http://phabricator.test/D1234"
290-
actual_result = revision_url(revision_id)
290+
actual_result = phabricator_revision_url(revision_id)
291291
assert expected_result == actual_result
292292

293293

294294
def test_revision_url__string():
295295
revision_id = "1234"
296296
expected_result = "http://phabricator.test/D1234"
297-
actual_result = revision_url(revision_id)
297+
actual_result = phabricator_revision_url(revision_id)
298298
assert expected_result == actual_result
299299

300300

301301
def test_revision_url__general_case_with_diff():
302302
revision_id = 123
303303
diff_id = 456
304304
expected_result = "http://phabricator.test/D123?id=456"
305-
actual_result = revision_url(revision_id, diff_id)
305+
actual_result = phabricator_revision_url(revision_id, diff_id)
306306
assert expected_result == actual_result
307307

308308

0 commit comments

Comments
 (0)