Skip to content

Commit 379f24d

Browse files
Support wildcards in COPR allowed list (#2907)
Support wildcards in COPR allowed list TODO: Write new tests or update the old ones to cover new functionality. Update doc-strings where appropriate. Update or write new documentation in packit/packit.dev. Fixes #2906 Related to fedora-copr/copr#3804 Merge before/after RELEASE NOTES BEGIN Packit now supports wildcards in COPR allow lists RELEASE NOTES END Reviewed-by: gemini-code-assist[bot] Reviewed-by: Evgeni Golov Reviewed-by: Laura Barcziová Reviewed-by: nikromen Reviewed-by: Nikola Forró
2 parents 73d780f + 14c3e57 commit 379f24d

3 files changed

Lines changed: 37 additions & 6 deletions

File tree

packit_service/worker/helpers/build/copr_build.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Copyright Contributors to the Packit project.
22
# SPDX-License-Identifier: MIT
33

4+
import fnmatch
45
import logging
56
import re
67
from collections.abc import Iterable
@@ -388,7 +389,7 @@ def is_forge_project_allowed_to_build_in_copr(self) -> bool:
388389
self.job_project,
389390
)
390391
allowed_projects = copr_project["packit_forge_projects_allowed"]
391-
allowed = self.forge_project in allowed_projects
392+
allowed = any(fnmatch.fnmatch(self.forge_project, pattern) for pattern in allowed_projects)
392393
if not allowed:
393394
logger.warning(
394395
f"git-forge project {self.forge_project} "

tests/integration/test_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def test_precheck_push(github_push_event):
224224
config={"username": "nobody"},
225225
project_proxy=flexmock(
226226
get=lambda owner, project: {
227-
"packit_forge_projects_allowed": "github.com/packit-service/hello-world",
227+
"packit_forge_projects_allowed": ["github.com/packit-service/hello-world"],
228228
},
229229
),
230230
),

tests/unit/test_build_helper.py

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2679,7 +2679,7 @@ def test_copr_project_and_namespace(
26792679
),
26802680
},
26812681
),
2682-
"",
2682+
[],
26832683
False,
26842684
id="empty",
26852685
),
@@ -2694,7 +2694,7 @@ def test_copr_project_and_namespace(
26942694
),
26952695
},
26962696
),
2697-
"something/different",
2697+
["something/different"],
26982698
False,
26992699
id="not-present",
27002700
),
@@ -2709,7 +2709,7 @@ def test_copr_project_and_namespace(
27092709
),
27102710
},
27112711
),
2712-
"git.instance.io/the/example/namespace/the-example-repo",
2712+
["git.instance.io/the/example/namespace/the-example-repo"],
27132713
True,
27142714
id="present",
27152715
),
@@ -2724,10 +2724,40 @@ def test_copr_project_and_namespace(
27242724
),
27252725
},
27262726
),
2727-
"something/different\ngit.instance.io/the/example/namespace/the-example-repo",
2727+
["git.instance.io/the/example/namespace/*"],
2728+
True,
2729+
id="wildcard",
2730+
),
2731+
pytest.param(
2732+
JobConfig(
2733+
type=JobType.copr_build,
2734+
trigger=JobConfigTriggerType.pull_request,
2735+
packages={
2736+
"package": CommonPackageConfig(
2737+
owner="the-owner",
2738+
project="the-project",
2739+
),
2740+
},
2741+
),
2742+
["something/different", "git.instance.io/the/example/namespace/the-example-repo"],
27282743
True,
27292744
id="present-more-values",
27302745
),
2746+
pytest.param(
2747+
JobConfig(
2748+
type=JobType.copr_build,
2749+
trigger=JobConfigTriggerType.pull_request,
2750+
packages={
2751+
"package": CommonPackageConfig(
2752+
owner="the-owner",
2753+
project="the-project",
2754+
),
2755+
},
2756+
),
2757+
["something/different", "git.instance.io/the/example/namespace/*"],
2758+
True,
2759+
id="wildcard-more-values",
2760+
),
27312761
],
27322762
)
27332763
def test_check_if_custom_copr_can_be_used_and_report(

0 commit comments

Comments
 (0)