Initial commit

This commit is contained in:
Xevion
2022-06-18 12:54:17 -05:00
commit f770eccb26
4 changed files with 113 additions and 0 deletions

21
LICENSE Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2022 Ryan Walters
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

42
database.py Normal file
View File

@@ -0,0 +1,42 @@
"""
Manages all behavior related to reading and writing commits to the internal database.
"""
import logging
import sqlite3
from typing import Optional
logger = logging.getLogger(__name__)
class Database:
"""
Operates and handles reading/writing to the local commit database.
"""
def __init__(self) -> None:
logger.debug('Initializing...')
self.__is_closed: bool = True # Becomes false after this statement.
self.conn: Optional[sqlite3.Connection] = None
self.open()
def open(self) -> None:
"""Opens a connection to the database file."""
if self.__is_closed:
logger.debug('Opening new database connection.')
self.conn = sqlite3.connect('commits.db')
self.__is_closed = False
def close(self) -> None:
"""Closes the currently active database connection."""
if self.__is_closed:
logger.warning('Attempted to close while database connection is already closed...')
else:
logger.debug('Closing database connection.')
self.conn.close()
self.conn = None
self.__is_closed = True
def check_exists(self, id: str) -> bool:
"""Returns true if the commit in question exists."""
return False

36
main.py Normal file
View File

@@ -0,0 +1,36 @@
import logging
from logging.handlers import TimedRotatingFileHandler
from typing import List
from rich.logging import RichHandler
from database import Database
from models import Commit
from sources import Gitlab
logging.basicConfig(level=logging.WARNING, handlers=[
RichHandler(),
TimedRotatingFileHandler(filename='recommit-log', backupCount=25)
])
logger = logging.getLogger(__name__)
sources = [Gitlab()]
def main() -> None:
"""The main method for this application. When executed, it will use all available sources and create commits to act as contributions."""
logger.info('Starting recommit.')
commits: List[Commit] = []
db = Database()
# TODO: Fetch all commits from the available sources
# TODO: Check that the commit has been written
# TODO: Write commits into the git log
# TODO: Push to GitHub
logger.info('Shutting down.')
if __name__ == '__main__':
main()

14
models.py Normal file
View File

@@ -0,0 +1,14 @@
from dataclasses import dataclass
from datetime import datetime
@dataclass
class Commit:
"""Describes a specific commit event in time."""
# A unique identifier for this commit. Not necessarily the commit hash.
id: int
# A name, description etc. for this commit. Not required to be based on the original comit message.
name: str
# A timestamp
timestamp: datetime