Make ReleaseContextRepository stateless
This commit is contained in:
parent
b6b283d2b2
commit
a25453cdbf
3 changed files with 7 additions and 9 deletions
|
@ -106,23 +106,20 @@ class ReleaseTypeRepository:
|
||||||
raise ValueError("No valid api passed to ReleaseTypeRepository")
|
raise ValueError("No valid api passed to ReleaseTypeRepository")
|
||||||
|
|
||||||
|
|
||||||
# TODO: Repo has state & repository should exist only for AggregateRoot
|
|
||||||
class ReleaseContextRepository:
|
class ReleaseContextRepository:
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
version_repository: VersionRepository,
|
version_repository: VersionRepository,
|
||||||
release_type_repository: ReleaseTypeRepository,
|
release_type_repository: ReleaseTypeRepository,
|
||||||
main_branch: str,
|
|
||||||
):
|
):
|
||||||
self.version_repository = version_repository
|
self.version_repository = version_repository
|
||||||
self.release_type_repository = release_type_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(
|
result = ReleaseContext(
|
||||||
self.release_type_repository.get_release_type(),
|
self.release_type_repository.get_release_type(),
|
||||||
self.version_repository.get_version(),
|
self.version_repository.get_version(),
|
||||||
self.main_branch,
|
main_branch,
|
||||||
)
|
)
|
||||||
result.throw_if_invalid()
|
result.throw_if_invalid()
|
||||||
return result
|
return result
|
||||||
|
|
|
@ -9,6 +9,7 @@ class ReleaseMixin(DevopsBuild):
|
||||||
def __init__(self, project: Project, release: Release):
|
def __init__(self, project: Project, release: Release):
|
||||||
super().__init__(project, devops=release.devops)
|
super().__init__(project, devops=release.devops)
|
||||||
self.repo.set_release(self.project, release)
|
self.repo.set_release(self.project, release)
|
||||||
|
self.main_branch = release.main_branch
|
||||||
|
|
||||||
git_api = GitApi()
|
git_api = GitApi()
|
||||||
environment_api = EnvironmentApi()
|
environment_api = EnvironmentApi()
|
||||||
|
@ -21,13 +22,13 @@ class ReleaseMixin(DevopsBuild):
|
||||||
release_type_repo = ReleaseTypeRepository.from_git(git_api)
|
release_type_repo = ReleaseTypeRepository.from_git(git_api)
|
||||||
|
|
||||||
version_repo = VersionRepository(release.config_file)
|
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.prepare_release_service = PrepareReleaseService()
|
||||||
self.tag_and_push_release_service = TagAndPushReleaseService(git_api)
|
self.tag_and_push_release_service = TagAndPushReleaseService(git_api)
|
||||||
|
|
||||||
def prepare_release(self):
|
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_release(release, self.release_repo.version_repository)
|
||||||
self.prepare_release_service.write_and_commit_bump(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'))
|
release_type_repo = ReleaseTypeRepository.from_git(MockGitApi('MINOR test'))
|
||||||
|
|
||||||
# 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
|
assert release is not None
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue