diff --git a/docs/gl_objects/remote_mirrors.rst b/docs/gl_objects/remote_mirrors.rst index 902422848..58ecc578a 100644 --- a/docs/gl_objects/remote_mirrors.rst +++ b/docs/gl_objects/remote_mirrors.rst @@ -32,3 +32,7 @@ Update an existing remote mirror's attributes:: mirror.enabled = False mirror.only_protected_branches = True mirror.save() + +Delete an existing remote mirror:: + + mirror.delete() diff --git a/gitlab/v4/objects/projects.py b/gitlab/v4/objects/projects.py index 5175f9f90..61030c12f 100644 --- a/gitlab/v4/objects/projects.py +++ b/gitlab/v4/objects/projects.py @@ -23,6 +23,7 @@ from gitlab.mixins import ( CreateMixin, CRUDMixin, + DeleteMixin, GetWithoutIdMixin, ListMixin, ObjectDeleteMixin, @@ -1199,11 +1200,13 @@ def create( return cast(ProjectFork, CreateMixin.create(self, data, path=path, **kwargs)) -class ProjectRemoteMirror(SaveMixin, RESTObject): +class ProjectRemoteMirror(ObjectDeleteMixin, SaveMixin, RESTObject): pass -class ProjectRemoteMirrorManager(ListMixin, CreateMixin, UpdateMixin, RESTManager): +class ProjectRemoteMirrorManager( + ListMixin, CreateMixin, UpdateMixin, DeleteMixin, RESTManager +): _path = "/projects/{project_id}/remote_mirrors" _obj_cls = ProjectRemoteMirror _from_parent_attrs = {"project_id": "id"} diff --git a/tests/functional/api/test_projects.py b/tests/functional/api/test_projects.py index 91319dab8..ff9109c68 100644 --- a/tests/functional/api/test_projects.py +++ b/tests/functional/api/test_projects.py @@ -282,6 +282,8 @@ def test_project_remote_mirrors(project): assert mirror.url == mirror_url assert mirror.enabled is True + mirror.delete() + def test_project_services(project): # Use 'update' to create a service as we don't have a 'create' method and diff --git a/tests/unit/objects/test_remote_mirrors.py b/tests/unit/objects/test_remote_mirrors.py index 1ac35a25b..f493032e8 100644 --- a/tests/unit/objects/test_remote_mirrors.py +++ b/tests/unit/objects/test_remote_mirrors.py @@ -48,6 +48,12 @@ def resp_remote_mirrors(): content_type="application/json", status=200, ) + + rsps.add( + method=responses.DELETE, + url="http://localhost/api/v4/projects/1/remote_mirrors/1", + status=204, + ) yield rsps @@ -70,3 +76,8 @@ def test_update_project_remote_mirror(project, resp_remote_mirrors): mirror.save() assert mirror.update_status == "finished" assert mirror.only_protected_branches + + +def test_delete_project_remote_mirror(project, resp_remote_mirrors): + mirror = project.remote_mirrors.create({"url": "https://example.com"}) + mirror.delete()