Skip to content

Commit a636d5a

Browse files
author
Gauvain Pocentek
committed
Provide a create method for GitlabObject's
Instead of using the constructor to do everything (get, list and create), we now provide a class method for each action. This should make code easier to read.
1 parent 7e61a28 commit a636d5a

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

gitlab/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,16 @@ def delete(self, **kwargs):
761761

762762
return self.gitlab.delete(self, **kwargs)
763763

764+
@classmethod
765+
def create(cls, gl, data, **kwargs):
766+
if not cls.canCreate:
767+
raise NotImplementedError
768+
769+
obj = cls(gl, data, **kwargs)
770+
obj.save()
771+
772+
return obj
773+
764774
def __init__(self, gl, data=None, **kwargs):
765775
self._created = False
766776
self.gitlab = gl

gitlab/cli.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ def do_create(cls, gl, what, args):
149149
die("%s objects can't be created" % what)
150150

151151
try:
152-
o = cls(gl, args)
153-
o.save()
152+
o = cls.create(gl, args)
154153
except Exception as e:
155154
die("Impossible to create object (%s)" % str(e))
156155

0 commit comments

Comments
 (0)