Make ReleaseContextRepository stateless

This commit is contained in:
bom 2023-04-28 13:38:22 +02:00 committed by Michael Jerger
parent b6b283d2b2
commit a25453cdbf
3 changed files with 7 additions and 9 deletions

View file

@ -106,23 +106,20 @@ class ReleaseTypeRepository:
raise ValueError("No valid api passed to ReleaseTypeRepository")
# TODO: Repo has state & repository should exist only for AggregateRoot
class ReleaseContextRepository:
def __init__(
self,
version_repository: VersionRepository,
release_type_repository: ReleaseTypeRepository,
main_branch: str,
):
self.version_repository = version_repository
self.release_type_repository = release_type_repository
self.main_branch = main_branch
def get_release(self) -> ReleaseContext:
def get_release(self, main_branch: str) -> ReleaseContext:
result = ReleaseContext(
self.release_type_repository.get_release_type(),
self.version_repository.get_version(),
self.main_branch,
main_branch,
)
result.throw_if_invalid()
return result

View file

@ -9,6 +9,7 @@ class ReleaseMixin(DevopsBuild):
def __init__(self, project: Project, release: Release):
super().__init__(project, devops=release.devops)
self.repo.set_release(self.project, release)
self.main_branch = release.main_branch
git_api = GitApi()
environment_api = EnvironmentApi()
@ -21,13 +22,13 @@ class ReleaseMixin(DevopsBuild):
release_type_repo = ReleaseTypeRepository.from_git(git_api)
version_repo = VersionRepository(release.config_file)
self.release_repo = ReleaseContextRepository(version_repo, release_type_repo, release.main_branch)
self.release_repo = ReleaseContextRepository(version_repo, release_type_repo)
self.prepare_release_service = PrepareReleaseService()
self.tag_and_push_release_service = TagAndPushReleaseService(git_api)
def prepare_release(self):
release = self.release_repo.get_release()
release = self.release_repo.get_release(self.main_branch)
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)

View file

@ -22,9 +22,9 @@ def test_release_repository(tmp_path):
release_type_repo = ReleaseTypeRepository.from_git(MockGitApi('MINOR test'))
# test
sut = ReleaseContextRepository(version_repo, release_type_repo, 'main')
sut = ReleaseContextRepository(version_repo, release_type_repo)
release = sut.get_release()
release = sut.get_release('main')
assert release is not None