Skip to content
This repository was archived by the owner on Nov 4, 2020. It is now read-only.

Project visibility level #101

Merged
merged 2 commits into from
Oct 23, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions gitlab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -443,12 +443,32 @@ 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:
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:
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:
Expand Down