Skip to content

Commit

Permalink
Allow creation of objects using the "hidden API"
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauvain Pocentek committed May 18, 2013
1 parent 123a01e commit 1d55e67
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions gitlab.py
Expand Up @@ -374,6 +374,11 @@ def _getListOrObject(self, cls, id, **kwargs):
raise GitlabGetError

return cls.list(self.gitlab, **kwargs)
elif isinstance(id, dict):
if not cls.canCreate:
raise GitlabCreateError

return cls(self.gitlab, id, **kwargs)
else:
if not cls.canGet:
raise GitlabGetError
Expand Down Expand Up @@ -536,28 +541,28 @@ class ProjectCommit(GitlabObject):
class ProjectKey(GitlabObject):
_url = '/projects/%(project_id)d/keys'
canUpdate = False
requiredCreateAttrs = ['title', 'key']
requiredCreateAttrs = ['project_id', 'title', 'key']


class ProjectHook(GitlabObject):
_url = '/projects/%(project_id)d/hooks'
requiredCreateAttrs = ['url']
requiredCreateAttrs = ['project_id', 'url']


class ProjectIssueNote(GitlabObject):
_url = '/projects/%(project_id)d/issues/%(issue_id)d/notes'
_constructorTypes = {'author': 'User'}
canUpdate = False
canDelete = False
requiredCreateAttrs = ['body']
requiredCreateAttrs = ['project_id', 'body']


class ProjectIssue(GitlabObject):
_url = '/projects/%(project_id)s/issues/'
_constructorTypes = {'author': 'User', 'assignee': 'User',
'milestone': 'ProjectMilestone'}
canDelete = False
requiredCreateAttrs = ['title']
requiredCreateAttrs = ['project_id', 'title']
optionalCreateAttrs = ['description', 'assignee_id', 'milestone_id',
'labels']

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


class ProjectNote(GitlabObject):
_url = '/projects/%(project_id)d/notes'
_constructorTypes = {'author': 'User'}
canUpdate = False
canDelete = False
requiredCreateAttrs = ['body']
requiredCreateAttrs = ['project_id', 'body']


class ProjectTag(GitlabObject):
Expand All @@ -603,7 +608,7 @@ class ProjectMergeRequest(GitlabObject):
_url = '/projects/%(project_id)d/merge_request'
_constructorTypes = {'author': 'User', 'assignee': 'User'}
canDelete = False
requiredCreateAttrs = ['source_branch', 'target_branch', 'title']
requiredCreateAttrs = ['project_id', 'source_branch', 'target_branch', 'title']
optionalCreateAttrs = ['assignee_id']

def Note(self, id=None, **kwargs):
Expand All @@ -616,7 +621,7 @@ def Note(self, id=None, **kwargs):
class ProjectMilestone(GitlabObject):
_url = '/projects/%(project_id)s/milestones'
canDelete = False
requiredCreateAttrs = ['title']
requiredCreateAttrs = ['project_id', 'title']
optionalCreateAttrs = ['description', 'due_date']


Expand All @@ -625,13 +630,13 @@ class ProjectSnippetNote(GitlabObject):
_constructorTypes = {'author': 'User'}
canUpdate = False
canDelete = False
requiredCreateAttrs = ['body']
requiredCreateAttrs = ['project_id', 'snippet_id', 'body']


class ProjectSnippet(GitlabObject):
_url = '/projects/%(project_id)d/snippets'
_constructorTypes = {'author': 'User'}
requiredCreateAttrs = ['title', 'file_name', 'code']
requiredCreateAttrs = ['project_id', 'title', 'file_name', 'code']
optionalCreateAttrs = ['lifetime']

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

0 comments on commit 1d55e67

Please sign in to comment.