Compare commits
8 commits
7eb7a2647a
...
c137344932
Author | SHA1 | Date | |
---|---|---|---|
c137344932 | |||
fa7e10d3ce | |||
eb998cfdbb | |||
91f3d7d972 | |||
61629e9d97 | |||
ecdea88a6b | |||
88c3acb73c | |||
dac901769d |
4 changed files with 90 additions and 60 deletions
BIN
architecture.png
Normal file
BIN
architecture.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 65 KiB |
32
services.py
32
services.py
|
@ -3,6 +3,7 @@ class InitReleaseService():
|
|||
def __init__(self, commit_id, file):
|
||||
self.commit_id = commit_id
|
||||
self.file = file
|
||||
self.version_repo = None
|
||||
|
||||
def __read_commit_message(self):
|
||||
pass
|
||||
|
@ -10,24 +11,29 @@ class InitReleaseService():
|
|||
def __calculate_release_type(self):
|
||||
pass
|
||||
|
||||
def get_version(self):
|
||||
def get_version_repo(self):
|
||||
self.version_repo = VersionRepository.get(self.file)
|
||||
|
||||
current_version = VersionRepository.get_current_version(self.file)
|
||||
commit_message = self.read_commit_message(self.commit_id)
|
||||
release_type = self.calculate_release_type(commit_message)
|
||||
|
||||
release_version = create_release_version(current_version,release_type)
|
||||
bump_version = create_bump_version(current_version,release_type)
|
||||
|
||||
release_and_bump_version = tuple(release_version, bump_version)
|
||||
|
||||
return release_and_bump_version
|
||||
def get_version_list(self):
|
||||
self.get_version_repo()
|
||||
return self.version_repo.version_list
|
||||
|
||||
def create_release_version(self):
|
||||
pass
|
||||
commit_message = self.read_commit_message(self.commit_id)
|
||||
release_type = self.calculate_release_type(commit_message)
|
||||
version_list = self.get_version_list()
|
||||
|
||||
release_version = Version.create_release_version(version_list, release_type)
|
||||
self.version_repo.write_file(release_version.get_version_string())
|
||||
|
||||
def create_bump_version(self):
|
||||
pass
|
||||
if self.version_repo == None:
|
||||
raise Exception('VersionRepo was not created. Did you run create_lease_version()?')
|
||||
version_list = self.get_version_list()
|
||||
|
||||
bump_version = Version.create_bump_version(version_list)
|
||||
self.version_repo.write_file(bump_version.get_version_string())
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
81
version.py
81
version.py
|
@ -3,8 +3,8 @@ from file_handlers import FileHandler
|
|||
|
||||
def init_project():
|
||||
# validate_values()
|
||||
version = Version.from_file('build.gradle')
|
||||
version.increment(ReleaseLevel.SNAPSHOT)
|
||||
version = Version.from_file('build.gradle')
|
||||
version.increment(ReleaseType.SNAPSHOT)
|
||||
version.to_file()
|
||||
print(version.get())
|
||||
|
||||
|
@ -14,51 +14,54 @@ def prepare_release():
|
|||
def release_in_git():
|
||||
pass
|
||||
|
||||
class ReleaseLevel(Enum):
|
||||
class ReleaseType(Enum):
|
||||
MAJOR = 0
|
||||
MINOR = 1
|
||||
PATCH = 2
|
||||
SNAPSHOT = 3
|
||||
BUMP = None
|
||||
|
||||
class Version():
|
||||
|
||||
def __init__(self, version, is_snapshot):
|
||||
self.version = version
|
||||
self.is_snapshot = is_snapshot
|
||||
self.file_handler = None
|
||||
def __init__(self, version_list, release_type):
|
||||
self.version_list = None
|
||||
self.version_string = None
|
||||
self.is_snapshot = None
|
||||
|
||||
def increment(self, release_type: ReleaseType):
|
||||
self.is_snapshot = False
|
||||
match release_type:
|
||||
case ReleaseType.BUMP:
|
||||
self.is_snapshot = True
|
||||
self.version_list[ReleaseType.PATCH.value] += 1
|
||||
case ReleaseType.SNAPSHOT:
|
||||
self.is_snapshot = True
|
||||
case ReleaseType.PATCH:
|
||||
self.version_list[ReleaseType.PATCH.value] += 1
|
||||
case ReleaseType.MINOR:
|
||||
self.version_list[ReleaseType.PATCH.value] = 0
|
||||
self.version_list[ReleaseType.MINOR.value] += 1
|
||||
case ReleaseType.MAJOR:
|
||||
self.version_list[ReleaseType.PATCH.value] = 0
|
||||
self.version_list[ReleaseType.MINOR.value] = 0
|
||||
self.version_list[ReleaseType.MAJOR.value] += 1
|
||||
|
||||
def get_version_string(self) -> str:
|
||||
self.version_string = ".".join([str(x) for x in self.version_list])
|
||||
if self.is_snapshot:
|
||||
self.version_string += "-SNAPSHOT"
|
||||
|
||||
@classmethod
|
||||
def from_file(cls, config_file_path):
|
||||
file_handler = FileHandler.from_file_path(config_file_path)
|
||||
version, is_snapshot = file_handler.parse()
|
||||
inst = cls(version, is_snapshot)
|
||||
inst.file_handler = file_handler
|
||||
|
||||
def create_release_version(cls, version_list, release_type):
|
||||
inst = cls(version_list, release_type)
|
||||
if release_type == ReleaseType.PATCH:
|
||||
inst.is_snapshot = False
|
||||
else:
|
||||
inst.increment(release_type)
|
||||
return inst
|
||||
|
||||
def to_file(self):
|
||||
if self.file_handler is None:
|
||||
raise Exception('Version was not created by from_file method.')
|
||||
else:
|
||||
self.file_handler.write(self.get())
|
||||
|
||||
def increment(self, level: ReleaseLevel):
|
||||
self.is_snapshot = False
|
||||
match level:
|
||||
case ReleaseLevel.SNAPSHOT:
|
||||
self.is_snapshot = True
|
||||
case ReleaseLevel.PATCH:
|
||||
self.version[ReleaseLevel.PATCH.value] += 1
|
||||
case ReleaseLevel.MINOR:
|
||||
self.version[ReleaseLevel.PATCH.value] = 0
|
||||
self.version[ReleaseLevel.MINOR.value] += 1
|
||||
case ReleaseLevel.MAJOR:
|
||||
self.version[ReleaseLevel.PATCH.value] = 0
|
||||
self.version[ReleaseLevel.MINOR.value] = 0
|
||||
self.version[ReleaseLevel.MAJOR.value] += 1
|
||||
|
||||
def get(self) -> str:
|
||||
version_string = ".".join([str(x) for x in self.version])
|
||||
if self.is_snapshot:
|
||||
version_string += "-SNAPSHOT"
|
||||
return version_string
|
||||
@classmethod
|
||||
def create_bump_version(cls, version_list):
|
||||
inst = cls(version_list, ReleaseType.BUMP)
|
||||
inst.increment(release_type)
|
||||
return inst
|
||||
|
|
|
@ -4,14 +4,35 @@ class VersionRepository():
|
|||
|
||||
def __init__(self, file):
|
||||
self.file = file
|
||||
self.file_handler = None
|
||||
self.version_list = None
|
||||
self.is_snapshot = None
|
||||
|
||||
def load_file(self):
|
||||
self.file_handler = FileHandler.from_file_path(self.file)
|
||||
return file_handler
|
||||
|
||||
def write_file(self, version_string):
|
||||
if self.file_handler is None:
|
||||
raise Exception('Version was not created by load_file method.')
|
||||
if self.version_list is None or self.is_snapshot is None:
|
||||
raise Exception('Version or is_snapshot attribute not set.')
|
||||
else:
|
||||
self.file_handler.write(version_string)
|
||||
|
||||
def parse_file(self, file_handler):
|
||||
version_list, is_snapshot = file_handler.parse()
|
||||
return version_list, is_snapshot
|
||||
|
||||
@classmethod
|
||||
def load_file(cls, file):
|
||||
file_handler = FileHandler.from_file_path(file)
|
||||
version, is_snapshot = file_handler.parse()
|
||||
inst = cls(version, is_snapshot)
|
||||
inst.file_handler = file_handler
|
||||
|
||||
return inst
|
||||
def get(cls, file) -> VersionRepository:
|
||||
inst = cls(file)
|
||||
|
||||
|
||||
file_handler= inst.load_file(file)
|
||||
version_list, is_snapshot = inst.parse_file(file_handler)
|
||||
|
||||
inst.version_list = version_list
|
||||
inst.is_snapshot = is_snapshot
|
||||
inst.file_handler = file_handler
|
||||
|
||||
return inst
|
||||
|
|
Loading…
Reference in a new issue