2023-02-24 09:31:04 +00:00
|
|
|
from domain import Release, Version, ReleaseType
|
2023-02-24 09:46:43 +00:00
|
|
|
from infrastructure_api import FileHandler, SystemAPI, GitApi
|
2023-02-24 09:31:04 +00:00
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
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()
|
|
|
|
version = Version(version_list)
|
|
|
|
version.is_snapshot = is_snapshot
|
|
|
|
|
|
|
|
return version
|
2023-02-24 09:14:26 +00:00
|
|
|
|
|
|
|
class ReleaseRepository():
|
2023-02-24 09:31:04 +00:00
|
|
|
def __init__(self, version_repository: VersionRepository):
|
|
|
|
self.version_repository = version_repository
|
|
|
|
|
|
|
|
def get_current_release(self) -> Release:
|
|
|
|
pass
|
|
|
|
|
|
|
|
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
|