feat: Move getGitCommit from api to tools
All checks were successful
Build Docker / BuildImage (push) Successful in 1m4s
All checks were successful
Build Docker / BuildImage (push) Successful in 1m4s
This commit is contained in:
21
tools.py
21
tools.py
@@ -10,6 +10,27 @@ def getClientIP(request):
|
||||
ip = request.remote_addr
|
||||
return ip
|
||||
|
||||
def getGitCommit():
|
||||
# if .git exists, get the latest commit hash
|
||||
if os.path.isdir(".git"):
|
||||
git_dir = ".git"
|
||||
head_ref = ""
|
||||
with open(os.path.join(git_dir, "HEAD")) as file:
|
||||
head_ref = file.read().strip()
|
||||
if head_ref.startswith("ref: "):
|
||||
head_ref = head_ref[5:]
|
||||
with open(os.path.join(git_dir, head_ref)) as file:
|
||||
return file.read().strip()
|
||||
else:
|
||||
return head_ref
|
||||
|
||||
# Check if env SOURCE_COMMIT is set
|
||||
if "SOURCE_COMMIT" in os.environ:
|
||||
return os.environ["SOURCE_COMMIT"]
|
||||
|
||||
return "failed to get version"
|
||||
|
||||
|
||||
def isCurl(request: Request) -> bool:
|
||||
"""
|
||||
Check if the request is from curl
|
||||
|
||||
Reference in New Issue
Block a user