Merge branch 'totally-awesome-releasecontxtrepository-changes' into 'ddd-intro'

ReleaseContextRepository changes

See merge request domaindrivenarchitecture/dda-devops-build!10
This commit is contained in:
Mattis Böckle 2023-04-28 12:22:51 +00:00
commit f8df51b075
4 changed files with 13 additions and 12 deletions

View file

@ -18,6 +18,11 @@ class Validateable:
def is_valid(self) -> bool:
return len(self.validate()) < 1
def throw_if_invalid(self):
if not self.is_valid():
issues = '\n'.join(self.validate())
raise ValueError(f"Invalid Validateable: {issues}")
class DnsRecord(Validateable):

View file

@ -106,25 +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,
)
if not result.is_valid():
issues = '\n'.join(result.validate())
raise ValueError(f"invalid release: {issues}")
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