Merge branch 'totally-awesome-releasecontxtrepository-changes' into 'ddd-intro'
ReleaseContextRepository changes See merge request domaindrivenarchitecture/dda-devops-build!10
This commit is contained in:
commit
f8df51b075
4 changed files with 13 additions and 12 deletions
|
@ -19,6 +19,11 @@ class Validateable:
|
||||||
def is_valid(self) -> bool:
|
def is_valid(self) -> bool:
|
||||||
return len(self.validate()) < 1
|
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):
|
class DnsRecord(Validateable):
|
||||||
def __init__(self, fqdn, ipv4=None, ipv6=None):
|
def __init__(self, fqdn, ipv4=None, ipv6=None):
|
||||||
|
|
|
@ -106,25 +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,
|
||||||
)
|
)
|
||||||
if not result.is_valid():
|
result.throw_if_invalid()
|
||||||
issues = '\n'.join(result.validate())
|
|
||||||
raise ValueError(f"invalid release: {issues}")
|
|
||||||
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