1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-10-30 19:12:15 +01:00

Implement 'git-obs repo list' command

This commit is contained in:
2025-06-20 10:49:18 +02:00
parent 4a24707c84
commit 63067fd8ae
4 changed files with 202 additions and 0 deletions

View File

@@ -1,8 +1,11 @@
import copy
import http.client
import json
import re
import time
import urllib.parse
from typing import Dict
from typing import Generator
from typing import Optional
import urllib3
@@ -12,6 +15,19 @@ import urllib3.response
from .conf import Login
RE_HTTP_HEADER_LINK = re.compile('<(?P<url>.*?)>; rel="(?P<rel>.*?)",?')
def parse_http_header_link(link: str) -> Dict[str, str]:
"""
Parse RFC8288 "link" http headers into {"rel": "url"}
"""
result = {}
for match in RE_HTTP_HEADER_LINK.findall(link):
result[match[1]] = match[0]
return result
class GiteaHTTPResponse:
"""
A ``urllib3.response.HTTPResponse`` wrapper
@@ -153,3 +169,24 @@ class Connection:
raise response_to_exception(response, context=context)
return response
def request_all_pages(
self, method, url, json_data: Optional[dict] = None, *, context: Optional[dict] = None
) -> Generator[GiteaHTTPResponse, None, None]:
"""
Make a request and yield ``GiteaHTTPResponse`` instances for each page.
Arguments are forwarded to the underlying ``request()`` call.
"""
while True:
response = self.request(method, url, json_data=json_data, context=context)
yield response
if "link" not in response.headers:
break
links = parse_http_header_link(response.headers["link"])
if "next" in links:
url = links["next"]
else:
break