summaryrefslogtreecommitdiff
path: root/gitlab
diff options
context:
space:
mode:
Diffstat (limited to 'gitlab')
-rw-r--r--gitlab/__init__.py3
-rw-r--r--gitlab/cli.py4
-rw-r--r--gitlab/objects.py14
3 files changed, 18 insertions, 3 deletions
diff --git a/gitlab/__init__.py b/gitlab/__init__.py
index d8ee5bf..28ebfe3 100644
--- a/gitlab/__init__.py
+++ b/gitlab/__init__.py
@@ -551,7 +551,8 @@ class Gitlab(object):
if missing:
raise GitlabUpdateError('Missing attribute(s): %s' %
", ".join(missing))
- url = self._construct_url(id_=obj.id, obj=obj, parameters=params)
+ obj_id = params[obj.idAttr] if obj._id_in_update_url else None
+ url = self._construct_url(id_=obj_id, obj=obj, parameters=params)
headers = self._create_headers(content_type="application/json")
# build data that can really be sent to server
diff --git a/gitlab/cli.py b/gitlab/cli.py
index c2b2fa5..8ac8e45 100644
--- a/gitlab/cli.py
+++ b/gitlab/cli.py
@@ -89,7 +89,7 @@ def _populate_sub_parser_by_class(cls, sub_parser):
required=True)
[sub_parser_action.add_argument("--%s" % x.replace('_', '-'),
required=True)
- for x in cls.requiredGetAttrs]
+ for x in cls.requiredGetAttrs if x != cls.idAttr]
elif action_name == CREATE:
[sub_parser_action.add_argument("--%s" % x.replace('_', '-'),
@@ -109,7 +109,7 @@ def _populate_sub_parser_by_class(cls, sub_parser):
else cls.requiredCreateAttrs)
[sub_parser_action.add_argument("--%s" % x.replace('_', '-'),
required=True)
- for x in attrs]
+ for x in attrs if x != cls.idAttr]
attrs = (cls.optionalUpdateAttrs
if cls.optionalUpdateAttrs is not None
diff --git a/gitlab/objects.py b/gitlab/objects.py
index ddcbae7..0330807 100644
--- a/gitlab/objects.py
+++ b/gitlab/objects.py
@@ -178,6 +178,7 @@ class GitlabObject(object):
# plural
_urlPlural = None
_id_in_delete_url = True
+ _id_in_update_url = True
_returnClass = None
_constructorTypes = None
@@ -936,6 +937,7 @@ class ProjectMilestoneManager(BaseManager):
class ProjectLabel(GitlabObject):
_url = '/projects/%(project_id)s/labels'
_id_in_delete_url = False
+ _id_in_update_url = False
canGet = 'from_list'
requiredUrlAttrs = ['project_id']
idAttr = 'name'
@@ -1031,6 +1033,17 @@ class ProjectTriggerManager(BaseManager):
obj_cls = ProjectTrigger
+class ProjectVariable(GitlabObject):
+ _url = '/projects/%(project_id)s/variables'
+ idAttr = 'key'
+ requiredUrlAttrs = ['project_id']
+ requiredCreateAttrs = ['key', 'value']
+
+
+class ProjectVariableManager(BaseManager):
+ obj_cls = ProjectVariable
+
+
class Project(GitlabObject):
_url = '/projects'
_constructorTypes = {'owner': 'User', 'namespace': 'Group'}
@@ -1059,6 +1072,7 @@ class Project(GitlabObject):
('snippets', ProjectSnippetManager, [('project_id', 'id')]),
('tags', ProjectTagManager, [('project_id', 'id')]),
('triggers', ProjectTriggerManager, [('project_id', 'id')]),
+ ('variables', ProjectVariableManager, [('project_id', 'id')]),
]
def Branch(self, id=None, **kwargs):