From 61ba418040dcde7c8b5457f55429fe144c9bf1e7 Mon Sep 17 00:00:00 2001 From: Aquaticazelf <123787036+AquaticAzelf@users.noreply.github.com> Date: Fri, 28 Aug 2026 12:34:38 +0600 Subject: [PATCH] fix: add cancel API for BulkImport (#3292) Add BulkImport.cancel() to support POST /bulk_imports/:id/cancel per GitLab docs https://docs.gitlab.com/api/bulk_imports/#cancel-a-migration. Mirrors ProjectPipeline.cancel pattern, uses GitlabCancelError and cli.register_custom_action, verified with responses mock and pytest. Closes #3292 --- gitlab/v4/objects/bulk_imports.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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"