Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions app/services/github_notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class GitHubNotifier:
def __init__(self, flat_manager_client: FlatManagerClient | None = None):
self.flat_manager = flat_manager_client

def _get_flathub_build_url(self, pipeline: Pipeline) -> str:
return f"https://flathub.org/en/builds/{pipeline.id}"

async def notify_build_status(
self,
pipeline: Pipeline,
Expand Down Expand Up @@ -212,15 +215,14 @@ async def notify_pr_build_complete(
arch_info_comment = f"\n\n*Built for {arch_text} architecture{plural}.*"

if status == "committed":
build_url = self._get_flathub_build_url(pipeline)
if pipeline.build_id and self.flat_manager:
download_url = self.flat_manager.get_flatpakref_url(
pipeline.build_id, pipeline.app_id
)
comment = f"✅ [Test build succeeded]({log_url}). To test this build, install it from the testing repository:\n\n```\nflatpak install --user {download_url}\n```{arch_info_comment}"
comment = f"✅ [Test build succeeded]({log_url}). [Build page]({build_url}). To test this build, install it from the testing repository:\n\n```\nflatpak install --user {download_url}\n```{arch_info_comment}"
else:
comment = (
f"✅ [Test build succeeded]({log_url}).{arch_info_comment}"
)
comment = f"✅ [Test build succeeded]({log_url}). [Build page]({build_url}).{arch_info_comment}"
if linter_warnings:
warnings_text = "\n".join(f"- {w.strip()}" for w in linter_warnings)
comment += (
Expand All @@ -229,9 +231,9 @@ async def notify_pr_build_complete(
f"{warnings_text}"
)
elif status == "failure":
comment = f"❌ [Test build]({log_url}) failed.\n\n{footnote}"
comment = f"❌ [Test build]({log_url}) failed. [Build page]({self._get_flathub_build_url(pipeline)}).\n\n{footnote}"
elif status == "cancelled":
comment = f"❌ [Test build]({log_url}) was cancelled.\n\n{footnote}"
comment = f"❌ [Test build]({log_url}) was cancelled. [Build page]({self._get_flathub_build_url(pipeline)}).\n\n{footnote}"
elif status == "commit_failure":
status = "failure"
comment = (
Expand Down
17 changes: 14 additions & 3 deletions tests/test_github_notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,10 @@ async def test_notify_pr_build_complete_failure(
):
await github_notifier.notify_pr_build_complete(mock_pipeline, "failure")

build_url = f"https://flathub.org/en/builds/{mock_pipeline.id}"
expected_comment = (
"❌ [Test build](https://example.com/logs/123) failed.\n\n"
"❌ [Test build](https://example.com/logs/123) failed. "
f"[Build page]({build_url}).\n\n"
"<details><summary>Help</summary>\n\n"
"- <code>bot, build</code> - Restart the test build\n"
)
Expand Down Expand Up @@ -325,8 +327,10 @@ async def test_notify_pr_build_complete_committed_with_download(
):
await github_notifier.notify_pr_build_complete(mock_pipeline, "committed")

build_url = f"https://flathub.org/en/builds/{mock_pipeline.id}"
expected_comment = (
"✅ [Test build succeeded](https://example.com/logs/123). "
f"[Build page]({build_url}). "
"To test this build, install it from the testing repository:\n\n"
"```\nflatpak install --user "
"https://dl.flathub.org/build-repo/123/org.test.App.flatpakref\n```"
Expand Down Expand Up @@ -356,10 +360,15 @@ async def test_notify_pr_build_complete_committed_no_build_id(
):
await github_notifier.notify_pr_build_complete(mock_pipeline, "committed")

build_url = f"https://flathub.org/en/builds/{mock_pipeline.id}"
mock_comment.assert_called_once_with(
git_repo="flathub/org.test.App",
pr_number=42,
comment="✅ [Test build succeeded](https://example.com/logs/123).\n\n*Built for x86_64 architecture.*",
comment=(
"✅ [Test build succeeded](https://example.com/logs/123). "
f"[Build page]({build_url}).\n\n"
"*Built for x86_64 architecture.*"
),
)


Expand All @@ -374,11 +383,13 @@ async def test_notify_pr_build_complete_cancelled(github_notifier, mock_pipeline
):
await github_notifier.notify_pr_build_complete(mock_pipeline, "cancelled")

build_url = f"https://flathub.org/en/builds/{mock_pipeline.id}"
mock_comment.assert_called_once_with(
git_repo="flathub/org.test.App",
pr_number=42,
comment=(
"❌ [Test build](https://example.com/logs/123) was cancelled.\n\n"
"❌ [Test build](https://example.com/logs/123) was cancelled. "
f"[Build page]({build_url}).\n\n"
"<details><summary>Help</summary>\n\n"
"- <code>bot, build</code> - Restart the test build\n"
"- <code>bot, ping admins</code> - Contact Flathub admins\n"
Expand Down
Loading