mirror of
https://github.com/xuthus83/LittlePaimon.git
synced 2024-12-16 13:40:53 +08:00
🐛 修复检查更新
This commit is contained in:
parent
0224cd1d49
commit
7fd5394855
@ -4,34 +4,32 @@ import git
|
|||||||
from nonebot.utils import run_sync
|
from nonebot.utils import run_sync
|
||||||
from git.exc import GitCommandError, InvalidGitRepositoryError
|
from git.exc import GitCommandError, InvalidGitRepositoryError
|
||||||
from LittlePaimon import __version__, NICKNAME
|
from LittlePaimon import __version__, NICKNAME
|
||||||
|
from LittlePaimon.utils import aiorequests
|
||||||
|
|
||||||
|
|
||||||
def time_str(timestamp: int) -> str:
|
async def check_update():
|
||||||
time_local = time.localtime(timestamp)
|
resp = await aiorequests.get('https://api.github.com/repos/CMHopeSunshine/LittlePaimon/commits')
|
||||||
return time.strftime("%m-%d %H:%M:%S", time_local)
|
data = resp.json()
|
||||||
|
if not isinstance(data, list):
|
||||||
|
return '检查更新失败,可能是网络问题,请稍后再试'
|
||||||
@run_sync
|
|
||||||
def check_update():
|
|
||||||
try:
|
try:
|
||||||
repo = git.Repo(Path().absolute())
|
repo = git.Repo(Path().absolute())
|
||||||
except InvalidGitRepositoryError:
|
except InvalidGitRepositoryError:
|
||||||
return '没有发现git仓库,无法通过git检查更新'
|
return '没有发现git仓库,无法通过git检查更新'
|
||||||
local_commit = repo.head.commit
|
local_commit = repo.head.commit
|
||||||
remote_commit = []
|
remote_commit = []
|
||||||
for commit in repo.iter_commits(max_count=15):
|
for commit in data:
|
||||||
if local_commit == commit:
|
if local_commit.binsha == commit['sha']:
|
||||||
break
|
break
|
||||||
remote_commit.append(commit)
|
remote_commit.append(commit)
|
||||||
if not remote_commit:
|
if not remote_commit:
|
||||||
return f'当前已是最新版本:{__version__}'
|
return f'当前已是最新版本:{__version__}'
|
||||||
i = 1
|
|
||||||
result = '检查到更新,日志如下:\n'
|
result = '检查到更新,日志如下:\n'
|
||||||
for commit in remote_commit:
|
for i, commit in enumerate(remote_commit, start=1):
|
||||||
if isinstance(commit.message, str):
|
result += f'{i}.{commit["commit"]["committer"]["date"].replace("T", " ").replace("Z", "")}\n' + commit['commit']['message'].replace(':bug:', '🐛').replace(
|
||||||
result += f'{i}.{time_str(commit.committed_date)}\n' + commit.message.replace(':bug:', '🐛').replace(
|
':sparkles:', '✨').replace(':memo:', '📝') + '\n'
|
||||||
':sparkles:', '✨').replace(':memo:', '📝') + '\n'
|
if i >= 5:
|
||||||
i += 1
|
break
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user