2023-02-24 09:31:04 +00:00
|
|
|
from domain import Release, Version, ReleaseType
|
2023-03-02 14:08:41 +00:00
|
|
|
from infrastructure_api import FileHandler
|
2023-02-24 09:31:04 +00:00
|
|
|
|
|
|
|
class VersionRepository():
|
|
|
|
|
|
|
|
def __init__(self, file):
|
|
|
|
self.file = file
|
|
|
|
self.file_handler = None
|
|
|
|
|
|
|
|
def load_file(self):
|
|
|
|
self.file_handler = FileHandler.from_file_path(self.file)
|
|
|
|
return self.file_handler
|
|
|
|
|
|
|
|
def write_file(self, version_string):
|
|
|
|
if self.file_handler is None:
|
|
|
|
raise Exception('Version was not created by load_file method.')
|
|
|
|
else:
|
|
|
|
self.file_handler.write(version_string)
|
|
|
|
|
|
|
|
def parse_file(self):
|
|
|
|
version_list, is_snapshot = self.file_handler.parse()
|
|
|
|
return version_list, is_snapshot
|
|
|
|
|
|
|
|
def get_version(self) -> Version:
|
|
|
|
|
|
|
|
self.file_handler = self.load_file()
|
|
|
|
version_list, is_snapshot = self.parse_file()
|
2023-02-28 12:25:47 +00:00
|
|
|
version = Version(self.file, version_list)
|
2023-02-24 09:31:04 +00:00
|
|
|
version.is_snapshot = is_snapshot
|
|
|
|
|
|
|
|
return version
|
2023-02-24 09:14:26 +00:00
|
|
|
|
2023-02-24 09:31:04 +00:00
|
|
|
class ReleaseTypeRepository():
|
2023-02-24 09:46:43 +00:00
|
|
|
def __init__(self, git_api, environment_api=None):
|
|
|
|
self.git_api = git_api
|
2023-02-24 09:31:04 +00:00
|
|
|
|
2023-02-24 09:46:43 +00:00
|
|
|
def get_release_type(self):
|
|
|
|
latest_commit = self.git_api.get_latest_commit()
|
2023-02-24 09:31:04 +00:00
|
|
|
|
2023-02-24 09:46:43 +00:00
|
|
|
if ReleaseType.MAJOR.name in latest_commit.upper():
|
2023-02-24 09:31:04 +00:00
|
|
|
return ReleaseType.MAJOR
|
2023-02-24 09:46:43 +00:00
|
|
|
elif ReleaseType.MINOR.name in latest_commit.upper():
|
2023-02-24 09:31:04 +00:00
|
|
|
return ReleaseType.MINOR
|
2023-02-24 09:46:43 +00:00
|
|
|
elif ReleaseType.PATCH.name in latest_commit.upper():
|
2023-02-24 09:31:04 +00:00
|
|
|
return ReleaseType.PATCH
|
2023-02-24 09:46:43 +00:00
|
|
|
elif ReleaseType.SNAPSHOT.name in latest_commit.upper():
|
2023-02-24 09:31:04 +00:00
|
|
|
return ReleaseType.SNAPSHOT
|
|
|
|
else:
|
|
|
|
return None
|
2023-02-24 10:02:11 +00:00
|
|
|
|
|
|
|
class ReleaseRepository():
|
2023-02-28 12:25:47 +00:00
|
|
|
def __init__(self, version_repository: VersionRepository, release_type_repository: ReleaseTypeRepository, main_branch: str):
|
2023-02-24 10:02:11 +00:00
|
|
|
self.version_repository = version_repository
|
|
|
|
self.release_type_repository = release_type_repository
|
2023-02-28 12:25:47 +00:00
|
|
|
self.main_branch = main_branch
|
2023-02-24 10:02:11 +00:00
|
|
|
|
2023-02-24 10:39:38 +00:00
|
|
|
def get_release(self) -> Release:
|
2023-02-28 12:25:47 +00:00
|
|
|
return Release(self.release_type_repository.get_release_type(), self.version_repository.get_version(), self.main_branch)
|