ups/lib/gitea.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

64 lines
1.5 KiB
Python

from .provider import provider
from urllib import request
from typing import List
COMMITS_URL = "PROTO://HOST/api/v1/repos/OWNER/REPO/commits"
REPO_URL = "PROTO://HOST/api/v1/repos/OWNER/REPO"
PATCH_URL = ""
class gitea(provider):
def __init__(self, url: str) -> None:
super().__init__(url)
def check(self) -> bool:
res = self.GET(REPO_URL)
return not res["private"]
def until(self, commit: str) -> List[str]:
commits = []
found = False
page = 1
while not found:
res = self.GET(
COMMITS_URL,
{
"limit": 50,
"stat": False,
"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,
{
"limit": count,
"stat": False,
},
)
[commits.append(c["sha"]) for c in res]
return commits
def download(self, commit: str, file: str) -> None:
url = self.url(
"PROTO://HOST/api/v1/repos/OWNER/REPO/git/commits/%s.patch" % commit
)
request.urlretrieve(url, file)