finish version

This commit is contained in:
Michael Jerger 2023-05-10 19:37:15 +02:00
parent d38c2baaa1
commit 2e2c04c8ba
3 changed files with 53 additions and 3 deletions

View file

@ -51,8 +51,8 @@ classDiagram
get_version_string()
create_major()
create_minor()
create_patchn()
create_bump()
create_patch()
create_bump(snapshot_suffix)
}
Devops *-- "0..1" Image: spcialized_builds

View file

@ -50,6 +50,15 @@ class Version(Validateable):
result += [f"version_string not parsed correct. Input was {self.version_string} parsed was {self.to_string()}"]
return result
def create_bump(self, snapshot_suffix: str = None):
new_version_list = self.version_list.copy()
if self.is_snapshot():
return Version(new_version_list, snapshot_suffix=self.snapshot_suffix, version_str=None)
else:
new_version_list[2] = 0
new_version_list[1] += 1
return Version(new_version_list, snapshot_suffix=snapshot_suffix, version_str=None)
def create_patch(self):
new_version_list = self.version_list.copy()
if self.is_snapshot():
@ -66,3 +75,13 @@ class Version(Validateable):
new_version_list[2] = 0
new_version_list[1] += 1
return Version(new_version_list, snapshot_suffix=None, version_str=None)
def create_major(self):
new_version_list = self.version_list.copy()
if self.is_snapshot() and new_version_list[2] == 0 and new_version_list[1] == 0 :
return Version(new_version_list, snapshot_suffix=None, version_str=None)
else:
new_version_list[2] = 0
new_version_list[1] = 0
new_version_list[0] += 1
return Version(new_version_list, snapshot_suffix=None, version_str=None)

View file

@ -79,3 +79,34 @@ def test_should_create_minor():
version = Version.from_str("1.3.0")
sut = version.create_minor()
assert sut.to_string() == "1.4.0"
def test_should_create_major():
version = Version.from_str("1.2.3-SNAPSHOT")
sut = version.create_major()
assert sut.to_string() == "2.0.0"
version = Version.from_str("1.2.3")
sut = version.create_major()
assert sut.to_string() == "2.0.0"
version = Version.from_str("1.0.0-SNAPSHOT")
sut = version.create_major()
assert sut.to_string() == "1.0.0"
version = Version.from_str("1.0.0")
sut = version.create_major()
assert sut.to_string() == "2.0.0"
def test_should_create_bump():
version = Version.from_str("1.2.3-SNAPSHOT")
sut = version.create_bump()
assert sut.to_string() == "1.2.3-SNAPSHOT"
version = Version.from_str("1.2.3")
sut = version.create_bump("SNAPSHOT")
assert sut.to_string() == "1.3.0-SNAPSHOT"
version = Version.from_str("1.0.0")
sut = version.create_bump("SNAPSHOT")
assert sut.to_string() == "1.1.0-SNAPSHOT"