mirror of
https://github.com/Xevion/recommit.git
synced 2025-12-06 01:16:00 -06:00
Embed logger, session object and identifier property initializer in CommitSource baseclass
This commit is contained in:
21
sources.py
21
sources.py
@@ -12,11 +12,29 @@ from models import Commit
|
||||
class CommitSource(abc.ABC):
|
||||
"""A simple abstract class for representing different commit sources generally."""
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.session = requests.Session()
|
||||
|
||||
@abc.abstractmethod
|
||||
def fetch(self, check_function: Callable) -> List[Commit]:
|
||||
"""Fetch commits from the source."""
|
||||
pass
|
||||
|
||||
@property
|
||||
@abc.abstractmethod
|
||||
def source_type(self) -> str:
|
||||
"""Specifies the source type for storage in a database."""
|
||||
pass
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
"""Returns the name of this class."""
|
||||
return type(self).__name__
|
||||
|
||||
def getLogger(self, name: Optional[str] = None) -> logging.Logger:
|
||||
"""Returns a new instance of a Logger"""
|
||||
return logging.getLogger(name or self.name.lower())
|
||||
|
||||
|
||||
class Gitlab(CommitSource):
|
||||
"""Serves as the commit source for GitLab."""
|
||||
@@ -25,6 +43,9 @@ class Gitlab(CommitSource):
|
||||
API_KEY_CONSTANT: str = 'GITLAB_API_KEY'
|
||||
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
self.logger: logging.Logger = self.getLogger()
|
||||
self.__api_key: str = config(self.API_KEY_CONSTANT)
|
||||
self.__username: str = config(self.USERNAME_CONSTANT)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user