|
1 | | -from typing import Any, cast, Union |
| 1 | +from typing import Any, cast, Dict, TYPE_CHECKING, Union |
2 | 2 |
|
| 3 | +from gitlab import cli |
| 4 | +from gitlab import exceptions as exc |
3 | 5 | from gitlab import types |
4 | 6 | from gitlab.base import RESTManager, RESTObject |
5 | 7 | from gitlab.mixins import CRUDMixin, ObjectDeleteMixin, SaveMixin |
@@ -29,3 +31,39 @@ class TopicManager(CRUDMixin, RESTManager): |
29 | 31 |
|
30 | 32 | def get(self, id: Union[str, int], lazy: bool = False, **kwargs: Any) -> Topic: |
31 | 33 | return cast(Topic, super().get(id=id, lazy=lazy, **kwargs)) |
| 34 | + |
| 35 | + @cli.register_custom_action( |
| 36 | + "TopicManager", |
| 37 | + mandatory=("source_topic_id", "target_topic_id"), |
| 38 | + ) |
| 39 | + @exc.on_http_error(exc.GitlabMRClosedError) |
| 40 | + def merge( |
| 41 | + self, |
| 42 | + source_topic_id: Union[int, str], |
| 43 | + target_topic_id: Union[int, str], |
| 44 | + **kwargs: Any, |
| 45 | + ) -> Dict[str, Any]: |
| 46 | + """Merge two topics, assigning all projects to the target topic. |
| 47 | +
|
| 48 | + Args: |
| 49 | + source_topic_id: ID of source project topic |
| 50 | + target_topic_id: ID of target project topic |
| 51 | + **kwargs: Extra options to send to the server (e.g. sudo) |
| 52 | +
|
| 53 | + Raises: |
| 54 | + GitlabAuthenticationError: If authentication is not correct |
| 55 | + GitlabTopicMergeError: If the merge failed |
| 56 | +
|
| 57 | + Returns: |
| 58 | + The merged topic data (*not* a RESTObject) |
| 59 | + """ |
| 60 | + path = f"{self.path}/merge" |
| 61 | + data = { |
| 62 | + "source_topic_id": source_topic_id, |
| 63 | + "target_topic_id": target_topic_id, |
| 64 | + } |
| 65 | + |
| 66 | + server_data = self.gitlab.http_post(path, post_data=data, **kwargs) |
| 67 | + if TYPE_CHECKING: |
| 68 | + assert isinstance(server_data, dict) |
| 69 | + return server_data |
0 commit comments