Skip to content

Commit f5850d9

Browse files
author
Gauvain Pocentek
committed
Add support for features flags
Fixes #360
1 parent c281d95 commit f5850d9

File tree

6 files changed

+66
-1
lines changed

6 files changed

+66
-1
lines changed

docs/api-objects.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ API examples
1515
gl_objects/deploy_keys
1616
gl_objects/deployments
1717
gl_objects/environments
18+
gl_objects/features
1819
gl_objects/groups
1920
gl_objects/issues
2021
gl_objects/labels

docs/gl_objects/features.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
##############
2+
Features flags
3+
##############
4+
5+
Reference
6+
---------
7+
8+
* v4 API:
9+
10+
+ :class:`gitlab.v4.objects.Feature`
11+
+ :class:`gitlab.v4.objects.FeatureManager`
12+
+ :attr:`gitlab.Gitlab.features`
13+
14+
* GitLab API: https://docs.gitlab.com/ce/api/features.html
15+
16+
Examples
17+
--------
18+
19+
List features::
20+
21+
features = gl.features.list()
22+
23+
Create or set a feature::
24+
25+
feature = gl.features.set(feature_name, True)
26+
feature = gl.features.set(feature_name, 30)

gitlab/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ def __init__(self, url, private_token=None, oauth_token=None, email=None,
125125
self.teams = objects.TeamManager(self)
126126
else:
127127
self.dockerfiles = objects.DockerfileManager(self)
128+
self.features = objects.FeatureManager(self)
128129
self.pagesdomains = objects.PagesDomainManager(self)
129130
self.user_activities = objects.UserActivitiesManager(self)
130131

gitlab/mixins.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def set(self, key, value, **kwargs):
242242
GitlabSetError: If an error occured
243243
244244
Returns:
245-
UserCustomAttribute: The created/updated user attribute
245+
obj: The created/updated attribute
246246
"""
247247
path = '%s/%s' % (self.path, key.replace('/', '%2F'))
248248
data = {'value': value}

gitlab/v4/objects.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,38 @@ class DockerfileManager(RetrieveMixin, RESTManager):
400400
_obj_cls = Dockerfile
401401

402402

403+
class Feature(RESTObject):
404+
_id_attr = 'name'
405+
406+
407+
class FeatureManager(ListMixin, RESTManager):
408+
_path = '/features/'
409+
_obj_cls = Feature
410+
411+
@exc.on_http_error(exc.GitlabSetError)
412+
def set(self, name, value, feature_group=None, user=None, **kwargs):
413+
"""Create or update the object.
414+
415+
Args:
416+
name (str): The value to set for the object
417+
value (bool/int): The value to set for the object
418+
feature_group (str): A feature group name
419+
user (str): A GitLab username
420+
**kwargs: Extra options to send to the server (e.g. sudo)
421+
422+
Raises:
423+
GitlabAuthenticationError: If authentication is not correct
424+
GitlabSetError: If an error occured
425+
426+
Returns:
427+
obj: The created/updated attribute
428+
"""
429+
path = '%s/%s' % (self.path, name.replace('/', '%2F'))
430+
data = {'value': value, 'feature_group': feature_group, 'user': user}
431+
server_data = self.gitlab.http_post(path, post_data=data, **kwargs)
432+
return self._obj_cls(self, server_data)
433+
434+
403435
class Gitignore(RESTObject):
404436
_id_attr = 'name'
405437

tools/python_test_v4.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,11 @@
551551
ns = gl.namespaces.list(search='root', all=True)[0]
552552
assert(ns.kind == 'user')
553553

554+
# features
555+
feat = gl.features.set('foo', 30)
556+
assert(feat.name == 'foo')
557+
assert(len(gl.features.list()) == 1)
558+
554559
# broadcast messages
555560
msg = gl.broadcastmessages.create({'message': 'this is the message'})
556561
msg.color = '#444444'

0 commit comments

Comments
 (0)