diff options
| author | Nejc Habjan <nejc.habjan@siemens.com> | 2022-07-24 00:31:56 +0200 |
|---|---|---|
| committer | John Villalovos <john@sodarock.com> | 2022-07-24 14:17:17 -0700 |
| commit | 4882cb22f55c41d8495840110be2d338b5545a04 (patch) | |
| tree | ff4a6b944a72e814863146a5baa7d487fd327fc1 /gitlab/v4/objects | |
| parent | 1ecbc7c89b2d8104bd3dd3045ff551e808f06aac (diff) | |
| download | gitlab-4882cb22f55c41d8495840110be2d338b5545a04.tar.gz | |
feat(namespaces): add support for namespace existence API
Diffstat (limited to 'gitlab/v4/objects')
| -rw-r--r-- | gitlab/v4/objects/namespaces.py | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/gitlab/v4/objects/namespaces.py b/gitlab/v4/objects/namespaces.py index 91a1850..8957a5c 100644 --- a/gitlab/v4/objects/namespaces.py +++ b/gitlab/v4/objects/namespaces.py @@ -1,7 +1,10 @@ -from typing import Any, cast, Union +from typing import Any, cast, TYPE_CHECKING, Union +from gitlab import cli +from gitlab import exceptions as exc from gitlab.base import RESTManager, RESTObject from gitlab.mixins import RetrieveMixin +from gitlab.utils import EncodedId __all__ = [ "Namespace", @@ -20,3 +23,25 @@ class NamespaceManager(RetrieveMixin, RESTManager): def get(self, id: Union[str, int], lazy: bool = False, **kwargs: Any) -> Namespace: return cast(Namespace, super().get(id=id, lazy=lazy, **kwargs)) + + @cli.register_custom_action("NamespaceManager", ("namespace", "parent_id")) + @exc.on_http_error(exc.GitlabGetError) + def exists(self, namespace: str, **kwargs: Any) -> Namespace: + """Get existence of a namespace by path. + + Args: + namespace: The path to the namespace. + **kwargs: Extra options to send to the server (e.g. sudo) + + Raises: + GitlabAuthenticationError: If authentication is not correct + GitlabGetError: If the server failed to perform the request + + Returns: + Data on namespace existence returned from the server. + """ + path = f"{self.path}/{EncodedId(namespace)}/exists" + server_data = self.gitlab.http_get(path, **kwargs) + if TYPE_CHECKING: + assert isinstance(server_data, dict) + return self._obj_cls(self, server_data) |
