Skip to content

Commit 060cfe1

Browse files
JohnVillalovosnejch
authored andcommitted
feat(api): add support for getting a project's pull mirror details
Add the ability to get a project's pull mirror details. This was added in GitLab 15.5 and is a PREMIUM feature. https://docs.gitlab.com/ee/api/projects.html#get-a-projects-pull-mirror-details
1 parent 12aea32 commit 060cfe1

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

docs/gl_objects/projects.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,10 @@ Start the pull mirroring process (EE edition)::
250250

251251
project.mirror_pull()
252252

253+
Get a project’s pull mirror details (EE edition)::
254+
255+
mirror_pull_details = project.mirror_pull_details()
256+
253257
Import / Export
254258
===============
255259

gitlab/v4/objects/projects.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,29 @@ def mirror_pull(self, **kwargs: Any) -> None:
579579
path = f"/projects/{self.encoded_id}/mirror/pull"
580580
self.manager.gitlab.http_post(path, **kwargs)
581581

582+
@cli.register_custom_action("Project")
583+
@exc.on_http_error(exc.GitlabGetError)
584+
def mirror_pull_details(self, **kwargs: Any) -> Dict[str, Any]:
585+
"""Get a project's pull mirror details.
586+
587+
Introduced in GitLab 15.5.
588+
589+
Args:
590+
**kwargs: Extra options to send to the server (e.g. sudo)
591+
592+
Raises:
593+
GitlabAuthenticationError: If authentication is not correct
594+
GitlabGetError: If the server failed to perform the request
595+
596+
Returns:
597+
dict of the parsed json returned by the server
598+
"""
599+
path = f"/projects/{self.encoded_id}/mirror/pull"
600+
result = self.manager.gitlab.http_get(path, **kwargs)
601+
if TYPE_CHECKING:
602+
assert isinstance(result, dict)
603+
return result
604+
582605
@cli.register_custom_action("Project", ("to_namespace",))
583606
@exc.on_http_error(exc.GitlabTransferProjectError)
584607
def transfer(self, to_namespace: Union[int, str], **kwargs: Any) -> None:

tests/unit/objects/test_projects.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,27 @@ def resp_start_pull_mirroring_project():
530530
yield rsps
531531

532532

533+
@pytest.fixture
534+
def resp_pull_mirror_details_project():
535+
with responses.RequestsMock() as rsps:
536+
rsps.add(
537+
method=responses.GET,
538+
url="http://localhost/api/v4/projects/1/mirror/pull",
539+
json={
540+
"id": 101486,
541+
"last_error": None,
542+
"last_successful_update_at": "2020-01-06T17:32:02.823Z",
543+
"last_update_at": "2020-01-06T17:32:02.823Z",
544+
"last_update_started_at": "2020-01-06T17:31:55.864Z",
545+
"update_status": "finished",
546+
"url": "https://*****:*****@gitlab.com/gitlab-org/security/gitlab.git",
547+
},
548+
content_type="application/json",
549+
status=200,
550+
)
551+
yield rsps
552+
553+
533554
@pytest.fixture
534555
def resp_snapshot_project():
535556
with responses.RequestsMock() as rsps:
@@ -766,6 +787,12 @@ def test_project_pull_mirror(project, resp_start_pull_mirroring_project):
766787
project.mirror_pull()
767788

768789

790+
def test_project_pull_mirror_details(project, resp_pull_mirror_details_project):
791+
details = project.mirror_pull_details()
792+
assert details["last_error"] is None
793+
assert details["update_status"] == "finished"
794+
795+
769796
def test_project_restore(project, resp_restore_project):
770797
project.restore()
771798

0 commit comments

Comments
 (0)