Skip to content

Commit 275e658

Browse files
committed
api.views: update pr description on landing trigger (bug 2031664)
1 parent c194b3e commit 275e658

3 files changed

Lines changed: 56 additions & 28 deletions

File tree

src/lando/api/views.py

Lines changed: 51 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,42 @@ def generate_warnings_and_blockers(
8989
return {"warnings": warnings, "blockers": blockers}
9090

9191

92+
def generate_enhanced_pr_description(
93+
pull_request: PullRequest,
94+
target_repo: Repo,
95+
request: WSGIRequest,
96+
template: str = "pr_description.md",
97+
) -> str:
98+
context = {}
99+
context.update(generate_warnings_and_blockers(target_repo, pull_request, request))
100+
101+
context["landing_status"] = str(
102+
get_pull_request_last_landing_job_status(target_repo.name, pull_request.number)
103+
).lower()
104+
105+
path = reverse(
106+
"pull-request",
107+
kwargs={
108+
"repo_name": target_repo.name,
109+
"number": pull_request.number,
110+
},
111+
)
112+
113+
context["lando_url"] = f"{settings.SITE_URL}{path}"
114+
context["special_delimiter"] = SPECIAL_DELIMITER
115+
bugs = parse_bugs(pull_request.title)
116+
context["bugs"] = []
117+
118+
for bug in bugs:
119+
context["bugs"].append((bug, f"{settings.BUGZILLA_URL}/{bug}"))
120+
121+
context["title"] = pull_request.title
122+
context["body"] = pull_request.parsed_body
123+
124+
rendered = render_to_string(template, context)
125+
return rendered
126+
127+
92128
@method_decorator(csrf_exempt, name="dispatch")
93129
class LegacyDiffWarningView(View):
94130
"""
@@ -223,10 +259,10 @@ def get(
223259
self, request: WSGIRequest, repo_name: int, pull_number: int
224260
) -> JsonResponse:
225261
"""Return the status of a pull request based on landing job counts."""
226-
status = str(
262+
landing_status = str(
227263
get_pull_request_last_landing_job_status(repo_name, pull_number)
228264
).lower()
229-
return JsonResponse({"status": status}, status=200)
265+
return JsonResponse({"status": landing_status}, status=200)
230266

231267
@method_decorator(require_authenticated_user)
232268
def post(
@@ -292,6 +328,14 @@ class Form(forms.Form):
292328
job.status = JobStatus.SUBMITTED
293329
job.save()
294330

331+
description = generate_enhanced_pr_description(
332+
self.pull_request,
333+
self.target_repo,
334+
request,
335+
template="pr_description_landing.md",
336+
)
337+
self.client.update_pull_request_body(pull_number, description)
338+
295339
return JsonResponse({"id": job.id}, status=201)
296340

297341

@@ -368,30 +412,10 @@ def get(
368412
if not request.user.has_perm("main.can_change_landing_job"):
369413
raise PermissionError()
370414

371-
context = {}
372-
context.update(
373-
generate_warnings_and_blockers(self.target_repo, self.pull_request, request)
415+
description = generate_enhanced_pr_description(
416+
self.pull_request, self.target_repo, request
374417
)
375-
376-
path = reverse(
377-
"pull-request",
378-
kwargs={
379-
"repo_name": self.target_repo.name,
380-
"number": self.pull_request.number,
381-
},
418+
self.client.update_pull_request_body(pull_number, description)
419+
return JsonResponse(
420+
{"status": f"Pull request {pull_number} description updated."}
382421
)
383-
384-
context["lando_url"] = f"{settings.SITE_URL}{path}"
385-
context["special_delimiter"] = SPECIAL_DELIMITER
386-
bugs = parse_bugs(self.pull_request.title)
387-
context["bugs"] = []
388-
389-
for bug in bugs:
390-
context["bugs"].append((bug, f"{settings.BUGZILLA_URL}/{bug}"))
391-
392-
context["title"] = self.pull_request.title
393-
context["body"] = self.pull_request.parsed_body
394-
395-
rendered = render_to_string("pr_description.md", context)
396-
self.client.update_pull_request_body(pull_number, rendered)
397-
return JsonResponse({"context": context, "md": rendered})

src/lando/ui/jinja2/pr_description.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
{% endfor %}
1212
{% endmacro %}
1313

14-
{% block upper %}
1514
Lando: [link]({{ lando_url }})
1615
{% if bugs %}Bugzilla: {% for bug in bugs %}[bug {{ bug.0 }}]({{ bug.1 }}){% endfor %}{% endif %}
1716

17+
{% block upper %}
1818
{% if not warnings and not blockers %}
1919
:white_check_mark: All Lando checks passed
2020
{% endif %}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{% extends "pr_description.md" %}
2+
{% block upper %}
3+
**Landing request {{ landing_status }}**
4+
{% endblock %}

0 commit comments

Comments
 (0)