Skip to content

Commit 271f688

Browse files
chore(topics): 'title' is required when creating a topic
In GitLab >= 15.0 `title` is required when creating a topic.
1 parent 69014e9 commit 271f688

File tree

5 files changed

+37
-5
lines changed

5 files changed

+37
-5
lines changed

docs/gl_objects/topics.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Get a specific topic by its ID::
3030

3131
Create a new topic::
3232

33-
topic = gl.topics.create({"name": "my-topic"})
33+
topic = gl.topics.create({"name": "my-topic", "title": "my title"})
3434

3535
Update a topic::
3636

gitlab/v4/objects/topics.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ class TopicManager(CRUDMixin, RESTManager):
1919
_path = "/topics"
2020
_obj_cls = Topic
2121
_create_attrs = RequiredOptional(
22-
required=("name",), optional=("avatar", "description")
22+
# NOTE: The `title` field was added and is required in GitLab 15.0 or
23+
# newer. But not present before that.
24+
required=("name",),
25+
optional=("avatar", "description", "title"),
2326
)
2427
_update_attrs = RequiredOptional(optional=("avatar", "description", "name"))
2528
_types = {"avatar": types.ImageAttribute}

tests/functional/api/test_topics.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,18 @@
44
"""
55

66

7-
def test_topics(gl):
7+
def test_topics(gl, gitlab_version):
88
assert not gl.topics.list()
99

10-
topic = gl.topics.create({"name": "my-topic", "description": "My Topic"})
10+
create_dict = {"name": "my-topic", "description": "My Topic"}
11+
if gitlab_version.major >= 15:
12+
create_dict["title"] = "my topic title"
13+
topic = gl.topics.create(
14+
{"name": "my-topic", "title": "my topic title", "description": "My Topic"}
15+
)
1116
assert topic.name == "my-topic"
17+
if gitlab_version.major >= 15:
18+
assert topic.title == "my topic title"
1219
assert gl.topics.list()
1320

1421
topic.description = "My Updated Topic"

tests/functional/conftest.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import dataclasses
12
import logging
23
import tempfile
34
import time
@@ -12,6 +13,24 @@
1213
from tests.functional import helpers
1314

1415

16+
@dataclasses.dataclass
17+
class GitlabVersion:
18+
major: int
19+
minor: int
20+
patch: str
21+
revision: str
22+
23+
def __post_init__(self):
24+
self.major, self.minor = int(self.major), int(self.minor)
25+
26+
27+
@pytest.fixture(scope="session")
28+
def gitlab_version(gl) -> GitlabVersion:
29+
version, revision = gl.version()
30+
major, minor, patch = version.split(".")
31+
return GitlabVersion(major=major, minor=minor, patch=patch, revision=revision)
32+
33+
1534
@pytest.fixture(scope="session")
1635
def fixture_dir(test_dir):
1736
return test_dir / "functional" / "fixtures"

tests/unit/objects/test_topics.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
from gitlab.v4.objects import Topic
99

1010
name = "GitLab"
11+
topic_title = "topic title"
1112
new_name = "gitlab-test"
1213
topic_content = {
1314
"id": 1,
1415
"name": name,
16+
"title": topic_title,
1517
"description": "GitLab is an open source end-to-end software development platform.",
1618
"total_projects_count": 1000,
1719
"avatar_url": "http://www.gravatar.com/avatar/a0d477b3ea21970ce6ffcbb817b0b435?s=80&d=identicon",
@@ -102,9 +104,10 @@ def test_get_topic(gl, resp_get_topic):
102104

103105

104106
def test_create_topic(gl, resp_create_topic):
105-
topic = gl.topics.create({"name": name})
107+
topic = gl.topics.create({"name": name, "title": topic_title})
106108
assert isinstance(topic, Topic)
107109
assert topic.name == name
110+
assert topic.title == topic_title
108111

109112

110113
def test_update_topic(gl, resp_update_topic):

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy