Compare commits
5 commits
0b3daf595a
...
e578878b82
Author | SHA1 | Date | |
---|---|---|---|
e578878b82 | |||
f94d1879dc | |||
33fdf3073a | |||
ff4cb70266 | |||
ac564ade7e |
6 changed files with 104 additions and 71 deletions
|
@ -1,34 +0,0 @@
|
|||
import os
|
||||
import subprocess as sub
|
||||
from system_repository import SystemRepository
|
||||
from release_type import ReleaseType
|
||||
|
||||
# define semantics for release types by commit messages
|
||||
## snapshot - snapshot release
|
||||
## fix/patch - patch release
|
||||
## bump - version bump release
|
||||
## feature/feat/minor - minor release
|
||||
## major/breaking - major release
|
||||
|
||||
GIT = 'git'
|
||||
LOG = 'log'
|
||||
FORMAT = '"%h %s"'
|
||||
FORMAT_DEC = "%d"
|
||||
PRETTY_OPTION = '--pretty='
|
||||
DECORATE_OPTION = '--decorate=full'
|
||||
|
||||
|
||||
# git log --oneline --format="%s %b" origin/master...HEAD
|
||||
|
||||
class GitRepo():
|
||||
|
||||
def __init__(self):
|
||||
self.latest_commit = None
|
||||
self.system_repository = SystemRepository()
|
||||
|
||||
def get_latest_commit(self):
|
||||
self.latest_commit = self.system_repository.run_checked('git', 'log', '--oneline', '--format="%s %b"', '-n' + '1')
|
||||
|
||||
def get_release_type_from_latest_commit(self):
|
||||
if self.latest_commit is None:
|
||||
self.get_latest_commit()
|
35
git_repository.py
Normal file
35
git_repository.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
import os
|
||||
import subprocess as sub
|
||||
from system_repository import SystemRepository
|
||||
from release_type import ReleaseType
|
||||
|
||||
class GitRepository():
|
||||
|
||||
def __init__(self):
|
||||
self.latest_commit = None
|
||||
self.system_repository = SystemRepository()
|
||||
|
||||
@classmethod
|
||||
def create_from_commit_string(cls, commit_string):
|
||||
inst = cls()
|
||||
inst.latest_commit = commit_string
|
||||
return inst
|
||||
|
||||
def get_latest_commit(self):
|
||||
self.latest_commit = self.system_repository.run_checked('git', 'log', '--oneline', '--format="%s %b"', '-n' + '1')
|
||||
|
||||
def get_release_type_from_latest_commit(self):
|
||||
if self.latest_commit is None:
|
||||
self.get_latest_commit()
|
||||
|
||||
if ReleaseType.MAJOR.name in self.latest_commit.upper():
|
||||
return ReleaseType.MAJOR
|
||||
elif ReleaseType.MINOR.name in self.latest_commit.upper():
|
||||
return ReleaseType.MINOR
|
||||
elif ReleaseType.PATCH.name in self.latest_commit.upper():
|
||||
return ReleaseType.PATCH
|
||||
elif ReleaseType.SNAPSHOT.name in self.latest_commit.upper():
|
||||
return ReleaseType.SNAPSHOT
|
||||
else:
|
||||
return None
|
||||
|
12
services.py
12
services.py
|
@ -1,26 +1,24 @@
|
|||
from version_repository import VersionRepository
|
||||
from release_type import ReleaseType
|
||||
from git_repository import GitRepository
|
||||
|
||||
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
|
||||
self.version_repo = None
|
||||
|
||||
def __calculate_release_type(self):
|
||||
pass
|
||||
|
||||
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_message = self.read_commit_message(self.commit_id)
|
||||
release_type = self.calculate_release_type(commit_message)
|
||||
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())
|
||||
|
|
|
@ -1,30 +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 git_handler import *
|
||||
|
||||
def test_git_handler():
|
||||
|
||||
# init
|
||||
repo = GitRepo()
|
||||
repo.get_commits()
|
||||
|
||||
#test
|
||||
assert type(repo.commits) == dict
|
||||
assert repo.commits["decd36b"] == ["(tag:refs/tags/TEST)", "Initial commit"]
|
64
test/test_git_repository.py
Normal file
64
test/test_git_repository.py
Normal file
|
@ -0,0 +1,64 @@
|
|||
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 git_repository import *
|
||||
from release_type import ReleaseType
|
||||
|
||||
def test_git_repository():
|
||||
|
||||
# init
|
||||
commit_string = "Major bla"
|
||||
repo = GitRepository.create_from_commit_string(commit_string)
|
||||
release_type = repo.get_release_type_from_latest_commit()
|
||||
|
||||
#test
|
||||
assert release_type == ReleaseType.MAJOR
|
||||
|
||||
|
||||
# init
|
||||
commit_string = "MINOR bla"
|
||||
repo = GitRepository.create_from_commit_string(commit_string)
|
||||
release_type = repo.get_release_type_from_latest_commit()
|
||||
|
||||
#test
|
||||
assert release_type == ReleaseType.MINOR
|
||||
|
||||
# init
|
||||
commit_string = "PATCH bla"
|
||||
repo = GitRepository.create_from_commit_string(commit_string)
|
||||
release_type = repo.get_release_type_from_latest_commit()
|
||||
|
||||
# test
|
||||
assert release_type == ReleaseType.PATCH
|
||||
|
||||
# init
|
||||
commit_string = "SNAPSHOT bla"
|
||||
repo = GitRepository.create_from_commit_string(commit_string)
|
||||
release_type = repo.get_release_type_from_latest_commit()
|
||||
|
||||
#test
|
||||
assert release_type == ReleaseType.SNAPSHOT
|
||||
|
||||
# init
|
||||
commit_string = "bla"
|
||||
repo = GitRepository.create_from_commit_string(commit_string)
|
||||
release_type = repo.get_release_type_from_latest_commit()
|
||||
|
||||
#test
|
||||
assert release_type == None
|
0
test/test_services.py
Normal file
0
test/test_services.py
Normal file
Loading…
Reference in a new issue