Skip to content

Commit 61ba418

Browse files
committed
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
1 parent 3032667 commit 61ba418

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

‎gitlab/v4/objects/bulk_imports.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
from __future__ import annotations
22

3+
from typing import Any
4+
5+
import requests
6+
7+
from gitlab import cli
8+
from gitlab import exceptions as exc
39
from gitlab.base import RESTObject
410
from gitlab.mixins import CreateMixin, ListMixin, RefreshMixin, RetrieveMixin
511
from gitlab.types import RequiredOptional
@@ -17,6 +23,21 @@
1723
class BulkImport(RefreshMixin, RESTObject):
1824
entities: BulkImportEntityManager
1925

26+
@cli.register_custom_action(cls_names="BulkImport")
27+
@exc.on_http_error(exc.GitlabCancelError)
28+
def cancel(self, **kwargs: Any) -> dict[str, Any] | requests.Response:
29+
"""Cancel a bulk import.
30+
31+
Args:
32+
**kwargs: Extra options to send to the server (e.g. sudo)
33+
34+
Raises:
35+
GitlabAuthenticationError: If authentication is not correct
36+
GitlabCancelError: If the request failed
37+
"""
38+
path = f"{self.manager.path}/{self.encoded_id}/cancel"
39+
return self.manager.gitlab.http_post(path, **kwargs)
40+
2041

2142
class BulkImportManager(CreateMixin[BulkImport], RetrieveMixin[BulkImport]):
2243
_path = "/bulk_imports"

0 commit comments

Comments
 (0)