Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4882cb2

Browse files
nejchJohnVillalovos
authored andcommitted
feat(namespaces): add support for namespace existence API
1 parent1ecbc7c commit4882cb2

File tree

3 files changed

+49
-4
lines changed

3 files changed

+49
-4
lines changed

‎docs/gl_objects/namespaces.rst‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,15 @@ List namespaces::
2323
Search namespaces::
2424

2525
namespaces = gl.namespaces.list(search='foo')
26+
27+
Get a namespace by ID or path::
28+
29+
namespace = gl.namespaces.get("my-namespace")
30+
31+
Get existence of a namespace by path::
32+
33+
namespace = gl.namespaces.exists("new-namespace")
34+
35+
if namespace.exists:
36+
# get suggestions of namespaces that don't already exist
37+
print(namespace.suggests)

‎gitlab/v4/objects/namespaces.py‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
fromtypingimportAny,cast,Union
1+
fromtypingimportAny,cast,TYPE_CHECKING,Union
22

3+
fromgitlabimportcli
4+
fromgitlabimportexceptionsasexc
35
fromgitlab.baseimportRESTManager,RESTObject
46
fromgitlab.mixinsimportRetrieveMixin
7+
fromgitlab.utilsimportEncodedId
58

69
__all__= [
710
"Namespace",
@@ -20,3 +23,25 @@ class NamespaceManager(RetrieveMixin, RESTManager):
2023

2124
defget(self,id:Union[str,int],lazy:bool=False,**kwargs:Any)->Namespace:
2225
returncast(Namespace,super().get(id=id,lazy=lazy,**kwargs))
26+
27+
@cli.register_custom_action("NamespaceManager", ("namespace","parent_id"))
28+
@exc.on_http_error(exc.GitlabGetError)
29+
defexists(self,namespace:str,**kwargs:Any)->Namespace:
30+
"""Get existence of a namespace by path.
31+
32+
Args:
33+
namespace: The path to the namespace.
34+
**kwargs: Extra options to send to the server (e.g. sudo)
35+
36+
Raises:
37+
GitlabAuthenticationError: If authentication is not correct
38+
GitlabGetError: If the server failed to perform the request
39+
40+
Returns:
41+
Data on namespace existence returned from the server.
42+
"""
43+
path=f"{self.path}/{EncodedId(namespace)}/exists"
44+
server_data=self.gitlab.http_get(path,**kwargs)
45+
ifTYPE_CHECKING:
46+
assertisinstance(server_data,dict)
47+
returnself._obj_cls(self,server_data)

‎tests/functional/api/test_gitlab.py‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,20 @@ def test_hooks(gl):
126126

127127

128128
deftest_namespaces(gl,get_all_kwargs):
129-
namespace=gl.namespaces.list(**get_all_kwargs)
130-
assertnamespace
129+
current_user=gl.user.username
131130

132-
namespace=gl.namespaces.list(search="root",**get_all_kwargs)[0]
131+
namespaces=gl.namespaces.list(**get_all_kwargs)
132+
assertnamespaces
133+
134+
namespaces=gl.namespaces.list(search=current_user,**get_all_kwargs)
135+
assertnamespaces[0].kind=="user"
136+
137+
namespace=gl.namespaces.get(current_user)
133138
assertnamespace.kind=="user"
134139

140+
namespace=gl.namespaces.exists(current_user)
141+
assertnamespace.exists
142+
135143

136144
deftest_notification_settings(gl):
137145
settings=gl.notificationsettings.get()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp