Refactor to use ReleaseConfig object
This commit is contained in:
parent
d0ddeb3288
commit
537a5836b9
1 changed files with 36 additions and 26 deletions
|
@ -1,12 +1,13 @@
|
|||
# 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 .infrastructure import ReleaseRepository, ReleaseTypeRepository, VersionRepository
|
||||
from .infrastructure_api import GitApi, EnvironmentApi
|
||||
from .services import PrepareReleaseService, TagAndPushReleaseService
|
||||
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:
|
||||
config = {}
|
||||
config.update(
|
||||
|
@ -15,7 +16,6 @@ def create_release_mixin_config(config_file, main_branch) -> dict:
|
|||
'config_file': config_file}})
|
||||
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:
|
||||
config['ReleaseMixin'].update(
|
||||
{'release_version': release_version,
|
||||
|
@ -23,31 +23,41 @@ def add_versions(config, release_version, bump_version) -> dict:
|
|||
return config
|
||||
|
||||
class ReleaseMixin(DevopsBuild):
|
||||
# TODO: jem, zam - 2023_04_14: handover config as domain object
|
||||
def __init__(self, project, config): # todo: create services in init, dont expose repos etc in api
|
||||
super().__init__(project, config)
|
||||
def __init__(self, project: Project, config: Optional[dict] = None, release_config: Optional[ReleaseConfig] = None):
|
||||
if not release_config:
|
||||
if not config:
|
||||
raise Exception("Release parameters could not be set.")
|
||||
super().__init__(project, config=config)
|
||||
release_mixin_config = config['ReleaseMixin']
|
||||
self.config_file = release_mixin_config['config_file']
|
||||
self.main_branch = release_mixin_config['main_branch']
|
||||
self.git_api = GitApi()
|
||||
self.environment_api = EnvironmentApi()
|
||||
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)
|
||||
release_config = ReleaseConfig(
|
||||
main_branch = release_mixin_config['main_branch'],
|
||||
config_file = release_mixin_config['config_file'],
|
||||
devops=self.repo.get_devops(project)
|
||||
)
|
||||
else:
|
||||
self.release_type_repo = ReleaseTypeRepository.from_git(self.git_api)
|
||||
self.version_repo = VersionRepository(self.config_file)
|
||||
self.release_repo = ReleaseRepository(self.version_repo, self.release_type_repo, self.main_branch)
|
||||
super().__init__(project, devops=release_config.devops)
|
||||
self.repo.set_release(self.project, release_config)
|
||||
|
||||
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):
|
||||
# TODO: jem, zam - 2023_04_14: instantiate service on object creation?
|
||||
prepare_release_service = PrepareReleaseService(self.release_repo)
|
||||
prepare_release_service.write_and_commit_release()
|
||||
prepare_release_service.write_and_commit_bump()
|
||||
self.prepare_release_service.write_and_commit_release()
|
||||
self.prepare_release_service.write_and_commit_bump()
|
||||
|
||||
def tag_and_push_release(self):
|
||||
# TODO: jem, zam - 2023_04_14: instantiate service on object creation?
|
||||
tag_and_push_release_service = TagAndPushReleaseService(self.git_api)
|
||||
tag_and_push_release_service.tag_release(self.release_repo.get_release())
|
||||
tag_and_push_release_service.push_release()
|
||||
self.tag_and_push_release_service.tag_release()
|
||||
self.tag_and_push_release_service.push_release()
|
||||
|
|
Loading…
Reference in a new issue