FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat: add sync method to force remote mirror updates by JohnVillalovos · Pull Request #3232 · python-gitlab/python-gitlab · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
4 changes: 4 additions & 0 deletions docs/gl_objects/remote_mirrors.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ Update an existing remote mirror's attributes::
Delete an existing remote mirror::

mirror.delete()

Force push mirror update::

mirror.sync()
15 changes: 14 additions & 1 deletion gitlab/v4/objects/projects.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1233,7 +1233,20 @@ def create(self, data: dict[str, Any] | None = None, **kwargs: Any) -> ProjectFo


class ProjectRemoteMirror(ObjectDeleteMixin, SaveMixin, RESTObject):
pass
@cli.register_custom_action(cls_names="ProjectRemoteMirror")
@exc.on_http_error(exc.GitlabCreateError)
def sync(self, **kwargs: Any) -> dict[str, Any] | requests.Response:
"""Force push mirror update.

Args:
**kwargs: Extra options to send to the server (e.g. sudo)

Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabCreateError: If the server cannot perform the request
"""
path = f"{self.manager.path}/{self.encoded_id}/sync"
return self.manager.gitlab.http_post(path, **kwargs)


class ProjectRemoteMirrorManager(
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/objects/test_remote_mirrors.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ def resp_remote_mirrors():
url="http://localhost/api/v4/projects/1/remote_mirrors/1",
status=204,
)

rsps.add(
method=responses.POST,
url="http://localhost/api/v4/projects/1/remote_mirrors/1/sync",
status=204,
)
yield rsps


Expand Down Expand Up @@ -81,3 +87,9 @@ def test_update_project_remote_mirror(project, resp_remote_mirrors):
def test_delete_project_remote_mirror(project, resp_remote_mirrors):
mirror = project.remote_mirrors.create({"url": "https://example.com"})
mirror.delete()


def test_sync_project_remote_mirror(project, resp_remote_mirrors):
mirror = project.remote_mirrors.create({"url": "https://example.com"})
response = mirror.sync()
assert response.status_code == 204

Back | FazBrowse Home | New Git URL