Make ReleaseContextRepository stateless
This commit is contained in:
parent
f4fed5293a
commit
d801a71b49
3 changed files with 7 additions and 9 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue