Refactor to use ReleaseConfig object

This commit is contained in:
erik 2023-04-18 15:33:14 +02:00
parent d0ddeb3288
commit 537a5836b9

View file

@ -1,12 +1,13 @@
# TODO: jem, zam - 2023_04_14: mv file one dir up # TODO: jem, zam - 2023_04_14: mv file one dir up
from typing import Optional
from pybuilder.core import Project
from ..devops_build import DevopsBuild from ..devops_build import DevopsBuild
from .infrastructure import ReleaseRepository, ReleaseTypeRepository, VersionRepository from .infrastructure import ReleaseRepository, ReleaseTypeRepository, VersionRepository
from .infrastructure_api import GitApi, EnvironmentApi from .infrastructure_api import GitApi, EnvironmentApi
from .services import PrepareReleaseService, TagAndPushReleaseService from .services import PrepareReleaseService, TagAndPushReleaseService
from .domain import EnvironmentKeys from .domain import EnvironmentKeys
from src.main.python.ddadevops.domain.release_config import ReleaseConfig
# TODO: jem, zam - 2023_04_14: use of config fkts is deprecated - use domain object instead (see: devops_image_build.py)
def create_release_mixin_config(config_file, main_branch) -> dict: def create_release_mixin_config(config_file, main_branch) -> dict:
config = {} config = {}
config.update( config.update(
@ -15,7 +16,6 @@ def create_release_mixin_config(config_file, main_branch) -> dict:
'config_file': config_file}}) 'config_file': config_file}})
return config return config
# TODO: jem, zam - 2023_04_14: use of config fkts is deprecated - use domain object instead (see: devops_image_build.py)
def add_versions(config, release_version, bump_version) -> dict: def add_versions(config, release_version, bump_version) -> dict:
config['ReleaseMixin'].update( config['ReleaseMixin'].update(
{'release_version': release_version, {'release_version': release_version,
@ -23,31 +23,41 @@ def add_versions(config, release_version, bump_version) -> dict:
return config return config
class ReleaseMixin(DevopsBuild): class ReleaseMixin(DevopsBuild):
# TODO: jem, zam - 2023_04_14: handover config as domain object def __init__(self, project: Project, config: Optional[dict] = None, release_config: Optional[ReleaseConfig] = None):
def __init__(self, project, config): # todo: create services in init, dont expose repos etc in api if not release_config:
super().__init__(project, config) if not config:
raise Exception("Release parameters could not be set.")
super().__init__(project, config=config)
release_mixin_config = config['ReleaseMixin'] release_mixin_config = config['ReleaseMixin']
self.config_file = release_mixin_config['config_file'] release_config = ReleaseConfig(
self.main_branch = release_mixin_config['main_branch'] main_branch = release_mixin_config['main_branch'],
self.git_api = GitApi() config_file = release_mixin_config['config_file'],
self.environment_api = EnvironmentApi() devops=self.repo.get_devops(project)
self.env_key = EnvironmentKeys.DDADEVOPS_RELEASE_TYPE.name )
self.environment_val_set = self.environment_api.get(self.env_key) is not "" and self.environment_api.get(self.env_key) is not None
if (self.environment_val_set):
self.release_type_repo = ReleaseTypeRepository.from_environment(self.environment_api)
else: else:
self.release_type_repo = ReleaseTypeRepository.from_git(self.git_api) super().__init__(project, devops=release_config.devops)
self.version_repo = VersionRepository(self.config_file) self.repo.set_release(self.project, release_config)
self.release_repo = ReleaseRepository(self.version_repo, self.release_type_repo, self.main_branch)
git_api = GitApi()
environment_api = EnvironmentApi()
env_key = EnvironmentKeys.DDADEVOPS_RELEASE_TYPE.name
environment_val_set = environment_api.get(env_key) is not "" and environment_api.get(env_key) is not None
if environment_val_set:
release_type_repo = ReleaseTypeRepository.from_environment(environment_api)
else:
release_type_repo = ReleaseTypeRepository.from_git(git_api)
version_repo = VersionRepository(release_config.config_file)
release_repo = ReleaseRepository(version_repo, release_type_repo, release_config.main_branch)
self.prepare_release_service = PrepareReleaseService(release_repo)
self.tag_and_push_release_service = TagAndPushReleaseService(git_api, release_repo)
def prepare_release(self): def prepare_release(self):
# TODO: jem, zam - 2023_04_14: instantiate service on object creation? self.prepare_release_service.write_and_commit_release()
prepare_release_service = PrepareReleaseService(self.release_repo) self.prepare_release_service.write_and_commit_bump()
prepare_release_service.write_and_commit_release()
prepare_release_service.write_and_commit_bump()
def tag_and_push_release(self): def tag_and_push_release(self):
# TODO: jem, zam - 2023_04_14: instantiate service on object creation? self.tag_and_push_release_service.tag_release()
tag_and_push_release_service = TagAndPushReleaseService(self.git_api) self.tag_and_push_release_service.push_release()
tag_and_push_release_service.tag_release(self.release_repo.get_release())
tag_and_push_release_service.push_release()