diff options
| author | Nejc Habjan <nejc.habjan@siemens.com> | 2022-10-14 11:01:33 +0200 |
|---|---|---|
| committer | John Villalovos <john@sodarock.com> | 2022-10-14 10:18:29 -0700 |
| commit | 9a6d197f9d2a88bdba8dab1f9abaa4e081a14792 (patch) | |
| tree | 579b0b3d8d059c1e6c763359fa9e7e19853415ed /gitlab | |
| parent | 153d3739021d2375438fe35ce819c77142914567 (diff) | |
| download | gitlab-9a6d197f9d2a88bdba8dab1f9abaa4e081a14792.tar.gz | |
feat(api): add support for topics merge API
Diffstat (limited to 'gitlab')
| -rw-r--r-- | gitlab/exceptions.py | 4 | ||||
| -rw-r--r-- | gitlab/v4/objects/topics.py | 40 |
2 files changed, 43 insertions, 1 deletions
diff --git a/gitlab/exceptions.py b/gitlab/exceptions.py index 613e9a0..97f097d 100644 --- a/gitlab/exceptions.py +++ b/gitlab/exceptions.py @@ -221,6 +221,10 @@ class GitlabTodoError(GitlabOperationError): pass +class GitlabTopicMergeError(GitlabOperationError): + pass + + class GitlabTimeTrackingError(GitlabOperationError): pass diff --git a/gitlab/v4/objects/topics.py b/gitlab/v4/objects/topics.py index 143759d..995ff8b 100644 --- a/gitlab/v4/objects/topics.py +++ b/gitlab/v4/objects/topics.py @@ -1,5 +1,7 @@ -from typing import Any, cast, Union +from typing import Any, cast, Dict, TYPE_CHECKING, Union +from gitlab import cli +from gitlab import exceptions as exc from gitlab import types from gitlab.base import RESTManager, RESTObject from gitlab.mixins import CRUDMixin, ObjectDeleteMixin, SaveMixin @@ -29,3 +31,39 @@ class TopicManager(CRUDMixin, RESTManager): def get(self, id: Union[str, int], lazy: bool = False, **kwargs: Any) -> Topic: return cast(Topic, super().get(id=id, lazy=lazy, **kwargs)) + + @cli.register_custom_action( + "TopicManager", + mandatory=("source_topic_id", "target_topic_id"), + ) + @exc.on_http_error(exc.GitlabMRClosedError) + def merge( + self, + source_topic_id: Union[int, str], + target_topic_id: Union[int, str], + **kwargs: Any, + ) -> Dict[str, Any]: + """Merge two topics, assigning all projects to the target topic. + + Args: + source_topic_id: ID of source project topic + target_topic_id: ID of target project topic + **kwargs: Extra options to send to the server (e.g. sudo) + + Raises: + GitlabAuthenticationError: If authentication is not correct + GitlabTopicMergeError: If the merge failed + + Returns: + The merged topic data (*not* a RESTObject) + """ + path = f"{self.path}/merge" + data = { + "source_topic_id": source_topic_id, + "target_topic_id": target_topic_id, + } + + server_data = self.gitlab.http_post(path, post_data=data, **kwargs) + if TYPE_CHECKING: + assert isinstance(server_data, dict) + return server_data |
