From e7559bfa2ee265d7d664d7a18770b0a3e80cf999 Mon Sep 17 00:00:00 2001 From: Nejc Habjan Date: Sat, 11 Dec 2021 13:18:49 +0100 Subject: feat(api): add support for Topics API --- gitlab/client.py | 2 ++ gitlab/v4/objects/__init__.py | 1 + gitlab/v4/objects/topics.py | 27 +++++++++++++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 gitlab/v4/objects/topics.py (limited to 'gitlab') diff --git a/gitlab/client.py b/gitlab/client.py index 0dd4a6d..d3fdaab 100644 --- a/gitlab/client.py +++ b/gitlab/client.py @@ -180,6 +180,8 @@ class Gitlab(object): """See :class:`~gitlab.v4.objects.VariableManager`""" self.personal_access_tokens = objects.PersonalAccessTokenManager(self) """See :class:`~gitlab.v4.objects.PersonalAccessTokenManager`""" + self.topics = objects.TopicManager(self) + """See :class:`~gitlab.v4.objects.TopicManager`""" def __enter__(self) -> "Gitlab": return self diff --git a/gitlab/v4/objects/__init__.py b/gitlab/v4/objects/__init__.py index b1d6484..0ab3bd4 100644 --- a/gitlab/v4/objects/__init__.py +++ b/gitlab/v4/objects/__init__.py @@ -70,6 +70,7 @@ from .statistics import * from .tags import * from .templates import * from .todos import * +from .topics import * from .triggers import * from .users import * from .variables import * diff --git a/gitlab/v4/objects/topics.py b/gitlab/v4/objects/topics.py new file mode 100644 index 0000000..76208ed --- /dev/null +++ b/gitlab/v4/objects/topics.py @@ -0,0 +1,27 @@ +from typing import Any, cast, Union + +from gitlab import types +from gitlab.base import RequiredOptional, RESTManager, RESTObject +from gitlab.mixins import CRUDMixin, ObjectDeleteMixin, SaveMixin + +__all__ = [ + "Topic", + "TopicManager", +] + + +class Topic(SaveMixin, ObjectDeleteMixin, RESTObject): + pass + + +class TopicManager(CRUDMixin, RESTManager): + _path = "/topics" + _obj_cls = Topic + _create_attrs = RequiredOptional( + required=("name",), optional=("avatar", "description") + ) + _update_attrs = RequiredOptional(optional=("avatar", "description", "name")) + _types = {"avatar": types.ImageAttribute} + + def get(self, id: Union[str, int], lazy: bool = False, **kwargs: Any) -> Topic: + return cast(Topic, super().get(id=id, lazy=lazy, **kwargs)) -- cgit v1.2.1