Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 259668a

Browse filesBrowse files
nejchJohnVillalovos
authored andcommitted
feat(api): add project.transfer() and deprecate transfer_project()
1 parent 27e0742 commit 259668a
Copy full SHA for 259668a

File tree

Expand file treeCollapse file tree

5 files changed

+89
-6
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

5 files changed

+89
-6
lines changed
Open diff view settings
Collapse file

‎gitlab/v4/objects/projects.py‎

Copy file name to clipboardExpand all lines: gitlab/v4/objects/projects.py
+11-1Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import warnings
12
from typing import Any, Callable, cast, Dict, List, Optional, TYPE_CHECKING, Union
23

34
import requests
@@ -526,7 +527,7 @@ def mirror_pull(self, **kwargs: Any) -> None:
526527

527528
@cli.register_custom_action("Project", ("to_namespace",))
528529
@exc.on_http_error(exc.GitlabTransferProjectError)
529-
def transfer_project(self, to_namespace: str, **kwargs: Any) -> None:
530+
def transfer(self, to_namespace: str, **kwargs: Any) -> None:
530531
"""Transfer a project to the given namespace ID
531532
532533
Args:
@@ -543,6 +544,15 @@ def transfer_project(self, to_namespace: str, **kwargs: Any) -> None:
543544
path, post_data={"namespace": to_namespace}, **kwargs
544545
)
545546

547+
@cli.register_custom_action("Project", ("to_namespace",))
548+
def transfer_project(self, *args: Any, **kwargs: Any) -> None:
549+
warnings.warn(
550+
"The project.transfer_project() method is deprecated and will be "
551+
"removed in a future version. Use project.transfer() instead.",
552+
DeprecationWarning,
553+
)
554+
return self.transfer(*args, **kwargs)
555+
546556
@cli.register_custom_action("Project", ("ref_name", "job"), ("job_token",))
547557
@exc.on_http_error(exc.GitlabGetError)
548558
def artifacts(
Collapse file

‎tests/functional/api/test_groups.py‎

Copy file name to clipboardExpand all lines: tests/functional/api/test_groups.py
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,19 @@ def test_group_hooks(group):
231231
hook = group.hooks.get(hook.id)
232232
assert hook.note_events is True
233233
hook.delete()
234+
235+
236+
@pytest.mark.skip(reason="Pending #1807")
237+
def test_group_transfer(gl, group):
238+
transfer_group = gl.groups.create({"name": "transfer-test-group"})
239+
assert group.namespace["path"] != group.full_path
240+
241+
transfer_group.transfer(group.id)
242+
243+
transferred_group = gl.projects.get(transfer_group.id)
244+
assert transferred_group.namespace["path"] == group.full_path
245+
246+
transfer_group.transfer()
247+
248+
transferred_group = gl.projects.get(transfer_group.id)
249+
assert transferred_group.path == transferred_group.full_path
Collapse file

‎tests/functional/api/test_projects.py‎

Copy file name to clipboardExpand all lines: tests/functional/api/test_projects.py
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,3 +329,17 @@ def test_project_groups_list(gl, group):
329329
groups = project.groups.list()
330330
group_ids = set([x.id for x in groups])
331331
assert set((group.id, group2.id)) == group_ids
332+
333+
334+
def test_project_transfer(gl, project, group):
335+
assert project.namespace["path"] != group.full_path
336+
project.transfer_project(group.id)
337+
338+
project = gl.projects.get(project.id)
339+
assert project.namespace["path"] == group.full_path
340+
341+
gl.auth()
342+
project.transfer_project(gl.user.username)
343+
344+
project = gl.projects.get(project.id)
345+
assert project.namespace["path"] == gl.user.username
Collapse file

‎tests/unit/objects/test_groups.py‎

Copy file name to clipboardExpand all lines: tests/unit/objects/test_groups.py
+23-2Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import gitlab
1111
from gitlab.v4.objects import GroupDescendantGroup, GroupSubgroup
1212

13+
content = {"name": "name", "id": 1, "path": "path"}
1314
subgroup_descgroup_content = [
1415
{
1516
"id": 2,
@@ -41,8 +42,6 @@
4142

4243
@pytest.fixture
4344
def resp_groups():
44-
content = {"name": "name", "id": 1, "path": "path"}
45-
4645
with responses.RequestsMock(assert_all_requests_are_fired=False) as rsps:
4746
rsps.add(
4847
method=responses.GET,
@@ -96,6 +95,22 @@ def resp_create_import(accepted_content):
9695
yield rsps
9796

9897

98+
@pytest.fixture
99+
def resp_transfer_group():
100+
with responses.RequestsMock() as rsps:
101+
rsps.add(
102+
method=responses.PUT,
103+
url="http://localhost/api/v4/groups/1/transfer",
104+
json=content,
105+
content_type="application/json",
106+
status=200,
107+
match=[
108+
responses.matchers.json_params_matcher({"namespace": "test-namespace"})
109+
],
110+
)
111+
yield rsps
112+
113+
99114
def test_get_group(gl, resp_groups):
100115
data = gl.groups.get(1)
101116
assert isinstance(data, gitlab.v4.objects.Group)
@@ -153,3 +168,9 @@ def test_refresh_group_import_status(group, resp_groups):
153168
group_import = group.imports.get()
154169
group_import.refresh()
155170
assert group_import.import_status == "finished"
171+
172+
173+
@pytest.mark.skip("Pending #1807")
174+
def test_transfer_group(gl, resp_transfer_group):
175+
group = gl.groups.get(1, lazy=True)
176+
group.transfer("test-namespace")
Collapse file

‎tests/unit/objects/test_projects.py‎

Copy file name to clipboardExpand all lines: tests/unit/objects/test_projects.py
+25-3Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,22 @@ def resp_import_bitbucket_server():
5454
yield rsps
5555

5656

57+
@pytest.fixture
58+
def resp_transfer_project():
59+
with responses.RequestsMock() as rsps:
60+
rsps.add(
61+
method=responses.PUT,
62+
url="http://localhost/api/v4/projects/1/transfer",
63+
json=project_content,
64+
content_type="application/json",
65+
status=200,
66+
match=[
67+
responses.matchers.json_params_matcher({"namespace": "test-namespace"})
68+
],
69+
)
70+
yield rsps
71+
72+
5773
def test_get_project(gl, resp_get_project):
5874
data = gl.projects.get(1)
5975
assert isinstance(data, Project)
@@ -217,9 +233,15 @@ def test_delete_project_push_rule(gl):
217233
pass
218234

219235

220-
@pytest.mark.skip(reason="missing test")
221-
def test_transfer_project(gl):
222-
pass
236+
def test_transfer_project(gl, resp_transfer_project):
237+
project = gl.projects.get(1, lazy=True)
238+
project.transfer("test-namespace")
239+
240+
241+
def test_transfer_project_deprecated_warns(gl, resp_transfer_project):
242+
project = gl.projects.get(1, lazy=True)
243+
with pytest.warns(DeprecationWarning):
244+
project.transfer_project("test-namespace")
223245

224246

225247
@pytest.mark.skip(reason="missing test")

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.