mirror of
https://github.com/openSUSE/osc.git
synced 2025-08-05 15:13:39 +02:00
Extend 'gitea_api.User.get()' to take 'username' parameter
This commit is contained in:
@@ -5,6 +5,7 @@ from .exceptions import BranchExists
|
||||
from .exceptions import ForkExists
|
||||
from .exceptions import GiteaException
|
||||
from .exceptions import RepoExists
|
||||
from .exceptions import UserDoesNotExist
|
||||
from .exceptions import response_to_exception
|
||||
from .branch import Branch
|
||||
from .conf import Config
|
||||
|
@@ -177,5 +177,21 @@ class AutoMergeAlreadyScheduled(GiteaException):
|
||||
return result
|
||||
|
||||
|
||||
class UserDoesNotExist(GiteaException):
|
||||
RESPONSE_STATUS = 404
|
||||
# models/user/redirect.go: return fmt.Sprintf("user redirect does not exist [name: %s]", err.Name)
|
||||
RESPONSE_MESSAGE_RE = [
|
||||
re.compile(r"^user redirect does not exist \[name: (?P<username>.*)\]"),
|
||||
]
|
||||
|
||||
def __init__(self, response: GiteaHTTPResponse, username: str):
|
||||
super().__init__(response)
|
||||
self.username = username
|
||||
|
||||
def __str__(self):
|
||||
result = f"User '{self.username}' doesn't exist"
|
||||
return result
|
||||
|
||||
|
||||
# gather all exceptions from this module that inherit from GiteaException
|
||||
EXCEPTION_CLASSES = [i for i in globals().values() if hasattr(i, "RESPONSE_MESSAGE_RE") and inspect.isclass(i) and issubclass(i, GiteaException)]
|
||||
|
@@ -35,13 +35,19 @@ class User:
|
||||
def get(
|
||||
cls,
|
||||
conn: Connection,
|
||||
username: Optional[str] = None,
|
||||
) -> "Self":
|
||||
"""
|
||||
Retrieve details about the current user.
|
||||
Retrieve details about a user.
|
||||
If ``username`` is not specified, data about the current user is returned."
|
||||
|
||||
:param conn: Gitea ``Connection`` instance.
|
||||
:param username: Username of the queried user."
|
||||
"""
|
||||
url = conn.makeurl("user")
|
||||
if not username:
|
||||
url = conn.makeurl("user")
|
||||
else:
|
||||
url = conn.makeurl("users", username)
|
||||
response = conn.request("GET", url)
|
||||
obj = cls(response.json(), response=response)
|
||||
return obj
|
||||
|
Reference in New Issue
Block a user