Added /status command
This commit is contained in:
@@ -9,5 +9,6 @@ from .autocomplete_utils import (
|
||||
from .cache_utils import restore_from_cache
|
||||
from .datetime_utils import get_unix_timestamp
|
||||
from .event_utils import validate_event_validity
|
||||
from .git_utils import get_current_commit
|
||||
from .logging_utils import get_logger, get_logging_config
|
||||
from .validation_utils import is_event_status_valid, is_operation_confirmed
|
||||
|
27
modules/utils/git_utils.py
Normal file
27
modules/utils/git_utils.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from pathlib import Path
|
||||
|
||||
import aiofiles
|
||||
|
||||
|
||||
# TODO Add documentation
|
||||
async def get_current_commit() -> str | None:
|
||||
head_path: Path = Path(".git/HEAD")
|
||||
|
||||
if not head_path.exists():
|
||||
return None
|
||||
|
||||
async with aiofiles.open(head_path, "r", encoding="utf-8") as head_file:
|
||||
head_content: str = (await head_file.read()).strip()
|
||||
|
||||
if not head_content.startswith("ref:"):
|
||||
return head_content
|
||||
|
||||
head_ref_path: Path = Path(".git/").joinpath(" ".join(head_content.split(" ")[1:]))
|
||||
|
||||
if not head_ref_path.exists():
|
||||
return None
|
||||
|
||||
async with aiofiles.open(head_ref_path, "r", encoding="utf-8") as head_ref_file:
|
||||
head_ref_content: str = (await head_ref_file.read()).strip()
|
||||
|
||||
return head_ref_content
|
Reference in New Issue
Block a user