diff options
author | Gauvain Pocentek <gauvain@pocentek.net> | 2018-01-01 15:30:24 +0100 |
---|---|---|
committer | Gauvain Pocentek <gauvain@pocentek.net> | 2018-01-01 15:30:24 +0100 |
commit | f5850d950a77b1d985fdc3d1639e2627468d3548 (patch) | |
tree | 908316276b55d8897ff0dcb6c30315bc6efa731d | |
parent | c281d95c2f978d8d2eb1d77352babf5217d32062 (diff) | |
download | gitlab-f5850d950a77b1d985fdc3d1639e2627468d3548.tar.gz |
Add support for features flags
Fixes #360
-rw-r--r-- | docs/api-objects.rst | 1 | ||||
-rw-r--r-- | docs/gl_objects/features.rst | 26 | ||||
-rw-r--r-- | gitlab/__init__.py | 1 | ||||
-rw-r--r-- | gitlab/mixins.py | 2 | ||||
-rw-r--r-- | gitlab/v4/objects.py | 32 | ||||
-rw-r--r-- | tools/python_test_v4.py | 5 |
6 files changed, 66 insertions, 1 deletions
diff --git a/docs/api-objects.rst b/docs/api-objects.rst index b18c4ce..6879856 100644 --- a/docs/api-objects.rst +++ b/docs/api-objects.rst @@ -15,6 +15,7 @@ API examples gl_objects/deploy_keys gl_objects/deployments gl_objects/environments + gl_objects/features gl_objects/groups gl_objects/issues gl_objects/labels diff --git a/docs/gl_objects/features.rst b/docs/gl_objects/features.rst new file mode 100644 index 0000000..201d072 --- /dev/null +++ b/docs/gl_objects/features.rst @@ -0,0 +1,26 @@ +############## +Features flags +############## + +Reference +--------- + +* v4 API: + + + :class:`gitlab.v4.objects.Feature` + + :class:`gitlab.v4.objects.FeatureManager` + + :attr:`gitlab.Gitlab.features` + +* GitLab API: https://docs.gitlab.com/ce/api/features.html + +Examples +-------- + +List features:: + + features = gl.features.list() + +Create or set a feature:: + + feature = gl.features.set(feature_name, True) + feature = gl.features.set(feature_name, 30) diff --git a/gitlab/__init__.py b/gitlab/__init__.py index 950db86..b5f32c9 100644 --- a/gitlab/__init__.py +++ b/gitlab/__init__.py @@ -125,6 +125,7 @@ class Gitlab(object): self.teams = objects.TeamManager(self) else: self.dockerfiles = objects.DockerfileManager(self) + self.features = objects.FeatureManager(self) self.pagesdomains = objects.PagesDomainManager(self) self.user_activities = objects.UserActivitiesManager(self) diff --git a/gitlab/mixins.py b/gitlab/mixins.py index 0c06f92..cb35efc 100644 --- a/gitlab/mixins.py +++ b/gitlab/mixins.py @@ -242,7 +242,7 @@ class SetMixin(object): GitlabSetError: If an error occured Returns: - UserCustomAttribute: The created/updated user attribute + obj: The created/updated attribute """ path = '%s/%s' % (self.path, key.replace('/', '%2F')) data = {'value': value} diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py index 397bfb5..0a0cebd 100644 --- a/gitlab/v4/objects.py +++ b/gitlab/v4/objects.py @@ -400,6 +400,38 @@ class DockerfileManager(RetrieveMixin, RESTManager): _obj_cls = Dockerfile +class Feature(RESTObject): + _id_attr = 'name' + + +class FeatureManager(ListMixin, RESTManager): + _path = '/features/' + _obj_cls = Feature + + @exc.on_http_error(exc.GitlabSetError) + def set(self, name, value, feature_group=None, user=None, **kwargs): + """Create or update the object. + + Args: + name (str): The value to set for the object + value (bool/int): The value to set for the object + feature_group (str): A feature group name + user (str): A GitLab username + **kwargs: Extra options to send to the server (e.g. sudo) + + Raises: + GitlabAuthenticationError: If authentication is not correct + GitlabSetError: If an error occured + + Returns: + obj: The created/updated attribute + """ + path = '%s/%s' % (self.path, name.replace('/', '%2F')) + data = {'value': value, 'feature_group': feature_group, 'user': user} + server_data = self.gitlab.http_post(path, post_data=data, **kwargs) + return self._obj_cls(self, server_data) + + class Gitignore(RESTObject): _id_attr = 'name' diff --git a/tools/python_test_v4.py b/tools/python_test_v4.py index 1b86913..9a3d5e7 100644 --- a/tools/python_test_v4.py +++ b/tools/python_test_v4.py @@ -551,6 +551,11 @@ assert(len(ns) != 0) ns = gl.namespaces.list(search='root', all=True)[0] assert(ns.kind == 'user') +# features +feat = gl.features.set('foo', 30) +assert(feat.name == 'foo') +assert(len(gl.features.list()) == 1) + # broadcast messages msg = gl.broadcastmessages.create({'message': 'this is the message'}) msg.color = '#444444' |