Skip to content

Commit 07a4167

Browse files
feat: add sync method to force remote mirror updates
Add ProjectRemoteMirror.sync() method to trigger immediate push mirror updates. Closes: #3223
1 parent b483ece commit 07a4167

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

docs/gl_objects/remote_mirrors.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,7 @@ Update an existing remote mirror's attributes::
3636
Delete an existing remote mirror::
3737

3838
mirror.delete()
39+
40+
Force push mirror update::
41+
42+
mirror.sync()

gitlab/v4/objects/projects.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,20 @@ def create(self, data: dict[str, Any] | None = None, **kwargs: Any) -> ProjectFo
12331233

12341234

12351235
class ProjectRemoteMirror(ObjectDeleteMixin, SaveMixin, RESTObject):
1236-
pass
1236+
@cli.register_custom_action(cls_names="ProjectRemoteMirror")
1237+
@exc.on_http_error(exc.GitlabCreateError)
1238+
def sync(self, **kwargs: Any) -> dict[str, Any] | requests.Response:
1239+
"""Force push mirror update.
1240+
1241+
Args:
1242+
**kwargs: Extra options to send to the server (e.g. sudo)
1243+
1244+
Raises:
1245+
GitlabAuthenticationError: If authentication is not correct
1246+
GitlabCreateError: If the server cannot perform the request
1247+
"""
1248+
path = f"{self.manager.path}/{self.encoded_id}/sync"
1249+
return self.manager.gitlab.http_post(path, **kwargs)
12371250

12381251

12391252
class ProjectRemoteMirrorManager(

tests/unit/objects/test_remote_mirrors.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ def resp_remote_mirrors():
5454
url="http://localhost/api/v4/projects/1/remote_mirrors/1",
5555
status=204,
5656
)
57+
58+
rsps.add(
59+
method=responses.POST,
60+
url="http://localhost/api/v4/projects/1/remote_mirrors/1/sync",
61+
status=204,
62+
)
5763
yield rsps
5864

5965

@@ -81,3 +87,9 @@ def test_update_project_remote_mirror(project, resp_remote_mirrors):
8187
def test_delete_project_remote_mirror(project, resp_remote_mirrors):
8288
mirror = project.remote_mirrors.create({"url": "https://example.com"})
8389
mirror.delete()
90+
91+
92+
def test_sync_project_remote_mirror(project, resp_remote_mirrors):
93+
mirror = project.remote_mirrors.create({"url": "https://example.com"})
94+
response = mirror.sync()
95+
assert response.status_code == 204

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy