blob: a8575abe8d33f607be04dd5b0701690393703ee2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
from ATRI.exceptions import RequestError
from . import request
REPO_COMMITS_URL = "https://api.github.com/repos/Kyomotoi/ATRI/commits"
REPO_RELEASE_URL = "https://api.github.com/repos/Kyomotoi/ATRI/releases"
class CheckUpdate:
@staticmethod
async def _get_commits_info() -> dict:
req = await request.get(REPO_COMMITS_URL)
return req.json()
@staticmethod
async def _get_release_info() -> dict:
req = await request.get(REPO_RELEASE_URL)
return req.json()
@classmethod
async def show_latest_commit_info(cls) -> str:
try:
data = await cls._get_commits_info()
except RequestError:
raise RequestError("Getting commit info timeout...")
try:
commit_data: dict = data[0]
except Exception:
raise Exception("GitHub has been error!!!")
c_info = commit_data["commit"]
c_msg = c_info["message"]
c_sha = commit_data["sha"][0:5]
c_time = c_info["author"]["date"]
return f"Latest commit {c_msg} | sha: {c_sha} | time: {c_time}"
@classmethod
async def show_latest_version(cls) -> tuple:
try:
data = await cls._get_release_info()
except RequestError:
raise RequestError("Getting release list timeout...")
try:
release_data: dict = data[0]
except Exception:
raise Exception("GitHub has been error!!!")
l_v = release_data["tag_name"]
l_v_t = release_data["published_at"]
return l_v, l_v_t
|