We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
delete
1 parent 7646360 commit 0841a2aCopy full SHA for 0841a2a
gitlab/v4/objects/labels.py
@@ -1,11 +1,10 @@
1
-from typing import Any, cast, Dict, Optional, TYPE_CHECKING, Union
+from typing import Any, cast, Dict, Optional, Union
2
3
from gitlab import exceptions as exc
4
from gitlab.base import RequiredOptional, RESTManager, RESTObject
5
from gitlab.mixins import (
6
CreateMixin,
7
DeleteMixin,
8
- ListMixin,
9
ObjectDeleteMixin,
10
PromoteMixin,
11
RetrieveMixin,
@@ -47,7 +46,9 @@ def save(self, **kwargs: Any) -> None:
47
46
self._update_attrs(server_data)
48
49
50
-class GroupLabelManager(ListMixin, CreateMixin, UpdateMixin, DeleteMixin, RESTManager):
+class GroupLabelManager(
+ RetrieveMixin, CreateMixin, UpdateMixin, DeleteMixin, RESTManager
51
+):
52
_path = "/groups/{group_id}/labels"
53
_obj_cls = GroupLabel
54
_from_parent_attrs = {"group_id": "id"}
@@ -58,6 +59,9 @@ class GroupLabelManager(ListMixin, CreateMixin, UpdateMixin, DeleteMixin, RESTMa
58
59
required=("name",), optional=("new_name", "color", "description", "priority")
60
)
61
62
+ def get(self, id: Union[str, int], lazy: bool = False, **kwargs: Any) -> GroupLabel:
63
+ return cast(GroupLabel, super().get(id=id, lazy=lazy, **kwargs))
64
+
65
# Update without ID.
66
# NOTE(jlvillal): Signature doesn't match UpdateMixin.update() so ignore
67
# type error
@@ -78,25 +82,6 @@ def update( # type: ignore
78
82
new_data["name"] = name
79
83
return super().update(id=None, new_data=new_data, **kwargs)
80
84
81
- # Delete without ID.
- @exc.on_http_error(exc.GitlabDeleteError)
- # NOTE(jlvillal): Signature doesn't match DeleteMixin.delete() so ignore
- # type error
85
- def delete(self, name: str, **kwargs: Any) -> None: # type: ignore
86
- """Delete a Label on the server.
87
-
88
- Args:
89
- name: The name of the label
90
- **kwargs: Extra options to send to the server (e.g. sudo)
91
92
- Raises:
93
- GitlabAuthenticationError: If authentication is not correct
94
- GitlabDeleteError: If the server cannot perform the request
95
- """
96
- if TYPE_CHECKING:
97
- assert self.path is not None
98
- self.gitlab.http_delete(self.path, query_data={"name": name}, **kwargs)
99
100
101
class ProjectLabel(
102
PromoteMixin, SubscribableMixin, SaveMixin, ObjectDeleteMixin, RESTObject
@@ -162,22 +147,3 @@ def update( # type: ignore
162
147
if name:
163
148
164
149
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
tests/functional/api/test_groups.py
@@ -104,7 +104,6 @@ def test_groups(gl):
104
group2.members.delete(gl.user.id)
105
106
107
-@pytest.mark.skip(reason="Commented out in legacy test")
108
def test_group_labels(group):
109
group.labels.create({"name": "foo", "description": "bar", "color": "#112233"})
110
label = group.labels.get("foo")
@@ -116,6 +115,12 @@ def test_group_labels(group):
116
115
assert label.description == "baz"
117
assert len(group.labels.list()) == 1
118
+ label.new_name = "Label:that requires:encoding"
119
+ label.save()
120
+ assert label.name == "Label:that requires:encoding"
121
+ label = group.labels.get("Label:that requires:encoding")
122
123
124
label.delete()
125
assert len(group.labels.list()) == 0
126
tests/functional/api/test_projects.py
@@ -146,9 +146,11 @@ def test_project_labels(project):
146
label = project.labels.get("label")
assert label == labels[0]
- label.new_name = "labelupdated"
150
label.save()
151
- assert label.name == "labelupdated"
152
+ label = project.labels.get("Label:that requires:encoding")
153
154
155
label.subscribe()
156
assert label.subscribed is True