Skip to content

Commit 77d34b3

Browse files
author
Gauvain Pocentek
committed
Merge branch 'add_fork_support' of https://github.com/fgouteroux/python-gitlab into fgouteroux-add_fork_support
2 parents 2bf9794 + cedf080 commit 77d34b3

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

gitlab/__init__.py

+7
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,13 @@ def UserProject(self, id=None, **kwargs):
451451
DeprecationWarning)
452452
return UserProject._get_list_or_object(self, id, **kwargs)
453453

454+
def ProjectFork(self, id=None, **kwargs):
455+
"""Fork a project for a user.
456+
457+
id must be a dict.
458+
"""
459+
return ProjectFork._get_list_or_object(self, id, **kwargs)
460+
454461
def _list_projects(self, url, **kwargs):
455462
r = self._raw_get(url, **kwargs)
456463
raise_error_from_response(r, GitlabListError)

gitlab/objects.py

+28
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,15 @@ class ProjectEventManager(BaseManager):
545545
obj_cls = ProjectEvent
546546

547547

548+
class ProjectFork(GitlabObject):
549+
_url = '/projects/fork/%(project_id)s'
550+
canUpdate = False
551+
canDelete = False
552+
canList = False
553+
canGet = False
554+
requiredUrlAttrs = ['project_id']
555+
556+
548557
class ProjectHook(GitlabObject):
549558
_url = '/projects/%(project_id)s/hooks'
550559
requiredUrlAttrs = ['project_id']
@@ -956,6 +965,25 @@ def delete_file(self, path, branch, message, **kwargs):
956965
r = self.gitlab._raw_delete(url, **kwargs)
957966
raise_error_from_response(r, GitlabDeleteError)
958967

968+
def create_fork_relation(self, forked_from_id):
969+
"""Create a forked from/to relation between existing projects.
970+
971+
Args:
972+
forked_from_id (int): The ID of the project that was forked from
973+
974+
Raises:
975+
GitlabCreateError: Operation failed
976+
GitlabConnectionError: Connection to GitLab-server failed
977+
"""
978+
url = "/projects/%s/fork/%s" % (self.id, forked_from_id)
979+
r = self.gitlab._raw_post(url)
980+
raise_error_from_response(r, GitlabCreateError, 201)
981+
982+
def delete_fork_relation(self):
983+
url = "/projects/%s/fork" % self.id
984+
r = self.gitlab._raw_delete(url)
985+
raise_error_from_response(r, GitlabDeleteError)
986+
959987

960988
class TeamMember(GitlabObject):
961989
_url = '/user_teams/%(team_id)s/members'

0 commit comments

Comments
 (0)