16
16
# along with this program. If not, see <http://www.gnu.org/licenses/>.
17
17
18
18
import gitlab
19
- from gitlab import base
20
- from gitlab import cli
19
+ from gitlab import base , cli
21
20
from gitlab import exceptions as exc
22
21
from gitlab import types as g_types
23
22
from gitlab import utils
24
23
25
24
26
25
class GetMixin (object ):
27
26
@exc .on_http_error (exc .GitlabGetError )
28
- def get (self , id , lazy = False , ** kwargs ):
27
+ async def get (self , id , lazy = False , ** kwargs ):
29
28
"""Retrieve a single object.
30
29
31
30
Args:
@@ -48,12 +47,12 @@ def get(self, id, lazy=False, **kwargs):
48
47
if lazy is True :
49
48
return self ._obj_cls (self , {self ._obj_cls ._id_attr : id })
50
49
server_data = self .gitlab .http_get (path , ** kwargs )
51
- return self ._obj_cls (self , server_data )
50
+ return await self ._obj_cls (self , server_data )
52
51
53
52
54
53
class GetWithoutIdMixin (object ):
55
54
@exc .on_http_error (exc .GitlabGetError )
56
- def get (self , id = None , ** kwargs ):
55
+ async def get (self , id = None , ** kwargs ):
57
56
"""Retrieve a single object.
58
57
59
58
Args:
@@ -69,12 +68,12 @@ def get(self, id=None, **kwargs):
69
68
server_data = self .gitlab .http_get (self .path , ** kwargs )
70
69
if server_data is None :
71
70
return None
72
- return self ._obj_cls (self , server_data )
71
+ return await self ._obj_cls (self , server_data )
73
72
74
73
75
74
class RefreshMixin (object ):
76
75
@exc .on_http_error (exc .GitlabGetError )
77
- def refresh (self , ** kwargs ):
76
+ async def refresh (self , ** kwargs ):
78
77
"""Refresh a single object from server.
79
78
80
79
Args:
@@ -90,13 +89,13 @@ def refresh(self, **kwargs):
90
89
path = "%s/%s" % (self .manager .path , self .id )
91
90
else :
92
91
path = self .manager .path
93
- server_data = self .manager .gitlab .http_get (path , ** kwargs )
92
+ server_data = await self .manager .gitlab .http_get (path , ** kwargs )
94
93
self ._update_attrs (server_data )
95
94
96
95
97
96
class ListMixin (object ):
98
97
@exc .on_http_error (exc .GitlabListError )
99
- def list (self , ** kwargs ):
98
+ async def list (self , ** kwargs ):
100
99
"""Retrieve a list of objects.
101
100
102
101
Args:
@@ -138,7 +137,7 @@ def list(self, **kwargs):
138
137
# Allow to overwrite the path, handy for custom listings
139
138
path = data .pop ("path" , self .path )
140
139
141
- obj = self .gitlab .http_list (path , ** data )
140
+ obj = await self .gitlab .http_list (path , ** data )
142
141
if isinstance (obj , list ):
143
142
return [self ._obj_cls (self , item ) for item in obj ]
144
143
else :
@@ -170,7 +169,7 @@ def get_create_attrs(self):
170
169
return getattr (self , "_create_attrs" , (tuple (), tuple ()))
171
170
172
171
@exc .on_http_error (exc .GitlabCreateError )
173
- def create (self , data , ** kwargs ):
172
+ async def create (self , data , ** kwargs ):
174
173
"""Create a new object.
175
174
176
175
Args:
@@ -208,7 +207,9 @@ def create(self, data, **kwargs):
208
207
209
208
# Handle specific URL for creation
210
209
path = kwargs .pop ("path" , self .path )
211
- server_data = self .gitlab .http_post (path , post_data = data , files = files , ** kwargs )
210
+ server_data = await self .gitlab .http_post (
211
+ path , post_data = data , files = files , ** kwargs
212
+ )
212
213
return self ._obj_cls (self , server_data )
213
214
214
215
@@ -247,7 +248,7 @@ def _get_update_method(self):
247
248
return http_method
248
249
249
250
@exc .on_http_error (exc .GitlabUpdateError )
250
- def update (self , id = None , new_data = None , ** kwargs ):
251
+ async def update (self , id = None , new_data = None , ** kwargs ):
251
252
"""Update an object on the server.
252
253
253
254
Args:
@@ -290,12 +291,12 @@ def update(self, id=None, new_data=None, **kwargs):
290
291
new_data [attr_name ] = type_obj .get_for_api ()
291
292
292
293
http_method = self ._get_update_method ()
293
- return http_method (path , post_data = new_data , files = files , ** kwargs )
294
+ return await http_method (path , post_data = new_data , files = files , ** kwargs )
294
295
295
296
296
297
class SetMixin (object ):
297
298
@exc .on_http_error (exc .GitlabSetError )
298
- def set (self , key , value , ** kwargs ):
299
+ async def set (self , key , value , ** kwargs ):
299
300
"""Create or update the object.
300
301
301
302
Args:
@@ -312,13 +313,13 @@ def set(self, key, value, **kwargs):
312
313
"""
313
314
path = "%s/%s" % (self .path , utils .clean_str_id (key ))
314
315
data = {"value" : value }
315
- server_data = self .gitlab .http_put (path , post_data = data , ** kwargs )
316
+ server_data = await self .gitlab .http_put (path , post_data = data , ** kwargs )
316
317
return self ._obj_cls (self , server_data )
317
318
318
319
319
320
class DeleteMixin (object ):
320
321
@exc .on_http_error (exc .GitlabDeleteError )
321
- def delete (self , id , ** kwargs ):
322
+ async def delete (self , id , ** kwargs ):
322
323
"""Delete an object on the server.
323
324
324
325
Args:
@@ -335,7 +336,7 @@ def delete(self, id, **kwargs):
335
336
if not isinstance (id , int ):
336
337
id = utils .clean_str_id (id )
337
338
path = "%s/%s" % (self .path , id )
338
- self .gitlab .http_delete (path , ** kwargs )
339
+ await self .gitlab .http_delete (path , ** kwargs )
339
340
340
341
341
342
class CRUDMixin (GetMixin , ListMixin , CreateMixin , UpdateMixin , DeleteMixin ):
@@ -360,7 +361,7 @@ def _get_updated_data(self):
360
361
361
362
return updated_data
362
363
363
- def save (self , ** kwargs ):
364
+ async def save (self , ** kwargs ):
364
365
"""Save the changes made to the object to the server.
365
366
366
367
The object is updated to match what the server returns.
@@ -379,15 +380,15 @@ def save(self, **kwargs):
379
380
380
381
# call the manager
381
382
obj_id = self .get_id ()
382
- server_data = self .manager .update (obj_id , updated_data , ** kwargs )
383
+ server_data = await self .manager .update (obj_id , updated_data , ** kwargs )
383
384
if server_data is not None :
384
385
self ._update_attrs (server_data )
385
386
386
387
387
388
class ObjectDeleteMixin (object ):
388
389
"""Mixin for RESTObject's that can be deleted."""
389
390
390
- def delete (self , ** kwargs ):
391
+ async def delete (self , ** kwargs ):
391
392
"""Delete the object from the server.
392
393
393
394
Args:
@@ -397,13 +398,13 @@ def delete(self, **kwargs):
397
398
GitlabAuthenticationError: If authentication is not correct
398
399
GitlabDeleteError: If the server cannot perform the request
399
400
"""
400
- self .manager .delete (self .get_id ())
401
+ await self .manager .delete (self .get_id ())
401
402
402
403
403
404
class UserAgentDetailMixin (object ):
404
405
@cli .register_custom_action (("Snippet" , "ProjectSnippet" , "ProjectIssue" ))
405
406
@exc .on_http_error (exc .GitlabGetError )
406
- def user_agent_detail (self , ** kwargs ):
407
+ async def user_agent_detail (self , ** kwargs ):
407
408
"""Get the user agent detail.
408
409
409
410
Args:
@@ -414,15 +415,15 @@ def user_agent_detail(self, **kwargs):
414
415
GitlabGetError: If the server cannot perform the request
415
416
"""
416
417
path = "%s/%s/user_agent_detail" % (self .manager .path , self .get_id ())
417
- return self .manager .gitlab .http_get (path , ** kwargs )
418
+ return await self .manager .gitlab .http_get (path , ** kwargs )
418
419
419
420
420
421
class AccessRequestMixin (object ):
421
422
@cli .register_custom_action (
422
423
("ProjectAccessRequest" , "GroupAccessRequest" ), tuple (), ("access_level" ,)
423
424
)
424
425
@exc .on_http_error (exc .GitlabUpdateError )
425
- def approve (self , access_level = gitlab .DEVELOPER_ACCESS , ** kwargs ):
426
+ async def approve (self , access_level = gitlab .DEVELOPER_ACCESS , ** kwargs ):
426
427
"""Approve an access request.
427
428
428
429
Args:
@@ -436,7 +437,7 @@ def approve(self, access_level=gitlab.DEVELOPER_ACCESS, **kwargs):
436
437
437
438
path = "%s/%s/approve" % (self .manager .path , self .id )
438
439
data = {"access_level" : access_level }
439
- server_data = self .manager .gitlab .http_put (path , post_data = data , ** kwargs )
440
+ server_data = await self .manager .gitlab .http_put (path , post_data = data , ** kwargs )
440
441
self ._update_attrs (server_data )
441
442
442
443
@@ -445,7 +446,7 @@ class SubscribableMixin(object):
445
446
("ProjectIssue" , "ProjectMergeRequest" , "ProjectLabel" , "GroupLabel" )
446
447
)
447
448
@exc .on_http_error (exc .GitlabSubscribeError )
448
- def subscribe (self , ** kwargs ):
449
+ async def subscribe (self , ** kwargs ):
449
450
"""Subscribe to the object notifications.
450
451
451
452
Args:
@@ -456,14 +457,14 @@ def subscribe(self, **kwargs):
456
457
GitlabSubscribeError: If the subscription cannot be done
457
458
"""
458
459
path = "%s/%s/subscribe" % (self .manager .path , self .get_id ())
459
- server_data = self .manager .gitlab .http_post (path , ** kwargs )
460
+ server_data = await self .manager .gitlab .http_post (path , ** kwargs )
460
461
self ._update_attrs (server_data )
461
462
462
463
@cli .register_custom_action (
463
464
("ProjectIssue" , "ProjectMergeRequest" , "ProjectLabel" , "GroupLabel" )
464
465
)
465
466
@exc .on_http_error (exc .GitlabUnsubscribeError )
466
- def unsubscribe (self , ** kwargs ):
467
+ async def unsubscribe (self , ** kwargs ):
467
468
"""Unsubscribe from the object notifications.
468
469
469
470
Args:
@@ -474,14 +475,14 @@ def unsubscribe(self, **kwargs):
474
475
GitlabUnsubscribeError: If the unsubscription cannot be done
475
476
"""
476
477
path = "%s/%s/unsubscribe" % (self .manager .path , self .get_id ())
477
- server_data = self .manager .gitlab .http_post (path , ** kwargs )
478
+ server_data = await self .manager .gitlab .http_post (path , ** kwargs )
478
479
self ._update_attrs (server_data )
479
480
480
481
481
482
class TodoMixin (object ):
482
483
@cli .register_custom_action (("ProjectIssue" , "ProjectMergeRequest" ))
483
484
@exc .on_http_error (exc .GitlabTodoError )
484
- def todo (self , ** kwargs ):
485
+ async def todo (self , ** kwargs ):
485
486
"""Create a todo associated to the object.
486
487
487
488
Args:
@@ -492,13 +493,13 @@ def todo(self, **kwargs):
492
493
GitlabTodoError: If the todo cannot be set
493
494
"""
494
495
path = "%s/%s/todo" % (self .manager .path , self .get_id ())
495
- self .manager .gitlab .http_post (path , ** kwargs )
496
+ await self .manager .gitlab .http_post (path , ** kwargs )
496
497
497
498
498
499
class TimeTrackingMixin (object ):
499
500
@cli .register_custom_action (("ProjectIssue" , "ProjectMergeRequest" ))
500
501
@exc .on_http_error (exc .GitlabTimeTrackingError )
501
- def time_stats (self , ** kwargs ):
502
+ async def time_stats (self , ** kwargs ):
502
503
"""Get time stats for the object.
503
504
504
505
Args:
@@ -514,11 +515,11 @@ def time_stats(self, **kwargs):
514
515
return self .attributes ["time_stats" ]
515
516
516
517
path = "%s/%s/time_stats" % (self .manager .path , self .get_id ())
517
- return self .manager .gitlab .http_get (path , ** kwargs )
518
+ return await self .manager .gitlab .http_get (path , ** kwargs )
518
519
519
520
@cli .register_custom_action (("ProjectIssue" , "ProjectMergeRequest" ), ("duration" ,))
520
521
@exc .on_http_error (exc .GitlabTimeTrackingError )
521
- def time_estimate (self , duration , ** kwargs ):
522
+ async def time_estimate (self , duration , ** kwargs ):
522
523
"""Set an estimated time of work for the object.
523
524
524
525
Args:
@@ -531,11 +532,11 @@ def time_estimate(self, duration, **kwargs):
531
532
"""
532
533
path = "%s/%s/time_estimate" % (self .manager .path , self .get_id ())
533
534
data = {"duration" : duration }
534
- return self .manager .gitlab .http_post (path , post_data = data , ** kwargs )
535
+ return await self .manager .gitlab .http_post (path , post_data = data , ** kwargs )
535
536
536
537
@cli .register_custom_action (("ProjectIssue" , "ProjectMergeRequest" ))
537
538
@exc .on_http_error (exc .GitlabTimeTrackingError )
538
- def reset_time_estimate (self , ** kwargs ):
539
+ async def reset_time_estimate (self , ** kwargs ):
539
540
"""Resets estimated time for the object to 0 seconds.
540
541
541
542
Args:
@@ -546,11 +547,11 @@ def reset_time_estimate(self, **kwargs):
546
547
GitlabTimeTrackingError: If the time tracking update cannot be done
547
548
"""
548
549
path = "%s/%s/reset_time_estimate" % (self .manager .path , self .get_id ())
549
- return self .manager .gitlab .http_post (path , ** kwargs )
550
+ return await self .manager .gitlab .http_post (path , ** kwargs )
550
551
551
552
@cli .register_custom_action (("ProjectIssue" , "ProjectMergeRequest" ), ("duration" ,))
552
553
@exc .on_http_error (exc .GitlabTimeTrackingError )
553
- def add_spent_time (self , duration , ** kwargs ):
554
+ async def add_spent_time (self , duration , ** kwargs ):
554
555
"""Add time spent working on the object.
555
556
556
557
Args:
@@ -563,11 +564,11 @@ def add_spent_time(self, duration, **kwargs):
563
564
"""
564
565
path = "%s/%s/add_spent_time" % (self .manager .path , self .get_id ())
565
566
data = {"duration" : duration }
566
- return self .manager .gitlab .http_post (path , post_data = data , ** kwargs )
567
+ return await self .manager .gitlab .http_post (path , post_data = data , ** kwargs )
567
568
568
569
@cli .register_custom_action (("ProjectIssue" , "ProjectMergeRequest" ))
569
570
@exc .on_http_error (exc .GitlabTimeTrackingError )
570
- def reset_spent_time (self , ** kwargs ):
571
+ async def reset_spent_time (self , ** kwargs ):
571
572
"""Resets the time spent working on the object.
572
573
573
574
Args:
@@ -578,13 +579,13 @@ def reset_spent_time(self, **kwargs):
578
579
GitlabTimeTrackingError: If the time tracking update cannot be done
579
580
"""
580
581
path = "%s/%s/reset_spent_time" % (self .manager .path , self .get_id ())
581
- return self .manager .gitlab .http_post (path , ** kwargs )
582
+ return await self .manager .gitlab .http_post (path , ** kwargs )
582
583
583
584
584
585
class ParticipantsMixin (object ):
585
586
@cli .register_custom_action (("ProjectMergeRequest" , "ProjectIssue" ))
586
587
@exc .on_http_error (exc .GitlabListError )
587
- def participants (self , ** kwargs ):
588
+ async def participants (self , ** kwargs ):
588
589
"""List the participants.
589
590
590
591
Args:
@@ -604,15 +605,15 @@ def participants(self, **kwargs):
604
605
"""
605
606
606
607
path = "%s/%s/participants" % (self .manager .path , self .get_id ())
607
- return self .manager .gitlab .http_get (path , ** kwargs )
608
+ return await self .manager .gitlab .http_get (path , ** kwargs )
608
609
609
610
610
611
class BadgeRenderMixin (object ):
611
612
@cli .register_custom_action (
612
613
("GroupBadgeManager" , "ProjectBadgeManager" ), ("link_url" , "image_url" )
613
614
)
614
615
@exc .on_http_error (exc .GitlabRenderError )
615
- def render (self , link_url , image_url , ** kwargs ):
616
+ async def render (self , link_url , image_url , ** kwargs ):
616
617
"""Preview link_url and image_url after interpolation.
617
618
618
619
Args:
@@ -629,4 +630,4 @@ def render(self, link_url, image_url, **kwargs):
629
630
"""
630
631
path = "%s/render" % self .path
631
632
data = {"link_url" : link_url , "image_url" : image_url }
632
- return self .gitlab .http_get (path , data , ** kwargs )
633
+ return await self .gitlab .http_get (path , data , ** kwargs )
0 commit comments