diff --git a/gitlab/v4/objects/bulk_imports.py b/gitlab/v4/objects/bulk_imports.py index b171618a5..926a5e8d3 100644 --- a/gitlab/v4/objects/bulk_imports.py +++ b/gitlab/v4/objects/bulk_imports.py @@ -1,5 +1,11 @@ from __future__ import annotations +from typing import Any + +import requests + +from gitlab import cli +from gitlab import exceptions as exc from gitlab.base import RESTObject from gitlab.mixins import CreateMixin, ListMixin, RefreshMixin, RetrieveMixin from gitlab.types import RequiredOptional @@ -17,6 +23,21 @@ class BulkImport(RefreshMixin, RESTObject): entities: BulkImportEntityManager + @cli.register_custom_action(cls_names="BulkImport") + @exc.on_http_error(exc.GitlabCancelError) + def cancel(self, **kwargs: Any) -> dict[str, Any] | requests.Response: + """Cancel a bulk import. + + Args: + **kwargs: Extra options to send to the server (e.g. sudo) + + Raises: + GitlabAuthenticationError: If authentication is not correct + GitlabCancelError: If the request failed + """ + path = f"{self.manager.path}/{self.encoded_id}/cancel" + return self.manager.gitlab.http_post(path, **kwargs) + class BulkImportManager(CreateMixin[BulkImport], RetrieveMixin[BulkImport]): _path = "/bulk_imports"