Skip to content

Commit

Permalink
Merge branch 'group-variables'
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauvain Pocentek committed Sep 2, 2017
2 parents 0e0d4ae + eb191df commit fcccfbd
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
8 changes: 6 additions & 2 deletions docs/gl_objects/builds.py
@@ -1,13 +1,16 @@
# var list
variables = project.variables.list()
p_variables = project.variables.list()
g_variables = group.variables.list()
# end var list

# var get
var = project.variables.get(var_key)
p_var = project.variables.get(var_key)
g_var = group.variables.get(var_key)
# end var get

# var create
var = project.variables.create({'key': 'key1', 'value': 'value1'})
var = group.variables.create({'key': 'key1', 'value': 'value1'})
# end var create

# var update
Expand All @@ -17,6 +20,7 @@

# var delete
project.variables.delete(var_key)
group.variables.delete(var_key)
# or
var.delete()
# end var delete
Expand Down
16 changes: 11 additions & 5 deletions docs/gl_objects/builds.rst
Expand Up @@ -56,11 +56,11 @@ Remove a trigger:
:start-after: # trigger delete
:end-before: # end trigger delete

Project variables
=================
Projects and groups variables
=============================

You can associate variables to projects to modify the build/job script
behavior.
You can associate variables to projects and groups to modify the build/job
scripts behavior.

Reference
---------
Expand All @@ -70,6 +70,9 @@ Reference
+ :class:`gitlab.v4.objects.ProjectVariable`
+ :class:`gitlab.v4.objects.ProjectVariableManager`
+ :attr:`gitlab.v4.objects.Project.variables`
+ :class:`gitlab.v4.objects.GroupVariable`
+ :class:`gitlab.v4.objects.GroupVariableManager`
+ :attr:`gitlab.v4.objects.Group.variables`

* v3 API

Expand All @@ -78,7 +81,10 @@ Reference
+ :attr:`gitlab.v3.objects.Project.variables`
+ :attr:`gitlab.Gitlab.project_variables`

* GitLab API: https://docs.gitlab.com/ce/api/project_level_variables.html
* GitLab API

+ https://docs.gitlab.com/ce/api/project_level_variables.html
+ https://docs.gitlab.com/ce/api/group_level_variables.html

Examples
--------
Expand Down
13 changes: 13 additions & 0 deletions gitlab/v4/objects.py
Expand Up @@ -2185,6 +2185,18 @@ class GroupProjectManager(GetFromListMixin, RESTManager):
'ci_enabled_first')


class GroupVariable(SaveMixin, ObjectDeleteMixin, RESTObject):
_id_attr = 'key'


class GroupVariableManager(CRUDMixin, RESTManager):
_path = '/groups/%(group_id)s/variables'
_obj_cls = GroupVariable
_from_parent_attrs = {'group_id': 'id'}
_create_attrs = (('key', 'value'), ('protected',))
_update_attrs = (('key', 'value'), ('protected',))


class Group(SaveMixin, ObjectDeleteMixin, RESTObject):
_short_print_attr = 'name'
_managers = (
Expand All @@ -2193,6 +2205,7 @@ class Group(SaveMixin, ObjectDeleteMixin, RESTObject):
('notificationsettings', 'GroupNotificationSettingsManager'),
('projects', 'GroupProjectManager'),
('issues', 'GroupIssueManager'),
('variables', 'GroupVariableManager'),
)

@cli.register_custom_action('Group', ('to_project_id', ))
Expand Down
12 changes: 12 additions & 0 deletions tools/python_test_v4.py
Expand Up @@ -170,6 +170,18 @@
settings = group2.notificationsettings.get()
assert(settings.level == 'disabled')

# group variables
group1.variables.create({'key': 'foo', 'value': 'bar'})
g_v = group1.variables.get('foo')
assert(g_v.value == 'bar')
g_v.value = 'baz'
g_v.save()
g_v = group1.variables.get('foo')
assert(g_v.value == 'baz')
assert(len(group1.variables.list()) == 1)
g_v.delete()
assert(len(group1.variables.list()) == 0)

# hooks
hook = gl.hooks.create({'url': 'http://whatever.com'})
assert(len(gl.hooks.list()) == 1)
Expand Down

0 comments on commit fcccfbd

Please sign in to comment.