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 Mar 13, 2024
1 parent 276e736 commit 3fd1b3b
Show file tree
Hide file tree
Showing 6 changed files with 45 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 @@ -395,8 +395,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 @@ -488,6 +488,20 @@ def _report_errors_for_each_branch(self, message: str):
def get_resolved_bugs(self):
raise NotImplementedError("Use subclass.")

@staticmethod
def report_dashboard_url(
sync_release_pull_request: SyncReleasePullRequestModel,
downstream_pr: PullRequest,
dashboard_url: str,
):
msg = f"Logs and details of the syncing: [Packit dashboard]({dashboard_url})"
# this is a retrigger
if len(sync_release_pull_request.sync_release_targets) > 1:
downstream_pr.comment(msg)
else:
original_title = downstream_pr.title
downstream_pr.title = original_title + "\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 @@ -231,12 +231,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 @@ -248,7 +249,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
6 changes: 4 additions & 2 deletions tests/integration/test_new_hotness_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,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 @@ -158,7 +158,9 @@ 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, title="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 @@ -2598,7 +2598,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 @@ -2608,7 +2608,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 @@ -2712,7 +2712,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 @@ -52,7 +52,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 @@ -87,7 +92,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 @@ -139,7 +144,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 @@ -149,7 +156,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 @@ -219,7 +226,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 @@ -273,6 +280,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 @@ -317,7 +325,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 @@ -406,6 +414,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 @@ -468,7 +477,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 @@ -141,17 +141,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 3fd1b3b

Please sign in to comment.