mirror of
https://github.com/openSUSE/osc.git
synced 2025-11-07 06:33:16 +01:00
Implement 'git-obs repo list' command
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import functools
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
from typing import List
|
||||
from typing import Optional
|
||||
from typing import Tuple
|
||||
|
||||
@@ -9,11 +11,18 @@ from .connection import GiteaHTTPResponse
|
||||
from .user import User
|
||||
|
||||
|
||||
@functools.total_ordering
|
||||
class Repo:
|
||||
def __init__(self, data: dict, *, response: Optional[GiteaHTTPResponse] = None):
|
||||
self._data = data
|
||||
self._response = response
|
||||
|
||||
def __eq__(self, other):
|
||||
(self.owner, self.repo) == (other.owner, other.repo)
|
||||
|
||||
def __lt__(self, other):
|
||||
(self.owner, self.repo) < (other.owner, other.repo)
|
||||
|
||||
@property
|
||||
def owner(self) -> str:
|
||||
return self._data["owner"]["login"]
|
||||
@@ -179,3 +188,37 @@ class Repo:
|
||||
subprocess.run(cmd, cwd=cwd, check=True)
|
||||
|
||||
return directory_abspath
|
||||
|
||||
@classmethod
|
||||
def list_org_repos(cls, conn: Connection, owner: str) -> List["Repo"]:
|
||||
"""
|
||||
List repos owned by an organization.
|
||||
|
||||
:param conn: Gitea ``Connection`` instance.
|
||||
"""
|
||||
q = {
|
||||
# XXX: limit works in range 1..50, setting it any higher doesn't help, we need to handle paginated results
|
||||
"limit": 10**6,
|
||||
}
|
||||
url = conn.makeurl("orgs", owner, "repos", query=q)
|
||||
obj_list = []
|
||||
for response in conn.request_all_pages("GET", url):
|
||||
obj_list.extend([cls(i, response=response) for i in response.json()])
|
||||
return obj_list
|
||||
|
||||
@classmethod
|
||||
def list_user_repos(cls, conn: Connection, owner: str) -> List["Repo"]:
|
||||
"""
|
||||
List repos owned by a user.
|
||||
|
||||
:param conn: Gitea ``Connection`` instance.
|
||||
"""
|
||||
q = {
|
||||
# XXX: limit works in range 1..50, setting it any higher doesn't help, we need to handle paginated results
|
||||
"limit": 10**6,
|
||||
}
|
||||
url = conn.makeurl("users", owner, "repos", query=q)
|
||||
obj_list = []
|
||||
for response in conn.request_all_pages("GET", url):
|
||||
obj_list.extend([cls(i, response=response) for i in response.json()])
|
||||
return obj_list
|
||||
|
||||
Reference in New Issue
Block a user