Skip to content

Commit

Permalink
Link dashboard when reporting Koji and Bodhi errors
Browse files Browse the repository at this point in the history
Related to #2426

This makes it consistent with behaviour for release syncing.
  • Loading branch information
lbarcziova committed Nov 28, 2024
1 parent 6fb1e2f commit b7dc4a1
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 15 deletions.
4 changes: 4 additions & 0 deletions packit_service/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
"</tr>"
)

MSG_DOWNSTREAM_JOB_ERROR_ROW = (
'<tr><td><code>{branch}</code></td><td>See <a href="{url}">{url}</a></td></tr>\n'
)

MSG_GET_IN_TOUCH = f"\n\n---\n\n*Get in [touch with us]({CONTACTS_URL}) if you need some help.*"

MSG_RETRIGGER = (
Expand Down
4 changes: 4 additions & 0 deletions packit_service/service/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,7 @@ def get_pull_from_upstream_info_url(id_: int) -> str:

def get_openscanhub_info_url(id_: int) -> str:
return _get_url_for_dashboard_results("openscanhub", id_)


def get_bodhi_update_info_url(id_: int) -> str:
return _get_url_for_dashboard_results("bodhi", id_)
10 changes: 6 additions & 4 deletions packit_service/worker/handlers/bodhi.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from packit_service.constants import (
DEFAULT_RETRY_BACKOFF,
MSG_DOWNSTREAM_JOB_ERROR_HEADER,
MSG_DOWNSTREAM_JOB_ERROR_ROW,
MSG_GET_IN_TOUCH,
MSG_RETRIGGER,
)
Expand All @@ -28,6 +29,7 @@
KojiBuildTargetModel,
PipelineModel,
)
from packit_service.service.urls import get_bodhi_update_info_url
from packit_service.worker.checker.abstract import Checker
from packit_service.worker.checker.bodhi import (
HasIssueCommenterRetriggeringPermissions,
Expand Down Expand Up @@ -187,7 +189,7 @@ def run(self) -> TaskResults:
)

error = str(ex)
errors[target_model.target] = error
errors[target_model.target] = get_bodhi_update_info_url(target_model.id)

target_model.set_status("error")
target_model.set_data({"error": error})
Expand All @@ -198,7 +200,7 @@ def run(self) -> TaskResults:
raise

error = f"Internal error, please contact us: {ex}"
errors[target_model.target] = error
errors[target_model.target] = get_bodhi_update_info_url(target_model.id)

target_model.set_status("error")
target_model.set_data({"error": error})
Expand Down Expand Up @@ -285,8 +287,8 @@ def report_in_issue_repository(self, errors: dict[str, str]) -> None:
object="Bodhi update",
dist_git_url=self.packit_api.dg.local_project.git_url,
)
for branch, ex in errors.items():
body += "<tr>" f"<td><code>{branch}</code></td>" f"<td><pre>{ex}</pre></td>" "</tr>\n"
for branch, url in errors.items():
body += MSG_DOWNSTREAM_JOB_ERROR_ROW.format(branch=branch, url=url)
body += "</table>\n"

msg_retrigger = MSG_RETRIGGER.format(
Expand Down
14 changes: 6 additions & 8 deletions packit_service/worker/handlers/distgit.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
CONTACTS_URL,
DEFAULT_RETRY_BACKOFF,
MSG_DOWNSTREAM_JOB_ERROR_HEADER,
MSG_DOWNSTREAM_JOB_ERROR_ROW,
MSG_GET_IN_TOUCH,
MSG_RETRIGGER,
MSG_RETRIGGER_DISTGIT,
Expand Down Expand Up @@ -518,11 +519,8 @@ def run(self) -> TaskResults:
branch_errors = ""
for model in sorted(models_with_errors, key=lambda model: model.branch):
dashboard_url = self.get_dashboard_url(model.id)
branch_errors += (
"<tr>"
f"<td><code>{model.branch}</code></td>"
f'<td>See <a href="{dashboard_url}">{dashboard_url}</a></td>'
"</tr>\n"
branch_errors += MSG_DOWNSTREAM_JOB_ERROR_ROW.format(
branch=model.branch, url=dashboard_url
)
branch_errors += "</table>\n"

Expand Down Expand Up @@ -1072,7 +1070,7 @@ def run(self) -> TaskResults:
error += f"\n{ex.stderr_output}"
koji_build_model.set_build_submission_stdout(ex.stdout_output)

errors[branch] = error
errors[branch] = get_koji_build_info_url(koji_build_model.id)
koji_build_model.set_data({"error": error})
koji_build_model.set_status("error")
continue
Expand All @@ -1091,8 +1089,8 @@ def report_in_issue_repository(self, errors: dict[str, str]) -> None:
object="Koji build",
dist_git_url=self.packit_api.dg.local_project.git_url,
)
for branch, ex in errors.items():
body += "<tr>" f"<td><code>{branch}</code></td>" f"<td><pre>{ex}</pre></td>" "</tr>\n"
for branch, url in errors.items():
body += MSG_DOWNSTREAM_JOB_ERROR_ROW.format(branch=branch, url=url)
body += "</table>\n"

msg_retrigger = MSG_RETRIGGER.format(
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/test_bodhi_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ def test_bodhi_update_for_unknown_koji_build_failed_issue_created(
group_model = flexmock(
grouped_targets=[
flexmock(
id=12,
target="rawhide",
koji_nvrs="packit-0.43.0-1.fc36",
sidetag=None,
Expand Down Expand Up @@ -447,6 +448,7 @@ def test_bodhi_update_for_unknown_koji_build_failed_issue_comment(
group_model = flexmock(
grouped_targets=[
flexmock(
id=12,
target="rawhide",
koji_nvrs="packit-0.43.0-1.fc36",
sidetag=None,
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/test_dg_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ def test_downstream_koji_build_failure_issue_created():
nvr = "package-1.2.3-1.fc40"

koji_build = flexmock(
id=12,
target="main",
status="queued",
sidetag=None,
Expand Down Expand Up @@ -620,6 +621,7 @@ def test_downstream_koji_build_failure_issue_comment():
nvr = "package-1.2.3-1.fc40"

koji_build = flexmock(
id=12,
target="main",
status="queued",
sidetag=None,
Expand Down
6 changes: 5 additions & 1 deletion tests/integration/test_issue_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ def mock_repository_issue_retriggering():
nvr_f37 = "package-1.2.3-1.fc37"

koji_build_f37 = flexmock(
id=12,
target="f37",
status="queued",
sidetag=None,
Expand All @@ -376,6 +377,7 @@ def mock_repository_issue_retriggering():
nvr_f38 = "package-1.2.3-1.fc38"

koji_build_f38 = flexmock(
id=13,
target="f38",
status="queued",
sidetag=None,
Expand Down Expand Up @@ -622,7 +624,9 @@ def test_issue_comment_retrigger_koji_build_error_msg(
"Packit failed on creating Koji build in dist-git (an url):"
"\n\n<table><tr>"
"<th>dist-git branch</th><th>error</th></tr>"
"<tr><td><code>f37</code></td><td><pre>error abc</pre></td></tr>\n</table>\n\n"
"<tr><td><code>f37</code></td>"
'<td>See <a href="https://localhost/jobs/koji/12">https://localhost/jobs/koji/12</a></td>'
"</tr>\n</table>\n\n"
"Fedora Koji build was re-triggered by comment in issue 1.\n\n"
"You can retrigger the build by adding a comment "
"(`/packit koji-build`) into this issue.\n\n"
Expand Down
5 changes: 4 additions & 1 deletion tests/integration/test_koji_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ def test_koji_build_error_msg(distgit_push_packit):
nvr = "package-1.2.3-1.fc40"

koji_build = flexmock(
id=12,
target="f36",
status="queued",
sidetag=None,
Expand Down Expand Up @@ -211,7 +212,9 @@ def test_koji_build_error_msg(distgit_push_packit):
"<th>dist-git branch</th>"
"<th>error</th>"
"</tr>"
"<tr><td><code>f36</code></td><td><pre>error abc</pre></td></tr>\n"
"<tr><td><code>f36</code></td>"
'<td>See <a href="https://localhost/jobs/koji/12">https://localhost/jobs/koji/12</a></td>'
"</tr>\n"
"</table>\n\n"
"Fedora Koji build was triggered by push "
"with sha ad0c308af91da45cf40b253cd82f07f63ea9cbbf."
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/test_bodhi_update_error_msgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ def test_pull_request_retrigger_bodhi_update_with_koji_data(
"in dist-git (an url):\n\n"
"<table>"
"<tr><th>dist-git branch</th><th>error</th></tr>"
"<tr><td><code>f36</code></td><td><pre>error abc</pre></td></tr>\n"
"<tr><td><code>f36</code></td>"
'<td>See <a href="/jobs/bodhi/12">/jobs/bodhi/12</a></td></tr>\n'
"</table>\n\n"
"Fedora Bodhi update was re-triggered by comment in dist-git PR with id 123.\n\n"
"You can retrigger the update by adding a comment (`/packit create-update`) "
Expand Down Expand Up @@ -122,6 +123,7 @@ def test_pull_request_retrigger_bodhi_update_with_koji_data(
flexmock(
grouped_targets=[
flexmock(
id=12,
target="f36",
koji_nvrs="a_package_1.f36",
sidetag=None,
Expand Down

0 comments on commit b7dc4a1

Please sign in to comment.