Skip to content

Commit 52096ba

Browse files
committed
Support wildcards in COPR allowed list
Fixes: #2906
1 parent 079d040 commit 52096ba

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

packit_service/worker/helpers/build/copr_build.py

Lines changed: 5 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
@@ -392,7 +393,10 @@ def is_forge_project_allowed_to_build_in_copr(self) -> bool:
392393
self.job_project,
393394
)
394395
allowed_projects = copr_project["packit_forge_projects_allowed"]
395-
allowed = self.forge_project in allowed_projects
396+
allowed = any(
397+
fnmatch.fnmatch(self.forge_project, pattern)
398+
for pattern in allowed_projects.splitlines()
399+
)
396400
if not allowed:
397401
logger.warning(
398402
f"git-forge project {self.forge_project} "

tests/unit/test_build_helper.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2713,6 +2713,21 @@ def test_copr_project_and_namespace(
27132713
True,
27142714
id="present",
27152715
),
2716+
pytest.param(
2717+
JobConfig(
2718+
type=JobType.copr_build,
2719+
trigger=JobConfigTriggerType.pull_request,
2720+
packages={
2721+
"package": CommonPackageConfig(
2722+
owner="the-owner",
2723+
project="the-project",
2724+
),
2725+
},
2726+
),
2727+
"git.instance.io/the/example/namespace/*",
2728+
True,
2729+
id="wildcard",
2730+
),
27162731
pytest.param(
27172732
JobConfig(
27182733
type=JobType.copr_build,
@@ -2728,6 +2743,21 @@ def test_copr_project_and_namespace(
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\ngit.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)