4545 get_packit_commands_from_comment ,
4646)
4747from packit_service .worker .celery_task import CeleryTask
48+ from packit_service .worker .checker .abstract import Checker
49+ from packit_service .worker .checker .testing_farm import (
50+ IsFMFConfigPresent ,
51+ IsProjectOutsideOfTestsNamespace ,
52+ )
4853from packit_service .worker .helpers .build import CoprBuildJobHelper
4954from packit_service .worker .helpers .fedora_ci import FedoraCIHelper
5055from packit_service .worker .helpers .testing_farm_client import TestingFarmClient
@@ -685,14 +690,9 @@ def is_fmf_configured(self) -> bool:
685690 if self .custom_fmf :
686691 return True
687692
688- try :
689- self .project .get_file_content (
690- path = f"{ self .fmf_path } /.fmf/version" ,
691- ref = self .metadata .commit_sha ,
692- )
693- return True
694- except FileNotFoundError :
695- return False
693+ return IsFMFConfigPresent (
694+ package_config = None , job_config = None , event = self .metadata .event_dict , task_name = None
695+ ).pre_check ()
696696
697697 def report_missing_build_chroot (self , chroot : str ):
698698 self .report_status_to_tests_for_chroot (
@@ -1303,9 +1303,11 @@ def cancel_running_tests(self):
13031303FEDORA_CI_TESTS = {}
13041304
13051305
1306- def implements_fedora_ci_test (test_name : str , skipif : Optional [Callable ] = None ) -> Callable :
1306+ def implements_fedora_ci_test (
1307+ test_name : str , checkers : Optional [list [type [Checker ]]] = None
1308+ ) -> Callable :
13071309 def _update_mapping (function : Callable ) -> Callable :
1308- FEDORA_CI_TESTS [test_name ] = (function , skipif )
1310+ FEDORA_CI_TESTS [test_name ] = (function , checkers )
13091311 return function
13101312
13111313 return _update_mapping
@@ -1339,7 +1341,10 @@ def koji_helper(self):
13391341
13401342 @staticmethod
13411343 def get_fedora_ci_tests (
1342- service_config : ServiceConfig , project : GitProject , metadata : EventData
1344+ service_config : ServiceConfig ,
1345+ project : GitProject ,
1346+ metadata : EventData ,
1347+ filter_specific_tests : bool = True ,
13431348 ) -> list [str ]:
13441349 """
13451350 Gets relevant Fedora CI tests registered using the `@implements_fedora_ci_test()` decorator.
@@ -1351,31 +1356,47 @@ def get_fedora_ci_tests(
13511356 service_config: Service config.
13521357 project: Git project.
13531358 metadata: Event metadata.
1359+ filter_specific_tests: Whether to filter tests based on the command in user's comment.
13541360
13551361 Returns:
13561362 List of registered Fedora CI test names.
13571363 """
1364+
1365+ def filter_tests (tests ):
1366+ if metadata .event_type != pagure .pr .Comment .event_type ():
1367+ return tests
1368+ # TODO: remove this once Fedora CI has its own instances and comment_command_prefixes
1369+ # comment_command_prefixes for Fedora CI are /packit-ci and /packit-ci-stg
1370+ comment_command_prefix = (
1371+ "/packit-ci-stg"
1372+ if service_config .comment_command_prefix .endswith ("-stg" )
1373+ else "/packit-ci"
1374+ )
1375+ commands = get_packit_commands_from_comment (
1376+ metadata .event_dict .get ("comment" ), comment_command_prefix
1377+ )
1378+ if not commands :
1379+ return []
1380+ if len (commands ) > 1 and commands [1 ] in tests :
1381+ return [commands [1 ]]
1382+ return tests
1383+
13581384 all_tests = [
13591385 name
1360- for name , (_ , skipif ) in FEDORA_CI_TESTS .items ()
1361- if not skipif or not skipif (service_config , project , metadata )
1386+ for name , (_ , checkers ) in FEDORA_CI_TESTS .items ()
1387+ if all (
1388+ checker (
1389+ package_config = None ,
1390+ job_config = None ,
1391+ event = metadata .event_dict ,
1392+ task_name = None ,
1393+ ).pre_check ()
1394+ for checker in checkers
1395+ )
13621396 ]
1363- if metadata .event_type != pagure .pr .Comment .event_type ():
1364- return all_tests
1365- # TODO: remove this once Fedora CI has its own instances and comment_command_prefixes
1366- # comment_command_prefixes for Fedora CI are /packit-ci and /packit-ci-stg
1367- comment_command_prefix = (
1368- "/packit-ci-stg"
1369- if service_config .comment_command_prefix .endswith ("-stg" )
1370- else "/packit-ci"
1371- )
1372- commands = get_packit_commands_from_comment (
1373- metadata .event_dict .get ("comment" ), comment_command_prefix
1374- )
1375- if not commands :
1376- return []
1377- if len (commands ) > 1 and commands [1 ] in all_tests :
1378- return [commands [1 ]]
1397+
1398+ if filter_specific_tests :
1399+ return filter_tests (all_tests )
13791400 return all_tests
13801401
13811402 @property
@@ -1495,7 +1516,10 @@ def prepare_and_send_tf_request(
14951516 response = response ,
14961517 )
14971518
1498- @implements_fedora_ci_test ("installability" )
1519+ @implements_fedora_ci_test (
1520+ "installability" ,
1521+ checkers = [IsProjectOutsideOfTestsNamespace ],
1522+ )
14991523 def _payload_installability (self , distro : str , compose : str ) -> dict :
15001524 git_repo = "https://github.com/fedora-ci/installability-pipeline.git"
15011525 git_ref = (
@@ -1542,7 +1566,10 @@ def _payload_installability(self, distro: str, compose: str) -> dict:
15421566 },
15431567 }
15441568
1545- @implements_fedora_ci_test ("rpminspect" )
1569+ @implements_fedora_ci_test (
1570+ "rpminspect" ,
1571+ checkers = [IsProjectOutsideOfTestsNamespace ],
1572+ )
15461573 def _payload_rpminspect (self , distro : str , compose : str ) -> dict :
15471574 git_repo = "https://github.com/fedora-ci/rpminspect-pipeline.git"
15481575 git_ref = "master"
@@ -1557,7 +1584,10 @@ def _payload_rpminspect(self, distro: str, compose: str) -> dict:
15571584 }
15581585 return payload
15591586
1560- @implements_fedora_ci_test ("rpmlint" )
1587+ @implements_fedora_ci_test (
1588+ "rpmlint" ,
1589+ checkers = [IsProjectOutsideOfTestsNamespace ],
1590+ )
15611591 def _payload_rpmlint (self , distro : str , compose : str ) -> dict :
15621592 git_repo = "https://github.com/packit/tmt-plans.git"
15631593 git_ref = "main"
@@ -1573,22 +1603,9 @@ def _payload_rpmlint(self, distro: str, compose: str) -> dict:
15731603 }
15741604 return payload
15751605
1576- @staticmethod
1577- def is_fmf_configured (project : GitProject , metadata : EventData ) -> bool :
1578- try :
1579- project .get_file_content (
1580- path = ".fmf/version" ,
1581- ref = metadata .commit_sha ,
1582- )
1583- except FileNotFoundError :
1584- return False
1585- return True
1586-
15871606 @implements_fedora_ci_test (
15881607 "custom" ,
1589- skipif = lambda _ , project , metadata : not DownstreamTestingFarmJobHelper .is_fmf_configured (
1590- project , metadata
1591- ),
1608+ checkers = [IsFMFConfigPresent ],
15921609 )
15931610 def _payload_custom (self , distro : str , compose : str ) -> dict :
15941611 payload = self ._get_tf_base_payload (distro , compose )
0 commit comments