Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip actor pre_check if actor not present #1733

Merged
Merged
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
6 changes: 5 additions & 1 deletion packit_service/worker/checker/abstract.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from abc import abstractmethod
from typing import Optional

Expand All @@ -7,6 +8,8 @@
from packit_service.worker.events import EventData
from packit_service.worker.mixin import ConfigMixin, PackitAPIWithDownstreamMixin

logger = logging.getLogger(__name__)


class Checker(ConfigMixin, PackitAPIWithDownstreamMixin):
def __init__(
Expand Down Expand Up @@ -35,5 +38,6 @@ def _pre_check(self) -> bool:

def pre_check(self) -> bool:
if not self.actor:
return False
logger.debug("Actor not set for this event, skipping the actor check.")
return True
return self._pre_check()
Comment on lines 40 to 43
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't we checking also other non-actor conditions? (I went through the code really quickly and am not sure about the pre_check / _pre_check call chain...)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e.g. project allowed for internal TF,..

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think only _pre_checks in subclasses here or here are called, but I would wait for Maja's approval since she knows the code the best

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Laura for fixing this.
I did not realize I had changed the actor checker behaviour. You are right, before my changes it would have returned False only with a valid actor field.

Before my changes this code were called for every handler, but most of them just returned True, now it is called just for this two handlers Laura linked here.

24 changes: 24 additions & 0 deletions tests/integration/test_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,30 @@ def test_precheck_push_to_a_different_branch(github_push_event):
assert not CoprBuildHandler.pre_check(package_config, job_config, event)


def test_precheck_push_actor_check(github_push_event):
flexmock(GitBranchModel).should_receive("get_or_create").and_return(
flexmock(id=1, job_config_trigger_type=JobConfigTriggerType.commit)
)

package_config = PackageConfig(
jobs=[
JobConfig(
type=JobType.copr_build,
trigger=JobConfigTriggerType.commit,
branch="branch",
),
]
)
job_config = JobConfig(
type=JobType.copr_build,
trigger=JobConfigTriggerType.commit,
branch="branch",
)
event = github_push_event.get_dict()
actor_checker = CoprBuildHandler.get_checkers()[1]
assert actor_checker(package_config, job_config, event).pre_check()


def test_precheck_koji_build_non_scratch(github_pr_event):
flexmock(PullRequestModel).should_receive("get_or_create").with_args(
pr_id=342,
Expand Down