Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0ab0fc1

Browse filesBrowse files
authored
Merge pull request #1868 from python-gitlab/jlvillal/delete_label
fix: remove custom `delete` method for labels
2 parents 7646360 + 0841a2a commit 0ab0fc1
Copy full SHA for 0ab0fc1

File tree

Expand file treeCollapse file tree

3 files changed

+17
-44
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+17
-44
lines changed
Open diff view settings
Collapse file

‎gitlab/v4/objects/labels.py‎

Copy file name to clipboardExpand all lines: gitlab/v4/objects/labels.py
+7-41Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
from typing import Any, cast, Dict, Optional, TYPE_CHECKING, Union
1+
from typing import Any, cast, Dict, Optional, Union
22

33
from gitlab import exceptions as exc
44
from gitlab.base import RequiredOptional, RESTManager, RESTObject
55
from gitlab.mixins import (
66
CreateMixin,
77
DeleteMixin,
8-
ListMixin,
98
ObjectDeleteMixin,
109
PromoteMixin,
1110
RetrieveMixin,
@@ -47,7 +46,9 @@ def save(self, **kwargs: Any) -> None:
4746
self._update_attrs(server_data)
4847

4948

50-
class GroupLabelManager(ListMixin, CreateMixin, UpdateMixin, DeleteMixin, RESTManager):
49+
class GroupLabelManager(
50+
RetrieveMixin, CreateMixin, UpdateMixin, DeleteMixin, RESTManager
51+
):
5152
_path = "/groups/{group_id}/labels"
5253
_obj_cls = GroupLabel
5354
_from_parent_attrs = {"group_id": "id"}
@@ -58,6 +59,9 @@ class GroupLabelManager(ListMixin, CreateMixin, UpdateMixin, DeleteMixin, RESTMa
5859
required=("name",), optional=("new_name", "color", "description", "priority")
5960
)
6061

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+
6165
# Update without ID.
6266
# NOTE(jlvillal): Signature doesn't match UpdateMixin.update() so ignore
6367
# type error
@@ -78,25 +82,6 @@ def update( # type: ignore
7882
new_data["name"] = name
7983
return super().update(id=None, new_data=new_data, **kwargs)
8084

81-
# Delete without ID.
82-
@exc.on_http_error(exc.GitlabDeleteError)
83-
# NOTE(jlvillal): Signature doesn't match DeleteMixin.delete() so ignore
84-
# 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-
10085

10186
class ProjectLabel(
10287
PromoteMixin, SubscribableMixin, SaveMixin, ObjectDeleteMixin, RESTObject
@@ -162,22 +147,3 @@ def update( # type: ignore
162147
if name:
163148
new_data["name"] = name
164149
return super().update(id=None, new_data=new_data, **kwargs)
165-
166-
# Delete without ID.
167-
@exc.on_http_error(exc.GitlabDeleteError)
168-
# NOTE(jlvillal): Signature doesn't match DeleteMixin.delete() so ignore
169-
# type error
170-
def delete(self, name: str, **kwargs: Any) -> None: # type: ignore
171-
"""Delete a Label on the server.
172-
173-
Args:
174-
name: The name of the label
175-
**kwargs: Extra options to send to the server (e.g. sudo)
176-
177-
Raises:
178-
GitlabAuthenticationError: If authentication is not correct
179-
GitlabDeleteError: If the server cannot perform the request
180-
"""
181-
if TYPE_CHECKING:
182-
assert self.path is not None
183-
self.gitlab.http_delete(self.path, query_data={"name": name}, **kwargs)
Collapse file

‎tests/functional/api/test_groups.py‎

Copy file name to clipboardExpand all lines: tests/functional/api/test_groups.py
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ def test_groups(gl):
104104
group2.members.delete(gl.user.id)
105105

106106

107-
@pytest.mark.skip(reason="Commented out in legacy test")
108107
def test_group_labels(group):
109108
group.labels.create({"name": "foo", "description": "bar", "color": "#112233"})
110109
label = group.labels.get("foo")
@@ -116,6 +115,12 @@ def test_group_labels(group):
116115
assert label.description == "baz"
117116
assert len(group.labels.list()) == 1
118117

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+
assert label.name == "Label:that requires:encoding"
123+
119124
label.delete()
120125
assert len(group.labels.list()) == 0
121126

Collapse file

‎tests/functional/api/test_projects.py‎

Copy file name to clipboardExpand all lines: tests/functional/api/test_projects.py
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,11 @@ def test_project_labels(project):
146146
label = project.labels.get("label")
147147
assert label == labels[0]
148148

149-
label.new_name = "labelupdated"
149+
label.new_name = "Label:that requires:encoding"
150150
label.save()
151-
assert label.name == "labelupdated"
151+
assert label.name == "Label:that requires:encoding"
152+
label = project.labels.get("Label:that requires:encoding")
153+
assert label.name == "Label:that requires:encoding"
152154

153155
label.subscribe()
154156
assert label.subscribed is True

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.