This commit is contained in:
Michael Jerger 2023-04-21 15:11:08 +02:00
parent d717cd5a8c
commit 84cf82ac57

View file

@ -1,10 +1,18 @@
from typing import Optional from typing import Optional
from src.main.python.ddadevops.domain import Release, Version, ReleaseType, EnvironmentKeys from src.main.python.ddadevops.domain import (
from src.main.python.ddadevops.infrastructure.release_mixin import FileHandler, GitApi, EnvironmentApi Release,
Version,
ReleaseType,
EnvironmentKeys,
)
from src.main.python.ddadevops.infrastructure.release_mixin import (
FileHandler,
GitApi,
EnvironmentApi,
)
class VersionRepository(): class VersionRepository:
def __init__(self, file): def __init__(self, file):
self.file = file self.file = file
self.file_handler = None self.file_handler = None
@ -15,7 +23,7 @@ class VersionRepository():
def write_file(self, version_string): def write_file(self, version_string):
if self.file_handler is None: if self.file_handler is None:
raise Exception('Version was not created by load_file method.') raise Exception("Version was not created by load_file method.")
else: else:
self.file_handler.write(version_string) self.file_handler.write(version_string)
@ -24,7 +32,6 @@ class VersionRepository():
return version_list, is_snapshot return version_list, is_snapshot
def get_version(self) -> Version: def get_version(self) -> Version:
self.file_handler = self.load_file() self.file_handler = self.load_file()
version_list, is_snapshot = self.parse_file() version_list, is_snapshot = self.parse_file()
version = Version(self.file, version_list) version = Version(self.file, version_list)
@ -32,8 +39,13 @@ class VersionRepository():
return version return version
class ReleaseTypeRepository():
def __init__(self, git_api: GitApi = GitApi(), environment_api: EnvironmentApi = EnvironmentApi()): class ReleaseTypeRepository:
def __init__(
self,
git_api: GitApi = GitApi(),
environment_api: EnvironmentApi = EnvironmentApi(),
):
self.git_api: GitApi = git_api self.git_api: GitApi = git_api
self.environment_api: EnvironmentApi = environment_api self.environment_api: EnvironmentApi = environment_api
self.get_from_git: bool = False self.get_from_git: bool = False
@ -66,10 +78,14 @@ class ReleaseTypeRepository():
return None return None
def __get_release_type_environment(self) -> ReleaseType | None: def __get_release_type_environment(self) -> ReleaseType | None:
release_name = self.environment_api.get(EnvironmentKeys.DDADEVOPS_RELEASE_TYPE.name) release_name = self.environment_api.get(
EnvironmentKeys.DDADEVOPS_RELEASE_TYPE.name
)
if release_name is None: if release_name is None:
raise ValueError("Release Name not found. Is the Environment correctly configured?") raise ValueError(
"Release Name not found. Is the Environment correctly configured?"
)
elif ReleaseType.MAJOR.name in release_name.upper(): elif ReleaseType.MAJOR.name in release_name.upper():
return ReleaseType.MAJOR return ReleaseType.MAJOR
elif ReleaseType.MINOR.name in release_name.upper(): elif ReleaseType.MINOR.name in release_name.upper():
@ -87,13 +103,23 @@ class ReleaseTypeRepository():
elif self.get_from_env: elif self.get_from_env:
return self.__get_release_type_environment() return self.__get_release_type_environment()
else: else:
raise ValueError('No valid api passed to ReleaseTypeRepository') raise ValueError("No valid api passed to ReleaseTypeRepository")
class ReleaseRepository():
def __init__(self, version_repository: VersionRepository, release_type_repository: ReleaseTypeRepository, main_branch: str): class ReleaseRepository:
def __init__(
self,
version_repository: VersionRepository,
release_type_repository: ReleaseTypeRepository,
main_branch: str,
):
self.version_repository = version_repository self.version_repository = version_repository
self.release_type_repository = release_type_repository self.release_type_repository = release_type_repository
self.main_branch = main_branch self.main_branch = main_branch
def get_release(self) -> Release: def get_release(self) -> Release:
return Release(self.release_type_repository.get_release_type(), self.version_repository.get_version(), self.main_branch) return Release(
self.release_type_repository.get_release_type(),
self.version_repository.get_version(),
self.main_branch,
)