diff --git a/packit_service/worker/helpers/build/copr_build.py b/packit_service/worker/helpers/build/copr_build.py index c3dae6905..b788f516d 100644 --- a/packit_service/worker/helpers/build/copr_build.py +++ b/packit_service/worker/helpers/build/copr_build.py @@ -1,6 +1,7 @@ # Copyright Contributors to the Packit project. # SPDX-License-Identifier: MIT +import fnmatch import logging import re from collections.abc import Iterable @@ -392,7 +393,7 @@ def is_forge_project_allowed_to_build_in_copr(self) -> bool: self.job_project, ) allowed_projects = copr_project["packit_forge_projects_allowed"] - allowed = self.forge_project in allowed_projects + allowed = any(fnmatch.fnmatch(self.forge_project, pattern) for pattern in allowed_projects) if not allowed: logger.warning( f"git-forge project {self.forge_project} " diff --git a/tests/integration/test_handler.py b/tests/integration/test_handler.py index 7e21321c8..f3d4366f7 100644 --- a/tests/integration/test_handler.py +++ b/tests/integration/test_handler.py @@ -224,7 +224,7 @@ def test_precheck_push(github_push_event): config={"username": "nobody"}, project_proxy=flexmock( get=lambda owner, project: { - "packit_forge_projects_allowed": "github.com/packit-service/hello-world", + "packit_forge_projects_allowed": ["github.com/packit-service/hello-world"], }, ), ), diff --git a/tests/unit/test_build_helper.py b/tests/unit/test_build_helper.py index 0f2dc1c32..3b049dfa4 100644 --- a/tests/unit/test_build_helper.py +++ b/tests/unit/test_build_helper.py @@ -2679,7 +2679,7 @@ def test_copr_project_and_namespace( ), }, ), - "", + [], False, id="empty", ), @@ -2694,7 +2694,7 @@ def test_copr_project_and_namespace( ), }, ), - "something/different", + ["something/different"], False, id="not-present", ), @@ -2709,7 +2709,7 @@ def test_copr_project_and_namespace( ), }, ), - "git.instance.io/the/example/namespace/the-example-repo", + ["git.instance.io/the/example/namespace/the-example-repo"], True, id="present", ), @@ -2724,10 +2724,40 @@ def test_copr_project_and_namespace( ), }, ), - "something/different\ngit.instance.io/the/example/namespace/the-example-repo", + ["git.instance.io/the/example/namespace/*"], + True, + id="wildcard", + ), + pytest.param( + JobConfig( + type=JobType.copr_build, + trigger=JobConfigTriggerType.pull_request, + packages={ + "package": CommonPackageConfig( + owner="the-owner", + project="the-project", + ), + }, + ), + ["something/different", "git.instance.io/the/example/namespace/the-example-repo"], True, id="present-more-values", ), + pytest.param( + JobConfig( + type=JobType.copr_build, + trigger=JobConfigTriggerType.pull_request, + packages={ + "package": CommonPackageConfig( + owner="the-owner", + project="the-project", + ), + }, + ), + ["something/different", "git.instance.io/the/example/namespace/*"], + True, + id="wildcard-more-values", + ), ], ) def test_check_if_custom_copr_can_be_used_and_report(