def get_package_config_from_repo(sourcegit_project: GitProject, ref: str) -> Optional[PackageConfig]: for config_file_name in CONFIG_FILE_NAMES: try: config_file_content = sourcegit_project.get_file_content( path=config_file_name, ref=ref) logger.debug( f"Found a config file '{config_file_name}' " f"on ref '{ref}' " f"of the {sourcegit_project.full_repo_name} repository.") except FileNotFoundError as ex: logger.debug( f"The config file '{config_file_name}' " f"not found on ref '{ref}' " f"of the {sourcegit_project.full_repo_name} repository." f"{ex!r}") continue try: loaded_config = safe_load(config_file_content) except Exception as ex: logger.error(f"Cannot load package config '{config_file_name}'.") raise PackitException(f"Cannot load package config: {ex}.") return parse_loaded_config(loaded_config=loaded_config, config_file_path=config_file_name) logger.warning(f"No config file found on ref '{ref}' " f"of the {sourcegit_project.full_repo_name} repository.") return None
def get_package_config_from_repo(sourcegit_project: GitProject, ref: str) -> Optional[PackageConfig]: for config_file_name in CONFIG_FILE_NAMES: try: config_file_content = sourcegit_project.get_file_content( path=config_file_name, ref=ref) except FileNotFoundError: # do nothing pass else: logger.debug( f"Found a config file '{config_file_name}' " f"on ref '{ref}' " f"of the {sourcegit_project.full_repo_name} repository.") break else: logger.warning( f"No config file ({CONFIG_FILE_NAMES}) found on ref '{ref}' " f"of the {sourcegit_project.full_repo_name} repository.") return None try: loaded_config = safe_load(config_file_content) except Exception as ex: logger.error(f"Cannot load package config {config_file_name!r}. {ex}") raise PackitConfigException( f"Cannot load package config {config_file_name!r}. {ex}") return parse_loaded_config( loaded_config=loaded_config, config_file_path=config_file_name, repo_name=sourcegit_project.repo, spec_file_path=get_specfile_path_from_repo(sourcegit_project, ref), )
def get_packit_config_from_repo(sourcegit_project: GitProject, branch: str) -> Optional[PackageConfig]: for config_file_name in CONFIG_FILE_NAMES: try: config_file = sourcegit_project.get_file_content( path=config_file_name, ref=branch) logger.debug( f"Found a config file '{config_file_name}' " f"on branch '{branch}' " f"of the {sourcegit_project.full_repo_name} repository.") except FileNotFoundError: logger.debug( f"The config file '{config_file_name}' " f"not found on branch '{branch}' " f"of the {sourcegit_project.full_repo_name} repository.") continue try: loaded_config = anymarkup.parse(config_file) except Exception as ex: logger.error(f"Cannot load package config '{config_file_name}'.") raise Exception(f"Cannot load package config: {ex}.") return parse_loaded_config(loaded_config=loaded_config) return None
def get_package_config_from_repo( project: GitProject, ref: Optional[str] = None, spec_file_path: Optional[str] = None ) -> Optional[PackageConfig]: for config_file_name in CONFIG_FILE_NAMES: try: config_file_content = project.get_file_content( path=config_file_name, ref=ref ) except (FileNotFoundError, GithubAppNotInstalledError): # do nothing pass else: logger.debug( f"Found a config file {config_file_name!r} " f"on ref {ref!r} " f"of the {project.full_repo_name!r} repository." ) break else: logger.warning( f"No config file ({CONFIG_FILE_NAMES}) found on ref {ref!r} " f"of the {project.full_repo_name!r} repository." ) return None try: loaded_config = safe_load(config_file_content) except Exception as ex: logger.error(f"Cannot load package config {config_file_name!r}. {ex}") raise PackitConfigException( f"Cannot load package config {config_file_name!r}. {ex}" ) if not spec_file_path: logger.warning(f"Spec file path is not specified in {config_file_name}.") spec_file_path = get_specfile_path_from_repo(project=project, ref=ref) return parse_loaded_config( loaded_config=loaded_config, config_file_path=config_file_name, repo_name=project.repo, spec_file_path=spec_file_path, )