Skip to content

Commit 1d55e67

Browse files
author
Gauvain Pocentek
committed
Allow creation of objects using the "hidden API"
1 parent 123a01e commit 1d55e67

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

gitlab.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,11 @@ def _getListOrObject(self, cls, id, **kwargs):
374374
raise GitlabGetError
375375

376376
return cls.list(self.gitlab, **kwargs)
377+
elif isinstance(id, dict):
378+
if not cls.canCreate:
379+
raise GitlabCreateError
380+
381+
return cls(self.gitlab, id, **kwargs)
377382
else:
378383
if not cls.canGet:
379384
raise GitlabGetError
@@ -536,28 +541,28 @@ class ProjectCommit(GitlabObject):
536541
class ProjectKey(GitlabObject):
537542
_url = '/projects/%(project_id)d/keys'
538543
canUpdate = False
539-
requiredCreateAttrs = ['title', 'key']
544+
requiredCreateAttrs = ['project_id', 'title', 'key']
540545

541546

542547
class ProjectHook(GitlabObject):
543548
_url = '/projects/%(project_id)d/hooks'
544-
requiredCreateAttrs = ['url']
549+
requiredCreateAttrs = ['project_id', 'url']
545550

546551

547552
class ProjectIssueNote(GitlabObject):
548553
_url = '/projects/%(project_id)d/issues/%(issue_id)d/notes'
549554
_constructorTypes = {'author': 'User'}
550555
canUpdate = False
551556
canDelete = False
552-
requiredCreateAttrs = ['body']
557+
requiredCreateAttrs = ['project_id', 'body']
553558

554559

555560
class ProjectIssue(GitlabObject):
556561
_url = '/projects/%(project_id)s/issues/'
557562
_constructorTypes = {'author': 'User', 'assignee': 'User',
558563
'milestone': 'ProjectMilestone'}
559564
canDelete = False
560-
requiredCreateAttrs = ['title']
565+
requiredCreateAttrs = ['project_id', 'title']
561566
optionalCreateAttrs = ['description', 'assignee_id', 'milestone_id',
562567
'labels']
563568

@@ -571,15 +576,15 @@ def Note(self, id=None, **kwargs):
571576
class ProjectMember(GitlabObject):
572577
_url = '/projects/%(project_id)d/members'
573578
_returnClass = User
574-
requiredCreateAttrs = ['user_id', 'access_level']
579+
requiredCreateAttrs = ['project_id', 'user_id', 'access_level']
575580

576581

577582
class ProjectNote(GitlabObject):
578583
_url = '/projects/%(project_id)d/notes'
579584
_constructorTypes = {'author': 'User'}
580585
canUpdate = False
581586
canDelete = False
582-
requiredCreateAttrs = ['body']
587+
requiredCreateAttrs = ['project_id', 'body']
583588

584589

585590
class ProjectTag(GitlabObject):
@@ -603,7 +608,7 @@ class ProjectMergeRequest(GitlabObject):
603608
_url = '/projects/%(project_id)d/merge_request'
604609
_constructorTypes = {'author': 'User', 'assignee': 'User'}
605610
canDelete = False
606-
requiredCreateAttrs = ['source_branch', 'target_branch', 'title']
611+
requiredCreateAttrs = ['project_id', 'source_branch', 'target_branch', 'title']
607612
optionalCreateAttrs = ['assignee_id']
608613

609614
def Note(self, id=None, **kwargs):
@@ -616,7 +621,7 @@ def Note(self, id=None, **kwargs):
616621
class ProjectMilestone(GitlabObject):
617622
_url = '/projects/%(project_id)s/milestones'
618623
canDelete = False
619-
requiredCreateAttrs = ['title']
624+
requiredCreateAttrs = ['project_id', 'title']
620625
optionalCreateAttrs = ['description', 'due_date']
621626

622627

@@ -625,13 +630,13 @@ class ProjectSnippetNote(GitlabObject):
625630
_constructorTypes = {'author': 'User'}
626631
canUpdate = False
627632
canDelete = False
628-
requiredCreateAttrs = ['body']
633+
requiredCreateAttrs = ['project_id', 'snippet_id', 'body']
629634

630635

631636
class ProjectSnippet(GitlabObject):
632637
_url = '/projects/%(project_id)d/snippets'
633638
_constructorTypes = {'author': 'User'}
634-
requiredCreateAttrs = ['title', 'file_name', 'code']
639+
requiredCreateAttrs = ['project_id', 'title', 'file_name', 'code']
635640
optionalCreateAttrs = ['lifetime']
636641

637642
def Note(self, id=None, **kwargs):

0 commit comments

Comments
 (0)