diff options
| author | 2020-02-03 23:00:53 +0000 | |
|---|---|---|
| committer | 2020-02-03 23:00:53 +0000 | |
| commit | 7a15e5b2bf314093d6ce36ae56832a793712113a (patch) | |
| tree | 7722676b96e6b2a7043478849a1757d48bb94a2e /src/utils | |
| parent | actually return gitlab _note result (diff) | |
| signature | ||
store timestamp and current git commit when loading a module
Diffstat (limited to 'src/utils')
| -rw-r--r-- | src/utils/__init__.py | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/utils/__init__.py b/src/utils/__init__.py index 303c70c5..7180766b 100644 --- a/src/utils/__init__.py +++ b/src/utils/__init__.py @@ -1,5 +1,5 @@ -import contextlib, enum, ipaddress, multiprocessing, queue, signal, threading -import typing +import contextlib, enum, ipaddress, multiprocessing, os.path, queue, signal +import threading, typing from . import cli, consts, datetime, decorators, irc, http, parse, security from .decorators import export, hook, kwarg, spec @@ -126,3 +126,18 @@ def deadline_process(func: typing.Callable[[], DeadlineProcessReturnType], return out else: raise out # type: ignore + +def git_commit(bot_directory: str) -> typing.Optional[str]: + git_dir = os.path.join(bot_directory, ".git") + head_filepath = os.path.join(git_dir, "HEAD") + if os.path.isfile(head_filepath): + ref = None + with open(head_filepath, "r") as head_file: + ref = head_file.readline().split(" ", 1)[1].strip() + branch = ref.rsplit("/", 1)[1] + + ref_filepath = os.path.join(git_dir, ref) + if os.path.isfile(ref_filepath): + with open(ref_filepath, "r") as ref_file: + return ref_file.readline().strip()[:8] + return None |
