feat: 启动时检查是否有新版本并通知管理员

This commit is contained in:
Rock Chin
2023-01-05 20:52:59 +08:00
parent d2922afce2
commit 3bebeb4d99
2 changed files with 35 additions and 1 deletions

View File

@@ -58,3 +58,24 @@ def get_commit_id_and_time_and_msg() -> str:
dt = datetime.datetime.fromtimestamp(entry.commit.commit_time, tz)
return str(entry.commit.id)[2:9] + " " + dt.strftime('%Y-%m-%d %H:%M:%S') + " [" + str(entry.commit.message, encoding="utf-8").strip()+"]"
def is_new_version_available() -> bool:
"""检查是否有新版本"""
try:
import dulwich
except ModuleNotFoundError:
raise Exception("dulwich模块未安装,请查看 https://github.com/RockChinQ/QChatGPT/issues/77")
from dulwich import porcelain
repo = porcelain.open_repo('.')
fetch_res = porcelain.ls_remote(porcelain.get_remote_repo(repo, "origin")[1])
current_commit_id = ""
for entry in repo.get_walker():
current_commit_id = str(entry.commit.id)[2:9]
break
latest_commit_id = str(fetch_res[b'HEAD'])[2:9]
return current_commit_id != latest_commit_id