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

Commit74dc2ac

Browse files
author
Gauvain Pocentek
committed
Add a get method for GitlabObject
This change provides a way to implement GET for objects that don'tsupport it, but support LIST.It is also a first step to a cleaner API.
1 parentc580b1e commit74dc2ac

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

‎gitlab/__init__.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -695,12 +695,24 @@ def list(cls, gl, **kwargs):
695695

696696
returngl.list(cls,**kwargs)
697697

698+
@classmethod
699+
defget(cls,gl,id,**kwargs):
700+
ifcls.canGetisTrue:
701+
returncls(gl,id,**kwargs)
702+
elifcls.canGet=='from_list':
703+
forobjincls.list(gl,**kwargs):
704+
obj_id=getattr(obj,obj.idAttr)
705+
ifstr(obj_id)==str(id):
706+
returnobj
707+
708+
raiseGitlabGetError("Object not found")
709+
698710
@classmethod
699711
def_get_list_or_object(cls,gl,id,**kwargs):
700712
ifidisNoneandcls.getListWhenNoId:
701713
returncls.list(gl,**kwargs)
702714
else:
703-
returncls(gl,id,**kwargs)
715+
returncls.get(gl,id,**kwargs)
704716

705717
def_get_object(self,k,v):
706718
ifself._constructorTypesandkinself._constructorTypes:
@@ -834,7 +846,7 @@ def json(self):
834846

835847
classUserKey(GitlabObject):
836848
_url='/users/%(user_id)s/keys'
837-
canGet=False
849+
canGet='from_list'
838850
canUpdate=False
839851
requiredUrlAttrs= ['user_id']
840852
requiredCreateAttrs= ['title','key']
@@ -882,7 +894,7 @@ def Key(self, id=None, **kwargs):
882894

883895
classGroupMember(GitlabObject):
884896
_url='/groups/%(group_id)s/members'
885-
canGet=False
897+
canGet='from_list'
886898
requiredUrlAttrs= ['group_id']
887899
requiredCreateAttrs= ['access_level','user_id']
888900
requiredUpdateAttrs= ['access_level']
@@ -928,7 +940,7 @@ class Issue(GitlabObject):
928940
_url='/issues'
929941
_constructorTypes= {'author':'User','assignee':'User',
930942
'milestone':'ProjectMilestone'}
931-
canGet=False
943+
canGet='from_list'
932944
canDelete=False
933945
canUpdate=False
934946
canCreate=False
@@ -997,7 +1009,7 @@ class ProjectKey(GitlabObject):
9971009

9981010
classProjectEvent(GitlabObject):
9991011
_url='/projects/%(project_id)s/events'
1000-
canGet=False
1012+
canGet='from_list'
10011013
canDelete=False
10021014
canUpdate=False
10031015
canCreate=False
@@ -1073,7 +1085,7 @@ class ProjectNote(GitlabObject):
10731085
classProjectTag(GitlabObject):
10741086
_url='/projects/%(project_id)s/repository/tags'
10751087
idAttr='name'
1076-
canGet=False
1088+
canGet='from_list'
10771089
canDelete=False
10781090
canUpdate=False
10791091
requiredUrlAttrs= ['project_id']

‎gitlab/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,15 @@ def do_list(cls, gl, what, args):
170170

171171

172172
defdo_get(cls,gl,what,args):
173-
ifnotcls.canGet:
173+
ifcls.canGetisFalse:
174174
die("%s objects can't be retrieved"%what)
175175

176176
id=None
177177
ifclsnotin [gitlab.CurrentUser]andcls.getRequiresId:
178178
id=get_id(cls,args)
179179

180180
try:
181-
o=cls(gl,id,**args)
181+
o=cls.get(gl,id,**args)
182182
exceptExceptionase:
183183
die("Impossible to get object (%s)"%str(e))
184184

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp