-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathgithub.py
38 lines (29 loc) · 908 Bytes
/
github.py
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
import requests
from constants import HEADERS
from dataclasses import dataclass
@dataclass
class Asset:
browser_download_url: str
name: str
@dataclass
class GithubRelease:
tag_name: str
html_url: str
assets: list[Asset]
def get_last_build_version(repo_url: str) -> GithubRelease | None:
url = f"https://api.github.com/repos/{repo_url}/releases/latest"
response = requests.get(url, headers=HEADERS)
print(response.status_code)
if response.status_code == 200:
release = response.json()
assets = [
Asset(
browser_download_url=asset["browser_download_url"], name=asset["name"]
)
for asset in release["assets"]
]
return GithubRelease(
tag_name=release["tag_name"], html_url=release["html_url"], assets=assets
)
elif response.status_code == 404:
return