Skip to content

Commit cd688b4

Browse files
committed
Merge pull request pyapi-gitlab#101 from credativ/project-visibility_level
Project visibility level
2 parents caaa0b6 + cc3a548 commit cd688b4

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

gitlab/__init__.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,8 @@ def getprojectevents(self, id_, page=1, per_page=20):
424424
def createproject(self, name, namespace_id=None, description="",
425425
issues_enabled=0, wall_enabled=0,
426426
merge_requests_enabled=0, wiki_enabled=0,
427-
snippets_enabled=0, public=0, sudo="",
428-
import_url=""):
427+
snippets_enabled=0, public=0, visibility_level=-1,
428+
sudo="", import_url=""):
429429
"""
430430
Create a project
431431
:param name: Obligatory
@@ -443,12 +443,32 @@ def createproject(self, name, namespace_id=None, description="",
443443
if sudo != "":
444444
data['sudo'] = sudo
445445

446-
# if gitlab is the new 6th version, there is a public option for the
447-
# project creation
446+
# to define repository visibilty to other users, in gitlab version 6
447+
# there is a public option and in gitlab version 7 there is a
448+
# visibility_level option for the project creation.
448449
if type(public) != int:
449450
raise TypeError
451+
if type(visibility_level) != int:
452+
if type(visibility_level) == str:
453+
if visibility_level.lower() == "private":
454+
visibility_level = 0
455+
elif visibility_level.lower() == "internal":
456+
visibility_level = 10
457+
elif visibility_level.lower() == "public":
458+
visibility_level = 20
459+
else:
460+
raise ValueError
461+
else:
462+
raise TypeError
463+
464+
if visibility_level > 0:
465+
if public != 0:
466+
raise ValueError('Only one of public and visibility_level arguments may be provided')
467+
data['visibility_level'] = visibility_level
468+
450469
if public != 0:
451470
data['public'] = public
471+
452472
request = requests.post(self.projects_url, headers=self.headers,
453473
data=data, verify=self.verify_ssl)
454474
if request.status_code == 201:

0 commit comments

Comments
 (0)