Make services stateless
Resolves 2 TODOs
This commit is contained in:
parent
3a83be485c
commit
35465b543b
4 changed files with 28 additions and 37 deletions
|
@ -1,36 +1,32 @@
|
|||
from src.main.python.ddadevops.infrastructure.release_mixin import ReleaseContextRepository, GitApi
|
||||
from src.main.python.ddadevops.domain import Version
|
||||
from src.main.python.ddadevops.infrastructure.release_mixin import ReleaseContextRepository, VersionRepository, GitApi
|
||||
from src.main.python.ddadevops.domain import Version, Release
|
||||
|
||||
|
||||
class PrepareReleaseService():
|
||||
|
||||
def __init__(self, release_repo: ReleaseContextRepository):
|
||||
self.release_repo = release_repo
|
||||
self.release = release_repo.get_release() # TODO: make stateless: argument to receiving func
|
||||
def __init__(self):
|
||||
self.git_api = GitApi()
|
||||
|
||||
def __write_and_commit_version(self, version: Version, commit_message: str):
|
||||
self.release.is_valid()
|
||||
def __write_and_commit_version(self, release: Release, version_repository: VersionRepository, version: Version, commit_message: str):
|
||||
release.is_valid()
|
||||
|
||||
self.release_repo.version_repository.write_file(version.get_version_string())
|
||||
self.git_api.add_file(self.release_repo.version_repository.file)
|
||||
version_repository.write_file(version.get_version_string())
|
||||
self.git_api.add_file(version_repository.file)
|
||||
self.git_api.commit(commit_message)
|
||||
|
||||
def write_and_commit_release(self):
|
||||
self.__write_and_commit_version(self.release.release_version(), commit_message=f'Release v{self.release.release_version().get_version_string()}')
|
||||
def write_and_commit_release(self, release: Release, version_repository: VersionRepository):
|
||||
self.__write_and_commit_version(release, version_repository, release.release_version(), commit_message=f'Release v{release.release_version().get_version_string()}')
|
||||
|
||||
def write_and_commit_bump(self):
|
||||
self.__write_and_commit_version(self.release.bump_version(), commit_message='Version bump')
|
||||
def write_and_commit_bump(self, release: Release, version_repository: VersionRepository):
|
||||
self.__write_and_commit_version(release, version_repository, release.bump_version(), commit_message='Version bump')
|
||||
|
||||
class TagAndPushReleaseService():
|
||||
|
||||
def __init__(self, git_api: GitApi, release_repo: ReleaseContextRepository):
|
||||
def __init__(self, git_api: GitApi):
|
||||
self.git_api = git_api
|
||||
self.release_repo = release_repo
|
||||
self.release = release_repo.get_release() # TODO: make stateless: argument to receiving func
|
||||
|
||||
def tag_release(self):
|
||||
annotation = 'v' + self.release.version.get_version_string()
|
||||
def tag_release(self, release_repo: ReleaseContextRepository):
|
||||
annotation = 'v' + release_repo.get_release().version.get_version_string()
|
||||
message = 'Release ' + annotation
|
||||
self.git_api.tag_annotated_second_last(annotation, message)
|
||||
|
||||
|
|
|
@ -21,15 +21,16 @@ class ReleaseMixin(DevopsBuild):
|
|||
release_type_repo = ReleaseTypeRepository.from_git(git_api)
|
||||
|
||||
version_repo = VersionRepository(release.config_file)
|
||||
release_repo = ReleaseContextRepository(version_repo, release_type_repo, release.main_branch)
|
||||
self.release_repo = ReleaseContextRepository(version_repo, release_type_repo, release.main_branch)
|
||||
|
||||
self.prepare_release_service = PrepareReleaseService(release_repo)
|
||||
self.tag_and_push_release_service = TagAndPushReleaseService(git_api, release_repo)
|
||||
self.prepare_release_service = PrepareReleaseService()
|
||||
self.tag_and_push_release_service = TagAndPushReleaseService(git_api)
|
||||
|
||||
def prepare_release(self):
|
||||
self.prepare_release_service.write_and_commit_release()
|
||||
self.prepare_release_service.write_and_commit_bump()
|
||||
release = self.release_repo.get_release()
|
||||
self.prepare_release_service.write_and_commit_release(release, self.release_repo.version_repository)
|
||||
self.prepare_release_service.write_and_commit_bump(release, self.release_repo.version_repository)
|
||||
|
||||
def tag_and_push_release(self):
|
||||
self.tag_and_push_release_service.tag_release()
|
||||
self.tag_and_push_release_service.tag_release(self.release_repo)
|
||||
self.tag_and_push_release_service.push_release()
|
||||
|
|
|
@ -45,7 +45,7 @@ def test_release_mixin_git(tmp_path: Path, monkeypatch: pt.MonkeyPatch):
|
|||
|
||||
build = initialize_with_object(project, th.TEST_FILE_PATH)
|
||||
build.prepare_release()
|
||||
release_version = build.prepare_release_service.release_repo.version_repository.get_version()
|
||||
release_version = build.release_repo.version_repository.get_version()
|
||||
|
||||
# test
|
||||
assert "124.0.1-SNAPSHOT" in release_version.get_version_string()
|
||||
|
@ -71,7 +71,7 @@ def test_release_mixin_environment(tmp_path: Path, monkeypatch: pt.MonkeyPatch):
|
|||
|
||||
build = initialize_with_object(project, th.TEST_FILE_PATH)
|
||||
build.prepare_release()
|
||||
release_version = build.prepare_release_service.release_repo.version_repository.get_version()
|
||||
release_version = build.release_repo.version_repository.get_version()
|
||||
|
||||
# test
|
||||
assert "124.0.1-SNAPSHOT" in release_version.get_version_string()
|
||||
|
|
|
@ -5,32 +5,26 @@ from src.test.python.release_mixin import MockGitApi
|
|||
def test_prepare_release_service():
|
||||
# init
|
||||
mock_release_repo = MockReleaseRepository(MockVersionRepository(), MockReleaseTypeRepository(MockGitApi()), 'main')
|
||||
prepare_release_service = PrepareReleaseService(mock_release_repo)
|
||||
prepare_release_service = PrepareReleaseService()
|
||||
prepare_release_service.git_api = MockGitApi()
|
||||
prepare_release_service.write_and_commit_release()
|
||||
prepare_release_service.write_and_commit_release(mock_release_repo.get_release(), mock_release_repo.version_repository)
|
||||
|
||||
#test
|
||||
assert prepare_release_service.release_repo.get_release_count == 1
|
||||
assert prepare_release_service.release.validate_count == 1
|
||||
assert prepare_release_service.release_repo.version_repository.write_file_count == 1
|
||||
assert prepare_release_service.git_api.add_file_count == 1
|
||||
assert prepare_release_service.git_api.commit_count == 1
|
||||
|
||||
# init
|
||||
prepare_release_service.write_and_commit_bump()
|
||||
prepare_release_service.write_and_commit_bump(mock_release_repo.get_release(), mock_release_repo.version_repository)
|
||||
|
||||
# test
|
||||
assert prepare_release_service.release_repo.get_release_count == 1
|
||||
assert prepare_release_service.release.validate_count == 2
|
||||
assert prepare_release_service.release_repo.version_repository.write_file_count == 2
|
||||
assert prepare_release_service.git_api.add_file_count == 2
|
||||
assert prepare_release_service.git_api.commit_count == 2
|
||||
|
||||
def test_tag_and_push_release_service():
|
||||
# init
|
||||
mock_release_repo = MockReleaseRepository(MockVersionRepository(), MockReleaseTypeRepository(MockGitApi()), 'main')
|
||||
tag_and_push_release_service = TagAndPushReleaseService(MockGitApi(), mock_release_repo)
|
||||
tag_and_push_release_service.tag_release()
|
||||
tag_and_push_release_service = TagAndPushReleaseService(MockGitApi())
|
||||
tag_and_push_release_service.tag_release(mock_release_repo)
|
||||
tag_and_push_release_service.push_release()
|
||||
|
||||
#test
|
||||
|
|
Loading…
Reference in a new issue