25
25
from gitlab import utils
26
26
27
27
28
- async def async_postprocess (self , awaitable , callback , * args , ** kwargs ):
29
- obj = await awaitable
30
- return callback (self , obj , * args , ** kwargs )
31
-
32
-
33
- def awaitable_postprocess (f ):
34
- @functools .wraps (f )
35
- def wrapped_f (self , obj , * args , ** kwargs ):
36
- if asyncio .iscoroutine (obj ):
37
- return async_postprocess (self , obj , f , * args , ** kwarsg )
38
- else :
39
- return f (self , obj , * args , ** kwargs )
40
-
41
- return wrapped_f
42
-
43
-
44
- def update_attrs (f ):
45
- """Update attrs with returned server_data
46
-
47
- Updates object if data returned or coroutine
48
- """
49
-
50
- @functools .wraps (f )
51
- def wrapped_f (self , * args , ** kwargs ):
52
- server_data = f (self , * args , ** kwargs )
53
- if asyncio .iscoroutine (server_data ):
54
- return self ._aupdate_attrs (server_data )
55
- else :
56
- return self ._update_attrs (server_data )
57
-
58
- return wrapped_f
59
-
60
-
61
28
class GetMixin :
62
29
@exc .on_http_error (exc .GitlabGetError )
63
30
def get (self , id , lazy = False , ** kwargs ):
@@ -110,7 +77,6 @@ def get(self, id=None, **kwargs):
110
77
111
78
class RefreshMixin :
112
79
@exc .on_http_error (exc .GitlabGetError )
113
- @update_attrs
114
80
def refresh (self , ** kwargs ):
115
81
"""Refresh a single object from server.
116
82
@@ -127,7 +93,8 @@ def refresh(self, **kwargs):
127
93
path = "%s/%s" % (self .manager .path , self .id )
128
94
else :
129
95
path = self .manager .path
130
- return self .manager .gitlab .http_get (path , ** kwargs )
96
+ server_data = self .manager .gitlab .http_get (path , ** kwargs )
97
+ return self ._update_attrs (server_data )
131
98
132
99
133
100
class ListMixin :
@@ -405,7 +372,6 @@ def _get_updated_data(self):
405
372
406
373
return updated_data
407
374
408
- @update_attrs
409
375
def save (self , ** kwargs ):
410
376
"""Save the changes made to the object to the server.
411
377
@@ -425,7 +391,8 @@ def save(self, **kwargs):
425
391
426
392
# call the manager
427
393
obj_id = self .get_id ()
428
- return self .manager .update (obj_id , updated_data , ** kwargs )
394
+ server_data = self .manager .update (obj_id , updated_data , ** kwargs )
395
+ return self ._update_attrs (server_data )
429
396
430
397
431
398
class ObjectDeleteMixin (object ):
@@ -466,7 +433,6 @@ class AccessRequestMixin(object):
466
433
("ProjectAccessRequest" , "GroupAccessRequest" ), tuple (), ("access_level" ,)
467
434
)
468
435
@exc .on_http_error (exc .GitlabUpdateError )
469
- @update_attrs
470
436
def approve (self , access_level = gitlab .DEVELOPER_ACCESS , ** kwargs ):
471
437
"""Approve an access request.
472
438
@@ -481,15 +447,15 @@ def approve(self, access_level=gitlab.DEVELOPER_ACCESS, **kwargs):
481
447
482
448
path = "%s/%s/approve" % (self .manager .path , self .id )
483
449
data = {"access_level" : access_level }
484
- return self .manager .gitlab .http_put (path , post_data = data , ** kwargs )
450
+ server_data = self .manager .gitlab .http_put (path , post_data = data , ** kwargs )
451
+ return self ._update_attrs (server_data )
485
452
486
453
487
454
class SubscribableMixin (object ):
488
455
@cli .register_custom_action (
489
456
("ProjectIssue" , "ProjectMergeRequest" , "ProjectLabel" , "GroupLabel" )
490
457
)
491
458
@exc .on_http_error (exc .GitlabSubscribeError )
492
- @update_attrs
493
459
def subscribe (self , ** kwargs ):
494
460
"""Subscribe to the object notifications.
495
461
@@ -501,13 +467,13 @@ def subscribe(self, **kwargs):
501
467
GitlabSubscribeError: If the subscription cannot be done
502
468
"""
503
469
path = "%s/%s/subscribe" % (self .manager .path , self .get_id ())
504
- return self .manager .gitlab .http_post (path , ** kwargs )
470
+ server_data = self .manager .gitlab .http_post (path , ** kwargs )
471
+ return self ._update_attrs (server_data )
505
472
506
473
@cli .register_custom_action (
507
474
("ProjectIssue" , "ProjectMergeRequest" , "ProjectLabel" , "GroupLabel" )
508
475
)
509
476
@exc .on_http_error (exc .GitlabUnsubscribeError )
510
- @update_attrs
511
477
def unsubscribe (self , ** kwargs ):
512
478
"""Unsubscribe from the object notifications.
513
479
@@ -519,7 +485,8 @@ def unsubscribe(self, **kwargs):
519
485
GitlabUnsubscribeError: If the unsubscription cannot be done
520
486
"""
521
487
path = "%s/%s/unsubscribe" % (self .manager .path , self .get_id ())
522
- return self .manager .gitlab .http_post (path , ** kwargs )
488
+ server_data = self .manager .gitlab .http_post (path , ** kwargs )
489
+ return self ._update_attrs (server_data )
523
490
524
491
525
492
class TodoMixin (object ):
0 commit comments