From ec92d39be82c45e685e999162803847f0aa8b424 Mon Sep 17 00:00:00 2001 From: Elmar Hoffmann Date: Mon, 13 Oct 2014 17:33:55 +0200 Subject: [PATCH 1/2] support setting visibility_level on project creation --- gitlab/__init__.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/gitlab/__init__.py b/gitlab/__init__.py index efec5e5..874945e 100644 --- a/gitlab/__init__.py +++ b/gitlab/__init__.py @@ -424,8 +424,8 @@ def getprojectevents(self, id_, page=1, per_page=20): def createproject(self, name, namespace_id=None, description="", issues_enabled=0, wall_enabled=0, merge_requests_enabled=0, wiki_enabled=0, - snippets_enabled=0, public=0, sudo="", - import_url=""): + snippets_enabled=0, public=0, visibility_level=-1, + sudo="", import_url=""): """ Create a project :param name: Obligatory @@ -443,12 +443,22 @@ def createproject(self, name, namespace_id=None, description="", if sudo != "": data['sudo'] = sudo - # if gitlab is the new 6th version, there is a public option for the - # project creation + # to define repository visibilty to other users, in gitlab version 6 + # there is a public option and in gitlab version 7 there is a + # visibility_level option for the project creation. if type(public) != int: raise TypeError + if type(visibility_level) != int: + raise TypeError + + if visibility_level > 0: + if public != 0: + raise ValueError('Only one of public and visibility_level arguments may be provided') + data['visibility_level'] = visibility_level + if public != 0: data['public'] = public + request = requests.post(self.projects_url, headers=self.headers, data=data, verify=self.verify_ssl) if request.status_code == 201: From cc3a5484706da821e52e8b7a3dd9532e0cfb3a0d Mon Sep 17 00:00:00 2001 From: Elmar Hoffmann Date: Mon, 13 Oct 2014 17:50:03 +0200 Subject: [PATCH 2/2] allow specifying names for visibility_level --- gitlab/__init__.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/gitlab/__init__.py b/gitlab/__init__.py index 874945e..0ab676a 100644 --- a/gitlab/__init__.py +++ b/gitlab/__init__.py @@ -449,7 +449,17 @@ def createproject(self, name, namespace_id=None, description="", if type(public) != int: raise TypeError if type(visibility_level) != int: - raise TypeError + if type(visibility_level) == str: + if visibility_level.lower() == "private": + visibility_level = 0 + elif visibility_level.lower() == "internal": + visibility_level = 10 + elif visibility_level.lower() == "public": + visibility_level = 20 + else: + raise ValueError + else: + raise TypeError if visibility_level > 0: if public != 0: