Skip to content

Commit

Permalink
Store trigger for Bodhi updates of non-packit builds (#2528)
Browse files Browse the repository at this point in the history
Store trigger for Bodhi updates of non-packit builds

Fixes #2428
RELEASE NOTES BEGIN
We have fixed showing of Bodhi updates that are triggered by non-packit Koji builds.
RELEASE NOTES END

Reviewed-by: Maja Massarini
  • Loading branch information
softwarefactory-project-zuul[bot] authored Sep 16, 2024
2 parents 8e54543 + 80e2c18 commit 9e45eab
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 8 deletions.
12 changes: 12 additions & 0 deletions packit_service/worker/events/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,18 @@ def _add_project_object_and_event(self):
repo_name=self.project.repo,
project_url=self.project_url,
)
elif self.event_type in {
"KojiBuildEvent",
}:
(self._db_project_object, self._db_project_event) = (
ProjectEventModel.add_branch_push_event(
branch_name=self.event_dict.get("branch_name"),
namespace=self.project.namespace,
repo_name=self.project.repo,
project_url=self.project_url,
commit_sha=self.event_dict.get("commit_sha"),
)
)
else:
logger.warning(
"We don't know, what to search in the database for this event data."
Expand Down
45 changes: 37 additions & 8 deletions tests/integration/test_bodhi_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
KojiBuildTagModel,
SidetagModel,
SidetagGroupModel,
ProjectEventModelType,
)
from packit_service.utils import (
load_job_config,
Expand Down Expand Up @@ -86,7 +87,9 @@ def test_bodhi_update_for_unknown_koji_build(koji_build_completed_old_format):
# Database structure
run_model_flexmock = flexmock()
git_branch_model_flexmock = flexmock(
id=1, job_config_trigger_type=JobConfigTriggerType.commit
id=1,
job_config_trigger_type=JobConfigTriggerType.commit,
project_event_model_type=ProjectEventModelType.branch_push,
)
flexmock(KojiBuildTargetModel).should_receive("get_by_task_id").with_args(
79721403
Expand All @@ -110,6 +113,7 @@ def test_bodhi_update_for_unknown_koji_build(koji_build_completed_old_format):
)
],
)
flexmock(ProjectEventModel).should_receive("get_or_create")
flexmock(BodhiUpdateGroupModel).should_receive("create").and_return(group_model)
flexmock(BodhiUpdateTargetModel).should_receive("create").with_args(
target="rawhide",
Expand Down Expand Up @@ -184,14 +188,17 @@ def test_bodhi_update_for_unknown_koji_build_failed(koji_build_completed_old_for
# Database structure
run_model_flexmock = flexmock()
git_branch_model_flexmock = flexmock(
id=1, job_config_trigger_type=JobConfigTriggerType.commit
id=1,
job_config_trigger_type=JobConfigTriggerType.commit,
project_event_model_type=ProjectEventModelType.branch_push,
)
flexmock(KojiBuildTargetModel).should_receive("get_by_task_id").with_args(
79721403
).and_return(None)
flexmock(GitBranchModel).should_receive("get_or_create").and_return(
git_branch_model_flexmock
)
flexmock(ProjectEventModel).should_receive("get_or_create")
flexmock(PipelineModel).should_receive("create").and_return(run_model_flexmock)
group_model = flexmock(
id=12,
Expand Down Expand Up @@ -285,7 +292,9 @@ def test_bodhi_update_for_unknown_koji_build_failed_issue_created(
# Database structure
run_model_flexmock = flexmock()
git_branch_model_flexmock = flexmock(
id=1, job_config_trigger_type=JobConfigTriggerType.commit
id=1,
job_config_trigger_type=JobConfigTriggerType.commit,
project_event_model_type=ProjectEventModelType.branch_push,
)
flexmock(KojiBuildTargetModel).should_receive("get_by_task_id").with_args(
79721403
Expand All @@ -294,6 +303,7 @@ def test_bodhi_update_for_unknown_koji_build_failed_issue_created(
git_branch_model_flexmock
)
flexmock(PipelineModel).should_receive("create").and_return(run_model_flexmock)
flexmock(ProjectEventModel).should_receive("get_or_create")
group_model = flexmock(
grouped_targets=[
flexmock(
Expand Down Expand Up @@ -398,7 +408,9 @@ def test_bodhi_update_for_unknown_koji_build_failed_issue_comment(
# Database structure
run_model_flexmock = flexmock()
git_branch_model_flexmock = flexmock(
id=1, job_config_trigger_type=JobConfigTriggerType.commit
id=1,
job_config_trigger_type=JobConfigTriggerType.commit,
project_event_model_type=ProjectEventModelType.branch_push,
)
flexmock(KojiBuildTargetModel).should_receive("get_by_task_id").with_args(
79721403
Expand All @@ -407,6 +419,7 @@ def test_bodhi_update_for_unknown_koji_build_failed_issue_comment(
git_branch_model_flexmock
)
flexmock(PipelineModel).should_receive("create").and_return(run_model_flexmock)
flexmock(ProjectEventModel).should_receive("get_or_create")
group_model = flexmock(
grouped_targets=[
flexmock(
Expand Down Expand Up @@ -520,7 +533,9 @@ def test_bodhi_update_build_not_tagged_yet(
bodhi_update_group=group_model,
).and_return()
git_branch_model_flexmock = flexmock(
id=1, job_config_trigger_type=JobConfigTriggerType.commit
id=1,
job_config_trigger_type=JobConfigTriggerType.commit,
project_event_model_type=ProjectEventModelType.branch_push,
)
flexmock(KojiBuildTargetModel).should_receive("get_by_task_id").with_args(
79721403
Expand Down Expand Up @@ -625,7 +640,9 @@ def test_bodhi_update_for_unknown_koji_build_not_for_unfinished(
bodhi_update_group=group_model,
).and_return()
git_branch_model_flexmock = flexmock(
id=1, job_config_trigger_type=JobConfigTriggerType.commit
id=1,
job_config_trigger_type=JobConfigTriggerType.commit,
project_event_model_type=ProjectEventModelType.branch_push,
)
flexmock(KojiBuildTargetModel).should_receive("get_by_task_id").with_args(
79721403
Expand All @@ -634,6 +651,7 @@ def test_bodhi_update_for_unknown_koji_build_not_for_unfinished(
git_branch_model_flexmock
)
flexmock(PipelineModel).should_receive("create").and_return(run_model_flexmock)
flexmock(ProjectEventModel).should_receive("get_or_create")
flexmock(KojiBuildTargetModel).should_receive("create").with_args(
build_id="1864700",
commit_sha="0eb3e12005cb18f15d3054020f7ac934c01eae08",
Expand Down Expand Up @@ -764,7 +782,9 @@ def test_bodhi_update_for_not_configured_branch(koji_build_completed_old_format)
# Database structure
run_model_flexmock = flexmock()
git_branch_model_flexmock = flexmock(
id=1, job_config_trigger_type=JobConfigTriggerType.commit
id=1,
job_config_trigger_type=JobConfigTriggerType.commit,
project_event_model_type=ProjectEventModelType.branch_push,
)
flexmock(KojiBuildTargetModel).should_receive("get_by_task_id").with_args(
79721403
Expand Down Expand Up @@ -843,7 +863,16 @@ def test_bodhi_update_fedora_stable_by_default(koji_build_completed_f36):
status="queued",
bodhi_update_group=group_model,
).and_return()
flexmock(KojiBuildTargetModel).should_receive("get_by_task_id").with_args(80860789)
flexmock(KojiBuildTargetModel).should_receive("get_by_task_id").with_args(
80860789
).and_return(
flexmock(
get_project_event_object=lambda: flexmock(
id=1, job_config_trigger_type=JobConfigTriggerType.commit
),
group_of_targets=flexmock(runs=[flexmock()]),
)
)

processing_results = SteveJobs().process_message(koji_build_completed_f36)
# 1*CreateBodhiUpdateHandler + 1*KojiBuildReportHandler
Expand Down

0 comments on commit 9e45eab

Please sign in to comment.