Skip to content

Commit c8c4b42

Browse files
committed
Add support for unsharing projects to v3 API (untested)
1 parent 5fdd06e commit c8c4b42

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

gitlab/v3/cli.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
'archive': {'required': ['id']},
7070
'unarchive': {'required': ['id']},
7171
'share': {'required': ['id', 'group-id', 'group-access']},
72+
'unshare': {'required': ['id', 'group-id']},
7273
'upload': {'required': ['id', 'filename', 'filepath']}},
7374
gitlab.v3.objects.User: {
7475
'block': {'required': ['id']},
@@ -213,6 +214,13 @@ def do_project_share(self, cls, gl, what, args):
213214
except Exception as e:
214215
cli.die("Impossible to share project", e)
215216

217+
def do_project_unshare(self, cls, gl, what, args):
218+
try:
219+
o = self.do_get(cls, gl, what, args)
220+
o.unshare(args['group_id'])
221+
except Exception as e:
222+
cli.die("Impossible to unshare project", e)
223+
216224
def do_user_block(self, cls, gl, what, args):
217225
try:
218226
o = self.do_get(cls, gl, what, args)

gitlab/v3/objects.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2056,6 +2056,20 @@ def share(self, group_id, group_access, **kwargs):
20562056
r = self.gitlab._raw_post(url, data=data, **kwargs)
20572057
raise_error_from_response(r, GitlabCreateError, 201)
20582058

2059+
def unshare(self, group_id, **kwargs):
2060+
"""Delete a shared project link within a group.
2061+
2062+
Args:
2063+
group_id (int): ID of the group.
2064+
2065+
Raises:
2066+
GitlabConnectionError: If the server cannot be reached.
2067+
GitlabDeleteError: If the server fails to perform the request.
2068+
"""
2069+
url = "/projects/%s/share/%s" % (self.id, group_id)
2070+
r = self.gitlab._raw_delete(url, **kwargs)
2071+
raise_error_from_response(r, GitlabDeleteError, 204)
2072+
20592073
def trigger_build(self, ref, token, variables={}, **kwargs):
20602074
"""Trigger a CI build.
20612075

0 commit comments

Comments
 (0)