Skip to content

Commit c875c73

Browse files
committed
api.views: update pr description on landing trigger (bug 2031664)
1 parent 6b4a5a7 commit c875c73

3 files changed

Lines changed: 50 additions & 26 deletions

File tree

src/lando/api/views.py

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,38 @@ def generate_warnings_and_blockers(
9090
return {"warnings": warnings, "blockers": blockers}
9191

9292

93+
def generate_enhanced_pr_description(
94+
pull_request: PullRequest,
95+
target_repo: Repo,
96+
request: WSGIRequest,
97+
template: str = "pr_description.md",
98+
) -> str:
99+
context = {}
100+
context.update(generate_warnings_and_blockers(target_repo, pull_request, request))
101+
102+
path = reverse(
103+
"pull-request",
104+
kwargs={
105+
"repo_name": target_repo.name,
106+
"number": pull_request.number,
107+
},
108+
)
109+
110+
context["lando_url"] = f"{settings.SITE_URL}{path}"
111+
context["special_delimiter"] = SPECIAL_DELIMITER
112+
bugs = parse_bugs(pull_request.title)
113+
context["bugs"] = []
114+
115+
for bug in bugs:
116+
context["bugs"].append((bug, f"{settings.BUGZILLA_URL}/{bug}"))
117+
118+
context["title"] = pull_request.title
119+
context["body"] = pull_request.parsed_body
120+
121+
rendered = render_to_string(template, context)
122+
return rendered
123+
124+
93125
@method_decorator(csrf_exempt, name="dispatch")
94126
class LegacyDiffWarningView(View):
95127
"""
@@ -309,6 +341,14 @@ class Form(forms.Form):
309341
job.status = JobStatus.SUBMITTED
310342
job.save()
311343

344+
description = generate_enhanced_pr_description(
345+
self.pull_request,
346+
self.target_repo,
347+
request,
348+
template="pr_description_landing.md",
349+
)
350+
self.client.update_pull_request_body(pull_number, description)
351+
312352
return JsonResponse({"id": job.id}, status=201)
313353

314354

@@ -385,30 +425,10 @@ def post(
385425
if not request.user.has_perm("main.can_change_landing_job"):
386426
raise PermissionError()
387427

388-
context = {}
389-
context.update(
390-
generate_warnings_and_blockers(self.target_repo, self.pull_request, request)
428+
description = generate_enhanced_pr_description(
429+
self.pull_request, self.target_repo, request
391430
)
392-
393-
path = reverse(
394-
"pull-request",
395-
kwargs={
396-
"repo_name": self.target_repo.name,
397-
"number": self.pull_request.number,
398-
},
431+
self.client.update_pull_request_body(pull_number, description)
432+
return JsonResponse(
433+
{"status": f"Pull request {pull_number} description updated."}
399434
)
400-
401-
context["lando_url"] = f"{settings.SITE_URL}{path}"
402-
context["special_delimiter"] = SPECIAL_DELIMITER
403-
bugs = parse_bugs(self.pull_request.title)
404-
context["bugs"] = []
405-
406-
for bug in bugs:
407-
context["bugs"].append((bug, f"{settings.BUGZILLA_URL}/{bug}"))
408-
409-
context["title"] = self.pull_request.title
410-
context["body"] = self.pull_request.parsed_body
411-
412-
rendered = render_to_string("pr_description.md", context)
413-
self.client.update_pull_request_body(pull_number, rendered)
414-
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
@@ -1,7 +1,7 @@
1-
{% block upper %}
21
Lando: [link]({{ lando_url }})
32
{% if bugs %}Bugzilla: {% for bug in bugs %}[bug {{ bug.0 }}]({{ bug.1 }}){% endfor %}{% endif %}
43

4+
{% block upper %}
55
{% if warnings %}
66
|Warnings|
77
|---------|
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 was requested.**
4+
{% endblock %}

0 commit comments

Comments
 (0)