Compare commits

...

5 commits

Author SHA1 Message Date
bom
3bd8497522 WIP Create test_services 2023-02-22 10:58:27 +01:00
bom
9250d366b9 Use newly created version object 2023-02-22 10:58:11 +01:00
bom
e2f562aa8c Remove wildcard import 2023-02-22 10:57:55 +01:00
bom
fea5720161 Return version objects instead of mutating 2023-02-22 10:57:42 +01:00
bom
167eec4620 Make services testable 2023-02-22 10:57:24 +01:00
5 changed files with 62 additions and 18 deletions

View file

@ -4,28 +4,29 @@ from git_repository import GitRepository
class InitReleaseService(): class InitReleaseService():
def __init__(self, commit_id, file): def __init__(self, file):
self.commit_id = commit_id
self.file = file self.file = file
self.version_repo = None self.version_repo = None
def __calculate_release_type(self): def __calculate_release_type(self, commit_string = None):
return GitRepository().get_release_type_from_latest_commit() if commit_string is None:
return GitRepository().get_release_type_from_latest_commit()
else:
return GitRepository.create_from_commit_string(commit_string).get_release_type_from_latest_commit()
def get_version(self, release_type): def get_version(self, release_type):
self.version_repo = VersionRepository(self.file) self.version_repo = VersionRepository(self.file)
return self.version_repo.get_version(release_type) return self.version_repo.get_version(release_type)
def create_release_version(self): def create_release_version(self, commit_string = None):
commit_message = self.read_commit_message(self.commit_id) release_type = self.__calculate_release_type(commit_string)
release_type = self.__calculate_release_type(commit_message)
version = self.get_version(release_type).create_release_version() version = self.get_version(release_type).create_release_version()
self.version_repo.write_file(version.get_version_string()) self.version_repo.write_file(version.get_version_string())
def create_bump_version(self): def create_bump_version(self):
if self.version_repo == None: if self.version_repo == None:
raise Exception('VersionRepo was not created. Did you run create_lease_version()?') raise Exception('VersionRepo was not created. Did you run create_release_version()?')
version = self.get_version(ReleaseType.BUMP).create_bump_version() version = self.get_version(ReleaseType.BUMP).create_bump_version()
self.version_repo.write_file(version.get_version_string()) self.version_repo.write_file(version.get_version_string())

View file

@ -17,7 +17,7 @@ sys.path.append(parent)
# now we can import the module in the parent # now we can import the module in the parent
# directory. # directory.
from git_repository import * from git_repository import GitRepository
from release_type import ReleaseType from release_type import ReleaseType
def test_git_repository(): def test_git_repository():

View file

@ -0,0 +1,39 @@
from pathlib import Path
import sys
import os
# getting the name of the directory
# where the this file is present.
current = os.path.dirname(os.path.realpath(__file__))
# Getting the parent directory name
# where the current directory is present.
parent = os.path.dirname(current)
# adding the parent directory to
# the sys.path.
sys.path.append(parent)
# now we can import the module in the parent
# directory.
from services import InitReleaseService
from release_type import ReleaseType
def test_init_release_service(tmp_path):
# init
file_name = 'config.json'
with open(f'test/resources/{file_name}', 'r') as gradle_file:
contents = gradle_file.read()
f = tmp_path / file_name
f.write_text(contents)
release_service = InitReleaseService(f)
release_service.create_release_version(commit_string='Release MINOR')
assert '"version": "123.124.1"' in f.read_text()
release_service.create_bump_version()
assert '"version": "123.124.2-SNAPSHOT"' in f.read_text()

View file

@ -66,7 +66,7 @@ def test_gradle(tmp_path):
# test # test
repo = VersionRepository(f) repo = VersionRepository(f)
version = repo.get_version(ReleaseType.SNAPSHOT) version = repo.get_version(ReleaseType.SNAPSHOT)
version.create_release_version() version = version.create_release_version()
repo.write_file(version.get_version_string()) repo.write_file(version.get_version_string())
# check # check
@ -84,7 +84,7 @@ def test_json(tmp_path):
# test # test
repo = VersionRepository(f) repo = VersionRepository(f)
version = repo.get_version(ReleaseType.SNAPSHOT) version = repo.get_version(ReleaseType.SNAPSHOT)
version.create_release_version() version = version.create_release_version()
repo.write_file(version.get_version_string()) repo.write_file(version.get_version_string())
# check # check
@ -102,7 +102,7 @@ def test_clojure(tmp_path):
# test # test
repo = VersionRepository(f) repo = VersionRepository(f)
version = repo.get_version(ReleaseType.SNAPSHOT) version = repo.get_version(ReleaseType.SNAPSHOT)
version.create_release_version() version = version.create_release_version()
repo.write_file(version.get_version_string()) repo.write_file(version.get_version_string())
# check # check
@ -120,7 +120,7 @@ def test_python(tmp_path):
# test # test
repo = VersionRepository(f) repo = VersionRepository(f)
version = repo.get_version(ReleaseType.SNAPSHOT) version = repo.get_version(ReleaseType.SNAPSHOT)
version.create_release_version() version = version.create_release_version()
repo.write_file(version.get_version_string()) repo.write_file(version.get_version_string())
# check # check

View file

@ -36,10 +36,14 @@ class Version():
return self.version_string return self.version_string
def create_release_version(self): def create_release_version(self):
if self.release_type == ReleaseType.PATCH: release_version = Version(self.version_list, self.release_type)
self.is_snapshot = False release_version.is_snapshot = self.is_snapshot
else: release_version.increment()
self.increment() return release_version
def create_bump_version(self): def create_bump_version(self):
self.increment(ReleaseType.BUMP) bump_version = Version(self.version_list, self.release_type)
bump_version.is_snapshot = self.is_snapshot
bump_version.release_type = ReleaseType.BUMP
bump_version.increment()
return bump_version