terraformDummyRepo/git_repository.py

36 lines
1.1 KiB
Python
Raw Normal View History

2023-02-22 09:26:49 +00:00
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