@@ -40,6 +40,10 @@ class GitlabConnectionError(Exception):
40
40
pass
41
41
42
42
43
+ class GitlabListError (Exception ):
44
+ pass
45
+
46
+
43
47
class GitlabGetError (Exception ):
44
48
pass
45
49
@@ -166,6 +170,14 @@ def rawPut(self, path, with_token=False):
166
170
return r
167
171
168
172
def list (self , obj_class , ** kwargs ):
173
+ missing = []
174
+ for k in obj_class .requiredListAttrs :
175
+ if k not in kwargs :
176
+ missing .append (k )
177
+ if missing :
178
+ raise GitlabListError ('Missing attribute(s): %s' % \
179
+ ", " .join (missing ))
180
+
169
181
url = obj_class ._url
170
182
if kwargs :
171
183
url = obj_class ._url % kwargs
@@ -198,6 +210,14 @@ def list(self, obj_class, **kwargs):
198
210
raise GitlabGetError ('%d: %s' % (r .status_code , r .text ))
199
211
200
212
def get (self , obj_class , id = None , ** kwargs ):
213
+ missing = []
214
+ for k in obj_class .requiredGetAttrs :
215
+ if k not in kwargs :
216
+ missing .append (k )
217
+ if missing :
218
+ raise GitlabListError ('Missing attribute(s): %s' % \
219
+ ", " .join (missing ))
220
+
201
221
url = obj_class ._url
202
222
if kwargs :
203
223
url = obj_class ._url % kwargs
@@ -370,6 +390,8 @@ class GitlabObject(object):
370
390
canCreate = True
371
391
canUpdate = True
372
392
canDelete = True
393
+ requiredListAttrs = []
394
+ requiredGetAttrs = []
373
395
requiredCreateAttrs = []
374
396
optionalCreateAttrs = []
375
397
@@ -541,6 +563,8 @@ class ProjectBranch(GitlabObject):
541
563
canDelete = False
542
564
canUpdate = False
543
565
canCreate = False
566
+ requiredGetAttrs = ['project_id' ]
567
+ requiredListAttrs = ['project_id' ]
544
568
545
569
def protect (self , protect = True ):
546
570
url = self ._url % {'project_id' : self .project_id }
@@ -568,16 +592,21 @@ class ProjectCommit(GitlabObject):
568
592
canDelete = False
569
593
canUpdate = False
570
594
canCreate = False
595
+ requiredListAttrs = ['project_id' ]
571
596
572
597
573
598
class ProjectKey (GitlabObject ):
574
599
_url = '/projects/%(project_id)s/keys'
575
600
canUpdate = False
601
+ requiredListAttrs = ['project_id' ]
602
+ requiredGetAttrs = ['project_id' ]
576
603
requiredCreateAttrs = ['project_id' , 'title' , 'key' ]
577
604
578
605
579
606
class ProjectHook (GitlabObject ):
580
607
_url = '/projects/%(project_id)s/hooks'
608
+ requiredListAttrs = ['project_id' ]
609
+ requiredGetAttrs = ['project_id' ]
581
610
requiredCreateAttrs = ['project_id' , 'url' ]
582
611
583
612
@@ -586,6 +615,8 @@ class ProjectIssueNote(GitlabObject):
586
615
_constructorTypes = {'author' : 'User' }
587
616
canUpdate = False
588
617
canDelete = False
618
+ requiredListAttrs = ['project_id' , 'issue_id' ]
619
+ requiredGetAttrs = ['project_id' , 'issue_id' ]
589
620
requiredCreateAttrs = ['project_id' , 'body' ]
590
621
591
622
@@ -594,6 +625,8 @@ class ProjectIssue(GitlabObject):
594
625
_constructorTypes = {'author' : 'User' , 'assignee' : 'User' ,
595
626
'milestone' : 'ProjectMilestone' }
596
627
canDelete = False
628
+ requiredListAttrs = ['project_id' ]
629
+ requiredGetAttrs = ['project_id' ]
597
630
requiredCreateAttrs = ['project_id' , 'title' ]
598
631
optionalCreateAttrs = ['description' , 'assignee_id' , 'milestone_id' ,
599
632
'labels' ]
@@ -608,6 +641,8 @@ def Note(self, id=None, **kwargs):
608
641
class ProjectMember (GitlabObject ):
609
642
_url = '/projects/%(project_id)s/members'
610
643
_returnClass = User
644
+ requiredListAttrs = ['project_id' ]
645
+ requiredGetAttrs = ['project_id' ]
611
646
requiredCreateAttrs = ['project_id' , 'user_id' , 'access_level' ]
612
647
613
648
@@ -616,6 +651,8 @@ class ProjectNote(GitlabObject):
616
651
_constructorTypes = {'author' : 'User' }
617
652
canUpdate = False
618
653
canDelete = False
654
+ requiredListAttrs = ['project_id' ]
655
+ requiredGetAttrs = ['project_id' ]
619
656
requiredCreateAttrs = ['project_id' , 'body' ]
620
657
621
658
@@ -625,6 +662,7 @@ class ProjectTag(GitlabObject):
625
662
canDelete = False
626
663
canUpdate = False
627
664
canCreate = False
665
+ requiredListAttrs = ['project_id' ]
628
666
629
667
630
668
class ProjectMergeRequestNote (GitlabObject ):
@@ -634,12 +672,15 @@ class ProjectMergeRequestNote(GitlabObject):
634
672
canCreate = False
635
673
canUpdate = False
636
674
canDelete = False
675
+ requiredListAttrs = ['project_id' , 'merge_request_id' ]
637
676
638
677
639
678
class ProjectMergeRequest (GitlabObject ):
640
679
_url = '/projects/%(project_id)s/merge_request'
641
680
_constructorTypes = {'author' : 'User' , 'assignee' : 'User' }
642
681
canDelete = False
682
+ requiredListAttrs = ['project_id' ]
683
+ requiredGetAttrs = ['project_id' ]
643
684
requiredCreateAttrs = ['project_id' , 'source_branch' , 'target_branch' , 'title' ]
644
685
optionalCreateAttrs = ['assignee_id' ]
645
686
@@ -653,6 +694,8 @@ def Note(self, id=None, **kwargs):
653
694
class ProjectMilestone (GitlabObject ):
654
695
_url = '/projects/%(project_id)s/milestones'
655
696
canDelete = False
697
+ requiredListAttrs = ['project_id' ]
698
+ requiredGetAttrs = ['project_id' ]
656
699
requiredCreateAttrs = ['project_id' , 'title' ]
657
700
optionalCreateAttrs = ['description' , 'due_date' ]
658
701
@@ -662,12 +705,16 @@ class ProjectSnippetNote(GitlabObject):
662
705
_constructorTypes = {'author' : 'User' }
663
706
canUpdate = False
664
707
canDelete = False
708
+ requiredListAttrs = ['project_id' , 'snippet_id' ]
709
+ requiredGetAttrs = ['project_id' , 'snippet_id' ]
665
710
requiredCreateAttrs = ['project_id' , 'snippet_id' , 'body' ]
666
711
667
712
668
713
class ProjectSnippet (GitlabObject ):
669
714
_url = '/projects/%(project_id)s/snippets'
670
715
_constructorTypes = {'author' : 'User' }
716
+ requiredListAttrs = ['project_id' ]
717
+ requiredGetAttrs = ['project_id' ]
671
718
requiredCreateAttrs = ['project_id' , 'title' , 'file_name' , 'code' ]
672
719
optionalCreateAttrs = ['lifetime' ]
673
720
0 commit comments