From 33fdf3073a236e477f9a752b6b7f215749dddcaf Mon Sep 17 00:00:00 2001 From: erik Date: Wed, 22 Feb 2023 10:26:49 +0100 Subject: [PATCH] Rename for consitency --- git_handler.py | 34 ---------------------------------- git_repository.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 34 deletions(-) delete mode 100644 git_handler.py create mode 100644 git_repository.py diff --git a/git_handler.py b/git_handler.py deleted file mode 100644 index 95d2915..0000000 --- a/git_handler.py +++ /dev/null @@ -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() diff --git a/git_repository.py b/git_repository.py new file mode 100644 index 0000000..83c9ea5 --- /dev/null +++ b/git_repository.py @@ -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 +