diff options
-rw-r--r-- | gitlab/__init__.py | 10 | ||||
-rw-r--r-- | gitlab/cli.py | 3 |
2 files changed, 11 insertions, 2 deletions
diff --git a/gitlab/__init__.py b/gitlab/__init__.py index 638c5eb..ab4fc87 100644 --- a/gitlab/__init__.py +++ b/gitlab/__init__.py @@ -761,6 +761,16 @@ class GitlabObject(object): return self.gitlab.delete(self, **kwargs) + @classmethod + def create(cls, gl, data, **kwargs): + if not cls.canCreate: + raise NotImplementedError + + obj = cls(gl, data, **kwargs) + obj.save() + + return obj + def __init__(self, gl, data=None, **kwargs): self._created = False self.gitlab = gl diff --git a/gitlab/cli.py b/gitlab/cli.py index c3289df..2874a5f 100644 --- a/gitlab/cli.py +++ b/gitlab/cli.py @@ -149,8 +149,7 @@ def do_create(cls, gl, what, args): die("%s objects can't be created" % what) try: - o = cls(gl, args) - o.save() + o = cls.create(gl, args) except Exception as e: die("Impossible to create object (%s)" % str(e)) |