Implement priority: env first, then git

Add test for this behavior.
This commit is contained in:
erik 2023-04-11 16:16:59 +02:00
parent 3776116383
commit 4667c58dbb
2 changed files with 40 additions and 4 deletions

View file

@ -1,7 +1,8 @@
from ..devops_build import DevopsBuild
from .infrastructure import ReleaseRepository, ReleaseTypeRepository, VersionRepository
from .infrastructure_api import GitApi
from .infrastructure_api import GitApi, EnvironmentApi
from .services import PrepareReleaseService, TagAndPushReleaseService
from .domain import EnvironmentKeys
def create_release_mixin_config(config_file, main_branch) -> dict:
config = {}
@ -25,7 +26,13 @@ class ReleaseMixin(DevopsBuild):
self.config_file = release_mixin_config['config_file']
self.main_branch = release_mixin_config['main_branch']
self.git_api = GitApi()
self.release_type_repo = ReleaseTypeRepository.from_git(self.git_api)
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)
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)

View file

@ -3,7 +3,7 @@ from pathlib import Path
from pybuilder.core import Project
from src.main.python.ddadevops.release_mixin.release_mixin import ReleaseMixin, create_release_mixin_config
from src.main.python.ddadevops.release_mixin.infrastructure_api import GitApi
from src.main.python.ddadevops.release_mixin.infrastructure_api import GitApi, EnvironmentApi
from .helper import Helper
@ -29,7 +29,7 @@ def initialize(project, CONFIG_FILE):
build = MyBuild(project, config)
return build
def test_release_mixin(tmp_path: Path, monkeypatch: pt.MonkeyPatch):
def test_release_mixin_git(tmp_path: Path, monkeypatch: pt.MonkeyPatch):
# init
th = Helper()
@ -51,3 +51,32 @@ def test_release_mixin(tmp_path: Path, monkeypatch: pt.MonkeyPatch):
# test
assert "124.0.1-SNAPSHOT" in release_version.get_version_string()
def test_release_mixin_environment(tmp_path: Path, monkeypatch: pt.MonkeyPatch):
# init
th = Helper()
th.copy_files(th.TEST_FILE_PATH, tmp_path)
th.TEST_FILE_PATH = tmp_path / th.TEST_FILE_NAME
change_test_dir(tmp_path, monkeypatch)
project = Project(tmp_path)
git_api = GitApi()
git_api.init()
git_api.set_user_config("ex.ample@mail.com", "Ex Ample")
git_api.add_file(th.TEST_FILE_NAME)
git_api.commit("Commit Message")
environment_api = EnvironmentApi()
environment_api.set("DDADEVOPS_RELEASE_TYPE", "MAJOR")
build = initialize(project, th.TEST_FILE_PATH)
build.prepare_release()
release_version = build.version_repo.get_version()
# test
assert "124.0.1-SNAPSHOT" in release_version.get_version_string()
# tear down
environment_api.set("DDADEVOPS_RELEASE_TYPE", "")