import re from dataclasses import dataclass, asdict from typing import Optional, List, Dict, Any, Iterable from ci_utils import normalize_string from ci_config import CI from git_helper import Runner as GitRunner, GIT_PREFIX from pr_info import PRInfo # pylint: disable=too-many-return-statements @dataclass class CiSettings: # job will be included in the run if any keyword from the list matches job name include_keywords: Optional[List[str]] = None # job will be excluded in the run if any keyword from the list matches job name exclude_keywords: Optional[List[str]] = None # list of specified preconfigured ci sets to run ci_sets: Optional[List[str]] = None # list of specified jobs to run ci_jobs: Optional[List[str]] = None # batches to run for all multi-batch jobs job_batches: Optional[List[int]] = None do_not_test: bool = False no_ci_cache: bool = False upload_all: bool = False no_merge_commit: bool = False def as_dict(self) -> Dict[str, Any]: return asdict(self) @staticmethod def create_from_run_config(run_config: Dict[str, Any]) -> "CiSettings": return CiSettings(**run_config["ci_settings"]) @staticmethod def create_from_pr_message( debug_message: Optional[str], update_from_api: bool ) -> "CiSettings": """ Creates CiSettings instance based on tags found in PR body and/or commit message @commit_message - may be provided directly for debugging purposes, otherwise it will be retrieved from git. """ res = CiSettings() pr_info = PRInfo() if ( not pr_info.is_pr and not debug_message ): # if commit_message is provided it's test/debug scenario - do not return # CI options can be configured in PRs only # if debug_message is provided - it's a test return res message = debug_message or GitRunner(set_cwd_to_git_root=True).run( f"{GIT_PREFIX} log {pr_info.sha} --format=%B -n 1" ) # CI setting example we need to match with re: # - [x] Exclude: All with TSAN, MSAN, UBSAN, Coverage pattern = r"(#|- \[x\] +