Skip to content

Commit

Permalink
Don't comment about logs on just submitted sync PR
Browse files Browse the repository at this point in the history
  • Loading branch information
lbarcziova committed Jul 10, 2024
1 parent 99889c8 commit 3567b01
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 18 deletions.
18 changes: 16 additions & 2 deletions packit_service/worker/handlers/distgit.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,8 @@ def run_for_target(
model.set_logs(collect_packit_logs(buffer=buffer, handler=handler))

dashboard_url = self.get_dashboard_url(model.id)
downstream_pr.comment(
f"Logs and details of the syncing: [Packit dashboard]({dashboard_url})"
self.report_dashboard_url(
sync_release_pull_request, downstream_pr, dashboard_url
)
self.sync_release_helper.report_status_for_branch(
branch=branch,
Expand Down Expand Up @@ -497,6 +497,20 @@ def _report_errors_for_each_branch(self, message: str):
def get_resolved_bugs(self):
raise NotImplementedError("Use subclass.")

@staticmethod
def report_dashboard_url(
pr_model: SyncReleasePullRequestModel,
pr_object: PullRequest,
dashboard_url: str,
):
msg = f"Logs and details of the syncing: [Packit dashboard]({dashboard_url})"
# this is a retrigger
if len(pr_model.sync_release_targets) > 1:
pr_object.comment(msg)
else:
original_description = pr_object.description
pr_object.description = original_description + "\n---\n" + msg


class AbortSyncRelease(Exception):
"""Abort sync-release process"""
Expand Down
5 changes: 3 additions & 2 deletions tests/integration/test_issue_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,13 @@ def test_issue_comment_propose_downstream_handler(
job_type=SyncReleaseJobType.propose_downstream,
package_name="packit",
).and_return(propose_downstream_model, run_model).once()
sync_release_pr_model = flexmock(sync_release_targets=[flexmock(), flexmock()])
flexmock(SyncReleasePullRequestModel).should_receive("get_or_create").with_args(
pr_id=1,
namespace="downstream-namespace",
repo_name="downstream-repo",
project_url="https://src.fedoraproject.org/rpms/downstream-repo",
).and_return(object)
).and_return(sync_release_pr_model)
model = flexmock(status="queued", id=1234, branch="main")
flexmock(SyncReleaseTargetModel).should_receive("create").with_args(
status=SyncReleaseTargetStatus.queued, branch="main"
Expand All @@ -249,7 +250,7 @@ def test_issue_comment_propose_downstream_handler(
downstream_pr_url="https://xyz"
)
flexmock(model).should_receive("set_downstream_pr").with_args(
downstream_pr=object
downstream_pr=sync_release_pr_model
).once()
flexmock(model).should_receive("set_status").with_args(
status=SyncReleaseTargetStatus.submitted
Expand Down
9 changes: 7 additions & 2 deletions tests/integration/test_new_hotness_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def test_new_hotness_update(new_hotness_update, sync_release_model):
namespace="downstream-namespace",
repo_name="downstream-repo",
project_url="https://src.fedoraproject.org/rpms/downstream-repo",
).and_return(object)
).and_return(flexmock(sync_release_targets=[flexmock()]))

packit_yaml = (
"{'specfile_path': 'hello-world.spec', 'upstream_project_url': "
Expand Down Expand Up @@ -160,7 +160,12 @@ def test_new_hotness_update(new_hotness_update, sync_release_model):
.mock()
)
pr = (
flexmock(id=21, url="some_url", target_project=target_project)
flexmock(
id=21,
url="some_url",
target_project=target_project,
description="some-title",
)
.should_receive("comment")
.mock()
)
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/test_pr_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -2587,7 +2587,7 @@ def test_pull_from_upstream_retrigger_via_dist_git_pr_comment(pagure_pr_comment_
pagure_pr_comment_added["pullrequest"]["comments"][0][
"comment"
] = "/packit pull-from-upstream --with-pr-config --resolved-bugs rhbz#123,rhbz#124"

sync_release_pr_model = flexmock(sync_release_targets=[flexmock(), flexmock()])
model = flexmock(status="queued", id=1234, branch="main")
flexmock(SyncReleaseTargetModel).should_receive("create").with_args(
status=SyncReleaseTargetStatus.queued, branch="main"
Expand All @@ -2597,7 +2597,7 @@ def test_pull_from_upstream_retrigger_via_dist_git_pr_comment(pagure_pr_comment_
namespace="downstream-namespace",
repo_name="downstream-repo",
project_url="https://src.fedoraproject.org/rpms/downstream-repo",
).and_return(object)
).and_return(sync_release_pr_model)

packit_yaml = (
"{'specfile_path': 'hello-world.spec', 'upstream_project_url': "
Expand Down Expand Up @@ -2705,7 +2705,7 @@ def _get_project(url, *_, **__):
downstream_pr_url="some_url"
).once()
flexmock(model).should_receive("set_downstream_pr").with_args(
downstream_pr=object
downstream_pr=sync_release_pr_model
).once()
flexmock(model).should_receive("set_status").with_args(
status=SyncReleaseTargetStatus.submitted
Expand Down
23 changes: 16 additions & 7 deletions tests/integration/test_release_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ def fedora_branches():


@pytest.fixture
def propose_downstream_model():
def sync_release_pr_model():
return flexmock(sync_release_targets=[flexmock(), flexmock()])


@pytest.fixture
def propose_downstream_model(sync_release_pr_model):
db_project_object = flexmock(
id=12,
project_event_model_type=ProjectEventModelType.release,
Expand Down Expand Up @@ -89,7 +94,7 @@ def propose_downstream_model():
namespace="downstream-namespace",
repo_name="downstream-repo",
project_url="https://src.fedoraproject.org/rpms/downstream-repo",
).and_return(object)
).and_return(sync_release_pr_model)

flexmock(ProposeDownstreamJobHelper).should_receive(
"report_status_to_all"
Expand Down Expand Up @@ -141,7 +146,9 @@ def propose_downstream_target_models(fedora_branches):
yield models


def test_dist_git_push_release_handle(github_release_webhook, propose_downstream_model):
def test_dist_git_push_release_handle(
github_release_webhook, propose_downstream_model, sync_release_pr_model
):
model = flexmock(status="queued", id=1234, branch="main")
flexmock(SyncReleaseTargetModel).should_receive("create").with_args(
status=SyncReleaseTargetStatus.queued, branch="main"
Expand All @@ -151,7 +158,7 @@ def test_dist_git_push_release_handle(github_release_webhook, propose_downstream
namespace="downstream-namespace",
repo_name="downstream-repo",
project_url="https://src.fedoraproject.org/rpms/downstream-repo",
).and_return(object)
).and_return(sync_release_pr_model)

packit_yaml = (
"{'specfile_path': 'hello-world.spec', 'synced_files': []"
Expand Down Expand Up @@ -224,7 +231,7 @@ def test_dist_git_push_release_handle(github_release_webhook, propose_downstream
downstream_pr_url="some_url"
)
flexmock(model).should_receive("set_downstream_pr").with_args(
downstream_pr=object
downstream_pr=sync_release_pr_model
).once()
flexmock(model).should_receive("set_status").with_args(
status=SyncReleaseTargetStatus.submitted
Expand Down Expand Up @@ -278,6 +285,7 @@ def test_dist_git_push_release_handle_multiple_branches(
fedora_branches,
propose_downstream_model,
propose_downstream_target_models,
sync_release_pr_model,
):
packit_yaml = (
"{'specfile_path': 'hello-world.spec', 'synced_files': []"
Expand Down Expand Up @@ -323,7 +331,7 @@ def test_dist_git_push_release_handle_multiple_branches(
downstream_pr_url="some_url"
)
flexmock(model).should_receive("set_downstream_pr").with_args(
downstream_pr=object
downstream_pr=sync_release_pr_model
).once()
flexmock(model).should_receive("set_status").with_args(
status=SyncReleaseTargetStatus.submitted
Expand Down Expand Up @@ -414,6 +422,7 @@ def test_dist_git_push_release_handle_one_failed(
fedora_branches,
propose_downstream_model,
propose_downstream_target_models,
sync_release_pr_model,
):
packit_yaml = (
"{'specfile_path': 'hello-world.spec', 'synced_files': []"
Expand Down Expand Up @@ -478,7 +487,7 @@ def test_dist_git_push_release_handle_one_failed(
downstream_pr_url="some_url"
)
flexmock(model).should_receive("set_downstream_pr").with_args(
downstream_pr=object
downstream_pr=sync_release_pr_model
)
target_project = (
flexmock(namespace="downstream-namespace", repo="downstream-repo")
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/test_steve.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,18 @@ def test_process_message(event, private, enabled_private_namespaces, success):
flexmock(SyncReleaseTargetModel).should_receive("create").with_args(
status=SyncReleaseTargetStatus.queued, branch="main"
).and_return(model).times(1 if success else 0)
sync_release_pr_model = flexmock(sync_release_targets=[flexmock(), flexmock()])
flexmock(SyncReleasePullRequestModel).should_receive("get_or_create").with_args(
pr_id=21,
namespace="downstream-namespace",
repo_name="downstream-repo",
project_url="https://src.fedoraproject.org/rpms/downstream-repo",
).and_return(object).times(1 if success else 0)
).and_return(sync_release_pr_model).times(1 if success else 0)
flexmock(model).should_receive("set_downstream_pr_url").with_args(
downstream_pr_url="some_url"
).times(1 if success else 0)
flexmock(model).should_receive("set_downstream_pr").with_args(
downstream_pr=object
downstream_pr=sync_release_pr_model
).times(1 if success else 0)
flexmock(model).should_receive("set_status").with_args(
status=SyncReleaseTargetStatus.running
Expand Down

0 comments on commit 3567b01

Please sign in to comment.