Compare commits
No commits in common. "3bd8497522e90901898a68dc092d0e3d527bd4dc" and "e578878b82019af7f4ac7811c379a3db116fb8dc" have entirely different histories.
3bd8497522
...
e578878b82
5 changed files with 18 additions and 62 deletions
15
services.py
15
services.py
|
@ -4,29 +4,28 @@ from git_repository import GitRepository
|
||||||
|
|
||||||
class InitReleaseService():
|
class InitReleaseService():
|
||||||
|
|
||||||
def __init__(self, file):
|
def __init__(self, commit_id, 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, commit_string = None):
|
def __calculate_release_type(self):
|
||||||
if commit_string is None:
|
|
||||||
return GitRepository().get_release_type_from_latest_commit()
|
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, commit_string = None):
|
def create_release_version(self):
|
||||||
release_type = self.__calculate_release_type(commit_string)
|
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()
|
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_release_version()?')
|
raise Exception('VersionRepo was not created. Did you run create_lease_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())
|
||||||
|
|
|
@ -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 GitRepository
|
from git_repository import *
|
||||||
from release_type import ReleaseType
|
from release_type import ReleaseType
|
||||||
|
|
||||||
def test_git_repository():
|
def test_git_repository():
|
||||||
|
|
|
@ -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()
|
|
|
@ -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 = version.create_release_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 = version.create_release_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 = version.create_release_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 = version.create_release_version()
|
version.create_release_version()
|
||||||
repo.write_file(version.get_version_string())
|
repo.write_file(version.get_version_string())
|
||||||
|
|
||||||
# check
|
# check
|
||||||
|
|
14
version.py
14
version.py
|
@ -36,14 +36,10 @@ class Version():
|
||||||
return self.version_string
|
return self.version_string
|
||||||
|
|
||||||
def create_release_version(self):
|
def create_release_version(self):
|
||||||
release_version = Version(self.version_list, self.release_type)
|
if self.release_type == ReleaseType.PATCH:
|
||||||
release_version.is_snapshot = self.is_snapshot
|
self.is_snapshot = False
|
||||||
release_version.increment()
|
else:
|
||||||
return release_version
|
self.increment()
|
||||||
|
|
||||||
def create_bump_version(self):
|
def create_bump_version(self):
|
||||||
bump_version = Version(self.version_list, self.release_type)
|
self.increment(ReleaseType.BUMP)
|
||||||
bump_version.is_snapshot = self.is_snapshot
|
|
||||||
bump_version.release_type = ReleaseType.BUMP
|
|
||||||
bump_version.increment()
|
|
||||||
return bump_version
|
|
||||||
|
|
Loading…
Reference in a new issue