ups/lib/github.py
ngn ab580d6a18
Some checks failed
format / build (push) Failing after 6s
initial commit
Signed-off-by: ngn <ngn@ngn.tf>
2025-05-02 18:20:24 +03:00

59 lines
1.4 KiB
Python

from .provider import provider
from urllib import request
from typing import List
REPO_URL = "https://api.github.com/repos/OWNER/REPO"
COMMITS_URL = "https://api.github.com/repos/OWNER/REPO/commits"
class github(provider):
def __init__(self, url: str) -> None:
super().__init__(url)
def check(self) -> bool:
res = self.GET(REPO_URL)
return res["full_name"] == "%s/%s" % (self.owner, self.repo)
def until(self, commit: str) -> List[str]:
commits = []
found = False
page = 1
while not found:
res = self.GET(
COMMITS_URL,
{
"per_page": 50,
"page": page,
},
)
if len(res) <= 0:
break
for c in res:
if c["sha"] == commit:
found = True
break
commits.append(c["sha"])
page += 1
return commits
def last(self, count=1) -> List[str]:
commits = []
res = self.GET(
COMMITS_URL,
{
"per_page": count,
},
)
[commits.append(c["sha"]) for c in res]
return commits
def download(self, commit: str, file: str) -> None:
url = self.url("PROTO://github.com/OWNER/REPO/commit/%s.patch" % commit)
request.urlretrieve(url, file)