Files
nanobot/nanobot/build_info.py
T
chengyongru b0d28af321 feat(webui): show commit and prefill bug report diagnostics (#6080)
* feat(webui): show gateway commit in About settings

* feat(webui): prefill revision in bug reports

* fix(webui): use parentheses for commit details

* feat(webui): prefill gateway diagnostics in bug reports

* docs: remove About settings explanation

* fix(webui): prefill dedicated issue diagnostic fields

* fix(docker): include revision helper in dependency build layer
2026-10-06 18:53:50 +08:00

32 lines
989 B
Python

"""Source revision of the running installation and built distributions."""
from __future__ import annotations
import re
import subprocess
from pathlib import Path
def read_commit(root: Path) -> str | None:
"""Read this checkout's HEAD, or the revision recorded when packaging it."""
if (root / ".git").exists():
try:
commit = subprocess.run(
["git", "-C", str(root), "rev-parse", "--verify", "HEAD"],
capture_output=True,
text=True,
check=True,
timeout=2,
).stdout.strip()
except (OSError, subprocess.SubprocessError):
return None
else:
try:
commit = (root / "nanobot" / "_build_commit.txt").read_text(encoding="utf-8").strip()
except OSError:
return None
return commit if re.fullmatch(r"[0-9a-f]{40}|[0-9a-f]{64}", commit) else None
COMMIT = read_commit(Path(__file__).resolve().parent.parent)