Compare commits

..

No commits in common. "3bd8497522e90901898a68dc092d0e3d527bd4dc" and "e578878b82019af7f4ac7811c379a3db116fb8dc" have entirely different histories.

5 changed files with 18 additions and 62 deletions

View file

@ -4,29 +4,28 @@ from git_repository import GitRepository
class InitReleaseService():
def __init__(self, file):
def __init__(self, commit_id, file):
self.commit_id = commit_id
self.file = file
self.version_repo = None
def __calculate_release_type(self, commit_string = None):
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 __calculate_release_type(self):
return GitRepository().get_release_type_from_latest_commit()
def get_version(self, release_type):
self.version_repo = VersionRepository(self.file)
return self.version_repo.get_version(release_type)
def create_release_version(self, commit_string = None):
release_type = self.__calculate_release_type(commit_string)
def create_release_version(self):
commit_message = self.read_commit_message(self.commit_id)
release_type = self.__calculate_release_type(commit_message)
version = self.get_version(release_type).create_release_version()
self.version_repo.write_file(version.get_version_string())
def create_bump_version(self):
if self.version_repo == None:
raise Exception('VersionRepo was not created. Did you run create_release_version()?')
raise Exception('VersionRepo was not created. Did you run create_lease_version()?')
version = self.get_version(ReleaseType.BUMP).create_bump_version()
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
# directory.
from git_repository import GitRepository
from git_repository import *
from release_type import ReleaseType
def test_git_repository():

View file

@ -1,39 +0,0 @@
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
repo = VersionRepository(f)
version = repo.get_version(ReleaseType.SNAPSHOT)
version = version.create_release_version()
version.create_release_version()
repo.write_file(version.get_version_string())
# check
@ -84,7 +84,7 @@ def test_json(tmp_path):
# test
repo = VersionRepository(f)
version = repo.get_version(ReleaseType.SNAPSHOT)
version = version.create_release_version()
version.create_release_version()
repo.write_file(version.get_version_string())
# check
@ -102,7 +102,7 @@ def test_clojure(tmp_path):
# test
repo = VersionRepository(f)
version = repo.get_version(ReleaseType.SNAPSHOT)
version = version.create_release_version()
version.create_release_version()
repo.write_file(version.get_version_string())
# check
@ -120,7 +120,7 @@ def test_python(tmp_path):
# test
repo = VersionRepository(f)
version = repo.get_version(ReleaseType.SNAPSHOT)
version = version.create_release_version()
version.create_release_version()
repo.write_file(version.get_version_string())
# check

View file

@ -36,14 +36,10 @@ class Version():
return self.version_string
def create_release_version(self):
release_version = Version(self.version_list, self.release_type)
release_version.is_snapshot = self.is_snapshot
release_version.increment()
return release_version
if self.release_type == ReleaseType.PATCH:
self.is_snapshot = False
else:
self.increment()
def create_bump_version(self):
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
self.increment(ReleaseType.BUMP)