Skip to content

Commit

Permalink
get or create github kebechet installation
Browse files Browse the repository at this point in the history
  • Loading branch information
KPostOffice committed Apr 29, 2021
1 parent 96acfa5 commit 214b42e
Showing 1 changed file with 42 additions and 13 deletions.
55 changes: 42 additions & 13 deletions thoth/storages/graph/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -3711,48 +3711,77 @@ 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

python_stack = self._create_python_software_stack(
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.installation_id == installation_id).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."""
Expand Down

0 comments on commit 214b42e

Please sign in to comment.