diff --git a/thoth/storages/graph/postgres.py b/thoth/storages/graph/postgres.py index 4e0cfb6f5..f3dcb0bdb 100644 --- a/thoth/storages/graph/postgres.py +++ b/thoth/storages/graph/postgres.py @@ -3711,22 +3711,25 @@ def get_kebechet_github_installations_info_for_python_package_version( def update_kebechet_installation_using_files( self, slug: str, + installation_id: str, requirements: Optional[dict] = None, requirements_lock: Optional[dict] = None, thoth_config: Optional[dict] = None, + private: bool = False, ): """Update info about kebechet installation.""" with self._session_scope() as session, session.begin(subtransactions=True): if "runtime_environments" in thoth_config: env_dict = thoth_config["runtime_environments"][0] software_env = ExternalSoftwareEnvironment.get_or_create( + session=session, environment_name=env_dict["name"], os_name=env_dict["operating_system"]["name"], os_version=env_dict["operating_system"]["version"], python_version=env_dict.get("python_version"), cuda_version=env_dict.get("cuda_version"), environment_type=EnvironmentTypeEnum.RUNTIME.value, - ) + )[0] else: software_env = None @@ -3734,25 +3737,54 @@ def update_kebechet_installation_using_files( session=session, requirements=requirements, requirements_lock=requirements_lock, - software_env=software_env, + software_environment=software_env, is_external=True, ) manager_info = thoth_config.get("managers") or {} all_managers = [i["name"] for i in manager_info] - session.query(KebechetGitHubAppInstallation).filter( - KebechetGithubAppInstallations.slug == slug - ).first().update( - external_python_software_stack_id=python_stack.id, - external_software_environment=software_env, - info_manager="info" in all_managers, - pipfile_requirements_manager="pipfile-requirements" in all_managers, - update_manager="update" in all_managers, - version_manager="version" in all_managers, - thoth_advise_manager="thoth-advise" in all_managers, - thoth_provenance_manager="thoth-provenance" in all_managers, + item = ( + session.query(KebechetGithubAppInstallations) + .filter(KebechetGithubAppInstallations.slug == slug) + .first() ) + if item is None: + KebechetGithubAppInstallations.get_or_create( + session=session, + slug=slug, + repo_name=slug.split("/")[1], + installation_id=installation_id, + private=private, + is_active=True, + external_python_software_stack_id=python_stack.id, + external_software_environment_id=software_env.id, + info_manager="info" in all_managers, + pipfile_requirements_manager="pipfile-requirements" in all_managers, + update_manager="update" in all_managers, + version_manager="version" in all_managers, + thoth_advise_manager="thoth-advise" in all_managers, + thoth_provenance_manager="thoth-provenance" in all_managers, + ) + else: + session.query(KebechetGithubAppInstallations).filter( + KebechetGithubAppInstallations.id == item.id + ).update( + { + "slug": slug, + "repo_name": slug.split("/")[1], + "installation_id": installation_id, + "private": private, + "is_active": True, + "external_python_software_stack_id": python_stack.id, + "external_software_environment_id": software_env.id, + "pipfile_requirements_manager": "pipfile-requirements" in all_managers, + "update_manager": "update" in all_managers, + "version_manager": "version" in all_managers, + "thoth_advise_manager": "thoth-advise" in all_managers, + "thoth_provenance_manager": "thoth-provenance" in all_managers, + } + ) def get_index_url_from_id(self, package_index_id: int) -> list: """Return index URL from id."""