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

Commit0268fc9

Browse files
author
Gauvain Pocentek
committed
[v4] fix CLI for some mixin methods
1 parent947feaf commit0268fc9

File tree

3 files changed

+36
-13
lines changed

3 files changed

+36
-13
lines changed

‎gitlab/cli.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,28 @@
3535
custom_actions= {}
3636

3737

38-
defregister_custom_action(cls_name,mandatory=tuple(),optional=tuple()):
38+
defregister_custom_action(cls_names,mandatory=tuple(),optional=tuple()):
3939
defwrap(f):
4040
@functools.wraps(f)
4141
defwrapped_f(*args,**kwargs):
4242
returnf(*args,**kwargs)
4343

4444
# in_obj defines whether the method belongs to the obj or the manager
4545
in_obj=True
46-
final_name=cls_name
47-
ifcls_name.endswith('Manager'):
48-
final_name=cls_name.replace('Manager','')
49-
in_obj=False
50-
iffinal_namenotincustom_actions:
51-
custom_actions[final_name]= {}
52-
53-
action=f.__name__
54-
custom_actions[final_name][action]= (mandatory,optional,in_obj)
46+
classes=cls_names
47+
iftype(cls_names)!=tuple:
48+
classes= (cls_names, )
49+
50+
forcls_nameincls_names:
51+
final_name=cls_name
52+
ifcls_name.endswith('Manager'):
53+
final_name=cls_name.replace('Manager','')
54+
in_obj=False
55+
iffinal_namenotincustom_actions:
56+
custom_actions[final_name]= {}
57+
58+
action=f.__name__.replace('_','-')
59+
custom_actions[final_name][action]= (mandatory,optional,in_obj)
5560

5661
returnwrapped_f
5762
returnwrap

‎gitlab/mixins.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
importgitlab
1919
fromgitlabimportbase
20+
fromgitlabimportcli
2021
fromgitlabimportexceptionsasexc
2122

2223

@@ -296,6 +297,8 @@ def delete(self, **kwargs):
296297

297298

298299
classAccessRequestMixin(object):
300+
@cli.register_custom_action(('ProjectAccessRequest','GroupAccessRequest'),
301+
tuple(), ('access_level', ))
299302
@exc.on_http_error(exc.GitlabUpdateError)
300303
defapprove(self,access_level=gitlab.DEVELOPER_ACCESS,**kwargs):
301304
"""Approve an access request.
@@ -317,6 +320,8 @@ def approve(self, access_level=gitlab.DEVELOPER_ACCESS, **kwargs):
317320

318321

319322
classSubscribableMixin(object):
323+
@cli.register_custom_action(('ProjectIssue','ProjectMergeRequest',
324+
'ProjectLabel'))
320325
@exc.on_http_error(exc.GitlabSubscribeError)
321326
defsubscribe(self,**kwargs):
322327
"""Subscribe to the object notifications.
@@ -332,6 +337,8 @@ def subscribe(self, **kwargs):
332337
server_data=self.manager.gitlab.http_post(path,**kwargs)
333338
self._update_attrs(server_data)
334339

340+
@cli.register_custom_action(('ProjectIssue','ProjectMergeRequest',
341+
'ProjectLabel'))
335342
@exc.on_http_error(exc.GitlabUnsubscribeError)
336343
defunsubscribe(self,**kwargs):
337344
"""Unsubscribe from the object notifications.
@@ -349,6 +356,7 @@ def unsubscribe(self, **kwargs):
349356

350357

351358
classTodoMixin(object):
359+
@cli.register_custom_action(('ProjectIssue','ProjectMergeRequest'))
352360
@exc.on_http_error(exc.GitlabHttpError)
353361
deftodo(self,**kwargs):
354362
"""Create a todo associated to the object.
@@ -365,6 +373,7 @@ def todo(self, **kwargs):
365373

366374

367375
classTimeTrackingMixin(object):
376+
@cli.register_custom_action(('ProjectIssue','ProjectMergeRequest'))
368377
@exc.on_http_error(exc.GitlabTimeTrackingError)
369378
deftime_stats(self,**kwargs):
370379
"""Get time stats for the object.
@@ -379,6 +388,8 @@ def time_stats(self, **kwargs):
379388
path='%s/%s/time_stats'% (self.manager.path,self.get_id())
380389
returnself.manager.gitlab.http_get(path,**kwargs)
381390

391+
@cli.register_custom_action(('ProjectIssue','ProjectMergeRequest'),
392+
('duration', ))
382393
@exc.on_http_error(exc.GitlabTimeTrackingError)
383394
deftime_estimate(self,duration,**kwargs):
384395
"""Set an estimated time of work for the object.
@@ -395,6 +406,7 @@ def time_estimate(self, duration, **kwargs):
395406
data= {'duration':duration}
396407
returnself.manager.gitlab.http_post(path,post_data=data,**kwargs)
397408

409+
@cli.register_custom_action(('ProjectIssue','ProjectMergeRequest'))
398410
@exc.on_http_error(exc.GitlabTimeTrackingError)
399411
defreset_time_estimate(self,**kwargs):
400412
"""Resets estimated time for the object to 0 seconds.
@@ -409,6 +421,8 @@ def reset_time_estimate(self, **kwargs):
409421
path='%s/%s/rest_time_estimate'% (self.manager.path,self.get_id())
410422
returnself.manager.gitlab.http_post(path,**kwargs)
411423

424+
@cli.register_custom_action(('ProjectIssue','ProjectMergeRequest'),
425+
('duration', ))
412426
@exc.on_http_error(exc.GitlabTimeTrackingError)
413427
defadd_spent_time(self,duration,**kwargs):
414428
"""Add time spent working on the object.
@@ -425,6 +439,7 @@ def add_spent_time(self, duration, **kwargs):
425439
data= {'duration':duration}
426440
returnself.manager.gitlab.http_post(path,post_data=data,**kwargs)
427441

442+
@cli.register_custom_action(('ProjectIssue','ProjectMergeRequest'))
428443
@exc.on_http_error(exc.GitlabTimeTrackingError)
429444
defreset_spent_time(self,**kwargs):
430445
"""Resets the time spent working on the object.

‎gitlab/v4/cli.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def __init__(self, gl, what, action, args):
3333
self.cls_name=cli.what_to_cls(what)
3434
self.cls=gitlab.v4.objects.__dict__[self.cls_name]
3535
self.what=what.replace('-','_')
36-
self.action=action.lower().replace('-','')
36+
self.action=action.lower()
3737
self.gl=gl
3838
self.args=args
3939
self.mgr_cls=getattr(gitlab.v4.objects,
@@ -64,7 +64,8 @@ def do_custom(self):
6464
ifgitlab.mixins.GetWithoutIdMixinnotininspect.getmro(self.cls):
6565
data[self.cls._id_attr]=self.args.pop(self.cls._id_attr)
6666
o=self.cls(self.mgr,data)
67-
returngetattr(o,self.action)(**self.args)
67+
method_name=self.action.replace('-','_')
68+
returngetattr(o,method_name)(**self.args)
6869
else:
6970
returngetattr(self.mgr,self.action)(**self.args)
7071

@@ -314,7 +315,9 @@ def get_dict(obj):
314315
ifkinfields}
315316
returnobj.attributes
316317

317-
ifisinstance(ret_val,list):
318+
ifisinstance(ret_val,dict):
319+
printer.display(ret_val,verbose=True,obj=ret_val)
320+
elifisinstance(ret_val,list):
318321
forobjinret_val:
319322
ifisinstance(obj,gitlab.base.RESTObject):
320323
printer.display(get_dict(obj),verbose=verbose,obj=obj)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp